/// <summary> /// Adds the tick labels to the canvas of the control. /// </summary> private void InsertTickLabels() { foreach (var label in this.labelList) { var textBlock = new TextBlock { Text = label.Item2, FontSize = LabelFontSize, Foreground = _tickLabelBrush, Background = Brushes.Transparent, HorizontalAlignment = IsVertical ? HorizontalAlignment.Right : HorizontalAlignment.Center, VerticalAlignment = IsVertical ? VerticalAlignment.Center : VerticalAlignment.Bottom, Margin = new Thickness(0.0), Height = ValueIndicatorSize }; // Calculate the normalized (0..1) horizontal location of the label (which is centered below this) double location = GetLocation(label.Item1); // Scale to the actual width of the grid, but place it 1.5pixels inside the range.. location = location * (this.UsableSize - 1); this.TickLabelCanvas.Children.Add(textBlock); // Now position the label accordingly if (IsVertical) { textBlock.SetValue(Canvas.TopProperty, location); textBlock.SetValue(Canvas.RightProperty, 2.0 + MajorTickLength); } else { textBlock.SetValue(Canvas.LeftProperty, location + (LabelFontSize / 3) - ((label.Item2.Length - 1) * 0.75 * (LabelFontSize / 3))); textBlock.SetValue(Canvas.BottomProperty, 2.0 + MajorTickLength); } } var rotate90CCW = new RotateTransform(IsVertical ? -90 : 0); var axisLabelBlock = new TextBlock() { Text = AxisLabel, FontSize = LabelFontSize * 1.5, Foreground = _tickLabelBrush, Background = Brushes.Transparent, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0.0), RenderTransformOrigin = new Point(1.0, 0.5), RenderTransform = rotate90CCW, }; this.TickLabelCanvas.Children.Add(axisLabelBlock); if (IsVertical) { axisLabelBlock.SetValue(Canvas.TopProperty, (this.ActualHeight / 2) - (AxisLabel.Length * 0.4 * LabelFontSize)); axisLabelBlock.SetValue(Canvas.RightProperty, axisLabelBlock.FontSize + 9.0 + MajorTickLength); } else { axisLabelBlock.SetValue(Canvas.LeftProperty, (this.ActualWidth / 2) - (AxisLabel.Length * 0.4 * LabelFontSize)); axisLabelBlock.SetValue(Canvas.BottomProperty, axisLabelBlock.FontSize + 5.0 + MajorTickLength); } }
private void ellCenterBottom_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { double addToHeight = 0.0; Point deltaTranslation = e.Delta.Translation; RotateTransform lastRotateTransform = getLastRotateTransformation(); if (lastRotateTransform == null) { addToHeight = e.Delta.Translation.Y; } else if ((0.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < 90.0) || (-360.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < -270.0)) { if (deltaTranslation.X < 0.0 && deltaTranslation.Y >= 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y); } else if (deltaTranslation.X >= 0.0 && deltaTranslation.Y < 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y) * -1.0; } else { addToHeight = 0.0; } } else if (lastRotateTransform.Angle == 90.0 || lastRotateTransform.Angle == -270.0) { addToHeight = (e.Delta.Translation.X * -1.0); } else if ((90.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < 180.0) || (-270.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < -180.0)) { if (deltaTranslation.X < 0.0 && deltaTranslation.Y < 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y); } else if (deltaTranslation.X >= 0.0 && deltaTranslation.Y >= 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y) * -1.0; } else { addToHeight = 0.0; } } else if (lastRotateTransform.Angle == 180.0 || lastRotateTransform.Angle == -180.0) { addToHeight = (e.Delta.Translation.Y * -1.0); } else if ((180.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < 270.0) || (-180.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < -90.0)) { if (deltaTranslation.X >= 0.0 && deltaTranslation.Y < 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y); } else if (deltaTranslation.X < 0.0 && deltaTranslation.Y >= 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y) * -1.0; } else { addToHeight = 0.0; } } else if (lastRotateTransform.Angle == 270.0 || lastRotateTransform.Angle == -90.0) { addToHeight = (e.Delta.Translation.X); } else if ((270.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < 360.0) || (-90.0 < lastRotateTransform.Angle && lastRotateTransform.Angle < 0.0)) { if (deltaTranslation.X >= 0.0 && deltaTranslation.Y >= 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y); } else if (deltaTranslation.X < 0.0 && deltaTranslation.Y < 0.0) { addToHeight = Math.Sqrt(deltaTranslation.X * deltaTranslation.X + deltaTranslation.Y * deltaTranslation.Y) * -1.0; } else { addToHeight = 0.0; } } if ((GridMain.Height + addToHeight) >= _minGridMainHeight) { changeHeightOfUiElements(addToHeight); changeMarginBottomGridMain(addToHeight); setSizeOfRecBar(rectRectangleToDraw.Height, rectRectangleToDraw.Width); } }
public void RedrawIfVisible(Point mouseLocation, Canvas canvasToMagnify) { // nothing to draw if ((this.IsEnabled == false) || (this.IsVisible == false) || (this.Visibility != Visibility.Visible) || (canvasToMagnify == null) || (this.Parent.ImageToMagnify.Source == null)) { return; } // Given a mouse position over the displayed image, we need to know where the equivalent position is over the magnified image (which is a different size) // We do this by calculating the ratio of the point over the displayed image, and then using that to calculate the position over the cached image Point mousePosition = NativeMethods.GetCursorPos(this.Parent.ImageToDisplay); Point mouseLocationRatio = Marker.ConvertPointToRatio(mousePosition, this.Parent.ImageToDisplay.ActualWidth, this.Parent.ImageToDisplay.ActualHeight); Point magnifiedLocation = Marker.ConvertRatioToPoint(mouseLocationRatio, canvasToMagnify.Width, canvasToMagnify.Height); // Create an Visual brush from the unaltered image in the magnification canvas magCanvas, set its properties, and use it to fill the magnifying glass. // This includes calculating the position and zoom of the viewbox within that brush VisualBrush magnifierBrush = new VisualBrush(canvasToMagnify) { ViewboxUnits = BrushMappingMode.Absolute, ViewportUnits = BrushMappingMode.RelativeToBoundingBox, Viewport = new Rect(0, 0, 1, 1), Viewbox = new Rect(magnifiedLocation.X - this.ZoomFactor / 2.0, magnifiedLocation.Y - this.ZoomFactor / 2.0, this.ZoomFactor, this.ZoomFactor) }; // Finally, fill the magnifying glass with this brush this.magnifierLens.Fill = magnifierBrush; // Figure out the magnifying glass angle needed // The idea is that we will start rotating when the magnifying glass is near the top and the left of the display // The critical distance is size for the Y direction, and somewhat larger than size for the X direction (as we have to start // rotating earlier so it doesn't get clipped). xsize is somewhat arbitrary, i.e., determined by trial and error // positions of edges where angle should change const double EdgeThreshold = Constant.MarkableCanvas.MagnifyingGlassDiameter; // proximity to an edge where the magnifying glass change angles double leftEdge = EdgeThreshold; double rightEdge = this.Parent.ImageToDisplay.ActualWidth - EdgeThreshold; double topEdge = EdgeThreshold; double bottomEdge = this.Parent.ImageToDisplay.ActualHeight - EdgeThreshold; double newMagnifyingGlassAngle; // the new angle to rotate the magnifying glass to // In various cases, several angles can work so choose a new angle whose difference from the existing angle will cause the least amount of animation if ((mouseLocation.X < leftEdge) && (mouseLocation.Y < topEdge)) { newMagnifyingGlassAngle = 180; // upper left corner } else if ((mouseLocation.X < leftEdge) && (mouseLocation.Y > bottomEdge)) { newMagnifyingGlassAngle = 90; // lower left corner } else if (mouseLocation.X < leftEdge) { newMagnifyingGlassAngle = AdjustAngle(this.magnifyingGlassAngle, 90, 180); // middle left edge } else if ((mouseLocation.X > rightEdge) && (mouseLocation.Y < topEdge)) { newMagnifyingGlassAngle = 270; // upper right corner } else if ((mouseLocation.X > rightEdge) && (mouseLocation.Y > bottomEdge)) { newMagnifyingGlassAngle = 0; // lower right corner } else if (mouseLocation.X > rightEdge) { newMagnifyingGlassAngle = AdjustAngle(this.magnifyingGlassAngle, 270, 0); // middle right edge } else if (mouseLocation.Y < topEdge) { newMagnifyingGlassAngle = AdjustAngle(this.magnifyingGlassAngle, 270, 180); // top edge, middle } else if (mouseLocation.Y > bottomEdge) { newMagnifyingGlassAngle = AdjustAngle(this.magnifyingGlassAngle, 0, 90); // bottom edge, middle } else { newMagnifyingGlassAngle = this.magnifyingGlassAngle; // far enough from edges, any angle will work: magnifer stays on the display image at any angle; } // If the angle has changed, animate the magnifying glass and its contained image to the new angle double lensDiameter = this.magnifierLens.Width; if (this.magnifyingGlassAngle != newMagnifyingGlassAngle) { // Correct the rotation in those cases where it would turn the long way around. // Note that the new lens angle correction is hard coded rather than calculated, as it works. double newLensAngle; double uncorrectedNewLensAngle = -newMagnifyingGlassAngle; if (this.magnifyingGlassAngle == 270 && newMagnifyingGlassAngle == 0) { this.magnifyingGlassAngle = -90; newLensAngle = -360; // subtract the rotation of the magnifying glass to counter that rotational effect } else if (this.magnifyingGlassAngle == 0 && newMagnifyingGlassAngle == 270) { this.magnifyingGlassAngle = 360; newLensAngle = 90; } else { newLensAngle = uncorrectedNewLensAngle; } // Rotate the lens within the magnifying glass Duration animationDuration = new Duration(new TimeSpan(0, 0, 0, 0, 500)); DoubleAnimation lensAnimation = new DoubleAnimation(this.lensAngle, newLensAngle, animationDuration); RotateTransform rotateTransformLens = new RotateTransform(this.magnifyingGlassAngle, lensDiameter / 2, lensDiameter / 2); rotateTransformLens.BeginAnimation(RotateTransform.AngleProperty, lensAnimation); this.lensCanvas.RenderTransform = rotateTransformLens; // Now rotate and position the entire magnifying glass RotateTransform rotateTransformMagnifyingGlass = new RotateTransform(this.magnifyingGlassAngle, lensDiameter, lensDiameter); DoubleAnimation magnifyingGlassAnimation = new DoubleAnimation(this.magnifyingGlassAngle, newMagnifyingGlassAngle, animationDuration); rotateTransformMagnifyingGlass.BeginAnimation(RotateTransform.AngleProperty, magnifyingGlassAnimation); this.RenderTransform = rotateTransformMagnifyingGlass; // Save the angle so we can compare it on the next iteration. If any of them are 360, swap it to 0 if (newMagnifyingGlassAngle % 360 == 0) { newMagnifyingGlassAngle = 0; } if (newLensAngle % 360 == 0) { uncorrectedNewLensAngle = 0; } this.magnifyingGlassAngle = newMagnifyingGlassAngle; this.lensAngle = uncorrectedNewLensAngle; } Canvas.SetLeft(this, mouseLocation.X - lensDiameter); Canvas.SetTop(this, mouseLocation.Y - lensDiameter); }
public void SetRotation() { rotation = new RotateTransform(_rotation); Img.RenderTransform = rotation; }
private void Test() { var test = new TransformGroup { Children = new TransformCollection { new TranslateTransform { X = 10, Y = 20 }, new RotateTransform { Angle = 45 } } }; var v = test.Value; var st = new TransformGroup { Children = new TransformCollection { new SkewTransform { AngleX = 45 } } }; var tt = new TranslateTransform { X = 1 }; var tg1 = new TransformGroup { Children = new TransformCollection { st, tt } }; var tg2 = new TransformGroup { Children = new TransformCollection { tt, st } }; var tg3 = new TransformGroup { Children = new TransformCollection { st } }; var tg4 = new TransformGroup { Children = new TransformCollection { tt } }; var tg5 = new TransformGroup(); tg5.Children.Add(new TranslateTransform { X = 1, Y = 2 }); tg5.Children.Add(new RotateTransform { Angle = -90 }); var tg6 = new TransformGroup(); tg6.Children.Add(new RotateTransform { Angle = -90 }); tg6.Children.Add(new TranslateTransform { X = 1, Y = 2 }); var p = new RotateTransform { Angle = 90 }.Transform(new Point(1, 2)); var m3 = new Matrix3DProjection(); }
private void ApplyTextContainerStyle(Panel container, double y) { var font = _currentState.CurrentFont; if (font != null && container.Children.Count > 0) { Canvas.SetTop(container, y - ((TextBlock)container.Children[0]).FontSize); // Rotation if (font.Escapement != 0) { var block = ((TextBlock)container.Children[0]); var rotate = new RotateTransform { Angle = -1 * font.Escapement / 10.0 #if !NETFX_CORE , CenterY = block.FontSize * block.FontFamily.Baseline #endif }; container.RenderTransform = rotate; } } }
/// <summary> /// Updates this instance. /// </summary> internal void Update() { double desiredHeight = 0; double labelSize = 0; CalculateAutoInterval(); GenerateLabels(); if (this.ActualHeight > 0 && this.ActualWidth > 0) { double xAxisWidthStep = this.ActualWidth / ((MIntervalCount > 0) ? MIntervalCount : 1); double xAxisWidthPosition = 0; double minorstep = 0; AxisLine.X2 = this.ActualWidth; Rect oldRect = new Rect(0, 0, 0, 0); if (this.MLabels.Count == Labels.Count) { int k = 0; int minorCount = 0; for (int i = 0; i < this.MLabels.Count; i++) { xAxisWidthPosition = this.DataToPoint(MStartValue + (MInterval * k)); ContentControl label = Labels[k]; label.Content = MLabels[k]; label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect originalRect=new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height); Rect rotatedRect = GetRotatedRect(originalRect, labelRotation); //label.RenderTransformOrigin = new Point(0.5, 0.5); label.RenderTransform = labelRotation; Line tickLine = MajorTickLines[k]; double labelPadding = 0; tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); tickLine.X1 = xAxisWidthPosition ; tickLine.X2 = xAxisWidthPosition ; switch (MajorTicksPosition) { case TickPosition.Inside: if (this.ShowMajorTicks) { labelPadding = 0; desiredHeight = 0; } break; case TickPosition.Cross: if (this.ShowMajorTicks) { labelPadding = tickLine.Y2; desiredHeight = tickLine.Y2; } break; case TickPosition.Outside: if (this.ShowMajorTicks) { labelPadding = tickLine.Y2; desiredHeight = tickLine.Y2; } break; default: break; } if (!(i == this.MLabels.Count - 1)) { double minorWidth = xAxisWidthStep; minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = MinorTickLines[minorCount]; minorLine.X1 = (xAxisWidthPosition + minorstep * (j + 1)); minorLine.X2 = (xAxisWidthPosition + minorstep * (j + 1)); switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.Y1 = 0; break; case TickPosition.Cross: //minorLine.Y1 = MinorLineSize / 2; break; case TickPosition.Outside: minorLine.Y1 = 0; break; default: break; } minorCount++; } } //Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2)); //Canvas.SetTop(label, desiredHeight); if (this.LabelAngle == 0) { Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2)); Canvas.SetTop(label, desiredHeight); labelSize = Math.Max(labelSize, label.DesiredSize.Height); } else { Canvas.SetLeft(label, xAxisWidthPosition - (rotatedRect.Width / 2) - rotatedRect.X); Canvas.SetTop(label, desiredHeight - rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Height); } k++; } } else { if (this.MLabels.Count > Labels.Count) { int offset = this.MLabels.Count - Labels.Count; for (int j = 0; j < offset; j++) { ContentControl label = new ContentControl(); label.Content = MLabels[this.MLabels.Count - offset - 1]; Binding labelTemplateBinding = new Binding(); labelTemplateBinding.Path = new PropertyPath("LabelTemplate"); labelTemplateBinding.Source = this; label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding); label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); // label.RenderTransformOrigin = new Point(0.5, 0.5); label.RenderTransform = labelRotation; Labels.Add(label); Line tickLine = new Line(); Binding styleBinding = new Binding(); styleBinding.Path = new PropertyPath("MajorLineStyle"); styleBinding.Source = this; tickLine.SetBinding(Line.StyleProperty, styleBinding); tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); tickLine.X1 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2); tickLine.X2 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2); switch (this.MajorTicksPosition) { case TickPosition.Inside: tickLine.Y1 = 0; Binding tickSizeInsideBinding = new Binding(); tickSizeInsideBinding.Path = new PropertyPath("MajorLineSize"); tickSizeInsideBinding.Source = this; tickSizeInsideBinding.Converter = new NegativeConverter(); tickLine.SetBinding(Line.Y2Property, tickSizeInsideBinding); if (this.ShowMajorTicks) { desiredHeight = 0; } break; case TickPosition.Cross: Binding tickSizeNegativeCrossBinding = new Binding(); tickSizeNegativeCrossBinding.Path = new PropertyPath("MajorLineSize"); tickSizeNegativeCrossBinding.Source = this; tickSizeNegativeCrossBinding.Converter = new NegativeHalfConverter(); tickLine.SetBinding(Line.Y1Property, tickSizeNegativeCrossBinding); Binding tickSizeCrossBinding = new Binding(); tickSizeCrossBinding.Path = new PropertyPath("MajorLineSize"); tickSizeCrossBinding.Source = this; tickSizeCrossBinding.Converter = new HalfValueConverter(); tickLine.SetBinding(Line.Y2Property, tickSizeCrossBinding); if (this.ShowMajorTicks) { desiredHeight = MajorLineSize / 2; } break; case TickPosition.Outside: tickLine.Y1 = 0; Binding tickSizeBinding = new Binding(); tickSizeBinding.Path = new PropertyPath("MajorLineSize"); tickSizeBinding.Source = this; tickLine.SetBinding(Line.Y2Property, tickSizeBinding); if (this.ShowMajorTicks) { desiredHeight = MajorLineSize; } break; } Binding ticklineVisibilityBinding = new Binding(); ticklineVisibilityBinding.Path = new PropertyPath("ShowMajorTicks"); ticklineVisibilityBinding.Source = this; ticklineVisibilityBinding.Converter = new BooleanToVisibilityConverter(); tickLine.SetBinding(Line.VisibilityProperty, ticklineVisibilityBinding); double minorWidth = xAxisWidthStep; minorstep = minorWidth / (MinorTicksCount + 1); for (int k = 0; k < this.MinorTicksCount; k++) { Line minorLine = new Line(); Binding minorstyleBinding = new Binding(); minorstyleBinding.Path = new PropertyPath("MinorLineStyle"); minorstyleBinding.Source = this; minorLine.SetBinding(Line.StyleProperty, minorstyleBinding); minorLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); minorLine.X1 = (xAxisWidthPosition + minorstep); minorLine.X2 = (xAxisWidthPosition + minorstep); switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.Y1 = 0; Binding minortickInsideSizeBinding = new Binding(); minortickInsideSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickInsideSizeBinding.Source = this; minortickInsideSizeBinding.Converter = new NegativeConverter(); minorLine.SetBinding(Line.Y2Property, minortickInsideSizeBinding); break; case TickPosition.Cross: Binding minortickNegativeCrossSizeBinding = new Binding(); minortickNegativeCrossSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickNegativeCrossSizeBinding.Source = this; minortickNegativeCrossSizeBinding.Converter = new NegativeHalfConverter(); minorLine.SetBinding(Line.Y1Property, minortickNegativeCrossSizeBinding); Binding minortickCrossSizeBinding = new Binding(); minortickCrossSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickCrossSizeBinding.Source = this; minortickCrossSizeBinding.Converter = new HalfValueConverter(); minorLine.SetBinding(Line.Y2Property, minortickCrossSizeBinding); break; case TickPosition.Outside: minorLine.Y1 = 0; Binding minortickSizeBinding = new Binding(); minortickSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickSizeBinding.Source = this; minorLine.SetBinding(Line.Y2Property, minortickSizeBinding); break; } MinorTickLines.Add(minorLine); this.Children.Add(minorLine); minorstep += minorstep; } MajorTickLines.Add(tickLine); this.Children.Add(label); this.Children.Add(tickLine); } } else { int offset = Labels.Count - this.MLabels.Count; for (int j = 0; j < offset; j++) { this.Children.Remove(Labels[Labels.Count - 1]); Labels.RemoveAt(Labels.Count - 1); for (int k = 0; k < this.MinorTicksCount; k++) { this.Children.Remove(MinorTickLines[MinorTickLines.Count - 1]); MinorTickLines.RemoveAt(MinorTickLines.Count - 1); } this.Children.Remove(MajorTickLines[MajorTickLines.Count - 1]); MajorTickLines.RemoveAt(MajorTickLines.Count - 1); } } for (int i = 0; i < this.MLabels.Count; i++) { ContentControl label = Labels[i]; label.Content = MLabels[i]; label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); //label.RenderTransformOrigin = new Point(0.5, 0.5); label.RenderTransform = labelRotation; Line tickLine = MajorTickLines[i]; double labelPadding = 0; int minorCount = 0; tickLine.X1 = xAxisWidthPosition; tickLine.X2 = xAxisWidthPosition; tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); if (!(i == this.MLabels.Count - 1)) { double minorWidth = xAxisWidthStep; minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = MinorTickLines[minorCount]; minorLine.X1 = (xAxisWidthPosition + minorstep * (j + 1)); minorLine.X2 = (xAxisWidthPosition + minorstep * (j + 1)); minorCount++; } } if (this.LabelAngle == 0) { Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2)); Canvas.SetTop(label, desiredHeight); labelSize = Math.Max(labelSize, label.DesiredSize.Height); } else { Canvas.SetLeft(label, xAxisWidthPosition - (rotatedRect.Width / 2) - rotatedRect.X); Canvas.SetTop(label, desiredHeight - rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Height); } xAxisWidthPosition += xAxisWidthStep; } } desiredHeight += labelSize; header.Measure(new Size(this.ActualHeight, this.ActualWidth)); Canvas.SetLeft(header, (this.ActualWidth / 2) - (header.DesiredSize.Width / 2)); Canvas.SetTop(header, desiredHeight); desiredHeight += header.DesiredSize.Height; this.Chart.AxisHeight = desiredHeight; } //if (this.Chart.AxisHeight < desiredHeight) }
public static XamlBrush MapsuiBrushToXaml(Styles.Brush brush, SymbolCache symbolCache = null, double rotate = 0) { if (brush == null) { return(null); } switch (brush.FillStyle) { case FillStyle.Cross: return(CreateHatchBrush(brush, 12, 10, new List <Geometry> { Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 0 10 l 10 -10") })); case FillStyle.BackwardDiagonal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 10 l 10 -10"), Geometry.Parse("M -0.5 0.5 l 10 -10"), Geometry.Parse("M 8 12 l 10 -10") })); case FillStyle.Bitmap: return(GetOrCreateBitmapImage(brush, symbolCache).ToTiledImageBrush()); case FillStyle.BitmapRotated: RotateTransform aRotateTransform = new RotateTransform(); aRotateTransform.CenterX = 0.5; aRotateTransform.CenterY = 0.5; aRotateTransform.Angle = rotate; var b = GetOrCreateBitmapImage(brush, symbolCache).ToTiledImageBrush(); b.RelativeTransform = aRotateTransform; return(b); case FillStyle.Svg: return(null); case FillStyle.Dotted: return(DottedBrush(brush)); case FillStyle.DiagonalCross: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 0 10 l 10 -10") })); case FillStyle.ForwardDiagonal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M -1 9 l 10 10"), Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 9 -1 l 10 10") })); case FillStyle.Hollow: return(new SolidColorBrush(Colors.Transparent)); case FillStyle.Horizontal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 5 h 10") })); case FillStyle.Solid: return(new SolidColorBrush(brush.Color != null ? brush.Color.ToXaml() : brush.Background != null ? brush.Color.ToXaml() : Colors.Transparent)); case FillStyle.Vertical: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 5 0 l 0 10") })); default: return((brush.Color != null) ? new SolidColorBrush(brush.Color.ToXaml()) : null); } }
//Drawing the scale with the Scale Radius private void DrawScale() { //Calculate one major tick angle Double majorTickUnitAngle = ScaleSweepAngle / MajorDivisionsCount; //Obtaining One minor tick angle Double minorTickUnitAngle = ScaleSweepAngle / MinorDivisionsCount; //Obtaining One major ticks value Double majorTicksUnitValue = (MaxValue - MinValue) / MajorDivisionsCount; majorTicksUnitValue = Math.Round(majorTicksUnitValue, ScaleValuePrecision); Double minvalue = MinValue;; // Drawing Major scale ticks for (Double i = ScaleStartAngle; i <= (ScaleStartAngle + ScaleSweepAngle); i = i + majorTickUnitAngle) { //Majortick is drawn as a rectangle Rectangle majortickrect = new Rectangle(); majortickrect.Height = MajorTickSize.Height; majortickrect.Width = MajorTickSize.Width; majortickrect.Fill = new SolidColorBrush(MajorTickColor); Point p = new Point(0.5, 0.5); majortickrect.RenderTransformOrigin = p; majortickrect.HorizontalAlignment = HorizontalAlignment.Center; majortickrect.VerticalAlignment = VerticalAlignment.Center; TransformGroup majortickgp = new TransformGroup(); RotateTransform majortickrt = new RotateTransform(); //Obtaining the angle in radians for calulating the points Double i_radian = (i * Math.PI) / 180; majortickrt.Angle = i; majortickgp.Children.Add(majortickrt); TranslateTransform majorticktt = new TranslateTransform(); //Finding the point on the Scale where the major ticks are drawn //here drawing the points with center as (0,0) majorticktt.X = (int)((ScaleRadius) * Math.Cos(i_radian)); majorticktt.Y = (int)((ScaleRadius) * Math.Sin(i_radian)); //Points for the textblock which hold the scale value TranslateTransform majorscalevaluett = new TranslateTransform(); //here drawing the points with center as (0,0) majorscalevaluett.X = (int)((ScaleLabelRadius) * Math.Cos(i_radian)); majorscalevaluett.Y = (int)((ScaleLabelRadius) * Math.Sin(i_radian)); //Defining the properties of the scale value textbox TextBlock tb = new TextBlock(); tb.Height = ScaleLabelSize.Height; tb.Width = ScaleLabelSize.Width; tb.FontSize = ScaleLabelFontSize; tb.Foreground = new SolidColorBrush(ScaleLabelForeground); tb.TextAlignment = TextAlignment.Center; tb.VerticalAlignment = VerticalAlignment.Center; tb.HorizontalAlignment = HorizontalAlignment.Center; //Writing and appending the scale value //checking minvalue < maxvalue w.r.t scale precion value if (Math.Round(minvalue, ScaleValuePrecision) <= Math.Round(MaxValue, ScaleValuePrecision)) { minvalue = Math.Round(minvalue, ScaleValuePrecision); tb.Text = minvalue.ToString(); minvalue = minvalue + majorTicksUnitValue; } else { break; } majortickgp.Children.Add(majorticktt); majortickrect.RenderTransform = majortickgp; tb.RenderTransform = majorscalevaluett; rootGrid.Children.Add(majortickrect); rootGrid.Children.Add(tb); //Drawing the minor axis ticks Double onedegree = ((i + majorTickUnitAngle) - i) / (MinorDivisionsCount); if ((i < (ScaleStartAngle + ScaleSweepAngle)) && (Math.Round(minvalue, ScaleValuePrecision) <= Math.Round(MaxValue, ScaleValuePrecision))) { //Drawing the minor scale for (Double mi = i + onedegree; mi < (i + majorTickUnitAngle); mi = mi + onedegree) { //here the minortick is drawn as a rectangle Rectangle mr = new Rectangle(); mr.Height = MinorTickSize.Height; mr.Width = MinorTickSize.Width; mr.Fill = new SolidColorBrush(MinorTickColor); mr.HorizontalAlignment = HorizontalAlignment.Center; mr.VerticalAlignment = VerticalAlignment.Center; Point p1 = new Point(0.5, 0.5); mr.RenderTransformOrigin = p1; TransformGroup minortickgp = new TransformGroup(); RotateTransform minortickrt = new RotateTransform(); minortickrt.Angle = mi; minortickgp.Children.Add(minortickrt); TranslateTransform minorticktt = new TranslateTransform(); //Obtaining the angle in radians for calulating the points Double mi_radian = (mi * Math.PI) / 180; //Finding the point on the Scale where the minor ticks are drawn minorticktt.X = (int)((ScaleRadius) * Math.Cos(mi_radian)); minorticktt.Y = (int)((ScaleRadius) * Math.Sin(mi_radian)); minortickgp.Children.Add(minorticktt); mr.RenderTransform = minortickgp; rootGrid.Children.Add(mr); } } } }
/// <summary> /// Gets the rotated rect. /// </summary> /// <param name="rect">The rect.</param> /// <param name="rotate">The rotate.</param> /// <returns></returns> public Rect GetRotatedRect(Rect rect, RotateTransform rotate) { #if !WINRT Point leftTop = rotate.Transform(new Point(rect.Left, rect.Top)); Point rightTop = rotate.Transform(new Point(rect.Right, rect.Top)); Point leftBottom = rotate.Transform(new Point(rect.Left, rect.Bottom)); Point rightBottom = rotate.Transform(new Point(rect.Right, rect.Bottom)); double left = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X)); double top = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y)); double right = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X)); double bottom = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y)); return new Rect(left, top, right - left, bottom - top); #else Point leftTop = rotate.TransformPoint(new Point(rect.Left, rect.Top)); Point rightTop = rotate.TransformPoint(new Point(rect.Right, rect.Top)); Point leftBottom = rotate.TransformPoint(new Point(rect.Left, rect.Bottom)); Point rightBottom = rotate.TransformPoint(new Point(rect.Right, rect.Bottom)); double left = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X)); double top = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y)); double right = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X)); double bottom = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y)); return new Rect(left, top, right - left, bottom - top); #endif }
/// <summary> /// Walks the Transform and returns the corresponding matrix. /// </summary> /// <param name="transform">The transform to create a matrix for. /// </param> /// <returns>The matrix calculated from the transform.</returns> private Matrix GetTransformMatrix(Transform transform) { if (null != transform) { // WPF equivalent of this entire method: // return transform.Value; // Process the TransformGroup TransformGroup transformGroup = transform as TransformGroup; if (null != transformGroup) { Matrix groupMatrix = Matrix.Identity; foreach (Transform child in transformGroup.Children) { groupMatrix = MatrixMultiply(groupMatrix, GetTransformMatrix(child)); } return(groupMatrix); } // Process the RotateTransform RotateTransform rotateTransform = transform as RotateTransform; if (null != rotateTransform) { double angle = rotateTransform.Angle; double angleRadians = (2 * Math.PI * angle) / 360; double sine = Math.Sin(angleRadians); double cosine = Math.Cos(angleRadians); return(new Matrix(cosine, sine, -sine, cosine, 0, 0)); } // Process the ScaleTransform ScaleTransform scaleTransform = transform as ScaleTransform; if (null != scaleTransform) { double scaleX = scaleTransform.ScaleX; double scaleY = scaleTransform.ScaleY; return(new Matrix(scaleX, 0, 0, scaleY, 0, 0)); } // Process the SkewTransform SkewTransform skewTransform = transform as SkewTransform; if (null != skewTransform) { double angleX = skewTransform.AngleX; double angleY = skewTransform.AngleY; double angleXRadians = (2 * Math.PI * angleX) / 360; double angleYRadians = (2 * Math.PI * angleY) / 360; return(new Matrix(1, angleYRadians, angleXRadians, 1, 0, 0)); } // Process the MatrixTransform MatrixTransform matrixTransform = transform as MatrixTransform; if (null != matrixTransform) { return(matrixTransform.Matrix); } // TranslateTransform has no effect in LayoutTransform } // Fall back to no-op transformation return(Matrix.Identity); }
private void Initialize() { double desiredWidth = 0; CalculateAutoInterval(); GenerateLabels(); if (this.ActualHeight > 0 && this.ActualWidth > 0) { this.Children.Clear(); double yAxisHeightStep = this.ActualHeight / ((MIntervalCount > 0) ? MIntervalCount : 1); double yAxisHeightPosition = this.DataToPoint(MStartValue); Rect oldRect = new Rect(0, 0, 0, 0); AxisLine = new Line(); Binding binding = new Binding(); binding.Path = new PropertyPath("AxisLineStyle"); binding.Source = this; AxisLine.SetBinding(Line.StyleProperty, binding); AxisLine.X1 = this.ActualWidth; AxisLine.X2 = this.ActualWidth; AxisLine.Y1 = 0; AxisLine.Y2 = this.ActualHeight; AxisLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); Labels = new List<ContentControl>(); MajorTickLines = new List<Line>(); MinorTickLines = new List<Line>(); double labelSize = 0; for (int i = this.MLabels.Count - 1; i >= 0; i--) { ContentControl label = new ContentControl(); label.Content = MLabels[i]; //label.ContentTemplate = this.LabelTemplate; Binding labelTemplateBinding = new Binding(); labelTemplateBinding.Path = new PropertyPath("LabelTemplate"); labelTemplateBinding.Source = this; label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding); label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); label.RenderTransform = labelRotation; Labels.Add(label); Line tickLine = new Line(); double labelPadding = 0; Binding styleBinding = new Binding(); styleBinding.Path = new PropertyPath("MajorLineStyle"); styleBinding.Source = this; tickLine.SetBinding(Line.StyleProperty, styleBinding); //tickLine.Style = MajorLineStyle; tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); tickLine.Y1 = yAxisHeightPosition; tickLine.Y2 = yAxisHeightPosition; switch (MajorTicksPosition) { case TickPosition.Inside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 + MajorLineSize; if (this.ShowMajorTicks) { labelPadding = 0; desiredWidth = 0; } break; case TickPosition.Cross: tickLine.X1 = this.ActualWidth -(MajorLineSize / 2); tickLine.X2 = this.ActualWidth + (MajorLineSize / 2); if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize / 2; } break; case TickPosition.Outside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 - MajorLineSize; if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize; } break; default: break; } Binding ticklineVisibilityBinding = new Binding(); ticklineVisibilityBinding.Path = new PropertyPath("ShowMajorTicks"); ticklineVisibilityBinding.Source = this; ticklineVisibilityBinding.Converter = new BooleanToVisibilityConverter(); tickLine.SetBinding(Line.VisibilityProperty, ticklineVisibilityBinding); MajorTickLines.Add(tickLine); this.Children.Add(tickLine); //desiredWidth = 0; double minorstep = 0; if (!(i == 0)) { double minorWidth = yAxisHeightStep; minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = new Line(); Binding minorstyleBinding = new Binding(); minorstyleBinding.Path = new PropertyPath("MinorLineStyle"); minorstyleBinding.Source = this; minorLine.SetBinding(Line.StyleProperty, minorstyleBinding); minorLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1)); minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1)); switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 + MinorLineSize; break; case TickPosition.Cross: minorLine.X1 = this.ActualWidth - (MinorLineSize / 2); minorLine.X2 = this.ActualWidth + (MinorLineSize / 2); break; case TickPosition.Outside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 - MinorLineSize; break; default: break; } MinorTickLines.Add(minorLine); this.Children.Add(minorLine); } } if (this.LabelAngle == 0) { Canvas.SetLeft(label, this.ActualWidth - (label.DesiredSize.Width) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (label.DesiredSize.Height / 2)); labelSize = Math.Max(labelSize, label.DesiredSize.Width); } else { Canvas.SetLeft(label, this.ActualWidth - (rotatedRect.Width-rotatedRect.X) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (rotatedRect.Height / 2) - rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Width); } this.Children.Add(label); yAxisHeightPosition += yAxisHeightStep; } header = new ContentControl(); header.DataContext = null; header.Content = this.Header; //header.ContentTemplate = this.HeaderTemplate; Binding contentBinding = new Binding(); contentBinding.Path = new PropertyPath("Header"); contentBinding.Source = this; header.SetBinding(ContentControl.ContentProperty, contentBinding); Binding headerTemplateBinding = new Binding(); headerTemplateBinding.Path = new PropertyPath("HeaderTemplate"); headerTemplateBinding.Source = this; header.SetBinding(ContentControl.ContentTemplateProperty, headerTemplateBinding); header.Measure(new Size(this.ActualHeight, this.ActualWidth)); desiredWidth += labelSize; Canvas.SetLeft(header, this.ActualWidth - labelSize - header.DesiredSize.Height - this.MajorLineSize - 1); Canvas.SetTop(header, this.ActualHeight / 2); desiredWidth = desiredWidth + header.DesiredSize.Height ; this.Children.Add(header); this.Children.Add(AxisLine); IsInitialized = true; this.Chart.AxisWidth = desiredWidth; } }
/// <summary> /// Updates this instance. /// </summary> internal void Update() { double desiredWidth = 0; CalculateAutoInterval(); GenerateLabels(); if (this.ActualHeight > 0 && this.ActualWidth > 0) { double yAxisHeightStep = this.ActualHeight / ((MIntervalCount > 0) ? MIntervalCount : 1); double yAxisHeightPosition = 0; Rect oldRect = new Rect(0, 0, 0, 0); AxisLine.X1 = this.ActualWidth; AxisLine.X2 = this.ActualWidth; AxisLine.Y1 = 0; AxisLine.Y2 = this.ActualHeight; Binding binding = new Binding(); binding.Path = new PropertyPath("AxisLineStyle"); binding.Source = this; AxisLine.SetBinding(Line.StyleProperty, binding); double labelSize = 0; int minorCount = 0; if (this.MLabels.Count == Labels.Count) { for (int i = this.MLabels.Count - 1; i >=0; i--) { yAxisHeightPosition = this.DataToPoint(MLabelValues[i]); ContentControl label = Labels[i]; label.Content = MLabels[i]; label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); label.RenderTransform = labelRotation; Line tickLine = MajorTickLines[i]; double labelPadding = 0; tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); //tickLine.X1 = this.ActualWidth; tickLine.Y1 = yAxisHeightPosition; tickLine.Y2 = yAxisHeightPosition; //tickLine.X2 = tickLine.X1 - MajorLineSize; switch (MajorTicksPosition) { case TickPosition.Inside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 + MajorLineSize; if (this.ShowMajorTicks) { labelPadding = 0; desiredWidth = 0; } break; case TickPosition.Cross: tickLine.X1 = this.ActualWidth - (MajorLineSize / 2); tickLine.X2 = this.ActualWidth + (MajorLineSize / 2); if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize / 2; } break; case TickPosition.Outside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 - MajorLineSize; if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize; } break; default: break; } //desiredWidth = 0; if (i != 0) { double minorWidth = yAxisHeightStep; double minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = MinorTickLines[minorCount]; minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1)); minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1)); //minorLine.X1 = this.ActualWidth - (minorLine.StrokeThickness); // minorLine.X2 = minorLine.X1 - MinorLineSize; switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 + MinorLineSize; break; case TickPosition.Cross: minorLine.X1 = this.ActualWidth - (MinorLineSize / 2); minorLine.X2 = this.ActualWidth + (MinorLineSize / 2); break; case TickPosition.Outside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 - MinorLineSize; break; default: break; } minorCount++; } } if (this.LabelAngle == 0) { Canvas.SetLeft(label, this.ActualWidth - (label.DesiredSize.Width) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (label.DesiredSize.Height / 2)); labelSize = Math.Max(labelSize, label.DesiredSize.Width); } else { Canvas.SetLeft(label, this.ActualWidth - (rotatedRect.Width)-rotatedRect.X - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (rotatedRect.Height / 2)-rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Width); } } } else { if (this.MLabels.Count > Labels.Count) { int offset = this.MLabels.Count - Labels.Count; for (int j = 0; j < offset; j++) { ContentControl label = new ContentControl(); label.Content = MLabels[this.MLabels.Count - offset - 1]; //label.ContentTemplate = this.LabelTemplate; Binding labelTemplateBinding = new Binding(); labelTemplateBinding.Path = new PropertyPath("LabelTemplate"); labelTemplateBinding.Source = this; label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding); label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); label.RenderTransform = labelRotation; Labels.Add(label); Line tickLine = new Line(); Binding styleBinding = new Binding(); styleBinding.Path = new PropertyPath("MajorLineStyle"); styleBinding.Source = this; tickLine.SetBinding(Line.StyleProperty, styleBinding); tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); tickLine.Y1 = yAxisHeightPosition; tickLine.Y2 = yAxisHeightPosition; //tickLine.X2 = tickLine.X1 - MajorLineSize; switch (MajorTicksPosition) { case TickPosition.Inside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 + MajorLineSize; break; case TickPosition.Cross: tickLine.X1 = this.ActualWidth - (MajorLineSize / 2); tickLine.X2 = this.ActualWidth + (MajorLineSize / 2); break; case TickPosition.Outside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 - MajorLineSize; break; default: break; } //Binding tickSizeBinding = new Binding(); //tickSizeBinding.Path = new PropertyPath("MajorLineSize"); //tickSizeBinding.Source = this; //tickSizeBinding.Converter = new MajorSizeThicknessConverter(); //tickSizeBinding.ConverterParameter = tickLine.X1; //tickLine.SetBinding(Line.X2Property, tickSizeBinding); Binding ticklineVisibilityBinding = new Binding(); ticklineVisibilityBinding.Path = new PropertyPath("ShowMajorTicks"); ticklineVisibilityBinding.Source = this; ticklineVisibilityBinding.Converter = new BooleanToVisibilityConverter(); tickLine.SetBinding(Line.VisibilityProperty, ticklineVisibilityBinding); double minorWidth = yAxisHeightStep; double minorstep = minorWidth / (MinorTicksCount + 1); for (int k = 0; k < this.MinorTicksCount; j++) { Line minorLine = new Line(); Binding minorstyleBinding = new Binding(); minorstyleBinding.Path = new PropertyPath("MinorLineStyle"); minorstyleBinding.Source = this; minorLine.SetBinding(Line.StyleProperty, minorstyleBinding); minorLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1)); minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1)); switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 + MinorLineSize; break; case TickPosition.Cross: minorLine.X1 = this.ActualWidth - (MinorLineSize / 2); minorLine.X2 = this.ActualWidth + (MinorLineSize / 2); break; case TickPosition.Outside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 - MinorLineSize; break; default: break; } MinorTickLines.Add(minorLine); this.Children.Add(minorLine); } this.Children.Add(label); MajorTickLines.Add(tickLine); this.Children.Add(tickLine); } } else { int offset = Labels.Count - this.MLabels.Count; for (int j = 0; j < offset; j++) { this.Children.Remove(Labels[Labels.Count - 1]); Labels.RemoveAt(Labels.Count - 1); for (int k = 0; k < this.MinorTicksCount; k++) { this.Children.Remove(MinorTickLines[MinorTickLines.Count - 1]); MinorTickLines.RemoveAt(MinorTickLines.Count - 1); } this.Children.Remove(MajorTickLines[MajorTickLines.Count - 1]); MajorTickLines.RemoveAt(MajorTickLines.Count - 1); } } for (int i = this.MLabels.Count - 1; i >= 0; i--) { ContentControl label = Labels[i]; label.Content = MLabels[i]; label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); label.RenderTransform = labelRotation; Line tickLine = MajorTickLines[i]; double labelPadding = 0; tickLine.Y1 = yAxisHeightPosition; tickLine.Y2 = yAxisHeightPosition; switch (MajorTicksPosition) { case TickPosition.Inside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 + MajorLineSize; if (this.ShowMajorTicks) { labelPadding = 0; desiredWidth = 0; } break; case TickPosition.Cross: tickLine.X1 = this.ActualWidth - (MajorLineSize / 2); tickLine.X2 = this.ActualWidth + (MajorLineSize / 2); if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize / 2; } break; case TickPosition.Outside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 - MajorLineSize; if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize; } break; default: break; } tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); //desiredWidth = 0; double minorstep = 0; if (!(i == 0)) { double minorWidth = yAxisHeightStep; minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = MinorTickLines[minorCount]; minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1)); minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1)); //minorLine.X1 = this.ActualWidth - (minorLine.StrokeThickness); //minorLine.X2 = minorLine.X1 - MinorLineSize; switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 + MinorLineSize; break; case TickPosition.Cross: minorLine.X1 = this.ActualWidth - (MinorLineSize / 2); minorLine.X2 = this.ActualWidth + (MinorLineSize / 2); break; case TickPosition.Outside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 - MinorLineSize; break; default: break; } minorCount++; } } if (this.LabelAngle == 0) { Canvas.SetLeft(label, this.ActualWidth - (label.DesiredSize.Width) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (label.DesiredSize.Height / 2)); labelSize = Math.Max(labelSize, label.DesiredSize.Width); } else { Canvas.SetLeft(label, this.ActualWidth - (rotatedRect.Width - rotatedRect.X) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (rotatedRect.Height / 2) - rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Width); } yAxisHeightPosition += yAxisHeightStep; //desiredWidth = desiredWidth + labelSize; } } header.Measure(new Size(this.ActualHeight, this.ActualWidth)); Canvas.SetLeft(header, this.ActualWidth - labelSize - header.DesiredSize.Height - this.MajorLineSize - 1); Canvas.SetTop(header, this.ActualHeight / 2); desiredWidth = desiredWidth+ header.DesiredSize.Height + labelSize; } if (this.Chart.AxisWidth < desiredWidth) this.Chart.AxisWidth = desiredWidth + 1; }
public void AddGraphPort(IGraphPort aPort) { SetPixelHandler += new NewTOAPIA.Drawing.SetPixel(aPort.SetPixel); DrawLineHandler += new DrawLine(aPort.DrawLine); DrawLinesHandler += new DrawLines(aPort.DrawLines); DrawRectangleHandler += new NewTOAPIA.Drawing.DrawRectangle(aPort.DrawRectangle); DrawRectanglesHandler += new NewTOAPIA.Drawing.DrawRectangles(aPort.DrawRectangles); FillRectangleHandler += new NewTOAPIA.Drawing.FillRectangle(aPort.FillRectangle); DrawEllipseHandler += new NewTOAPIA.Drawing.DrawEllipse(aPort.DrawEllipse); FillEllipseHandler += new NewTOAPIA.Drawing.FillEllipse(aPort.FillEllipse); DrawRoundRectHandler += new NewTOAPIA.Drawing.DrawRoundRect(aPort.DrawRoundRect); PolygonHandler += new NewTOAPIA.Drawing.Polygon(aPort.Polygon); DrawBeziersHandler += new NewTOAPIA.Drawing.DrawBeziers(aPort.DrawBeziers); DrawPathHandler += new NewTOAPIA.Drawing.DrawPath(aPort.DrawPath); FillPathHandler += new FillPath(aPort.FillPath); //// Gradient fills //DrawGradientRectangleHandler += new NewTOAPIA.Drawing.DrawGradientRectangle(aPort.DrawGradientRectangle); //// Drawing Text DrawStringHandler += new NewTOAPIA.Drawing.DrawString(aPort.DrawString); ///// Draw bitmaps PixBltHandler += new NewTOAPIA.Drawing.PixBlt(aPort.PixBlt); //PixmapShardBltHandler += new NewTOAPIA.Drawing.PixmapShardBlt(aPort.PixmapShardBlt); //AlphaBlendHandler += new NewTOAPIA.Drawing.AlphaBlend(aPort.AlphaBlend); // Path handling //DrawPathHandler += new NewTOAPIA.Drawing.DrawPath(aPort.DrawPath); //SetPathAsClipRegionHandler += new NewTOAPIA.Drawing.SetPathAsClipRegion(aPort.SetPathAsClipRegion); //// Setting some objects SetPenHandler += new NewTOAPIA.Drawing.SetPen(aPort.SetPen); SetBrushHandler += new SetBrush(aPort.SetBrush); SetFontHandler += new SetFont(aPort.SetFont); //SelectStockObjectHandler += new NewTOAPIA.Drawing.SelectStockObject(aPort.SelectStockObject); SelectUniqueObjectHandler += new NewTOAPIA.Drawing.SelectUniqueObject(aPort.SelectUniqueObject); //// State Management FlushHandler += new NewTOAPIA.Drawing.Flush(aPort.Flush); SaveStateHandler += new NewTOAPIA.Drawing.SaveState(aPort.SaveState); ResetStateHandler += new NewTOAPIA.Drawing.ResetState(aPort.ResetState); RestoreStateHandler += new NewTOAPIA.Drawing.RestoreState(aPort.RestoreState); //// Setting Attributes and modes SetTextColorHandler += new NewTOAPIA.Drawing.SetTextColor(aPort.SetTextColor); //// Setting some modes SetBkColorHandler += new NewTOAPIA.Drawing.SetBkColor(aPort.SetBkColor); SetBkModeHandler += new NewTOAPIA.Drawing.SetBkMode(aPort.SetBkMode); SetMappingModeHandler += new NewTOAPIA.Drawing.SetMappingMode(aPort.SetMappingMode); SetPolyFillModeHandler += new NewTOAPIA.Drawing.SetPolyFillMode(aPort.SetPolyFillMode); SetROP2Handler += new NewTOAPIA.Drawing.SetROP2(aPort.SetROP2); SetClipRectangleHandler += new SetClipRectangle(aPort.SetClipRectangle); // World transform management SetWorldTransformHandler += new NewTOAPIA.Drawing.SetWorldTransform(aPort.SetWorldTransform); TranslateTransformHandler += new TranslateTransform(aPort.TranslateTransform); ScaleTransformHandler += new ScaleTransform(aPort.ScaleTransform); RotateTransformHandler += new RotateTransform(aPort.RotateTransform); }
private void Portrait_Selected(object sender, RoutedEventArgs e) { RotateTransform rt = new RotateTransform(90); imgMain.LayoutTransform = rt; }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or /// internal processes (such as a rebuilding layout pass) call /// <see cref="M:System.Windows.Controls.Control.ApplyTemplate"/>. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); RotateRing = GetTemplateChild("RotateRing") as FrameworkElement; TransformRotate = GetTemplateChild("TransformRotate") as RotateTransform; if (TransformRotate != null && Map != null) { TransformRotate.Angle = Map.Rotation; } PanLeft = GetTemplateChild("PanLeft") as FrameworkElement; PanRight = GetTemplateChild("PanRight") as FrameworkElement; PanUp = GetTemplateChild("PanUp") as FrameworkElement; PanDown = GetTemplateChild("PanDown") as FrameworkElement; ZoomSlider = GetTemplateChild("ZoomSlider") as Slider; ZoomFullExtent = GetTemplateChild("ZoomFullExtent") as Button; ResetRotation = GetTemplateChild("ResetRotation") as Button; ZoomInButton = GetTemplateChild("ZoomInButton") as Button; ZoomOutButton = GetTemplateChild("ZoomOutButton") as Button; enablePanElement(PanLeft); enablePanElement(PanRight); enablePanElement(PanUp); enablePanElement(PanDown); // Set control's flow direction to LTR to avoid flipping East and West keys: this.FlowDirection = System.Windows.FlowDirection.LeftToRight; if (ZoomSlider != null) { if (Map != null) { SetupZoom(); } ZoomSlider.Minimum = 0; ZoomSlider.Maximum = 1; ZoomSlider.SmallChange = .01; ZoomSlider.LargeChange = .1; ZoomSlider.LostMouseCapture += ZoomSlider_LostMouseCapture; ZoomSlider.LostFocus += ZoomSlider_LostMouseCapture; } if (ZoomInButton != null) { ZoomInButton.Click += ZoomInButton_Click; } if (ZoomOutButton != null) { ZoomOutButton.Click += ZoomOutButton_Click; } if (RotateRing != null) { RotateRing.MouseLeftButtonDown += RotateRing_MouseLeftButtonDown; RotateRing.LostMouseCapture += RotateRing_OnLostCapture; } if (ZoomFullExtent != null) { ZoomFullExtent.Click += ZoomFullExtent_Click; } if (ResetRotation != null) { ResetRotation.Click += ResetRotation_Click; } bool isDesignMode = System.ComponentModel.DesignerProperties.GetIsInDesignMode(this); if (isDesignMode) { mouseOver = isDesignMode; } ChangeVisualState(false); }
public override void RenderTextRun(SvgTextContentElement element, ref Point ctp, string text, double rotate, WpfTextPlacement placement) { if (string.IsNullOrWhiteSpace(text)) { return; } double emSize = GetComputedFontSize(element); FontFamily fontFamily = GetTextFontFamily(element, emSize); FontStyle fontStyle = GetTextFontStyle(element); FontWeight fontWeight = GetTextFontWeight(element); FontStretch fontStretch = GetTextFontStretch(element); WpfTextStringFormat stringFormat = GetTextStringFormat(element); // Fix the use of Postscript fonts... WpfFontFamilyVisitor fontFamilyVisitor = _context.FontFamilyVisitor; if (!string.IsNullOrWhiteSpace(_actualFontName) && fontFamilyVisitor != null) { WpfFontFamilyInfo currentFamily = new WpfFontFamilyInfo(fontFamily, fontWeight, fontStyle, fontStretch); WpfFontFamilyInfo familyInfo = fontFamilyVisitor.Visit(_actualFontName, currentFamily, _context); if (familyInfo != null && !familyInfo.IsEmpty) { fontFamily = familyInfo.Family; fontWeight = familyInfo.Weight; fontStyle = familyInfo.Style; fontStretch = familyInfo.Stretch; } } WpfSvgPaint fillPaint = new WpfSvgPaint(_context, element, "fill"); Brush textBrush = fillPaint.GetBrush(); WpfSvgPaint strokePaint = new WpfSvgPaint(_context, element, "stroke"); Pen textPen = strokePaint.GetPen(); if (textBrush == null && textPen == null) { return; } else if (textBrush == null) { // If here, then the pen is not null, and so the fill cannot be null. // We set this to transparent for stroke only text path... textBrush = Brushes.Transparent; } TextDecorationCollection textDecors = GetTextDecoration(element); if (textDecors == null) { SvgTextElement textElement = element.ParentNode as SvgTextElement; if (textElement != null) { textDecors = GetTextDecoration(textElement); } } TextAlignment alignment = stringFormat.Alignment; bool hasWordSpacing = false; string wordSpaceText = element.GetAttribute("word-spacing"); double wordSpacing = 0; if (!string.IsNullOrWhiteSpace(wordSpaceText) && double.TryParse(wordSpaceText, out wordSpacing) && (float)wordSpacing != 0) { hasWordSpacing = true; } bool hasLetterSpacing = false; string letterSpaceText = element.GetAttribute("letter-spacing"); double letterSpacing = 0; if (!string.IsNullOrWhiteSpace(letterSpaceText) && double.TryParse(letterSpaceText, out letterSpacing) && (float)letterSpacing != 0) { hasLetterSpacing = true; } bool isRotatePosOnly = false; IList <WpfTextPosition> textPositions = null; int textPosCount = 0; if ((placement != null && placement.HasPositions)) { textPositions = placement.Positions; textPosCount = textPositions.Count; isRotatePosOnly = placement.IsRotateOnly; } if (hasLetterSpacing || hasWordSpacing || textPositions != null) { double spacing = Convert.ToDouble(letterSpacing); for (int i = 0; i < text.Length; i++) { FormattedText formattedText = new FormattedText(new string(text[i], 1), _context.CultureInfo, stringFormat.Direction, new Typeface(fontFamily, fontStyle, fontWeight, fontStretch), emSize, textBrush); if (this.IsMeasuring) { this.AddTextWidth(formattedText.WidthIncludingTrailingWhitespace); continue; } formattedText.Trimming = stringFormat.Trimming; formattedText.TextAlignment = stringFormat.Alignment; if (textDecors != null && textDecors.Count != 0) { formattedText.SetTextDecorations(textDecors); } WpfTextPosition?textPosition = null; if (textPositions != null && i < textPosCount) { textPosition = textPositions[i]; } //float xCorrection = 0; //if (alignment == TextAlignment.Left) // xCorrection = emSize * 1f / 6f; //else if (alignment == TextAlignment.Right) // xCorrection = -emSize * 1f / 6f; double yCorrection = formattedText.Baseline; float rotateAngle = (float)rotate; if (textPosition != null) { if (!isRotatePosOnly) { Point pt = textPosition.Value.Location; ctp.X = pt.X; ctp.Y = pt.Y; } rotateAngle = (float)textPosition.Value.Rotation; } Point textStart = ctp; RotateTransform rotateAt = null; if (rotateAngle != 0) { rotateAt = new RotateTransform(rotateAngle, textStart.X, textStart.Y); _textContext.PushTransform(rotateAt); } Point textPoint = new Point(ctp.X, ctp.Y - yCorrection); if (textPen != null || _context.TextAsGeometry) { Geometry textGeometry = formattedText.BuildGeometry(textPoint); if (textGeometry != null && !textGeometry.IsEmpty()) { _textContext.DrawGeometry(textBrush, textPen, ExtractTextPathGeometry(textGeometry)); this.IsTextPath = true; } else { _textContext.DrawText(formattedText, textPoint); } } else { _textContext.DrawText(formattedText, textPoint); } //float bboxWidth = (float)formattedText.Width; double bboxWidth = formattedText.WidthIncludingTrailingWhitespace; if (alignment == TextAlignment.Center) { bboxWidth /= 2f; } else if (alignment == TextAlignment.Right) { bboxWidth = 0; } //ctp.X += bboxWidth + emSize / 4 + spacing; if (hasLetterSpacing) { ctp.X += bboxWidth + letterSpacing; } if (hasWordSpacing && Char.IsWhiteSpace(text[i])) { if (hasLetterSpacing) { ctp.X += wordSpacing; } else { ctp.X += bboxWidth + wordSpacing; } } else { if (!hasLetterSpacing) { ctp.X += bboxWidth; } } if (rotateAt != null) { _textContext.Pop(); } } } else { FormattedText formattedText = new FormattedText(text, _context.CultureInfo, stringFormat.Direction, new Typeface(fontFamily, fontStyle, fontWeight, fontStretch), emSize, textBrush); if (this.IsMeasuring) { this.AddTextWidth(formattedText.WidthIncludingTrailingWhitespace); return; } if (alignment == TextAlignment.Center && this.TextWidth > 0) { alignment = TextAlignment.Left; } formattedText.TextAlignment = alignment; formattedText.Trimming = stringFormat.Trimming; if (textDecors != null && textDecors.Count != 0) { formattedText.SetTextDecorations(textDecors); } //float xCorrection = 0; //if (alignment == TextAlignment.Left) // xCorrection = emSize * 1f / 6f; //else if (alignment == TextAlignment.Right) // xCorrection = -emSize * 1f / 6f; double yCorrection = formattedText.Baseline; float rotateAngle = (float)rotate; Point textPoint = new Point(ctp.X, ctp.Y - yCorrection); RotateTransform rotateAt = null; if (rotateAngle != 0) { rotateAt = new RotateTransform(rotateAngle, ctp.X, ctp.Y); _textContext.PushTransform(rotateAt); } if (textPen != null || _context.TextAsGeometry) { Geometry textGeometry = formattedText.BuildGeometry(textPoint); if (textGeometry != null && !textGeometry.IsEmpty()) { _textContext.DrawGeometry(textBrush, textPen, ExtractTextPathGeometry(textGeometry)); this.IsTextPath = true; } else { _textContext.DrawText(formattedText, textPoint); } } else { _textContext.DrawText(formattedText, textPoint); } //float bboxWidth = (float)formattedText.Width; double bboxWidth = formattedText.WidthIncludingTrailingWhitespace; if (alignment == TextAlignment.Center) { bboxWidth /= 2f; } else if (alignment == TextAlignment.Right) { bboxWidth = 0; } //ctp.X += bboxWidth + emSize / 4; ctp.X += bboxWidth; if (rotateAt != null) { _textContext.Pop(); } } }
/// <inheritdoc /> public override void MouseMove(int x, int y, int changeX, int changeY) { var rt = new RotateTransform(-RotationAngle, _rotationCenter.X, _rotationCenter.Y); var point = rt.TransformPoint(x, y); //See if we're resizing if (_selectionPoint != null && (_selectionPoint.PointType == PreviewPoint.PointTypes.Size || _selectionPoint.PointType == PreviewPoint.PointTypes.Rotate)) { //We are resizing, so figure our change and scale the points. if (_selectionPoint == _dragPoints[0]) { //Top Left var newHeight = Bounds.Height + (Bounds.TopLeft.Y - point.Y); var newWidth = Bounds.Width + (Bounds.TopLeft.X - point.X); var minSize = ClampSize(); var scaleY = newHeight > minSize ? newHeight / Bounds.Height : 1; var scaleX = newWidth > minSize ? newWidth / Bounds.Width : 1; if (Control.ModifierKeys == Keys.Shift) { scaleX = scaleY = MaxValue(scaleX, scaleY); } Layout(); Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[2].X), ZoomCoordToOriginal(_dragPoints[2].Y)); _selectionPoint = _dragPoints[0]; } else if (_selectionPoint == _dragPoints[1]) { //Top Right var newHeight = Bounds.Height + (Bounds.TopRight.Y - point.Y); var newWidth = Bounds.Width + (point.X - Bounds.TopRight.X); var minSize = ClampSize(); var scaleY = newHeight > minSize ? newHeight / Bounds.Height : 1; var scaleX = newWidth > minSize ? newWidth / Bounds.Width : 1; if (Control.ModifierKeys == Keys.Shift) { scaleX = scaleY = MaxValue(scaleX, scaleY); } Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[3].X), ZoomCoordToOriginal(_dragPoints[3].Y)); Layout(); _selectionPoint = _dragPoints[1]; } else if (_selectionPoint == _dragPoints[2]) { //Bottom Right var newHeight = Bounds.Height + (point.Y - Bounds.BottomRight.Y); var newWidth = Bounds.Width + (point.X - Bounds.BottomRight.X); var minSize = ClampSize(); var scaleY = newHeight > minSize ? newHeight / Bounds.Height:1; var scaleX = newWidth > minSize ? newWidth / Bounds.Width:1; if (Control.ModifierKeys == Keys.Shift) { scaleX = scaleY = MaxValue(scaleX, scaleY); } Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[0].X), ZoomCoordToOriginal(_dragPoints[0].Y)); Layout(); _selectionPoint = _dragPoints[2]; } else if (_selectionPoint == _dragPoints[3]) { //Bottom Left var newHeight = Bounds.Height + (point.Y - Bounds.BottomLeft.Y); var newWidth = Bounds.Width + (Bounds.BottomLeft.X - point.X); var minSize = ClampSize(); var scaleY = newHeight > minSize ? newHeight / Bounds.Height : 1; var scaleX = newWidth > minSize ? newWidth / Bounds.Width : 1; if (Control.ModifierKeys == Keys.Shift) { scaleX = scaleY = MaxValue(scaleX, scaleY); } Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[1].X), ZoomCoordToOriginal(_dragPoints[1].Y)); Layout(); _selectionPoint = _dragPoints[3]; } else if (_selectionPoint == _dragPoints[4]) { //We are rotating! double angle = GetAngle(_rotationCenter, new Point(x, y)); // Use Detents of 0, 45, 90, 135, 180, 225, 270 and 315 when holding the Shift modifier key down. if (Control.ModifierKeys == Keys.Control) { if (angle >= 22.5 && angle < 67.5) { angle = 45; } else if (angle >= 67.5 && angle < 112.5) { angle = 90; } else if (angle >= 112.5 && angle < 157.5) { angle = 135; } else if (angle >= 157.5 && angle < 202.5) { angle = 180; } else if (angle >= 202.5 && angle < 247.5) { angle = 225; } else if (angle >= 247.5 && angle < 292.5) { angle = 270; } else if (angle >= 292.5 && angle < 337.5) { angle = 315; } else if (angle >= 337.5 || angle < 22.5) { angle = 0; } } RotationAngle = (int)Math.Round(angle, MidpointRounding.AwayFromZero); _selectionPoint = _dragPoints[4]; } } else { var newX = _p1Start.X + changeX; var newY = _p1Start.Y + changeY; MoveTo(newX, newY); } }
/// <summary> /// Update edge pointer position and angle /// </summary> public virtual Point Update(Point? position, Vector direction, double angle = 0d) { //var vecOffset = new Vector(direction.X * Offset.X, direction.Y * Offset.Y); if (DesiredSize.Width == 0 || DesiredSize.Height == 0 || !position.HasValue) return new Point(); var vecMove = new Vector(direction.X * DesiredSize.Width * .5, direction.Y * DesiredSize.Height * .5); position = new Point(position.Value.X - vecMove.X, position.Value.Y - vecMove.Y);// + vecOffset; if (!double.IsNaN(DesiredSize.Width) && DesiredSize.Width != 0 && !double.IsNaN(position.Value.X)) { LastKnownRectSize = new Rect(new Point(position.Value.X - DesiredSize.Width * .5, position.Value.Y - DesiredSize.Height * .5), DesiredSize); Arrange(LastKnownRectSize); } if(NeedRotation) RenderTransform = new RotateTransform { Angle = angle, CenterX = 0, CenterY = 0 }; return new Point(direction.X * ActualWidth, direction.Y * ActualHeight); }
public static Point TransformPreviewPoint(this RotateTransform @this, PreviewPoint point) { var p = new Point(point.X, point.Y); return(@this.Transform(p)); }
private void Retangle_MouseMove(object sender, MouseEventArgs e) { if (m_IsCaptured) { lock (m_MoveLock) { var control = sender as FrameworkElement; Canvas canvas = this.Parent as Canvas; if (control != null && this.Parent != null && canvas != null) { e.Handled = true; Vector sizeOffset = e.GetPosition(canvas) - m_LastSizePoint; Vector deltaSize = this.GetPointByRotation(new Point(sizeOffset.X, sizeOffset.Y), -m_Radian, new Point(RectRotateTransform.CenterX, RectRotateTransform.CenterY)) - new Point(-RectRotateTransform.CenterX, -RectRotateTransform.CenterY); switch (control.Name) { case "Size_NW": RectRotateTransform = new RotateTransform(Rotation, this.Width > this.MinWidth ? m_RectWidth / 2 - deltaSize.X : this.MinWidth / 2 - m_RectWidth / 2, this.Height > this.MinHeight ? m_RectHeight / 2 - deltaSize.Y : this.MinHeight / 2 - m_RectHeight / 2); if (m_RectWidth - deltaSize.X > this.MinWidth) { this.OriginX = m_RectOriginX + deltaSize.X; this.Width = m_RectWidth - deltaSize.X; } else { this.Width = this.MinWidth; } if (m_RectHeight - deltaSize.Y > this.MinHeight) { this.OriginY = m_RectOriginY + deltaSize.Y; this.Height = m_RectHeight - deltaSize.Y; } else { this.Height = this.MinHeight; } break; case "Size_NE": RectRotateTransform = new RotateTransform(Rotation, m_RectWidth / 2, this.Height > this.MinHeight ? m_RectHeight / 2 - deltaSize.Y : this.MinHeight / 2 - m_RectHeight / 2); if (m_RectWidth + deltaSize.X > this.MinWidth) { this.Width = m_RectWidth + deltaSize.X; } else { this.Width = this.MinWidth; } if (m_RectHeight - deltaSize.Y > this.MinHeight) { this.OriginY = m_RectOriginY + deltaSize.Y; this.Height = m_RectHeight - deltaSize.Y; } else { this.Height = this.MinHeight; } break; case "Size_SW": RectRotateTransform = new RotateTransform(Rotation, this.Width > this.MinWidth ? m_RectWidth / 2 - deltaSize.X : this.MinWidth / 2 - m_RectWidth / 2, m_RectHeight / 2); if (m_RectWidth - deltaSize.X > this.MinWidth) { this.OriginX = m_RectOriginX + deltaSize.X; this.Width = m_RectWidth - deltaSize.X; } else { this.Width = this.MinWidth; } if (m_RectHeight + deltaSize.Y > this.MinHeight) { this.Height = m_RectHeight + deltaSize.Y; } else { this.Height = this.MinHeight; } break; case "Size_SE": RectRotateTransform = new RotateTransform(Rotation, m_RectWidth / 2, m_RectHeight / 2); if (m_RectWidth + deltaSize.X > this.MinWidth) { this.Width = m_RectWidth + deltaSize.X; } else { this.Width = this.MinWidth; } if (m_RectHeight + deltaSize.Y > this.MinHeight) { this.Height = m_RectHeight + deltaSize.Y; } else { this.Height = this.MinHeight; } break; case "Movable_Grid": if (m_LastMovePoint.X == 0 && m_LastMovePoint.Y == 0) { m_LastMovePoint = e.GetPosition(canvas); break; } Vector moveOffset = e.GetPosition(canvas) - m_LastMovePoint; this.OriginX += moveOffset.X; this.OriginY += moveOffset.Y; m_LastMovePoint = e.GetPosition(canvas); break; case "Rotate_Grid": if (m_RotationLine == null) { m_RotationLine = new Line { X1 = m_RectOriginX + m_RectWidth / 2, Y1 = m_RectOriginY + m_RectHeight / 2, Stroke = Brushes.Red, StrokeThickness = 2, StrokeDashArray = DoubleCollection.Parse("4,3") }; canvas.Children.Add(m_RotationLine); } m_RotationLine.X2 = e.GetPosition(canvas).X; m_RotationLine.Y2 = e.GetPosition(canvas).Y; Radian = Math.Atan2(e.GetPosition(canvas).Y - GetCenter().Y, e.GetPosition(canvas).X - GetCenter().X); break; } } } } }
public static Point TransformPoint(this RotateTransform @this, double x, double y) { var p = new Point(x, y); return(@this.Transform(p)); }
public void NonUIElementContentInContentTemplate() { DataTemplate contentTemplate = (DataTemplate)XamlReader. #if SILVERLIGHT Load( #else Parse( #endif @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>" + @"<Grid Width='150' Height='150'>" + @"<ContentControl Content='{Binding}'/>" + @"</Grid>" + @"</DataTemplate>"); Size containerSize = new Size(150, 150); Size contentSize = new Size(106, 106); LayoutTestPanel panel = new LayoutTestPanel(containerSize, containerSize); List <ContentControl> controlsToTest = new List <ContentControl>(ControlsToTest); foreach (ContentControl control in controlsToTest) { control.Content = 1.0; Transform transform = new RotateTransform { Angle = 45 }; LayoutTransformer layoutTransformer = control as LayoutTransformer; if (null != layoutTransformer) { layoutTransformer.LayoutTransform = transform; } #if !SILVERLIGHT else { control.LayoutTransform = transform; } #endif control.ContentTemplate = contentTemplate; panel.Children.Add(control); } TestAsync( panel, () => { foreach (ContentControl control in controlsToTest) { control.ApplyTemplate(); ContentPresenter contentPresenter; DependencyObject child = VisualTreeHelper.GetChild(control, 0); contentPresenter = child as ContentPresenter; if (null == contentPresenter) { contentPresenter = VisualTreeHelper.GetChild(child, 0) as ContentPresenter; } Assert.IsNotNull(contentPresenter); #if !SILVERLIGHT control.Measure(containerSize); #endif AssertAreEqual(contentSize, contentPresenter.DesiredSize, control, "Measure"); #if !SILVERLIGHT control.Arrange(new Rect(new Point(), containerSize)); #endif AssertAreEqual(contentSize, contentPresenter.RenderSize, control, "Arrange"); } }); }
//fix MAINWINDOW bug public CardDragAdorner(CardControl anchor, CardControl sourceCard, Vector mousePoint) : base(Program.PlayWindow.Content as UIElement) { SourceCard = sourceCard; bool isCardInverted = anchor.IsOnTableCanvas && (Player.LocalPlayer.InvertedTable ^ anchor.IsInverted); Point cardOrigin; if (isCardInverted) { CardDef cardDef = Program.Game.Definition.CardDefinition; cardOrigin = new Point(cardDef.Width, cardDef.Height); _mouseOffset = new Vector(cardDef.Width - mousePoint.X, cardDef.Height - mousePoint.Y); } else { cardOrigin = new Point(); _mouseOffset = mousePoint; } //fix MAINWINDOW bug _basePt = anchor.TranslatePoint(cardOrigin, Program.PlayWindow.Content as UIElement); _faceUp = sourceCard.IsAlwaysUp || sourceCard.Card.FaceUp; _lightRedBrush = Brushes.Red.Clone(); _faceDownBrush = new ImageBrush(sourceCard.Card.GetBitmapImage(false)); var bim = new BitmapImage(); bim.BeginInit(); bim.CacheOption = BitmapCacheOption.OnLoad; bim.UriSource = new Uri(Program.Game.Definition.CardDefinition.Front); bim.EndInit(); _faceUpBrush = _faceUp ? new VisualBrush(sourceCard.GetCardVisual()) { Viewbox = new Rect(0, 0, sourceCard.ActualWidth, sourceCard.ActualHeight), ViewboxUnits = BrushMappingMode.Absolute } : (Brush) new ImageBrush(bim); _invertTransform = new ScaleTransform { CenterX = 0.5, CenterY = 0.5 }; _faceUpBrush.RelativeTransform = _invertTransform; if (_faceUpBrush is VisualBrush) { RenderOptions.SetCachingHint(_faceUpBrush, CachingHint.Cache); } _child.BeginInit(); _child.Width = anchor.ActualWidth * CardControl.ScaleFactor.Width; _child.Height = anchor.ActualHeight * CardControl.ScaleFactor.Height; _child.Fill = _faceUp ? _faceUpBrush : _faceDownBrush; _child.StrokeThickness = 3; var transforms = new TransformGroup(); _child.RenderTransform = transforms; _rot = sourceCard.Card.Orientation; if ((_rot & CardOrientation.Rot180) != 0) { _rot180Transform = new RotateTransform(180, _child.Width / 2, _child.Height / 2); transforms.Children.Add(_rot180Transform); } if ((_rot & CardOrientation.Rot90) != 0) { _rot90Transform = isCardInverted ? new RotateTransform(90, _child.Width / 2, _child.Width / 2) : new RotateTransform(90, _child.Width / 2, _child.Height - _child.Width / 2); transforms.Children.Add(_rot90Transform); } _translate = new TranslateTransform(); transforms.Children.Add(_translate); _child.IsHitTestVisible = false; _child.EndInit(); AddVisualChild(_child); var animation = new DoubleAnimation(0.55, 0.75, new Duration(TimeSpan.FromMilliseconds(500))) { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }; animation.Freeze(); _faceUpBrush.BeginAnimation(Brush.OpacityProperty, animation); _faceDownBrush.BeginAnimation(Brush.OpacityProperty, animation); _lightRedBrush.BeginAnimation(Brush.OpacityProperty, animation); }
protected override void OnRender(DrawingContext drawingContext) { double minimum = this.Minimum; double maximum = this.Maximum; double tickFrequency = this.TickFrequency; int minTicksCount = this.MinTicksCount; double majorTickValuesOffset = this.MajorTicksOffset; double startAngle = base.StartAngle; double endAngle = base.EndAngle; double ringThickness = base.RingThickness; double scale = range / (maximum - minimum); Point point = new Point(base.ActualWidth / 2.0, base.ActualHeight / 2.0); Point point2 = new Point(point.X, 0.0); Point point3 = new Point(point.X, ringThickness); Point point4 = new Point(point.X, ringThickness / 2); var stops = this.RangeColors; if (stops.Count != 0) { bool sign = base.SweepDirection == SweepDirection.Clockwise; double x = 0.0; double angle = 450 - startAngle; Color startColor = stops[0].Color; Color color = stops[0].Color; Size size = new Size(point.X, point.Y); Size size2 = new Size(Math.Abs(size.Width - ringThickness), Math.Abs(size.Height - ringThickness)); for (int i = 0; i <= stops.Count; i++) { double scaleAngle; if (i < stops.Count) { double offset = stops[i].Offset; if (offset > maximum) { offset = maximum; } scaleAngle = (offset - x) * scale; x = offset; color = stops[i].Color; } else { scaleAngle = (maximum - x) * scale; x = maximum; } RotateTransform transform1 = new RotateTransform(angle, point.X, point.Y); Point point12 = transform1.Transform(point2); Point point13 = transform1.Transform(point3); transform1.Angle = scaleAngle; StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext context = geometry.Open()) { context.BeginFigure(point12, true, true); context.ArcTo(transform1.Transform(point12), size, 0.0, scaleAngle > 180.0, sign ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, true, true); context.LineTo(transform1.Transform(point13), true, true); context.ArcTo(point13, size2, 0.0, scaleAngle > 180.0, sign ? SweepDirection.Counterclockwise : SweepDirection.Clockwise, true, true); } geometry.Freeze(); transform1 = new RotateTransform(angle + (scaleAngle / 2.0), 0.5, 0.5); drawingContext.DrawGeometry(new LinearGradientBrush(sign ? startColor : color, sign ? color : startColor, transform1.Transform(new Point(0.0, 0.5)), transform1.Transform(new Point(1.0, 0.5))), null, geometry); //drawingContext.DrawGeometry(Brushes.Blue, null, geometry); if (x >= maximum) { break; } startColor = color; angle += scaleAngle; } } var ticks = this.Ticks; if (ticks.Count == 0 && tickFrequency == 0.0) { return; } int count = ticks.Count == 0 ? Convert.ToInt32((maximum - minimum) / tickFrequency) : ticks.Count; double angle1 = range / count; RotateTransform transform = new RotateTransform(0.0, point.X, point.Y); transform.Angle = 450 - startAngle; Point point5 = new Point(point.X, majorTickValuesOffset); Pen pen2 = new Pen(base.Foreground, base.StrokeThickness * 2.0); string text = ""; for (int i = 0; i <= count; i++) { drawingContext.DrawLine(pen2, transform.Transform(point2), transform.Transform(point3)); text = (i == count ? maximum : ticks.Count != 0 ? ticks[i] : i * tickFrequency).ToString(this.TickStringFormat); FormattedText formattedText = new FormattedText(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(base.FontFamily, base.FontStyle, base.FontWeight, base.FontStretch), base.FontSize, base.Foreground); Point origin = transform.Transform(point5); drawingContext.PushTransform(new ScaleTransform(1.0, 1.0, origin.X, origin.Y)); origin.X -= formattedText.Width / 2.0; origin.Y -= formattedText.Height / 2.0; drawingContext.DrawText(formattedText, origin); drawingContext.Pop(); transform.Angle += angle1; } if (minTicksCount > 0) { count *= minTicksCount; angle1 = range / count; Pen pen = new Pen(base.Foreground, base.StrokeThickness); transform.Angle = 450 - startAngle; for (int j = 0; j < count; j++) { drawingContext.DrawLine(pen, transform.Transform(point2), transform.Transform(point4)); transform.Angle += angle1; } } if (!string.IsNullOrEmpty(base.Caption)) { double size = base.FontSize; FormattedText formattedText = new FormattedText(base.Caption, System.Globalization.CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(base.FontFamily, base.FontStyle, base.FontWeight, base.FontStretch), size, base.Foreground); drawingContext.DrawText(formattedText, new Point((base.ActualWidth - Caption.Length * size) / 2.0, 0.2 * base.ActualHeight)); } }
// Connect right and up from row1,col1 to row2,col2 private void ConnectEndIf(int row1, int col1, int row2, int col2) { Line connect; ImageSource arrow = MainWindow.ImageSourceFromBitmap(Properties.Resources.Arrow); Image img; if (col2 > col1) { connect = new Line() { X1 = borderSpace + (width + widthSpace) * col1 + width, X2 = borderSpace + (width + widthSpace) * col2 + width / 2, Y1 = borderSpace + heightSpace * row1 + height / 2, Y2 = borderSpace + heightSpace * row1 + height / 2, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); connect = new Line() { X1 = borderSpace + (width + widthSpace) * col2 + width / 2, X2 = borderSpace + (width + widthSpace) * col2 + width / 2, Y1 = borderSpace + heightSpace * row1 + height / 2, Y2 = borderSpace + heightSpace * row1, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); img = new Image() { Width = 24, Height = 24, Source = arrow }; canvas.Children.Add(img); Canvas.SetLeft(img, borderSpace + (width + widthSpace) * col1 + width - 3); Canvas.SetTop(img, borderSpace + heightSpace * row1 + height / 2 - 13); Canvas.SetZIndex(img, 1); } int rowUp = row1 - 1; while (rowUp >= 0 && null == HasSymbol(rowUp, col2)) { connect = new Line() { X1 = borderSpace + (width + widthSpace) * col2 + width / 2, X2 = borderSpace + (width + widthSpace) * col2 + width / 2, Y1 = borderSpace + heightSpace * (rowUp + 1) + height / 2, Y2 = borderSpace + heightSpace * rowUp, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); rowUp--; } connect = new Line() { X1 = borderSpace + (width + widthSpace) * col2 + width / 2, X2 = borderSpace + (width + widthSpace) * col2 + width / 2, Y1 = borderSpace + heightSpace * (rowUp + 1), Y2 = borderSpace + heightSpace * rowUp + height, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); img = new Image() { Width = 24, Height = 24, Source = arrow, }; RotateTransform rotateTransform = new RotateTransform(); rotateTransform.CenterX = 12; rotateTransform.CenterY = 12; rotateTransform.Angle = -90; img.RenderTransform = new TransformGroup(); ((TransformGroup)img.RenderTransform).Children.Add(rotateTransform); canvas.Children.Add(img); Canvas.SetLeft(img, borderSpace + (width + widthSpace) * col1 + width / 2 - 13); Canvas.SetTop(img, borderSpace + heightSpace * row1 - 24); Canvas.SetZIndex(img, 1); }
public static void BreakGroup(SchemaView view) { Canvas parent = (Canvas)view.MainPanel; Viewbox g = view.SelectionManager.SelectedObjects[0] as Viewbox; try { Canvas gc = (Canvas)g.Child; while (gc.Children.Count > 0) { System.Windows.FrameworkElement child = gc.Children[0] as System.Windows.FrameworkElement; //this code need for ungrouping not stretched shapes child.SetValue(System.Windows.Controls.Panel.MarginProperty, System.Windows.DependencyProperty.UnsetValue); //Rect b=VisualTreeHelper.GetContentBounds(child); Rect b = VisualTreeHelper.GetDescendantBounds(child); double left = Canvas.GetLeft(child); double top = Canvas.GetTop(child); left = double.IsNaN(left) ? 0 : left; top = double.IsNaN(top) ? 0 : top; if ((child is Shape) && child.ReadLocalValue(System.Windows.Shapes.Shape.StretchProperty).Equals(System.Windows.DependencyProperty.UnsetValue)) { child.Width = b.Width; child.Height = b.Height; Canvas.SetLeft(child, left + b.X); Canvas.SetTop(child, top + b.Y); child.SetValue(System.Windows.Shapes.Shape.StretchProperty, System.Windows.Media.Stretch.Fill); gc.UpdateLayout(); } // excluding rotate from common matrix // need to separate scale*skew matrix on scale and transform transformations Matrix matrGtr = ((Transform)child.TransformToVisual(parent)).Value; double x = matrGtr.OffsetX; double y = matrGtr.OffsetY; double angleY = Math.Atan(matrGtr.M12 / matrGtr.M11) * 180 / Math.PI; matrGtr.OffsetY = 0; matrGtr.OffsetX = 0; RotateTransform rt = new RotateTransform(angleY); matrGtr.Rotate(-angleY); TransformGroup gtr = new TransformGroup(); gtr.Children.Add(new MatrixTransform(matrGtr)); gtr.Children.Add(rt); child.RenderTransform = gtr; child.RenderTransformOrigin = new Point(0.5, 0.5); Point pO = new Point(child.Width * child.RenderTransformOrigin.X, child.Height * child.RenderTransformOrigin.Y); Point p = gtr.Transform(pO); Canvas.SetLeft(child, x - (pO - p).X); Canvas.SetTop(child, y - (pO - p).Y); gc.Children.Remove(child); parent.Children.Add(child); //tool.NotifyObjectCreated(child); } g.Child = null; //tool.NotifyObjectDeleted(g); parent.Children.Remove(g); view.SelectionManager.SelectObject(null); } catch (Exception) { } }
// Connect left and up/down from row1,col1 to row2,col2 private void ConnectLoop(int row1, int col1, int row2, int col2) { Line connect; ImageSource arrow = MainWindow.ImageSourceFromBitmap(Properties.Resources.Arrow); Image img; int space = 26; List <CodeLine> working = new List <CodeLine>(); for (int row = Math.Min(row1, row2); row <= Math.Max(row1, row2); row++) { CodeLine codeLine = HasSymbol(row, col2); if (null != codeLine) { working.Add(codeLine); space = Math.Max(space, codeLine.linkDist + 4); } } space = Math.Min(space, (int)widthSpace - 4); foreach (CodeLine codeLine in working) { codeLine.linkDist = space; } connect = new Line() { X1 = borderSpace + (width + widthSpace) * col1, X2 = borderSpace + (width + widthSpace) * col2 - space, Y1 = borderSpace + heightSpace * row1 + height / 2, Y2 = borderSpace + heightSpace * row1 + height / 2, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); connect = new Line() { X1 = borderSpace + (width + widthSpace) * col2 - space, X2 = borderSpace + (width + widthSpace) * col2 - space, Y1 = borderSpace + heightSpace * row1 + height / 2, Y2 = borderSpace + heightSpace * row2 + height / 2, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); connect = new Line() { X1 = borderSpace + (width + widthSpace) * col2 - space, X2 = borderSpace + (width + widthSpace) * col2, Y1 = borderSpace + heightSpace * row2 + height / 2, Y2 = borderSpace + heightSpace * row2 + height / 2, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); img = new Image() { Width = 24, Height = 24, Source = arrow, }; RotateTransform rotateTransform = new RotateTransform(); rotateTransform.CenterX = 12; rotateTransform.CenterY = 12; rotateTransform.Angle = 180; img.RenderTransform = new TransformGroup(); ((TransformGroup)img.RenderTransform).Children.Add(rotateTransform); canvas.Children.Add(img); Canvas.SetLeft(img, borderSpace + (width + widthSpace) * col2 - 24); Canvas.SetTop(img, borderSpace + heightSpace * row2 + height / 2 - 11); Canvas.SetZIndex(img, 1); }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart) { if (IsNew) { Canvas.SetTop(Rectangle, ZeroReference); Canvas.SetLeft(Rectangle, Data.Left); Rectangle.Width = Data.Width; Rectangle.Height = 0; } if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel))) { Canvas.SetTop(DataLabel, ZeroReference); Canvas.SetLeft(DataLabel, current.ChartLocation.X); } Func <double> getY = () => { double y; #pragma warning disable 618 if (LabelPosition == BarLabelPosition.Parallel || LabelPosition == BarLabelPosition.Merged) #pragma warning restore 618 { if (Transform == null) { Transform = new RotateTransform(270); } y = Data.Top + Data.Height / 2 + DataLabel.ActualWidth * .5; DataLabel.RenderTransform = Transform; } else if (LabelPosition == BarLabelPosition.Perpendicular) { y = Data.Top + Data.Height / 2 - DataLabel.ActualHeight * .5; } else { if (ZeroReference > Data.Top) { y = Data.Top - DataLabel.ActualHeight; if (y < 0) { y = Data.Top; } } else { y = Data.Top + Data.Height; if (y + DataLabel.ActualHeight > chart.DrawMargin.Height) { y -= DataLabel.ActualHeight; } } } return(y); }; Func <double> getX = () => { double x; #pragma warning disable 618 if (LabelPosition == BarLabelPosition.Parallel || LabelPosition == BarLabelPosition.Merged) #pragma warning restore 618 { x = Data.Left + Data.Width / 2 - DataLabel.ActualHeight / 2; } else if (LabelPosition == BarLabelPosition.Perpendicular) { x = Data.Left + Data.Width / 2 - DataLabel.ActualWidth / 2; } else { x = Data.Left + Data.Width / 2 - DataLabel.ActualWidth / 2; if (x < 0) { x = 2; } if (x + DataLabel.ActualWidth > chart.DrawMargin.Width) { x -= x + DataLabel.ActualWidth - chart.DrawMargin.Width + 2; } } return(x); }; if (chart.View.DisableAnimations) { Rectangle.Width = Data.Width; Rectangle.Height = Data.Height; Canvas.SetTop(Rectangle, Data.Top); Canvas.SetLeft(Rectangle, Data.Left); if (DataLabel != null) { DataLabel.UpdateLayout(); Canvas.SetTop(DataLabel, getY()); Canvas.SetLeft(DataLabel, getX()); } if (HoverShape != null) { Canvas.SetTop(HoverShape, Data.Top); Canvas.SetLeft(HoverShape, Data.Left); HoverShape.Height = Data.Height; HoverShape.Width = Data.Width; } return; } var animSpeed = chart.View.AnimationsSpeed; if (DataLabel != null) { DataLabel.UpdateLayout(); DataLabel.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(getX(), animSpeed)); DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(getY(), animSpeed)); } Rectangle.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(Data.Left, animSpeed)); Rectangle.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(Data.Top, animSpeed)); Rectangle.BeginAnimation(FrameworkElement.WidthProperty, new DoubleAnimation(Data.Width, animSpeed)); Rectangle.BeginAnimation(FrameworkElement.HeightProperty, new DoubleAnimation(Data.Height, animSpeed)); if (HoverShape != null) { Canvas.SetTop(HoverShape, Data.Top); Canvas.SetLeft(HoverShape, Data.Left); HoverShape.Height = Data.Height; HoverShape.Width = Data.Width; } }
public void Display() { Cursor cursor = Mouse.OverrideCursor; Mouse.OverrideCursor = Cursors.Wait; try { canvas.Children.Clear(); codeLines.Clear(); subs.Clear(); sbDocument = mainWindow.GetActiveDocument(); //scaleView = 1; //scaleTransform.ScaleX = 1.0; //scaleTransform.ScaleY = 1.0; lastHighlight = null; Parse(); maxrow = 0; maxcol = 0; foreach (CodeLine codeLine in codeLines) { int row = codeLine.row; int col = codeLine.col; if (codeLine.block != eBlock.START && codeLine.block != eBlock.SUB && codeLine.block != eBlock.ELSE && codeLine.block != eBlock.ELSEIF) { ConnectEndIf(row, col, 0, col); } if (codeLine.block == eBlock.ELSE || codeLine.block == eBlock.ELSEIF) { Line connect = new Line() { X1 = borderSpace + (width + widthSpace) * col + 2, X2 = borderSpace + (width + widthSpace) * col - widthSpace - 2, Y1 = borderSpace + heightSpace * row + height / 2, Y2 = borderSpace + heightSpace * row + height / 2, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect); int testCol = col - 1; while (null == HasSymbol(row, testCol) && testCol > 0) { Line connect2 = new Line() { X1 = borderSpace + (width + widthSpace) * (testCol + 1) + 2, X2 = borderSpace + (width + widthSpace) * testCol - widthSpace - 2, Y1 = borderSpace + heightSpace * row + height / 2, Y2 = borderSpace + heightSpace * row + height / 2, Stroke = new SolidColorBrush(foreground), StrokeThickness = 2, }; canvas.Children.Add(connect2); testCol--; } ImageSource arrow = MainWindow.ImageSourceFromBitmap(Properties.Resources.Arrow); Image img = new Image() { Width = 24, Height = 24, Source = arrow, }; RotateTransform rotateTransform = new RotateTransform(); rotateTransform.CenterX = 12; rotateTransform.CenterY = 12; rotateTransform.Angle = 180; img.RenderTransform = new TransformGroup(); ((TransformGroup)img.RenderTransform).Children.Add(rotateTransform); canvas.Children.Add(img); Canvas.SetLeft(img, borderSpace + (width + widthSpace) * col - 22); Canvas.SetTop(img, borderSpace + heightSpace * row + height / 2 - 11); Canvas.SetZIndex(img, 1); } if (codeLine.block == eBlock.IF || codeLine.block == eBlock.ELSEIF) { if (TFshape) { Grid imgTrue = CodeShape.GetBlock(Colors.Green, "T", 24, 24, eShape.ELLIPSE); canvas.Children.Add(imgTrue); Canvas.SetLeft(imgTrue, borderSpace + (width + widthSpace) * col + width / 2 - imgTrue.Width / 2); Canvas.SetTop(imgTrue, borderSpace + heightSpace * row + height + 2); Canvas.SetZIndex(imgTrue, 1); Grid imgFalse = CodeShape.GetBlock(Colors.Red, "F", 24, 24, eShape.ELLIPSE); canvas.Children.Add(imgFalse); Canvas.SetLeft(imgFalse, borderSpace + (width + widthSpace) * col + width + 2); Canvas.SetTop(imgFalse, borderSpace + heightSpace * row + height / 2 - imgTrue.Height / 2); Canvas.SetZIndex(imgFalse, 1); } else { TextBlock condition = new TextBlock() { Foreground = new SolidColorBrush(foreground), Text = "True", }; condition.Measure(new Size(double.MaxValue, double.MaxValue)); canvas.Children.Add(condition); Canvas.SetLeft(condition, borderSpace + (width + widthSpace) * col + width / 2 + 2); Canvas.SetTop(condition, borderSpace + heightSpace * row + height + 2); condition = new TextBlock() { Foreground = new SolidColorBrush(foreground), Text = "False", }; condition.Measure(new Size(double.MaxValue, double.MaxValue)); canvas.Children.Add(condition); Canvas.SetLeft(condition, borderSpace + (width + widthSpace) * col + width + 2); Canvas.SetTop(condition, borderSpace + heightSpace * row + height / 2 - condition.DesiredSize.Height - 2); } } if (codeLine.block == eBlock.ENDIF) { int rowIf = codeLine.rootLine.row; for (int colIf = 0; colIf <= maxcol; colIf++) { CodeLine cl = HasSymbol(rowIf, colIf); if (null != cl && cl.rootLine == codeLine.rootLine) { ConnectEndIf(codeLine.row, codeLine.col, rowIf, colIf); } } } if (codeLine.block == eBlock.ENDFOR || codeLine.block == eBlock.ENDWHILE || codeLine.block == eBlock.GOTO) { ConnectLoop(codeLine.row, codeLine.col, codeLine.rootLine.row, codeLine.rootLine.col); } Color color; switch (codeLine.block) { case eBlock.IF: case eBlock.ELSE: case eBlock.ELSEIF: color = MainWindow.IntToColor(MainWindow.CHART_CONDITION_COLOR); break; case eBlock.START: case eBlock.SUB: color = MainWindow.IntToColor(MainWindow.CHART_START_COLOR); break; case eBlock.GOTO: case eBlock.LABEL: case eBlock.CALL: color = MainWindow.IntToColor(MainWindow.CHART_CALL_COLOR); break; case eBlock.FOR: case eBlock.ENDFOR: color = MainWindow.IntToColor(MainWindow.CHART_FOR_COLOR); break; case eBlock.WHILE: case eBlock.ENDWHILE: color = MainWindow.IntToColor(MainWindow.CHART_WHILE_COLOR); break; default: color = MainWindow.IntToColor(MainWindow.CHART_STATEMENT_COLOR); break; } CodeShape border = new CodeShape(codeLine, width, height, color); codeLine.border = border; border.grid.MouseDown += new MouseButtonEventHandler(codeClick); canvas.Children.Add(border.grid); Canvas.SetLeft(border.grid, borderSpace + (width + widthSpace) * col); Canvas.SetTop(border.grid, borderSpace + heightSpace * row++); maxcol = Math.Max(maxcol, col); maxrow = Math.Max(maxrow, row); } canvas.Width = -widthSpace + 2 * borderSpace + (width + widthSpace) * (maxcol + 1); canvas.Height = borderSpace + heightSpace * maxrow; } catch (Exception ex) { MainWindow.Errors.Add(new Error("Flow Chart : " + ex.Message)); OnError(); } Mouse.OverrideCursor = cursor; }
private void Landscape_Selected(object sender, RoutedEventArgs e) { RotateTransform rt = new RotateTransform(0); imgMain.LayoutTransform = rt; }
private void BtnRotate_Click(object sender, RoutedEventArgs e) { RotateTransform transform = new RotateTransform(20); this.myCanvas.LayoutTransform = transform; }
private async void button1_Click(object sender, EventArgs e) { int flag = -900; int flag1 = 0; int flag2 = 200; int flag3 = 0; int flag4 = 0; pov.Angle = 65.339; for (int i = 0; i < 8 & BR.IsChecked == true; i++) { string pathImage = "../../Profile_picture_of_TehPlaneFreak.png"; BitmapImage imageFile = new BitmapImage(new Uri(pathImage, UriKind.Relative)); Image imageControl = new Image(); imageControl.Source = imageFile; imageControl.Width = 70; imageControl.Height = 70; imageControl.Margin = new Thickness(100 + 40 * i, 40 * i, 0, 0); TransformGroup tr = new TransformGroup(); SkewTransform sktr = new SkewTransform(); RotateTransform rot = new RotateTransform(); rot.Angle = 65.339; tr.Children.Add(sktr); tr.Children.Add(rot); imageControl.RenderTransform = tr; Background.Children.Add(imageControl); } for (int i = 1; i < 8 & BR.IsChecked == true; i++) { string pathImage = "../../Profile_picture_of_TehPlaneFreak.png"; BitmapImage imageFile = new BitmapImage(new Uri(pathImage, UriKind.Relative)); Image imageControl = new Image(); imageControl.Source = imageFile; imageControl.Width = 70; imageControl.Height = 70; imageControl.Margin = new Thickness(380 - 40 * i, 280 + 40 * i, 0, 0); TransformGroup tr = new TransformGroup(); SkewTransform sktr = new SkewTransform(); RotateTransform rot = new RotateTransform(); rot.Angle = 65.339; tr.Children.Add(sktr); tr.Children.Add(rot); imageControl.RenderTransform = tr; Background.Children.Add(imageControl); } for (int i = 0; i < 100; i++) { await Task.Delay(1); pictureBox1.Margin = new Thickness(flag++, 0, 0, 0); } pictureBox2.Opacity = 100; for (int i = 0; i < 200; i++) { await Task.Delay(1); pictureBox1.Margin = new Thickness(flag++, 0, 0, 0); pictureBox2.Margin = new Thickness(flag3 -= 3, flag2--, 0, 0); } pictureBox2.Opacity = 0; for (int i = 0; i < 45; i++) { pov.Angle++; } for (int i = 0; i < 500; pov.Angle++, i++) { await Task.Delay(1); pictureBox1.Margin = new Thickness(flag++, flag1--, 0, 0); } for (int i = 0; i < 100; i++) { await Task.Delay(1); pictureBox1.Margin = new Thickness(flag, flag1, 0, flag4--); } }
/// <summary> /// Does a recursive deep copy of the specified transform. /// </summary> /// <param name="transform">The transform to clone.</param> /// <returns>A deep copy of the specified transform, or null if the specified transform is null.</returns> /// <exception cref="System.ArgumentException">Thrown if the type of the Transform is not recognized.</exception> internal static Transform CloneTransform(Transform transform) { ScaleTransform scaleTransform = null; RotateTransform rotateTransform = null; SkewTransform skewTransform = null; TranslateTransform translateTransform = null; MatrixTransform matrixTransform = null; TransformGroup transformGroup = null; if (transform == null) { return(null); } Type transformType = transform.GetType(); if ((scaleTransform = transform as ScaleTransform) != null) { return(new ScaleTransform() { CenterX = scaleTransform.CenterX, CenterY = scaleTransform.CenterY, ScaleX = scaleTransform.ScaleX, ScaleY = scaleTransform.ScaleY, }); } else if ((rotateTransform = transform as RotateTransform) != null) { return(new RotateTransform() { Angle = rotateTransform.Angle, CenterX = rotateTransform.CenterX, CenterY = rotateTransform.CenterY, }); } else if ((skewTransform = transform as SkewTransform) != null) { return(new SkewTransform() { AngleX = skewTransform.AngleX, AngleY = skewTransform.AngleY, CenterX = skewTransform.CenterX, CenterY = skewTransform.CenterY, }); } else if ((translateTransform = transform as TranslateTransform) != null) { return(new TranslateTransform() { X = translateTransform.X, Y = translateTransform.Y, }); } else if ((matrixTransform = transform as MatrixTransform) != null) { return(new MatrixTransform() { Matrix = matrixTransform.Matrix, }); } else if ((transformGroup = transform as TransformGroup) != null) { TransformGroup group = new TransformGroup(); foreach (Transform childTransform in transformGroup.Children) { group.Children.Add(CloneTransform(childTransform)); } return(group); } Debug.Assert(false, "Unexpected Transform type encountered"); return(null); }
public VerticalAxisTitle() { LayoutTransform = new RotateTransform(-90); VerticalAlignment = VerticalAlignment.Center; FontSize = 16; }
/// <summary> /// zdarzenie odpowiadajace za poruszanie sie pojazdu /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Departure_Tick(object sender, EventArgs e) { //punkt na srodku przedniej osi pojazdu Point mycarpoint = new Point(vehicleControl.Margin.Left + vehicleControl.ActualWidth / 2, vehicleControl.Margin.Top + vehicleControl.ActualHeight / 5); //odleglosc miedzy punktem X pojazdu a punktem X punktu docelowego double xDistance = Math.Abs(whereTo[0].X - mycarpoint.X); //odleglosc miedzy punktem Y pojazdu a punktem Y punktu docelowego double yDistance = Math.Abs(whereTo[0].Y - mycarpoint.Y); //proporcje przesuwania sie pojazdow na osi x i y double xVelocity = xDistance / (xDistance + yDistance); double yVelocity = yDistance / (xDistance + yDistance); //pobranie obecnego kata obrocenia pojazdu double angle = (vehicleControl.RenderTransform as RotateTransform).Angle; //obliczenie wartosci przesuniecia sie punktu X na osi uwzgledniajac kat pod jakim pojazd znajduje sie wlocie double xRotationValue = Math.Cos((angle * 2 * Math.PI) / 360) * vehicleControl.ActualWidth / 2; //obliczenie wartosci przesuniecia sie punktu Y na osi uwzgledniajac kat pod jakim pojazd znajduje sie wlocie double yRotationValue = Math.Sin((angle * 2 * Math.PI) / 360) * vehicleControl.ActualWidth / 2; //punkt lewego gornego rogu pojazdu z uwzglednieniem nowego katu Point vehicleLeftTop = new Point(vehicleControl.Margin.Left + vehicleControl.ActualWidth / 2 - xRotationValue, vehicleControl.Margin.Top - yRotationValue); //punkt prawego gornego rogu pojazdu z uwzglednieniem nowego katu Point vehicleRightTop = new Point(vehicleControl.Margin.Left + vehicleControl.ActualWidth / 2 + xRotationValue, vehicleControl.Margin.Top + yRotationValue); //odleglosc gornego lewego punktu pojazdu od punktu do ktorego zmierza double distanceFromTopLeft = Math.Sqrt(Math.Pow((whereTo[0].X - vehicleLeftTop.X), 2) + Math.Pow((whereTo[0].Y - vehicleLeftTop.Y), 2)); //odleglosc gornego prawego punktu pojazdu od punktu do ktorego zmierza double distanceFromTopRight = Math.Sqrt(Math.Pow((whereTo[0].X - vehicleRightTop.X), 2) + Math.Pow((whereTo[0].Y - vehicleRightTop.Y), 2)); //roznica pomiedzy rogami pojazdow a punktem docelowym double checkDistance = distanceFromTopRight - distanceFromTopLeft; //jesli lewy gorny punkt pojazdu jest dalej od punktu docelowego niz prawy gorny punkt pojazdu //wtedy pojazd obraca sie zgodnie ze wskazowkami zegara, aby odleglosci te zmierzaly do zera //a co za tym idzie, zeby pojazd jechaly prosto na wyznaczony punkt, a nie bokiem if (checkDistance > 2) { double turn = speed > 3.9 ? 3.9 : speed; RotateTransform rotateVehicle = vehicleControl.RenderTransform as RotateTransform; //obrocenie pojazdu o 1.5 radiana RotateTransform rotate = new RotateTransform(rotateVehicle.Angle - turn); //przypisanie nowego kata obrotu pojazdu vehicleControl.RenderTransform = rotate; } else if (checkDistance < -2) { double turn = speed > 3.9 ? 3.9 : speed; RotateTransform rotateVehicle = vehicleControl.RenderTransform as RotateTransform; //obrocenie pojazdu o 1.5 radiana RotateTransform rotate = new RotateTransform(rotateVehicle.Angle + turn); //przypisanie nowego kata obrotu pojazdu vehicleControl.RenderTransform = rotate; } //przesuniecie pojazdu do nowej pozycji w zaleznosci od tego z ktorej strony punktu docelowego byl na poczatku if (whereTo[0].X > mycarpoint.X) { vehicleControl.Margin = new Thickness(vehicleControl.Margin.Left + xVelocity * speed, vehicleControl.Margin.Top, 0, 0); } if (whereTo[0].X < mycarpoint.X) { vehicleControl.Margin = new Thickness(vehicleControl.Margin.Left - xVelocity * speed, vehicleControl.Margin.Top, 0, 0); } if (whereTo[0].Y > mycarpoint.Y) { vehicleControl.Margin = new Thickness(vehicleControl.Margin.Left, vehicleControl.Margin.Top + yVelocity * speed, 0, 0); } if (whereTo[0].Y < mycarpoint.Y) { vehicleControl.Margin = new Thickness(vehicleControl.Margin.Left, vehicleControl.Margin.Top - yVelocity * speed, 0, 0); } //jesli odleglosc pojazdu od punktu docelowego jest mniejsza niz dlugosc pojazdu... if ((whereTo[0].X - mycarpoint.X <vehicleControl.ActualHeight && whereTo[0].X - mycarpoint.X> -vehicleControl.ActualHeight) && (whereTo[0].Y - mycarpoint.Y <vehicleControl.ActualHeight && whereTo[0].Y - mycarpoint.Y> -vehicleControl.ActualHeight)) { //...wtedy usuwany jest obecny punkt do ktorego zmierzal whereTo.RemoveAt(0); //jezeli juz dojechal do wszystkich punktow pokolei if (!whereTo.Any()) { (vehicleControl.Parent as Grid).Children.Remove(vehicleControl); (sender as DispatcherTimer).Tick -= Departure_Tick; (sender as DispatcherTimer).Stop(); } } //zwiekszenie predkosci pojazdu speed = speed + 0.11; }
private void ApplyTextStyle(TextBlock block, double y, bool applyTransforms, ExtTextOutOptions? options) { block.Foreground = new SolidColorBrush(_currentState.TextColor); if (_currentState.BackgroundMode == MixMode.OPAQUE || (options.HasValue && (options.Value & ExtTextOutOptions.ETO_OPAQUE) == ExtTextOutOptions.ETO_OPAQUE)) { #if !NETFX_CORE block.Background = new SolidColorBrush(_currentState.BackgroundColour); #endif } var font = _currentState.CurrentFont; if (font != null) { block.FontFamily = new FontFamily(font.FaceName); block.FontSize = 12; // TODO //block.FontStretch = FontStretches.UltraExpanded; // TODO if (font.Height != 0) { block.FontSize = Math.Abs(ScaleHeight(font.Height)); } if (font.IsItalic) { #if NETFX_CORE block.FontStyle = FontStyle.Italic; #else block.FontStyle = FontStyles.Italic; #endif } #if !NETFX_CORE if (font.IsStrikeout) { block.TextDecorations.Add(TextDecorations.Strikethrough); } if (font.IsUnderline) { block.TextDecorations.Add(TextDecorations.Underline); } #endif if (font.Weight > 0) { #if NETFX_CORE block.FontWeight = new FontWeight() { Weight = (ushort)font.Weight }; #else block.FontWeight = FontWeight.FromOpenTypeWeight(font.Weight); #endif } if (applyTransforms) { Canvas.SetTop(block, y - block.FontSize); // Rotation if (font.Escapement != 0) { var rotate = new RotateTransform { Angle = -1 * font.Escapement / 10.0 #if !NETFX_CORE , CenterY = block.FontSize * block.FontFamily.Baseline #endif }; block.RenderTransform = rotate; } } } }
public static int CreateButton(ref ButtonProperty target) { int i; for (i = 0; i < 64; i++) { if (!buff_button[i].reg) { buff_button[i].reg = true; break; } if (buff_button[i].restore) { buff_button[i].restore = false; buff_button[i].button.Visibility = Visibility.Visible; buff_button[i].button.Click -= buff_button[i].bp.click; goto label1; } } Button button = new Button(); buff_button[i].button = button; label1 :; buff_button[i].bp = target; button = buff_button[i].button; target.margin.Left = target.x; // bp.margin.Right = screenX - bp.x - bp.Width; target.margin.Top = target.y; target.margin.Bottom = screenY - target.y - target.Width; button.Margin = target.margin; button.Content = target.text; if (target.angle > 0) { RotateTransform rtf = new RotateTransform(); rtf.Angle = target.angle; button.RenderTransform = rtf; } if (target.color.A > 0) { button.Foreground = new SolidColorBrush(target.color); } else { button.Foreground = new SolidColorBrush(font_color); } if (target.bk_color.A > 0) { button.Background = new SolidColorBrush(target.bk_color); } if (target.size > 0) { button.FontSize = target.size; } if (target.click != null) { button.Click += target.click; } button.DataContext = target.data; main_canv.Children.Add(button); return(i + 256); }
public static void NOPH_Graphics_drawTextAngle(int c_graphics, int c_text, int x, int y, int flags, int angle) { // mre.Reset(); int copy_graphics, copy_c_text, copy_x, copy_y, copy_flags, copy_angle; copy_graphics = c_graphics; copy_c_text = c_text; copy_x = x; copy_y = y; copy_flags = flags; copy_angle = angle; Color curr_pen = curr_color; int font_size = currFontSize; //todomt2 - what about flags? String text = CRunTime.charPtrToString(copy_c_text); System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { Canvas graphics = (Canvas)CRunTime.getRegisteredObject(copy_graphics); if (copy_angle == 0) { TextBlock tb = new TextBlock(); tb.FontFamily = new FontFamily("FreeSans"); tb.FontSize = font_size; tb.FontStyle = FontStyles.Normal; tb.Foreground = new SolidColorBrush(curr_pen); tb.Text = NBidi.NBidi.LogicalToVisual(text); tb.SetValue(Canvas.LeftProperty, (double)(copy_x));// - (tb.ActualWidth / 2))); tb.SetValue(Canvas.TopProperty, (double)(copy_y - tb.ActualHeight + 5 )); children_list.Add(tb); } else { TextBlock tb = new TextBlock(); tb.FontFamily = new FontFamily("FreeSans"); tb.FontSize = font_size; tb.FontStyle = FontStyles.Normal; tb.Foreground = new SolidColorBrush(curr_pen); tb.SetValue(Canvas.LeftProperty, (double)(copy_x));// - (tb.ActualWidth / 2))); tb.SetValue(Canvas.TopProperty, (double)(copy_y - tb.ActualHeight - 20.0)); tb.Text = NBidi.NBidi.LogicalToVisual(text); RotateTransform rt = new RotateTransform(); rt.Angle = copy_angle; tb.RenderTransform = rt; children_list.Add(tb); } //mre.Set(); }); //mre.WaitOne(); }
/// <summary> /// Initializes this instance. /// </summary> internal void Initialize() { double desiredHeight = 0; double labelSize = 0; //if (m_MinValue == m_startValue + m_Interval) CalculateAutoInterval(); GenerateLabels(); if (this.ActualHeight > 0 && this.ActualWidth > 0) { this.Children.Clear(); double xAxisWidthStep = this.ActualWidth / ((MIntervalCount > 0) ? MIntervalCount : 1); double xAxisWidthPosition = this.DataToPoint(MStartValue); double minorstep = 0; //m_offset = this.DataToPoint(m_MinValue + m_Interval); Rect oldRect = new Rect(0, 0, 0, 0); AxisLine = new Line(); AxisLine.X1 = 0; AxisLine.X2 = this.ActualWidth; AxisLine.Y1 = 0; AxisLine.Y2 = 0; Binding binding = new Binding(); binding.Path = new PropertyPath("AxisLineStyle"); binding.Source = this; AxisLine.SetBinding(Line.StyleProperty, binding); Labels = new List<ContentControl>(); MajorTickLines = new List<Line>(); MinorTickLines = new List<Line>(); for (int i = 0; i < this.MLabels.Count; i++) { ContentControl label = new ContentControl(); label.Content = MLabels[i]; Binding labelTemplateBinding = new Binding(); labelTemplateBinding.Path = new PropertyPath("LabelTemplate"); labelTemplateBinding.Source = this; label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding); label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); //label.RenderTransformOrigin = new Point(0.5, 0.5); label.RenderTransform = labelRotation; Labels.Add(label); Line tickLine = new Line(); double labelPadding = 0; Binding styleBinding = new Binding(); styleBinding.Path = new PropertyPath("MajorLineStyle"); styleBinding.Source = this; tickLine.SetBinding(Line.StyleProperty, styleBinding); tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); tickLine.X1 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2); tickLine.X2 = xAxisWidthPosition - (tickLine.DesiredSize.Width / 2); switch (this.MajorTicksPosition) { case TickPosition.Inside: tickLine.Y1 = 0; Binding tickSizeInsideBinding = new Binding(); tickSizeInsideBinding.Path = new PropertyPath("MajorLineSize"); tickSizeInsideBinding.Source = this; tickSizeInsideBinding.Converter = new NegativeConverter(); tickLine.SetBinding(Line.Y2Property, tickSizeInsideBinding); if (this.ShowMajorTicks) { labelPadding = 0; desiredHeight = 0; } break; case TickPosition.Cross: Binding tickSizeNegativeCrossBinding = new Binding(); tickSizeNegativeCrossBinding.Path = new PropertyPath("MajorLineSize"); tickSizeNegativeCrossBinding.Source = this; tickSizeNegativeCrossBinding.Converter = new NegativeHalfConverter(); tickLine.SetBinding(Line.Y1Property, tickSizeNegativeCrossBinding); Binding tickSizeCrossBinding = new Binding(); tickSizeCrossBinding.Path = new PropertyPath("MajorLineSize"); tickSizeCrossBinding.Source = this; tickSizeCrossBinding.Converter = new HalfValueConverter(); tickLine.SetBinding(Line.Y2Property, tickSizeCrossBinding); if (this.ShowMajorTicks) { labelPadding = tickLine.Y2; desiredHeight = MajorLineSize / 2; } break; case TickPosition.Outside: tickLine.Y1 = 0; Binding tickSizeBinding = new Binding(); tickSizeBinding.Path = new PropertyPath("MajorLineSize"); tickSizeBinding.Source = this; tickLine.SetBinding(Line.Y2Property, tickSizeBinding); if (this.ShowMajorTicks) { labelPadding = tickLine.Y2; desiredHeight = MajorLineSize; } break; } Binding ticklineVisibilityBinding = new Binding(); ticklineVisibilityBinding.Path = new PropertyPath("ShowMajorTicks"); ticklineVisibilityBinding.Source = this; ticklineVisibilityBinding.Converter = new BooleanToVisibilityConverter(); tickLine.SetBinding(Line.VisibilityProperty, ticklineVisibilityBinding); MajorTickLines.Add(tickLine); this.Children.Add(tickLine); if (!(i == this.MLabels.Count - 1)) { double minorWidth = xAxisWidthStep; minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = new Line(); Binding minorstyleBinding = new Binding(); minorstyleBinding.Path = new PropertyPath("MinorLineStyle"); minorstyleBinding.Source = this; minorLine.SetBinding(Line.StyleProperty, minorstyleBinding); minorLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); minorLine.X1 = (xAxisWidthPosition + minorstep * (j + 1)); minorLine.X2 = (xAxisWidthPosition + minorstep * (j + 1)); switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.Y1 = 0; Binding minortickInsideSizeBinding = new Binding(); minortickInsideSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickInsideSizeBinding.Source = this; minortickInsideSizeBinding.Converter = new NegativeConverter(); minorLine.SetBinding(Line.Y2Property, minortickInsideSizeBinding); break; case TickPosition.Cross: Binding minortickNegativeCrossSizeBinding = new Binding(); minortickNegativeCrossSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickNegativeCrossSizeBinding.Source = this; minortickNegativeCrossSizeBinding.Converter = new NegativeHalfConverter(); minorLine.SetBinding(Line.Y1Property, minortickNegativeCrossSizeBinding); Binding minortickCrossSizeBinding = new Binding(); minortickCrossSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickCrossSizeBinding.Source = this; minortickCrossSizeBinding.Converter = new HalfValueConverter(); minorLine.SetBinding(Line.Y2Property, minortickCrossSizeBinding); break; case TickPosition.Outside: minorLine.Y1 = 0; Binding minortickSizeBinding = new Binding(); minortickSizeBinding.Path = new PropertyPath("MinorLineSize"); minortickSizeBinding.Source = this; minorLine.SetBinding(Line.Y2Property, minortickSizeBinding); break; } MinorTickLines.Add(minorLine); this.Children.Add(minorLine); } } if (this.LabelAngle == 0) { Canvas.SetLeft(label, xAxisWidthPosition - (label.DesiredSize.Width / 2)); Canvas.SetTop(label, desiredHeight); labelSize = Math.Max(labelSize, label.DesiredSize.Height); } else { Canvas.SetLeft(label, xAxisWidthPosition - (rotatedRect.Width / 2) - rotatedRect.X); Canvas.SetTop(label, desiredHeight - rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Height); } //labelSize = Math.Max(labelSize, label.ActualHeight); this.Children.Add(label); xAxisWidthPosition += xAxisWidthStep; } header = new ContentControl(); header.DataContext = null; Binding contentBinding = new Binding(); contentBinding.Path = new PropertyPath("Header"); contentBinding.Source = this; header.SetBinding(ContentControl.ContentProperty, contentBinding); Binding headerTemplateBinding = new Binding(); headerTemplateBinding.Path = new PropertyPath("HeaderTemplate"); headerTemplateBinding.Source = this; header.SetBinding(ContentControl.ContentTemplateProperty, headerTemplateBinding); header.Measure(new Size(this.ActualHeight, this.ActualWidth)); desiredHeight+=labelSize; Canvas.SetLeft(header, (this.ActualWidth / 2) - (header.DesiredSize.Width / 2)); Canvas.SetTop(header, (this.ActualHeight / 2) - (header.DesiredSize.Height / 2) + desiredHeight); desiredHeight += header.DesiredSize.Height ; this.Children.Add(header); this.Children.Add(AxisLine); IsInitialized = true; this.Chart.AxisHeight = desiredHeight; } // if (this.Chart.AxisHeight < desiredHeight) }