private void SetToolbox() { ToolBox = new Toolbox(); ToolBox.SetActiveCanvas(DrawingCanvas); LineTool LineToolStrip = new LineTool(); LineToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(LineToolStrip); EllipseTool EllipseToolStrip = new EllipseTool(); EllipseToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(EllipseToolStrip); RectangleTool RectangleToolStrip = new RectangleTool(); RectangleToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(RectangleToolStrip); ToolBox.AddSeparator(); SelectionTool SelectionToolStrip = new SelectionTool(); SelectionToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(SelectionToolStrip); this.Controls.Add(ToolBox); }
public void DrawEllipse(int x, int y) { if (IsShapeOptionSelected(EllipseTool) == false) { EllipseTool.Click(); } DragAndDropOnCanvas(x, y); }
public FormMain() { InitializeComponent(); //WindowState = FormWindowState.Maximized; openImageDialog.Title = "Открыть изображение"; saveImageDialog.Title = "Сохранить изображение"; templateShown = false; isTemplateOn = false; BackgroundImage = null; //is it correct way to clear BackgroundImage of the form? templatePanel.Enabled = false; templatePanel.Visible = false; templatePanelMinimized.Enabled = false; templatePanelMinimized.Visible = false; isImageSaved = false; snapshot = new Bitmap(mainPictureBox.Width, mainPictureBox.Height); backPic = new Bitmap(mainImagePanel.Width, mainImagePanel.Height); loadPic = null; mouseDown = false; clearFlag = false; loadPicFlag = false; activeToolControlName = null; activeColorControlName = null; width = lineThicknessTrackBar.Value; eraser = new EraserTool(width); pencil = new PencilTool(width); rect = new RectangleTool(width); line = new LineTool(width); ellipse = new EllipseTool(width); fill = new FillTool(); toolsList = new Dictionary <string, ITool>(); toolsList.Add("labelPencil", pencil); toolsList.Add("labelEraser", eraser); toolsList.Add("labelRect", rect); toolsList.Add("labelLine", line); toolsList.Add("labelEllipse", ellipse); toolsList.Add("labelFill", fill); loadTemplate = new FormLoadTemplate(); }
// Should create elipse from [50,50] to [0,25] public void EllipseTest() { ITool CurrentTool = new EllipseTool(); // user clicked on point [50,50] CurrentTool.GetShape(new CanvasEventArgs(new Point(50, 50), MouseState.DOWN), style); // user hold mouse and move, this should update current ellipse on canvas CurrentTool.GetShape(new CanvasEventArgs(new Point(80, 170), MouseState.MOVE), style); CurrentTool.GetShape(new CanvasEventArgs(new Point(60, 100), MouseState.MOVE), style); // user release mouse, at this point ellipse shouldn't be modified by any mouse action Ellipse e = (Ellipse)CurrentTool.GetShape(new CanvasEventArgs(new Point(0, 25), MouseState.UP), style).TikzShape.Shape; Assert.AreEqual(50, e.Width); Assert.AreEqual(25, e.Height); }
private void EllipseButtonClick(object sender, EventArgs e) { outputPanel.Add(EllipseTool.Build()); listView1.Items.Add(new ListViewItem("Ellipse")); Invalidate(true); }
public IToolContext CreateToolContext() { var editorToolContext = new EditorToolContext() { ContainerFactory = this }; var hitTest = new HitTest(); var tools = new ObservableCollection <ITool>(); var noneTool = new NoneTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = false, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } }, new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = false, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } } }, Settings = new NoneToolSettings() }; var selectionTool = new SelectionTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = false, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new SelectionToolSettings() { Mode = SelectionMode.Point | SelectionMode.Shape, Targets = SelectionTargets.Shapes, SelectionModifier = Modifier.Control, ConnectionModifier = Modifier.Shift, SelectionStyle = "Selection", ClearSelectionOnClean = false, HitTestRadius = 7.0, ConnectPoints = true, ConnectTestRadius = 10.0, DisconnectPoints = true, DisconnectTestRadius = 10.0 } }; var pointTool = new PointTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new PointToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var lineTool = new LineTool() { Intersections = new ObservableCollection <IPointIntersection> { new LineLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new LineLineSettings() { IsEnabled = true } }, new RectangleLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new RectangleLineSettings() { IsEnabled = true } }, new EllipseLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new EllipseLineSettings() { IsEnabled = true } } }, Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new LineToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, SplitIntersections = false } }; var polyLineTool = new PolyLineTool() { Intersections = new ObservableCollection <IPointIntersection> { new LineLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new LineLineSettings() { IsEnabled = true } }, new RectangleLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new RectangleLineSettings() { IsEnabled = true } }, new EllipseLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new EllipseLineSettings() { IsEnabled = true } } }, Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new PolyLineToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var cubicBezierTool = new CubicBezierTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new CubicBezierToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var quadraticBezierTool = new QuadraticBezierTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new QuadraticBezierToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var conicTool = new ConicTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new ConicToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, Weight = 1.0 } }; var pathTool = new PathTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new PathToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, FillType = PathFillType.Winding, IsFilled = true, IsClosed = true } }; pathTool.Settings.Tools = new ObservableCollection <ITool> { new LineTool(), new CubicBezierTool(), new QuadraticBezierTool(), new ConicTool(), new MoveTool(pathTool) }; pathTool.Settings.CurrentTool = pathTool.Settings.Tools[0]; var scribbleTool = new ScribbleTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = false, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new ScribbleToolSettings() { Simplify = true, Epsilon = 1.0, FillType = PathFillType.Winding, IsFilled = false, IsClosed = false } }; var rectangleTool = new RectangleTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new RectangleToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var ellipseTool = new EllipseTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new EllipseToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var textTool = new TextTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new TextToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; void SetToolDefaults(ITool tool) { tool.CurrentIntersection = tool.Intersections.Count > 0 ? tool.Intersections[0] : null; tool.CurrentFilter = tool.Filters.Count > 0 ? tool.Filters[0] : null; } SetToolDefaults(noneTool); SetToolDefaults(selectionTool); SetToolDefaults(pointTool); SetToolDefaults(lineTool); SetToolDefaults(polyLineTool); SetToolDefaults(cubicBezierTool); SetToolDefaults(quadraticBezierTool); SetToolDefaults(conicTool); SetToolDefaults(pathTool); SetToolDefaults(scribbleTool); SetToolDefaults(rectangleTool); SetToolDefaults(ellipseTool); SetToolDefaults(textTool); tools.Add(noneTool); tools.Add(selectionTool); tools.Add(pointTool); tools.Add(lineTool); tools.Add(polyLineTool); tools.Add(cubicBezierTool); tools.Add(quadraticBezierTool); tools.Add(conicTool); tools.Add(pathTool); tools.Add(scribbleTool); tools.Add(rectangleTool); tools.Add(ellipseTool); tools.Add(textTool); editorToolContext.Selection = selectionTool; editorToolContext.HitTest = hitTest; editorToolContext.CurrentDirectory = null; editorToolContext.Files = new ObservableCollection <string>(); editorToolContext.StyleLibrary = null; editorToolContext.GroupLibrary = null; var pointTemplate = new RectangleShape(new PointShape(-4, -4, null), new PointShape(4, 4, null)) { Points = new ObservableCollection <IPointShape>(), Text = new Text(), StyleId = "PointTemplate" }; pointTemplate.StartPoint.Owner = pointTemplate; pointTemplate.Point.Owner = pointTemplate; editorToolContext.PointTemplate = pointTemplate; editorToolContext.ContainerViews = new ObservableCollection <IContainerView>(); editorToolContext.ContainerView = null; editorToolContext.Tools = tools; editorToolContext.CurrentTool = selectionTool; editorToolContext.EditMode = EditMode.Mouse; return(editorToolContext); }
public LayerContainerViewModel CreateDemoViewModel() { var hitTest = new HitTest(); hitTest.Register(new PointHitTest()); hitTest.Register(new LineHitTest()); hitTest.Register(new CubicBezierHitTest()); hitTest.Register(new QuadraticBezierHitTest()); hitTest.Register(new GroupHitTest()); hitTest.Register(new PathHitTest()); hitTest.Register(new RectangleHitTest()); hitTest.Register(new EllipseHitTest()); hitTest.Register(new TextHitTest()); var gridSnapPointFilter = new GridSnapPointFilter() { Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true) } }; var lineSnapPointFilter = new LineSnapPointFilter() { Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Guides | LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true) } }; var tools = new ObservableCollection <ToolBase>(); var noneTool = new NoneTool() { Settings = new NoneToolSettings() }; var selectionTool = new SelectionTool() { Filters = new List <PointFilter> { new GridSnapPointFilter() { Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true) } } }, Settings = new SelectionToolSettings() { Mode = SelectionMode.Point | SelectionMode.Shape, Targets = SelectionTargets.Shapes | SelectionTargets.Guides, SelectionModifier = Modifier.Control, ConnectionModifier = Modifier.Shift, SelectionStyle = new ShapeStyle(new ArgbColor(255, 0, 120, 215), new ArgbColor(60, 170, 204, 238), 2.0, true, true), ClearSelectionOnClean = false, HitTestRadius = 7.0, ConnectPoints = true, ConnectTestRadius = 10.0, DisconnectPoints = true, DisconnectTestRadius = 10.0 } }; var guideTool = new GuideTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new GuideToolSettings() { GuideStyle = new ShapeStyle(new ArgbColor(128, 0, 255, 255), new ArgbColor(128, 0, 255, 255), 2.0, true, true) } }; var pointTool = new PointTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new PointToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var lineTool = new LineTool() { Intersections = new List <PointIntersection> { new LineLineIntersection() { Settings = new LineLineSettings() { IsEnabled = true } }, new RectangleLineIntersection() { Settings = new RectangleLineSettings() { IsEnabled = true } }, new EllipseLineIntersection() { Settings = new EllipseLineSettings() { IsEnabled = true } } }, Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new LineToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, SplitIntersections = false } }; var polyLineTool = new PolyLineTool() { Intersections = new List <PointIntersection> { new LineLineIntersection() { Settings = new LineLineSettings() { IsEnabled = true } }, new RectangleLineIntersection() { Settings = new RectangleLineSettings() { IsEnabled = true } }, new EllipseLineIntersection() { Settings = new EllipseLineSettings() { IsEnabled = true } } }, Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new PolyLineToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var cubicBezierTool = new CubicBezierTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new CubicBezierToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var quadraticBezierTool = new QuadraticBezierTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new QuadraticBezierToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var pathTool = new PathTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new PathToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, FillRule = PathFillRule.EvenOdd, IsFilled = true, IsClosed = true } }; pathTool.Settings.Tools = new ObservableCollection <ToolBase> { new LineTool(), new CubicBezierTool(), new QuadraticBezierTool(), new MoveTool(pathTool) }; pathTool.Settings.CurrentTool = pathTool.Settings.Tools[0]; var scribbleTool = new ScribbleTool() { Filters = new List <PointFilter> { lineSnapPointFilter }, Settings = new ScribbleToolSettings() { Simplify = true, Epsilon = 1.0, FillRule = PathFillRule.EvenOdd, IsFilled = false, IsClosed = false } }; var rectangleTool = new RectangleTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new RectangleToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var ellipseTool = new EllipseTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new EllipseToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var textTool = new TextTool() { Filters = new List <PointFilter> { lineSnapPointFilter, gridSnapPointFilter }, Settings = new TextToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; tools.Add(noneTool); tools.Add(selectionTool); tools.Add(guideTool); tools.Add(pointTool); tools.Add(lineTool); tools.Add(polyLineTool); tools.Add(cubicBezierTool); tools.Add(quadraticBezierTool); tools.Add(pathTool); tools.Add(scribbleTool); tools.Add(rectangleTool); tools.Add(ellipseTool); tools.Add(textTool); var currentTool = tools.FirstOrDefault(t => t.Title == "Selection"); var presenter = new DefaultShapePresenter() { Helpers = new Dictionary <Type, ShapeHelper> { { typeof(PointShape), new PointHelper() }, { typeof(LineShape), new LineHelper() }, { typeof(CubicBezierShape), new CubicBezierHelper() }, { typeof(QuadraticBezierShape), new QuadraticBezierHelper() }, { typeof(PathShape), new PathHelper() }, { typeof(RectangleShape), new RectangleHelper() }, { typeof(EllipseShape), new EllipseHelper() }, { typeof(TextShape), new TextHelper() } } }; return(new LayerContainerViewModel() { Tools = tools, CurrentTool = currentTool, Mode = EditMode.Mouse, Presenter = presenter, Renderer = null, HitTest = hitTest, CurrentContainer = null, WorkingContainer = null, CurrentStyle = null, PointShape = null, Capture = null, Release = null, Invalidate = null, Reset = null, AutoFit = null, StretchNone = null, StretchFill = null, StretchUniform = null, StretchUniformToFill = null }); }
public void SwitchTool(ToolType toolType) { if (toolType != ToolType.Move && ToolWhileMoveTool != null && ToolWhileMoveTool.GetToolType() == toolType) { ToolCurrent = ToolWhileMoveTool; ToolWhileMoveTool = null; return; } ToolWhileMoveTool = null; if (ToolCurrent != null) { ToolCurrent.ResetUsedElements(); } switch (toolType) { case ToolType.Brush: ToolCurrent = new BrushTool(); break; case ToolType.Crop: ToolCurrent = new CropTool(); break; case ToolType.Cursor: ToolCurrent = new CursorTool(); break; case ToolType.Fill: ToolCurrent = new FillTool(); break; case ToolType.Ellipse: ToolCurrent = new EllipseTool(); break; case ToolType.Eraser: ToolCurrent = new EraserTool(); break; case ToolType.ImportPng: ToolCurrent = new ImportTool(); break; case ToolType.Flip: ToolCurrent = new FlipTool(); break; case ToolType.Line: ToolCurrent = new LineTool(); break; case ToolType.Zoom: ToolCurrent = new MoveZoomTool(); break; case ToolType.Move: ToolWhileMoveTool = ToolCurrent; ToolCurrent = new MoveZoomTool(false); break; case ToolType.Pipette: ToolCurrent = new PipetteTool(); break; case ToolType.Rotate: ToolCurrent = new RotateTool(); break; case ToolType.Rect: ToolCurrent = new RectangleTool(); break; case ToolType.Stamp: ToolCurrent = new StampTool(); break; default: break; } }
private void SetTool() { // // Toolbar // ToolBar = new Toolbar(); ToolBar.SetActiveCanvas(DrawingCanvas); ToolBar.AddSeparator(); ToolBar.ItemClicked += new ToolStripItemClickedEventHandler(Toolbar_ItemClicked); OutlineColorChooser OColorChooser = new OutlineColorChooser(); ToolBar.AddTool(OColorChooser); ToolBar.AddSeparator(); FillColorChooser IColorChooser = new FillColorChooser(); ToolBar.AddTool(IColorChooser); ToolBar.AddSeparator(); this.Controls.Add(ToolBar); // // Toolbox // ToolBox = new Toolbox(); ToolBox.SetActiveCanvas(DrawingCanvas); LineTool LineToolStrip = new LineTool(); LineToolStrip.Click += new EventHandler(Toolbox_ItemClicked); LineToolStrip.SubscribeLine(OColorChooser); ToolBox.AddTool(LineToolStrip); EllipseTool EllipseToolStrip = new EllipseTool(); EllipseToolStrip.Click += new EventHandler(Toolbox_ItemClicked); EllipseToolStrip.SubscribeFill(IColorChooser); EllipseToolStrip.SubscribeLine(OColorChooser); ToolBox.AddTool(EllipseToolStrip); RectangleTool RectangleToolStrip = new RectangleTool(); RectangleToolStrip.Click += new EventHandler(Toolbox_ItemClicked); RectangleToolStrip.SubscribeFill(IColorChooser); RectangleToolStrip.SubscribeLine(OColorChooser); ToolBox.AddTool(RectangleToolStrip); ToolBox.AddSeparator(); SelectionTool SelectionToolStrip = new SelectionTool(); SelectionToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(SelectionToolStrip); ToolBox.AddSeparator(); LineFillTool LineFillToolStrip = new LineFillTool(); LineFillToolStrip.Click += new EventHandler(Toolbox_ItemClicked); LineFillToolStrip.SubscribeLine(OColorChooser); ToolBox.AddTool(LineFillToolStrip); FillTool FillToolStrip = new FillTool(); FillToolStrip.Click += new EventHandler(Toolbox_ItemClicked); FillToolStrip.SubscribeFill(IColorChooser); ToolBox.AddTool(FillToolStrip); this.Controls.Add(ToolBox); }