1 | using System.Drawing;
|
---|
2 | using System.Windows.Forms;
|
---|
3 |
|
---|
4 | namespace 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 | } |
---|