Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/RectangleTool.cs @ 18242

Last change on this file since 18242 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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