Free cookie consent management tool by TermsFeed Policy Generator

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

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

#424
Implemented zooming by holding the control key + scrolling

File size: 1.8 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    public static RectangleD ZoomClippingArea(RectangleD clippingArea, double zoomFactor) {
57      double x1, x2, y1, y2, width, height;
58
59      width = clippingArea.Width * zoomFactor;
60      height = clippingArea.Height * zoomFactor;
61
62      x1 = clippingArea.X1 - (width - clippingArea.Width) / 2;
63      y1 = clippingArea.Y1 - (height - clippingArea.Height) / 2;
64      x2 = width + x1;
65      y2 = height + y1;
66
67      return new RectangleD(x1, y1, x2, y2);
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.