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