1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 |
|
---|
4 | namespace Netron.Diagramming.Core
|
---|
5 | {
|
---|
6 | /// <summary>
|
---|
7 | /// Tool to draw an ellipse on the canvas
|
---|
8 | /// <seealso cref="RectangleTool"/>
|
---|
9 | /// </summary>
|
---|
10 | public class EllipseTool : AbstractDrawingTool
|
---|
11 | {
|
---|
12 | #region Fields
|
---|
13 |
|
---|
14 | #endregion
|
---|
15 |
|
---|
16 | #region Properties
|
---|
17 |
|
---|
18 | #endregion
|
---|
19 |
|
---|
20 | #region Constructor
|
---|
21 | public EllipseTool() : base("Ellipse Tool")
|
---|
22 | {
|
---|
23 | }
|
---|
24 | public EllipseTool(string name): base(name)
|
---|
25 | {
|
---|
26 |
|
---|
27 | }
|
---|
28 | #endregion
|
---|
29 |
|
---|
30 | #region Methods
|
---|
31 |
|
---|
32 | // ------------------------------------------------------------------
|
---|
33 | /// <summary>
|
---|
34 | /// Activates the tool - the cursor is set to the Cursors.DrawRectangle.
|
---|
35 | /// </summary>
|
---|
36 | // ------------------------------------------------------------------
|
---|
37 | protected override void OnActivateTool()
|
---|
38 | {
|
---|
39 | base.OnActivateTool();
|
---|
40 | Cursor = CursorPalette.DrawEllipse;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /// <summary>
|
---|
44 | /// Handles the mouse move event.
|
---|
45 | /// </summary>
|
---|
46 | /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
---|
47 | protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
|
---|
48 | {
|
---|
49 | base.OnMouseMove(e);
|
---|
50 | if (IsActive && started)
|
---|
51 | {
|
---|
52 | Point point = new Point(e.X, e.Y);
|
---|
53 | Controller.View.PaintGhostEllipse(startingPoint, point);
|
---|
54 | Controller.View.Invalidate(System.Drawing.Rectangle.Inflate(Controller.View.Ghost.Rectangle, 20, 20));
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /// <summary>
|
---|
60 | /// This method will be called when the user has finished drawing a ghost rectangle or bundle
|
---|
61 | /// and initiates the actual creation of a bundle and the addition to the model via the appropriate command.
|
---|
62 | /// </summary>
|
---|
63 | protected override void GhostDrawingComplete()
|
---|
64 | {
|
---|
65 | if ((IsActive == false) ||
|
---|
66 | (started == false))
|
---|
67 | {
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | try
|
---|
72 | {
|
---|
73 | SimpleEllipse shape = new SimpleEllipse(this.Controller.Model);
|
---|
74 | shape.Width = (int) Rectangle.Width;
|
---|
75 | shape.Height = (int) Rectangle.Height;
|
---|
76 | AddShapeCommand cmd = new AddShapeCommand(
|
---|
77 | this.Controller,
|
---|
78 | shape,
|
---|
79 | new Point((int) Rectangle.X, (int)Rectangle.Y));
|
---|
80 | this.Controller.UndoManager.AddUndoCommand(cmd);
|
---|
81 | cmd.Redo();
|
---|
82 | }
|
---|
83 | catch
|
---|
84 | {
|
---|
85 | base.Controller.DeactivateTool(this);
|
---|
86 | Controller.View.Invalidate();
|
---|
87 | throw;
|
---|
88 | }
|
---|
89 |
|
---|
90 | //base.Controller.DeactivateTool(this);
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | #endregion
|
---|
95 | }
|
---|
96 |
|
---|
97 | }
|
---|