Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2868 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

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