public override void Draw(Cairo.Context dc) { Pen p = IsDashed ? PensAndBrushes.DashedPen : ThePen; float R = (float)(center - p1).Length; // the radius of the circle var diag = new System.Windows.Vector(R, R); Rect re = new System.Windows.Rect(center + diag, center - diag); // BB of the circle System.Windows.Vector v1 = p1 - center, v2 = p2 - center; if (IsPie) { dc.DrawLine(center, p1); //p, dc.DrawLine(center, p2); //p, } float angle2 = (float)(Math.Atan2(v2.Y, v2.X) * 180 / Math.PI); float angle1 = (float)(Math.Atan2(v1.Y, v1.X) * 180 / Math.PI); float angle = angle2 - angle1; float bngle = angle + (angle > 0?-360:360); if ((IsLargeArc && Math.Abs(angle) < 180) || (!IsLargeArc && Math.Abs(angle) > 180)) { angle = bngle; } if (re.Height * re.Width > 0) { dc.Arc(re.Center().X, re.Center().Y, re.Width / 2, angle1, angle);//p, // hack } /* TODO * context.BeginFigure(p1, false, IsPie); * * SweepDirection sd; * if ((v1.X * v2.Y - v1.Y * v2.X > 0) != LargeArc) * sd = SweepDirection.Clockwise; * else * sd = SweepDirection.Counterclockwise; * * context.ArcTo(p2, new Size(r, r), 0, LargeArc, sd, true, false);*/ }
private static void ExportTextShape(RadDiagramTextShape shape, Rect enclosingBounds, RadFixedPage page) { var bounds = new Rect(shape.Bounds.X - enclosingBounds.X, shape.Bounds.Y - enclosingBounds.Y, shape.Bounds.Width, shape.Bounds.Height); var transformGroup = new TransformGroup(); transformGroup.Children.Add(new RotateTransform() { Angle = shape.RotationAngle, CenterX = bounds.Width / 2, CenterY = bounds.Height / 2 }); transformGroup.Children.Add(new TranslateTransform() { X = bounds.X, Y = bounds.Y }); var position = new MatrixPosition(transformGroup.Value); FixedContentEditor containerEditor = CreateEditor(new EditorInfo(page, position, shape, bounds, shape.BorderBrush, shape.RotationAngle), true); containerEditor.DrawRectangle(new Rect(new Point(), bounds.ToSize())); if (shape.Content != null) { var center = bounds.Center(); ExportContent(shape, bounds, shape.RotationAngle, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, center.Y - s.Height / 2); }); } }
public static ColorBase GetColor(Brush brush, double opacity, Rect bounds, double angle = 0) { var solidBrush = brush as SolidColorBrush; if (solidBrush != null) { return GetRgbColor(solidBrush.Color, opacity); } var linerBrush = brush as LinearGradientBrush; if (linerBrush != null) { var startPoint = new Point(bounds.X + linerBrush.StartPoint.X * bounds.Width, bounds.Y + linerBrush.StartPoint.Y * bounds.Height); var endPoint = new Point(bounds.X + linerBrush.EndPoint.X * bounds.Width, bounds.Y + linerBrush.EndPoint.Y * bounds.Height); LinearGradient gradient = new LinearGradient(startPoint, endPoint); foreach (var stop in linerBrush.GradientStops) { gradient.GradientStops.Add(new Telerik.Windows.Documents.Fixed.Model.ColorSpaces.GradientStop(GetRgbColor(stop.Color, opacity), stop.Offset)); } gradient.Position.RotateAt(angle, bounds.Center().X, bounds.Center().Y); return gradient; } var radialBrush = brush as RadialGradientBrush; if (radialBrush != null) { var startPoint = new Point(bounds.X + radialBrush.GradientOrigin.X * bounds.Width, bounds.Y + radialBrush.GradientOrigin.Y * bounds.Height); var endPoint = new Point(bounds.X + radialBrush.Center.X * bounds.Width, bounds.Y + radialBrush.Center.Y * bounds.Height); var radiusX = radialBrush.RadiusX * bounds.Width; var radiusY = radialBrush.RadiusY * bounds.Height; Point scale = new Point(1, 1); if (radiusX > radiusY) scale.X = radiusX / radiusY; else if (radiusY > radiusX) scale.Y = radiusY / radiusX; RadialGradient gradient = new RadialGradient(startPoint, endPoint, 0, Math.Min(radiusX, radiusY)); for (int i = 0; i < radialBrush.GradientStops.Count; i++) { var stop = radialBrush.GradientStops[i]; var color = GetRgbColor(stop.Color, opacity); gradient.GradientStops.Add(new Telerik.Windows.Documents.Fixed.Model.ColorSpaces.GradientStop(color, stop.Offset)); } gradient.Position.ScaleAt(scale.X, scale.Y, bounds.Center().X, bounds.Center().Y); gradient.Position.RotateAt(angle, bounds.Center().X, bounds.Center().Y); return gradient; } return RgbColors.Black; }
public override void Draw(Cairo.Context dc) { Pen p = IsDashed ? PensAndBrushes.DashedPen : ThePen; float R = (float) (center-p1).Length; // the radius of the circle var diag = new System.Windows.Vector(R,R); Rect re = new System.Windows.Rect(center+diag, center-diag); // BB of the circle System.Windows.Vector v1 = p1 - center, v2 = p2 - center; if (IsPie) { dc.DrawLine(center, p1); //p, dc.DrawLine(center, p2); //p, } float angle2 = (float)( Math.Atan2(v2.Y, v2.X) *180 / Math.PI); float angle1 = (float)( Math.Atan2(v1.Y, v1.X) *180 / Math.PI); float angle = angle2 - angle1; float bngle = angle + (angle>0?-360:360); if ( ( IsLargeArc && Math.Abs(angle) < 180) || (!IsLargeArc && Math.Abs(angle) > 180) ) angle = bngle; if (re.Height * re.Width > 0) { dc.Arc( re.Center().X, re.Center().Y, re.Width/2, angle1, angle);//p, // hack } /* TODO context.BeginFigure(p1, false, IsPie); SweepDirection sd; if ((v1.X * v2.Y - v1.Y * v2.X > 0) != LargeArc) sd = SweepDirection.Clockwise; else sd = SweepDirection.Counterclockwise; context.ArcTo(p2, new Size(r, r), 0, LargeArc, sd, true, false);*/ }
private static void ExportConnection(RadDiagramConnection connection, Rect enclosingBounds, RadFixedPage page) { var bounds = new Rect(connection.Bounds.X - enclosingBounds.X, connection.Bounds.Y - enclosingBounds.Y, connection.Bounds.Width, connection.Bounds.Height); var pathGeometry = connection.Geometry as PathGeometry; var pathBounds = connection.ConnectionType == ConnectionType.Bezier ? pathGeometry.Bounds : new Rect(); var transformGroup = new TransformGroup(); transformGroup.Children.Add(new TranslateTransform() { X = bounds.X - pathBounds.X, Y = bounds.Y - pathBounds.Y }); var position = new MatrixPosition(transformGroup.Value); EditorInfo info = new EditorInfo(page, position, connection, bounds, connection.Stroke, 0); FixedContentEditor editor = CreateEditor(info, false); FixedContentEditor filledEditor = CreateEditor(info, true); ExportGeometry(editor, filledEditor, pathGeometry, true); if (connection.Content != null) { var center = bounds.Center(); ExportContent(connection, bounds, 0, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, center.Y - s.Height / 2); }); } }
private static void ExportShape(RadDiagramShape shape, Rect enclosingBounds, RadFixedPage page) { var bounds = new Rect(shape.Bounds.X - enclosingBounds.X, shape.Bounds.Y - enclosingBounds.Y, shape.Bounds.Width, shape.Bounds.Height); var pathGeometry = shape.Geometry as PathGeometry; var transformGroup = new TransformGroup(); #if WPF if (pathGeometry == null) { var streamGeometry = shape.Geometry as StreamGeometry; if (streamGeometry != null) pathGeometry = streamGeometry.AsPathGeometry(); } #endif var geometrySize = shape.Geometry.Bounds.ToSize(); if (IsValidSize(geometrySize) && (geometrySize.Width != bounds.Width || geometrySize.Width != bounds.Width)) transformGroup.Children.Add(new ScaleTransform() { ScaleX = bounds.Width / geometrySize.Width, ScaleY = bounds.Height / geometrySize.Height }); transformGroup.Children.Add(new RotateTransform() { Angle = shape.RotationAngle, CenterX = bounds.Width / 2, CenterY = bounds.Height / 2 }); transformGroup.Children.Add(new TranslateTransform() { X = bounds.X, Y = bounds.Y }); var position = new MatrixPosition(transformGroup.Value); EditorInfo info = new EditorInfo(page, position, shape, bounds, shape.BorderBrush, shape.RotationAngle); FixedContentEditor editor = CreateEditor(info, false); FixedContentEditor filledEditor = CreateEditor(info, true); ExportGeometry(editor, filledEditor, pathGeometry); if (shape.Content != null) { var center = bounds.Center(); ExportContent(shape, bounds, shape.RotationAngle, page, (s) => { return new Point(center.X - s.Width / 2, center.Y - s.Height / 2); }); } }
private static void ExportContainerShape(RadDiagramContainerShape container, Rect enclosingBounds, RadFixedPage page) { var bounds = new Rect(container.Bounds.X - enclosingBounds.X, container.Bounds.Y - enclosingBounds.Y, container.Bounds.Width, container.Bounds.Height); var transformGroup = new TransformGroup(); transformGroup.Children.Add(new RotateTransform() { Angle = container.RotationAngle, CenterX = bounds.Width / 2, CenterY = bounds.Height / 2 }); transformGroup.Children.Add(new TranslateTransform() { X = bounds.X, Y = bounds.Y }); var position = new MatrixPosition(transformGroup.Value); FixedContentEditor containerEditor = CreateEditor(new EditorInfo(page, position, container, bounds, container.BorderBrush, container.RotationAngle), true); containerEditor.DrawRectangle(new Rect(new Point(), bounds.ToSize())); containerEditor.GraphicProperties.StrokeThickness = 0.5; var headerHeight = container.ContentBounds.Y - container.Bounds.Y - DiagramConstants.ContainerMargin; containerEditor.DrawRectangle(new Rect(new Point(0, headerHeight), new Size(bounds.Width, 0.5))); if (container.IsCollapsible) { var buttonTop = headerHeight / 2 - 2.5; var buttonLeft = bounds.Width - 20; if (container.IsCollapsed) { containerEditor.DrawLine(new Point(buttonLeft, buttonTop), new Point(buttonLeft + 4, buttonTop + 4)); containerEditor.DrawLine(new Point(buttonLeft + 4, buttonTop + 4), new Point(buttonLeft + 8, buttonTop)); if (container.CollapsedContent != null) { var contentHeight = container.ActualHeight - headerHeight; ExportContent(container, bounds, container.RotationAngle, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, bounds.Bottom - contentHeight / 2 - s.Height / 2); }, container.CollapsedContent.ToString()); } } else { containerEditor.DrawLine(new Point(buttonLeft, buttonTop + 4), new Point(buttonLeft + 4, buttonTop)); containerEditor.DrawLine(new Point(buttonLeft + 4, buttonTop), new Point(buttonLeft + 8, buttonTop + 4)); } } if (container.Content != null) { ExportContent(container, bounds, container.RotationAngle, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, bounds.Top + headerHeight / 2 - s.Height / 2); }); } }