Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/ZoomListener.cs @ 2592

Last change on this file since 2592 was 2019, checked in by bspisic, 15 years ago

Added some comments (#664)

File size: 1.3 KB
Line 
1using System;
2using System.Drawing;
3using System.Windows.Forms;
4
5namespace HeuristicLab.Visualization {
6  /// <summary>
7  /// Supports the state zooming.
8  /// </summary>
9  public class ZoomListener : IMouseEventListener {
10    private readonly Point startPoint;
11
12    /// <summary>
13    /// This event will be fired every MouseMove call.
14    /// </summary>
15    public event RectangleHandler DrawRectangle;
16
17    /// <summary>
18    /// This event will be fired on the MouseUp call.
19    /// </summary>
20    public event RectangleHandler Zoom;
21
22    public ZoomListener(Point startPoint) {
23      this.startPoint = startPoint;
24    }
25
26    #region IMouseEventListener Members
27
28    public void MouseMove(object sender, MouseEventArgs e) {
29      if(DrawRectangle != null) {
30        DrawRectangle(CalcRectangle(e.Location));
31      }
32    }
33
34    public void MouseUp(object sender, MouseEventArgs e) {
35     if(Zoom != null) {
36       Zoom(CalcRectangle(e.Location));
37     }
38    }
39
40    #endregion
41
42    private Rectangle CalcRectangle(Point actualPoint) {
43      int x = Math.Min(startPoint.X, actualPoint.X);
44      int y = Math.Min(startPoint.Y, actualPoint.Y);
45      int width = Math.Abs(actualPoint.X - startPoint.X);
46      int height = Math.Abs(actualPoint.Y - startPoint.Y);
47     
48      return new Rectangle(x, y, width, height);
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.