Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/ZoomListener.cs @ 1055

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

#424
Did some code refactoring (created concrete MouseEventListeners)

File size: 1.4 KB
Line 
1using System.Drawing;
2using System.Windows.Forms;
3
4namespace HeuristicLab.Visualization {
5  public class ZoomListener : IMouseEventListener {
6    private readonly Point startPoint;
7
8    public event DrawRectangleHandler DrawRectangle;
9
10    public ZoomListener(Point startPoint) {
11      this.startPoint = startPoint;
12    }
13
14    #region IMouseEventListener Members
15
16    public event MouseEventHandler OnMouseMove;
17    public event MouseEventHandler OnMouseUp;
18
19    public void MouseMove(object sender, MouseEventArgs e) {
20      Rectangle r = new Rectangle();
21      Point actualPoint = e.Location;
22
23      if (startPoint.X < actualPoint.X) {
24        r.X = startPoint.X;
25        r.Width = actualPoint.X - startPoint.X;
26      } else {
27        r.X = actualPoint.X;
28        r.Width = startPoint.X - actualPoint.X;
29      }
30
31      if (startPoint.Y < actualPoint.Y) {
32        r.Y = startPoint.Y;
33        r.Height = actualPoint.Y - startPoint.Y;
34      } else {
35        r.Y = actualPoint.Y;
36        r.Height = startPoint.Y - actualPoint.Y;
37      }
38
39      if(DrawRectangle != null) {
40        DrawRectangle(r);
41      }
42
43      if (OnMouseMove != null) {
44        OnMouseMove(sender, e);
45      }
46    }
47
48    public void MouseUp(object sender, MouseEventArgs e) {
49      if (OnMouseUp != null) {
50        OnMouseUp(sender, e);
51      }
52    }
53
54    #endregion
55  }
56}
Note: See TracBrowser for help on using the repository browser.