/// <summary> /// Creates a new instance of the <see cref="XContainer"/> class. /// </summary> /// <param name="factory">The project factory.</param> /// <param name="project">The new container owner project.</param> /// <param name="name">The new container name.</param> /// <returns>The new instance of the <see cref="XContainer"/>.</returns> private XContainer CreateGridTemplate(IProjectFactory factory, XProject project, string name) { var template = factory.GetTemplate(project, name); var style = project .StyleLibraries.FirstOrDefault(g => g.Name == "Template") .Items.FirstOrDefault(s => s.Name == "Grid"); var layer = template.Layers.FirstOrDefault(); var builder = layer.Shapes.ToBuilder(); var grid = XRectangle.Create( 0, 0, template.Width, template.Height, style, project.Options.PointShape); grid.IsStroked = true; grid.IsFilled = false; grid.IsGrid = true; grid.OffsetX = 30.0; grid.OffsetY = 30.0; grid.CellWidth = 30.0; grid.CellHeight = 30.0; grid.State.Flags &= ~ShapeStateFlags.Printable; builder.Add(grid); layer.Shapes = builder.ToImmutable(); return(template); }
/// <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; _rectangle = XRectangle.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) { _rectangle.TopLeft = result; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_rectangle); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateOne(); Move(_rectangle); _currentState = ToolState.One; _editor.CancelAvailable = true; } break; case ToolState.One: { if (_rectangle != null) { _rectangle.BottomRight.X = sx; _rectangle.BottomRight.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _rectangle.BottomRight = result; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_rectangle); Remove(); Finalize(_rectangle); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, _rectangle); _currentState = ToolState.None; _editor.CancelAvailable = false; } } break; } }
/// <summary> /// Transfer selection state to <see cref="ToolState.One"/>. /// </summary> public void ToStateOne() { _helperRectangle = XRectangle.Create(0, 0, _style, null); _topLeftHelperPoint = XPoint.Create(0, 0, _point); _bottomRightHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_helperRectangle); _layer.Shapes = _layer.Shapes.Add(_topLeftHelperPoint); _layer.Shapes = _layer.Shapes.Add(_bottomRightHelperPoint); }
/// <inheritdoc/> XRectangle IShapeFactory.Rectangle(XPoint topLeft, XPoint bottomRight, bool isStroked, bool isFilled, string text) { var style = _editor.Project.CurrentStyleLibrary.Selected; var rectangle = XRectangle.Create( topLeft, bottomRight, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked, isFilled, text); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, rectangle); return(rectangle); }
/// <inheritdoc/> XRectangle IShapeFactory.Rectangle(double x1, double y1, double x2, double y2, bool isStroked, bool isFilled, string text) { var style = _editor.Project.CurrentStyleLibrary.Selected; var rectangle = XRectangle.Create( x1, y1, x2, y2, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked, isFilled, text); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, rectangle); return(rectangle); }
/// <inheritdoc/> public override void LeftDown(double x, double y) { base.LeftDown(x, y); switch (_currentState) { case ToolState.None: { _editor.Dehover(_editor.Project.CurrentContainer.CurrentLayer); if (_editor.Renderers[0].State.SelectedShape == null && _editor.Renderers[0].State.SelectedShapes != null) { var result = ShapeHitTestPoint.HitTest(_editor.Project.CurrentContainer.CurrentLayer.Shapes, new Vector2(x, y), _editor.Project.Options.HitThreshold); if (result != null) { _startX = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x; _startY = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y; _historyX = _startX; _historyY = _startY; GenerateMoveSelectionCache(); _currentState = ToolState.One; _editor.CancelAvailable = true; break; } } if (_editor.TryToSelectShape(_editor.Project.CurrentContainer.CurrentLayer, x, y)) { _startX = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x; _startY = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y; _historyX = _startX; _historyY = _startY; GenerateMoveSelectionCache(); _currentState = ToolState.One; _editor.CancelAvailable = true; break; } _rectangle = XRectangle.Create( x, y, _editor.Project.Options.SelectionStyle, null, true, true); _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_rectangle); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); _currentState = ToolState.One; _editor.CancelAvailable = true; } break; case ToolState.One: { if (_rectangle != null) { _rectangle.BottomRight.X = x; _rectangle.BottomRight.Y = y; _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_rectangle); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); _currentState = ToolState.None; _editor.CancelAvailable = false; } } break; } }
/// <summary> /// Creates a new <see cref="BaseShape"/> instance. /// </summary> /// <param name="pss">The point shape <see cref="ShapeStyle"/>.</param> /// <returns>The new instance of the <see cref="BaseShape"/> class.</returns> public static BaseShape FilledRectanglePointShape(ShapeStyle pss) { return(XRectangle.Create(-3, -3, 3, 3, pss, null, true, true)); }
/// <summary> /// Creates a new <see cref="BaseShape"/> instance. /// </summary> /// <param name="pss">The point shape <see cref="ShapeStyle"/>.</param> /// <returns>The new instance of the <see cref="BaseShape"/> class.</returns> public static BaseShape RectanglePointShape(ShapeStyle pss) { return(XRectangle.Create(-4, -4, 4, 4, pss, null, true, false)); }
/// <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); }