Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ZoomAreaTool.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/ZoomAreaTool.cs
r2901 r4068 1 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 2 using System.Drawing; 4 3 using System.Windows.Forms; 5 using System.Drawing;6 4 7 namespace Netron.Diagramming.Core 8 { 9 // ---------------------------------------------------------------------- 5 namespace Netron.Diagramming.Core { 6 // ---------------------------------------------------------------------- 7 /// <summary> 8 /// Allows the user to zoom in to a user-drawn rectangle area. 9 /// </summary> 10 // ---------------------------------------------------------------------- 11 public class ZoomAreaTool : AbstractTool, IMouseListener { 12 #region Fields 13 14 // ------------------------------------------------------------------ 10 15 /// <summary> 11 /// Allows the user to zoom in to a user-drawn rectangle area.16 /// The location of the mouse when the motion starts. 12 17 /// </summary> 13 // ---------------------------------------------------------------------- 14 public class ZoomAreaTool : AbstractTool, IMouseListener 15 { 16 #region Fields 18 // ------------------------------------------------------------------ 19 protected Point initialPoint; 17 20 18 // ------------------------------------------------------------------ 19 /// <summary> 20 /// The location of the mouse when the motion starts. 21 /// </summary> 22 // ------------------------------------------------------------------ 23 protected Point initialPoint; 21 // ------------------------------------------------------------------ 22 /// <summary> 23 /// Says whether the startingPoint was set, otherwise the ghost will 24 /// appear even before an initial point was set! 25 /// </summary> 26 // ------------------------------------------------------------------ 27 protected bool started; 24 28 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; 29 #endregion 32 30 33 #endregion 31 // ------------------------------------------------------------------ 32 /// <summary> 33 /// Constructor. 34 /// </summary> 35 /// <param name="toolName">string: The name of the tool.</param> 36 // ------------------------------------------------------------------ 37 public ZoomAreaTool(string toolName) 38 : base(toolName) { 39 } 34 40 35 // ------------------------------------------------------------------ 36 /// <summary> 37 /// Constructor. 38 /// </summary> 39 /// <param name="toolName">string: The name of the tool.</param> 40 // ------------------------------------------------------------------ 41 public ZoomAreaTool(string toolName) 42 : base(toolName) 43 { 41 #region Methods 42 43 // ------------------------------------------------------------------ 44 /// <summary> 45 /// Called when the tool is activated. 46 /// </summary> 47 // ------------------------------------------------------------------ 48 protected override void OnActivateTool() { 49 base.OnActivateTool(); 50 Controller.View.CurrentCursor = CursorPalette.Cross; 51 } 52 53 // ------------------------------------------------------------------ 54 /// <summary> 55 /// Handles the mouse down event 56 /// </summary> 57 /// <param name="e">The 58 /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance 59 /// containing the event data.</param> 60 // ------------------------------------------------------------------ 61 public bool MouseDown(MouseEventArgs e) { 62 if (e == null) { 63 throw new ArgumentNullException( 64 "The argument object is 'null'"); 65 } 66 67 if (e.Button == MouseButtons.Left && IsActive && !IsSuspended) { 68 initialPoint = e.Location; 69 started = true; 70 return true; // This tells the tool-loop to stop looking 71 // for another handler, which keeps the CPU low. 72 73 } 74 return false; 75 } 76 77 // ------------------------------------------------------------------ 78 /// <summary> 79 /// Handles the mouse move event 80 /// </summary> 81 /// <param name="e">The 82 /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance 83 /// containing the event data.</param> 84 // ------------------------------------------------------------------ 85 public void MouseMove(MouseEventArgs e) { 86 if (e == null) { 87 throw new ArgumentNullException( 88 "The argument object is 'null'"); 89 } 90 if (IsActive && !IsSuspended && started) { 91 IView view = this.Controller.View; 92 Point point = e.Location; 93 94 Controller.View.PaintGhostRectangle(initialPoint, point); 95 Rectangle area = System.Drawing.Rectangle.Inflate( 96 Controller.View.Ghost.Rectangle, 20, 20); 97 98 Controller.View.Invalidate(area); 99 } 100 } 101 102 // ------------------------------------------------------------------ 103 /// <summary> 104 /// Handles the mouse up event. 105 /// </summary> 106 /// <param name="e">The 107 /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance 108 /// containing the event data.</param> 109 // ------------------------------------------------------------------ 110 public void MouseUp(MouseEventArgs e) { 111 if (IsActive) { 112 IView view = Controller.View; 113 if (view.Ghost != null) { 114 Rectangle zoomArea = view.Ghost.Rectangle; 115 view.ZoomArea(zoomArea); 116 started = false; 44 117 } 118 Controller.View.ResetGhost(); 119 } 120 } 45 121 46 #region Methods 47 48 // ------------------------------------------------------------------ 49 /// <summary> 50 /// Called when the tool is activated. 51 /// </summary> 52 // ------------------------------------------------------------------ 53 protected override void OnActivateTool() 54 { 55 base.OnActivateTool(); 56 Controller.View.CurrentCursor = CursorPalette.Cross; 57 } 58 59 // ------------------------------------------------------------------ 60 /// <summary> 61 /// Handles the mouse down event 62 /// </summary> 63 /// <param name="e">The 64 /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance 65 /// containing the event data.</param> 66 // ------------------------------------------------------------------ 67 public bool MouseDown(MouseEventArgs e) 68 { 69 if (e == null) 70 { 71 throw new ArgumentNullException( 72 "The argument object is 'null'"); 73 } 74 75 if (e.Button == MouseButtons.Left && IsActive && !IsSuspended) 76 { 77 initialPoint = e.Location; 78 started = true; 79 return true; // This tells the tool-loop to stop looking 80 // for another handler, which keeps the CPU low. 81 82 } 83 return false; 84 } 85 86 // ------------------------------------------------------------------ 87 /// <summary> 88 /// Handles the mouse move event 89 /// </summary> 90 /// <param name="e">The 91 /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance 92 /// containing the event data.</param> 93 // ------------------------------------------------------------------ 94 public void MouseMove(MouseEventArgs e) 95 { 96 if (e == null) 97 { 98 throw new ArgumentNullException( 99 "The argument object is 'null'"); 100 } 101 if (IsActive && !IsSuspended && started) 102 { 103 IView view = this.Controller.View; 104 Point point = e.Location; 105 106 Controller.View.PaintGhostRectangle(initialPoint, point); 107 Rectangle area = System.Drawing.Rectangle.Inflate( 108 Controller.View.Ghost.Rectangle, 20, 20); 109 110 Controller.View.Invalidate(area); 111 } 112 } 113 114 // ------------------------------------------------------------------ 115 /// <summary> 116 /// Handles the mouse up event. 117 /// </summary> 118 /// <param name="e">The 119 /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance 120 /// containing the event data.</param> 121 // ------------------------------------------------------------------ 122 public void MouseUp(MouseEventArgs e) 123 { 124 if (IsActive) 125 { 126 IView view = Controller.View; 127 if (view.Ghost != null) 128 { 129 Rectangle zoomArea = view.Ghost.Rectangle; 130 view.ZoomArea(zoomArea); 131 started = false; 132 } 133 Controller.View.ResetGhost(); 134 } 135 } 136 137 #endregion 138 } 122 #endregion 123 } 139 124 }
Note: See TracChangeset
for help on using the changeset viewer.