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/AbstractDrawingTool.cs @ 3038

Last change on this file since 3038 was 2768, checked in by mkommend, 15 years ago

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

File size: 5.0 KB
Line 
1using System.Drawing;
2using System.Windows.Forms;
3using System.Diagnostics;
4
5namespace Netron.Diagramming.Core
6{
7    /// <summary>
8    /// The base class for a drawing tool.
9    /// </summary>
10    public abstract class AbstractDrawingTool :
11        AbstractTool,
12        IMouseListener,
13        IKeyboardListener
14    {
15
16        #region Fields
17
18        // ------------------------------------------------------------------
19        /// <summary>
20        /// The starting point of the rectangle being drawn.
21        /// </summary>
22        // ------------------------------------------------------------------
23        protected Point startingPoint;
24
25        // ------------------------------------------------------------------
26        /// <summary>
27        /// Says whether the startingPoint was set, otherwise the ghost will
28        /// appear even before an initial point was set!
29        /// </summary>
30        // ------------------------------------------------------------------
31        protected bool started;
32
33        // ------------------------------------------------------------------
34        /// <summary>
35        /// The actual rectangle which serves as a basis for the drawing of
36        /// ellipses, rectangles, etc.
37        /// </summary>
38        // ------------------------------------------------------------------
39        private RectangleF mRectangle;
40
41
42        #endregion
43
44        #region Properties
45        protected RectangleF Rectangle
46        {
47            get { return mRectangle; }
48            set { mRectangle = value; }
49        }
50
51
52
53        #endregion
54
55        #region Constructor
56        /// <summary>
57        /// Default constructor
58        /// </summary>
59        /// <param name="name"></param>
60        protected AbstractDrawingTool(string name)
61            : base(name)
62        {
63        }
64        #endregion
65
66        #region Methods
67
68        protected override void OnActivateTool()
69        {
70
71            Controller.View.CurrentCursor = CursorPalette.Add;
72
73        }
74
75        protected override void OnDeactivateTool()
76        {
77
78            base.OnDeactivateTool();
79        }
80
81        #region Explicit implementation of IKeyboardListener
82        void IKeyboardListener.KeyDown(KeyEventArgs e)
83        {
84            OnKeyDown(e);
85        }
86
87        void IKeyboardListener.KeyUp(KeyEventArgs e)
88        {
89            OnKeyUp(e);
90        }
91
92        void IKeyboardListener.KeyPress(KeyPressEventArgs e)
93        {
94            OnKeyPress(e);
95        }
96
97        protected virtual void OnKeyDown(KeyEventArgs e)
98        {
99            //if (e.Handled) return;
100
101            if (e.KeyData == Keys.Escape)
102            {
103                DeactivateTool();
104                Controller.View.ResetGhost();
105                e.Handled = true;
106            }
107        }
108        protected virtual void OnKeyUp(KeyEventArgs e)
109        {
110            if (e.Handled) return;
111        }
112
113        protected virtual void OnKeyPress(KeyPressEventArgs e)
114        {
115            if (e.Handled) return;
116        }
117        #endregion
118
119        #region Explicit implementation of IMouseListener
120        bool IMouseListener.MouseDown(MouseEventArgs e)
121        {
122            return OnMouseDown(e);
123        }
124
125        void IMouseListener.MouseMove(MouseEventArgs e)
126        {
127            OnMouseMove(e);
128        }
129
130        void IMouseListener.MouseUp(MouseEventArgs e)
131        {
132            OnMouseUp(e);
133        }
134
135
136        protected virtual bool OnMouseDown(MouseEventArgs e)
137        {
138            if (IsActive && e.Button == MouseButtons.Left)
139            {
140                startingPoint = new Point(e.X, e.Y);
141                started = true;
142                return true;
143            }
144            return false;
145        }
146
147        protected virtual void OnMouseMove(MouseEventArgs e)
148        {
149
150        }
151
152        protected virtual void OnMouseUp(MouseEventArgs e)
153        {
154            if ((IsActive) &&
155                (started) &&
156                (Controller.View.Ghost != null))
157            {
158
159                //base.RestoreCursor();
160                Point point = new Point(e.X, e.Y);
161                //mRectangle = new Rectangle(startingPoint.X, startingPoint.Y, point.X - startingPoint.X, point.Y - startingPoint.Y);
162                //mRectangle = base.Controller.View.ViewToWorld(base.Controller.View.DeviceToView(rectangle));
163                mRectangle = Controller.View.Ghost.Rectangle;
164                GhostDrawingComplete();
165                Controller.View.ResetGhost();
166                started = false;
167            }
168        }
169        #endregion
170
171        /// <summary>
172        /// This method will be called when the user has finished drawing a
173        /// ghost rectangle or bundle and initiates the actual creation of a
174        /// bundle and the addition to the model via the appropriate command.
175        /// </summary>
176        protected abstract void GhostDrawingComplete();
177
178        #endregion
179
180
181
182
183    }
184
185}
Note: See TracBrowser for help on using the repository browser.