/// <summary> /// /// </summary> /// <param name="arc"></param> /// <param name="v"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static BaseShape HitTestArc(XArc arc, Vector2 v, double threshold, double dx, double dy) { if (RectangleBounds.GetPointBounds(arc.Point1, threshold, dx, dy).Contains(v)) { return(arc.Point1); } if (RectangleBounds.GetPointBounds(arc.Point2, threshold, dx, dy).Contains(v)) { return(arc.Point2); } if (RectangleBounds.GetPointBounds(arc.Point3, threshold, dx, dy).Contains(v)) { return(arc.Point3); } if (RectangleBounds.GetPointBounds(arc.Point4, threshold, dx, dy).Contains(v)) { return(arc.Point4); } if (RectangleBounds.GetArcBounds(arc, dx, dy).Contains(v)) { return(arc); } return(null); }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="arc"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XArc arc, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var a = GdiArc.FromXArc(arc, dx, dy); if (a.Width <= 0.0 || a.Height <= 0.0) { return; } var _gfx = gfx as Graphics; Brush brush = ToSolidBrush(arc.Style.Fill); Pen pen = ToPen(arc.Style, _scaleToPage); if (arc.IsFilled) { var path = new GraphicsPath(); path.AddArc( _scaleToPage(a.X), _scaleToPage(a.Y), _scaleToPage(a.Width), _scaleToPage(a.Height), (float)a.StartAngle, (float)a.SweepAngle); _gfx.FillPath(brush, path); if (arc.IsStroked) { _gfx.DrawPath(pen, path); } path.Dispose(); } else { if (arc.IsStroked) { _gfx.DrawArc( pen, _scaleToPage(a.X), _scaleToPage(a.Y), _scaleToPage(a.Width), _scaleToPage(a.Height), (float)a.StartAngle, (float)a.SweepAngle); } } brush.Dispose(); pen.Dispose(); }
/// <inheritdoc/> XArc IShapeFactory.Arc(XPoint point1, XPoint point2, XPoint point3, XPoint point4, bool isStroked, bool isFilled) { var style = _editor.Project.CurrentStyleLibrary.Selected; var arc = XArc.Create( point1, point2, point3, point4, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked, isFilled); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, arc); return(arc); }
/// <inheritdoc/> XArc IShapeFactory.Arc(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, bool isStroked, bool isFilled) { var style = _editor.Project.CurrentStyleLibrary.Selected; var arc = XArc.Create( x1, y1, x2, y2, x3, y3, x4, y4, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked, isFilled); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, arc); return(arc); }
/// <summary> /// /// </summary> /// <param name="arc"></param> /// <param name="rect"></param> /// <param name="selected"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static bool HitTestArc(XArc arc, Rect2 rect, ISet <BaseShape> selected, double dx, double dy) { if (RectangleBounds.GetArcBounds(arc, dx, dy).IntersectsWith(rect)) { if (selected != null) { selected.Add(arc); return(false); } else { return(true); } } return(false); }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var a = new GdiArc( Point2.FromXY(arc.Point1.X, arc.Point1.Y), Point2.FromXY(arc.Point2.X, arc.Point2.Y), Point2.FromXY(arc.Point3.X, arc.Point3.Y), Point2.FromXY(arc.Point4.X, arc.Point4.Y)); if (a.Width <= 0.0 || a.Height <= 0.0) { return; } var _gfx = dc as Graphics; Brush brush = ToSolidBrush(arc.Style.Fill); Pen pen = ToPen(arc.Style, _scaleToPage); if (arc.IsFilled) { var path = new GraphicsPath(); path.AddArc( _scaleToPage(a.X + dx), _scaleToPage(a.Y + dy), _scaleToPage(a.Width), _scaleToPage(a.Height), (float)a.StartAngle, (float)a.SweepAngle); _gfx.FillPath(brush, path); } if (arc.IsStroked) { _gfx.DrawArc( pen, _scaleToPage(a.X + dx), _scaleToPage(a.Y + dy), _scaleToPage(a.Width), _scaleToPage(a.Height), (float)a.StartAngle, (float)a.SweepAngle); } brush.Dispose(); pen.Dispose(); }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(arc.Style.Fill)) using (SKPaint pen = ToSKPaintPen(arc.Style, _scaleToPage, _sourceDpi, _targetDpi)) using (var path = new SKPath()) { var a = GdiArc.FromXArc(arc, dx, dy); var rect = new SKRect( _scaleToPage(a.X), _scaleToPage(a.Y), _scaleToPage(a.X + a.Width), _scaleToPage(a.Y + a.Height)); path.AddArc(rect, (float)a.StartAngle, (float)a.SweepAngle); DrawPathInternal(canvas, brush, pen, arc.IsStroked, arc.IsFilled, path); } }
/// <summary> /// Get the bounding rectangle for <see cref="XArc"/> shape. /// </summary> /// <param name="arc"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 GetArcBounds(XArc arc, double dx, double dy) { double x1 = arc.Point1.X + dx; double y1 = arc.Point1.Y + dy; double x2 = arc.Point2.X + dx; double y2 = arc.Point2.Y + dy; double x0 = (x1 + x2) / 2.0; double y0 = (y1 + y2) / 2.0; double r = Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); double x = x0 - r; double y = y0 - r; double width = 2.0 * r; double height = 2.0 * r; return(new Rect2(x, y, width, height)); }
private IArc ReadArc() { var arc = new XArc() { Id = _reader.ReadInt32(), Point1 = ReadPoint(), Point2 = ReadPoint(), StartAngle = _reader.ReadDouble(), SweepAngle = _reader.ReadDouble(), Stroke = ReadColor(), StrokeThickness = _reader.ReadDouble(), Fill = ReadColor(), IsFilled = _reader.ReadBoolean(), IsClosed = _reader.ReadBoolean() }; _natives.Add(arc.Id, arc); return(arc); }
public void Draw(object ds, XArc arc, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var a = WpfArc.FromXArc(arc, dx, dy); var _ds = ds as CanvasDrawingSession; double thickness = arc.Style.Thickness / _state.Zoom; var brush = ToColor(arc.Style.Fill); var pen = ToColor(arc.Style.Stroke); var ss = CreateStrokeStyle(arc.Style); CanvasGeometry g; using (var builder = new CanvasPathBuilder(_ds)) { builder.BeginFigure((float)a.Start.X, (float)a.Start.Y); builder.AddArc( new N.Vector2( (float)a.End.X, (float)a.End.Y), (float)a.Radius.Width, (float)a.Radius.Height, 0f, CanvasSweepDirection.Clockwise, a.IsLargeArc ? CanvasArcSize.Large : CanvasArcSize.Small); builder.EndFigure(CanvasFigureLoop.Open); g = CanvasGeometry.CreatePath(builder); } if (arc.IsFilled) { _ds.FillGeometry(g, brush); } if (arc.IsStroked) { _ds.DrawGeometry(g, pen, (float)thickness, ss); } g.Dispose(); ss.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="arc"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { if (!arc.IsFilled && !arc.IsStroked) { return; } var _dc = dc as DrawingContext; Brush brush = ToSolidBrush(arc.Style.Fill); Pen pen = ToPen(arc.Style, _scaleToPage); var sg = new StreamGeometry(); using (var sgc = sg.Open()) { var a = WpfArc.FromXArc(arc, dx, dy); sgc.BeginFigure( new Point(a.Start.X, a.Start.Y), arc.IsFilled); sgc.ArcTo( new Point(a.End.X, a.End.Y), new Size(a.Radius.Width, a.Radius.Height), 0.0, a.IsLargeArc, SweepDirection.Clockwise); sgc.EndFigure(false); } _dc.DrawGeometry( arc.IsFilled ? brush : null, arc.IsStroked ? pen : null, sg); // TODO: sg.Dispose(); // TODO: brush.Dispose(); // TODO: pen.Dispose(); }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { if (!arc.IsFilled && !arc.IsStroked) { return; } var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(arc.Style.Fill); AM.Pen pen = ToPen(arc.Style, _scaleToPage); var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { var a = WpfArc.FromXArc(arc, dx, dy); sgc.BeginFigure( new A.Point(a.Start.X, a.Start.Y), arc.IsFilled); sgc.ArcTo( new A.Point(a.End.X, a.End.Y), new A.Size(a.Radius.Width, a.Radius.Height), 0.0, a.IsLargeArc, AM.SweepDirection.Clockwise); sgc.EndFigure(false); } _dc.DrawGeometry( arc.IsFilled ? brush : null, arc.IsStroked ? pen : null, sg); }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = arc.Style; if (style == null) { return; } double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple <Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var a = WpfArc.FromXArc(arc, dx, dy); PathGeometry pg = _arcCache.Get(arc); if (pg != null) { var pf = pg.Figures[0]; pf.StartPoint = new Point(a.Start.X, a.Start.Y); pf.IsFilled = arc.IsFilled; var segment = pf.Segments[0] as ArcSegment; segment.Point = new Point(a.End.X, a.End.Y); segment.Size = new Size(a.Radius.Width, a.Radius.Height); segment.IsLargeArc = a.IsLargeArc; segment.IsStroked = arc.IsStroked; } else { var pf = new PathFigure() { StartPoint = new Point(a.Start.X, a.Start.Y), IsFilled = arc.IsFilled }; var segment = new ArcSegment( new Point(a.End.X, a.End.Y), new Size(a.Radius.Width, a.Radius.Height), 0.0, a.IsLargeArc, SweepDirection.Clockwise, arc.IsStroked); //segment.Freeze(); pf.Segments.Add(segment); //pf.Freeze(); pg = new PathGeometry(); pg.Figures.Add(pf); //pg.Freeze(); _arcCache.Set(arc, pg); } DrawPathGeometryInternal(_dc, half, fill, stroke, arc.IsStroked, arc.IsFilled, pg); }
private IArc ReadArc() { var arc = new XArc() { Id = _reader.ReadInt32(), Point1 = ReadPoint(), Point2 = ReadPoint(), StartAngle = _reader.ReadDouble(), SweepAngle = _reader.ReadDouble(), Stroke = ReadColor(), StrokeThickness = _reader.ReadDouble(), Fill = ReadColor(), IsFilled = _reader.ReadBoolean(), IsClosed = _reader.ReadBoolean() }; _natives.Add(arc.Id, arc); return arc; }
/// <summary> /// Draws a <see cref="XArc"/> shape using drawing context. /// </summary> /// <param name="dc">The native drawing context.</param> /// <param name="arc">The <see cref="XArc"/> shape.</param> /// <param name="dx">The X coordinate offset.</param> /// <param name="dy">The Y coordinate offset.</param> /// <param name="db">The properties database.</param> /// <param name="r">The data record.</param> public abstract void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r);
/// <inheritdoc/> public override void LeftDown(double x, double y) { base.LeftDown(x, y); double sx = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x; double sy = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y; switch (_currentState) { case ToolState.None: { var style = _editor.Project.CurrentStyleLibrary.Selected; _connectedPoint3 = false; _connectedPoint4 = false; _arc = XArc.Create( sx, sy, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, _editor.Project.Options.DefaultIsStroked, _editor.Project.Options.DefaultIsFilled); var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _arc.Point1 = result; } _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateOne(); Move(_arc); _currentState = ToolState.One; _editor.CancelAvailable = true; } break; case ToolState.One: { if (_arc != null) { _arc.Point2.X = sx; _arc.Point2.Y = sy; _arc.Point3.X = sx; _arc.Point3.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _arc.Point2 = result; } _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateTwo(); Move(_arc); _currentState = ToolState.Two; } } break; case ToolState.Two: { if (_arc != null) { _arc.Point3.X = sx; _arc.Point3.Y = sy; _arc.Point4.X = sx; _arc.Point4.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _arc.Point3 = result; _connectedPoint3 = true; } else { _connectedPoint3 = false; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_arc); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateThree(); Move(_arc); _currentState = ToolState.Three; } } break; case ToolState.Three: { if (_arc != null) { _arc.Point4.X = sx; _arc.Point4.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _arc.Point4 = result; _connectedPoint4 = true; } else { _connectedPoint4 = false; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_arc); Remove(); Finalize(_arc); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, _arc); _currentState = ToolState.None; _editor.CancelAvailable = false; } } break; } }
public IArc CreateArc() { var arc = new XArc() { Point1 = new XPoint(0.0, 0.0), Point2 = new XPoint(0.0, 0.0), StartAngle = 180.0, SweepAngle = 180.0, Stroke = new XColor(0xFF, 0x00, 0x00, 0x00), StrokeThickness = 2.0, Fill = new XColor(0x00, 0xFF, 0xFF, 0xFF), IsFilled = false, IsClosed = false }; arc.Point1.Connected.Add(arc); arc.Point2.Connected.Add(arc); return arc; }
/// <summary> /// Initializes static designer context. /// </summary> /// <param name="renderer">The design time renderer instance.</param> /// <param name="clipboard">The design time clipboard instance.</param> /// <param name="jsonSerializer">The design time Json serializer instance.</param> /// <param name="xamlSerializer">The design time Xaml serializer instance.</param> /// <returns>The new instance of the <see cref="DesignerContext"/> class.</returns> public static void InitializeContext(ShapeRenderer renderer, ITextClipboard clipboard, ITextSerializer jsonSerializer, ITextSerializer xamlSerializer) { // Editor Editor = new ProjectEditor() { CurrentTool = Tool.Selection, CurrentPathTool = PathTool.Line, CommandManager = new DesignerCommandManager(), Renderers = new ShapeRenderer[] { renderer }, ProjectFactory = new ProjectFactory(), TextClipboard = clipboard, JsonSerializer = jsonSerializer, XamlSerializer = xamlSerializer }.Defaults(); // Recent Projects Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test1", "Test1.project")); Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test2", "Test2.project")); // Commands Editor.InitializeCommands(); InitializeCommands(Editor); Editor.CommandManager.RegisterCommands(); // New Project Editor.OnNew(null); // Data var db = XDatabase.Create("Db"); var fields = new string[] { "Column0", "Column1" }; var columns = ImmutableArray.CreateRange(fields.Select(c => XColumn.Create(db, c))); db.Columns = columns; var values = Enumerable.Repeat("<empty>", db.Columns.Length).Select(c => XValue.Create(c)); var record = XRecord.Create( db, db.Columns, ImmutableArray.CreateRange(values)); db.Records = db.Records.Add(record); db.CurrentRecord = record; Database = db; Data = XContext.Create(record); Record = record; // Project IProjectFactory factory = new ProjectFactory(); Project = factory.GetProject(); Template = XContainer.CreateTemplate(); Page = XContainer.CreatePage(); var layer = Page.Layers.FirstOrDefault(); layer.Shapes = layer.Shapes.Add(XLine.Create(0, 0, null, null)); Page.CurrentLayer = layer; Page.CurrentShape = layer.Shapes.FirstOrDefault(); Page.Template = Template; Document = XDocument.Create(); Layer = XLayer.Create(); Options = XOptions.Create(); // State State = ShapeState.Create(); // Style ArgbColor = ArgbColor.Create(); ArrowStyle = ArrowStyle.Create(); FontStyle = FontStyle.Create(); LineFixedLength = LineFixedLength.Create(); LineStyle = LineStyle.Create(); Style = ShapeStyle.Create("Default"); TextStyle = TextStyle.Create(); // Shapes Arc = XArc.Create(0, 0, Style, null); CubicBezier = XCubicBezier.Create(0, 0, Style, null); Ellipse = XEllipse.Create(0, 0, Style, null); Group = XGroup.Create(Constants.DefaulGroupName); Image = XImage.Create(0, 0, Style, null, "key"); Line = XLine.Create(0, 0, Style, null); Path = XPath.Create("Path", Style, null); Point = XPoint.Create(); QuadraticBezier = XQuadraticBezier.Create(0, 0, Style, null); Rectangle = XRectangle.Create(0, 0, Style, null); Text = XText.Create(0, 0, Style, null, "Text"); // Path ArcSegment = XArcSegment.Create(XPoint.Create(), XPathSize.Create(), 180, true, XSweepDirection.Clockwise, true, true); CubicBezierSegment = XCubicBezierSegment.Create(XPoint.Create(), XPoint.Create(), XPoint.Create(), true, true); LineSegment = XLineSegment.Create(XPoint.Create(), true, true); PathFigure = XPathFigure.Create(XPoint.Create(), false, true); PathGeometry = XPathGeometry.Create(ImmutableArray.Create <XPathFigure>(), XFillRule.EvenOdd); PathSize = XPathSize.Create(); PolyCubicBezierSegment = XPolyCubicBezierSegment.Create(ImmutableArray.Create <XPoint>(), true, true); PolyLineSegment = XPolyLineSegment.Create(ImmutableArray.Create <XPoint>(), true, true); PolyQuadraticBezierSegment = XPolyQuadraticBezierSegment.Create(ImmutableArray.Create <XPoint>(), true, true); QuadraticBezierSegment = XQuadraticBezierSegment.Create(XPoint.Create(), XPoint.Create(), true, true); }
public void Inherits_From_BaseShape() { var target = new XArc(); Assert.True(target is BaseShape); }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { // TODO: Implement Draw arc. }