/// <summary> /// /// </summary> /// <param name="cubicBezier"></param> /// <param name="v"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static BaseShape HitTestCubicBezier(XCubicBezier cubicBezier, Vector2 v, double threshold, double dx, double dy) { if (RectangleBounds.GetPointBounds(cubicBezier.Point1, threshold, dx, dy).Contains(v)) { return(cubicBezier.Point1); } if (RectangleBounds.GetPointBounds(cubicBezier.Point2, threshold, dx, dy).Contains(v)) { return(cubicBezier.Point2); } if (RectangleBounds.GetPointBounds(cubicBezier.Point3, threshold, dx, dy).Contains(v)) { return(cubicBezier.Point3); } if (RectangleBounds.GetPointBounds(cubicBezier.Point4, threshold, dx, dy).Contains(v)) { return(cubicBezier.Point4); } if (ConvexHullBounds.Contains(cubicBezier.GetPoints().ToImmutableArray(), v, dx, dy)) { return(cubicBezier); } return(null); }
/// <inheritdoc/> public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { if (!cubicBezier.IsFilled && !cubicBezier.IsStroked) { return; } var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(cubicBezier.Style.Fill); AM.Pen pen = ToPen(cubicBezier.Style, _scaleToPage); var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure( new A.Point(cubicBezier.Point1.X, cubicBezier.Point1.Y), cubicBezier.IsFilled); sgc.CubicBezierTo( new A.Point(cubicBezier.Point2.X, cubicBezier.Point2.Y), new A.Point(cubicBezier.Point3.X, cubicBezier.Point3.Y), new A.Point(cubicBezier.Point4.X, cubicBezier.Point4.Y)); sgc.EndFigure(false); } _dc.DrawGeometry( cubicBezier.IsFilled ? brush : null, cubicBezier.IsStroked ? pen : null, sg); }
/// <inheritdoc/> XCubicBezier IShapeFactory.CubicBezier(XPoint point1, XPoint point2, XPoint point3, XPoint point4, bool isStroked, bool isFilled) { var style = _editor.Project.CurrentStyleLibrary.Selected; var cubicBezier = XCubicBezier.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, cubicBezier); return(cubicBezier); }
/// <inheritdoc/> XCubicBezier IShapeFactory.CubicBezier(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 cubicBezier = XCubicBezier.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, cubicBezier); return(cubicBezier); }
/// <summary> /// /// </summary> /// <param name="cubicBezier"></param> /// <param name="selection"></param> /// <param name="selected"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static bool HitTestCubicBezier(XCubicBezier cubicBezier, Vector2[] selection, ISet <BaseShape> selected, double dx, double dy) { var points = cubicBezier.GetPoints().ToImmutableArray(); if (ConvexHullBounds.Overlap(selection, points, dx, dy)) { if (selected != null) { selected.Add(cubicBezier); return(false); } else { return(true); } } return(false); }
/// <inheritdoc/> public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(cubicBezier.Style.Fill)) using (SKPaint pen = ToSKPaintPen(cubicBezier.Style, _scaleToPage, _sourceDpi, _targetDpi)) using (var path = new SKPath()) { path.MoveTo( _scaleToPage(cubicBezier.Point1.X + dx), _scaleToPage(cubicBezier.Point1.Y + dy)); path.CubicTo( _scaleToPage(cubicBezier.Point2.X + dx), _scaleToPage(cubicBezier.Point2.Y + dy), _scaleToPage(cubicBezier.Point3.X + dx), _scaleToPage(cubicBezier.Point3.Y + dy), _scaleToPage(cubicBezier.Point4.X + dx), _scaleToPage(cubicBezier.Point4.Y + dy)); DrawPathInternal(canvas, brush, pen, cubicBezier.IsStroked, cubicBezier.IsFilled, path); } }
/// <inheritdoc/> public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var _gfx = dc as Graphics; Brush brush = ToSolidBrush(cubicBezier.Style.Fill); Pen pen = ToPen(cubicBezier.Style, _scaleToPage); if (cubicBezier.IsFilled) { var path = new GraphicsPath(); path.AddBezier( _scaleToPage(cubicBezier.Point1.X), _scaleToPage(cubicBezier.Point1.Y), _scaleToPage(cubicBezier.Point2.X), _scaleToPage(cubicBezier.Point2.Y), _scaleToPage(cubicBezier.Point3.X), _scaleToPage(cubicBezier.Point3.Y), _scaleToPage(cubicBezier.Point4.X), _scaleToPage(cubicBezier.Point4.Y)); _gfx.FillPath(brush, path); } if (cubicBezier.IsStroked) { _gfx.DrawBezier( pen, _scaleToPage(cubicBezier.Point1.X), _scaleToPage(cubicBezier.Point1.Y), _scaleToPage(cubicBezier.Point2.X), _scaleToPage(cubicBezier.Point2.Y), _scaleToPage(cubicBezier.Point3.X), _scaleToPage(cubicBezier.Point3.Y), _scaleToPage(cubicBezier.Point4.X), _scaleToPage(cubicBezier.Point4.Y)); } brush.Dispose(); pen.Dispose(); }
/// <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; _cubicBezier = XCubicBezier.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) { _cubicBezier.Point1 = result; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_cubicBezier); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateOne(); Move(_cubicBezier); _currentState = ToolState.One; _editor.CancelAvailable = true; } break; case ToolState.One: { if (_cubicBezier != null) { _cubicBezier.Point3.X = sx; _cubicBezier.Point3.Y = sy; _cubicBezier.Point4.X = sx; _cubicBezier.Point4.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _cubicBezier.Point4 = result; } _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateTwo(); Move(_cubicBezier); _currentState = ToolState.Two; } } break; case ToolState.Two: { if (_cubicBezier != null) { _cubicBezier.Point2.X = sx; _cubicBezier.Point2.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _cubicBezier.Point2 = result; } _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateThree(); Move(_cubicBezier); _currentState = ToolState.Three; } } break; case ToolState.Three: { if (_cubicBezier != null) { _cubicBezier.Point3.X = sx; _cubicBezier.Point3.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _cubicBezier.Point3 = result; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_cubicBezier); Remove(); base.Finalize(_cubicBezier); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, _cubicBezier); _currentState = ToolState.None; _editor.CancelAvailable = false; } } break; } }
/// <inheritdoc/> public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = cubicBezier.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)); } PathGeometry pg = _cubicBezierCache.Get(cubicBezier); if (pg != null) { var pf = pg.Figures[0]; pf.StartPoint = new Point(cubicBezier.Point1.X + dx, cubicBezier.Point1.Y + dy); pf.IsFilled = cubicBezier.IsFilled; var bs = pf.Segments[0] as BezierSegment; bs.Point1 = new Point(cubicBezier.Point2.X + dx, cubicBezier.Point2.Y + dy); bs.Point2 = new Point(cubicBezier.Point3.X + dx, cubicBezier.Point3.Y + dy); bs.Point3 = new Point(cubicBezier.Point4.X + dx, cubicBezier.Point4.Y + dy); bs.IsStroked = cubicBezier.IsStroked; } else { var pf = new PathFigure() { StartPoint = new Point(cubicBezier.Point1.X + dx, cubicBezier.Point1.Y + dy), IsFilled = cubicBezier.IsFilled }; var bs = new BezierSegment( new Point(cubicBezier.Point2.X + dx, cubicBezier.Point2.Y + dy), new Point(cubicBezier.Point3.X + dx, cubicBezier.Point3.Y + dy), new Point(cubicBezier.Point4.X + dx, cubicBezier.Point4.Y + dy), cubicBezier.IsStroked); //bs.Freeze(); pf.Segments.Add(bs); //pf.Freeze(); pg = new PathGeometry(); pg.Figures.Add(pf); //pg.Freeze(); _cubicBezierCache.Set(cubicBezier, pg); } DrawPathGeometryInternal(_dc, half, fill, stroke, cubicBezier.IsStroked, cubicBezier.IsFilled, pg); }
public void Inherits_From_BaseShape() { var target = new XCubicBezier(); Assert.True(target is BaseShape); }
/// <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); }
/// <summary> /// Draws a <see cref="XCubicBezier"/> shape using drawing context. /// </summary> /// <param name="dc">The native drawing context.</param> /// <param name="cubicBezier">The <see cref="XCubicBezier"/> 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, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r);
/// <inheritdoc/> public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { // TODO: Implement Draw cubic bezier. }