Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ZoomAreaTool.cs @ 16462

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

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

File size: 4.2 KB
Line 
1using System;
2using System.Drawing;
3using System.Windows.Forms;
4
5namespace 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    // ------------------------------------------------------------------
15    /// <summary>
16    /// The location of the mouse when the motion starts.
17    /// </summary>
18    // ------------------------------------------------------------------
19    protected Point initialPoint;
20
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;
28
29    #endregion
30
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    }
40
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;
117        }
118        Controller.View.ResetGhost();
119      }
120    }
121
122    #endregion
123  }
124}
Note: See TracBrowser for help on using the repository browser.