1 | using System.Drawing;
|
---|
2 | using System.Windows.Forms;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Visualization {
|
---|
5 | public interface IMouseEventListener {
|
---|
6 | void MouseMove(object sender, MouseEventArgs e);
|
---|
7 | void MouseUp(object sender, MouseEventArgs e);
|
---|
8 |
|
---|
9 | event MouseEventHandler OnMouseMove;
|
---|
10 | event MouseEventHandler OnMouseUp;
|
---|
11 | }
|
---|
12 |
|
---|
13 | public delegate void SetNewClippingAreaHandler(RectangleD newClippingArea);
|
---|
14 |
|
---|
15 | public delegate void DrawRectangleHandler(Rectangle rectangle);
|
---|
16 |
|
---|
17 | public class PanListener : IMouseEventListener {
|
---|
18 | private readonly Rectangle viewPort;
|
---|
19 | private readonly RectangleD clippingArea;
|
---|
20 | private readonly Point startPoint;
|
---|
21 |
|
---|
22 | public PanListener(Rectangle viewPort, RectangleD clippingArea, Point startPoint) {
|
---|
23 | this.viewPort = viewPort;
|
---|
24 | this.clippingArea = clippingArea;
|
---|
25 | this.startPoint = startPoint;
|
---|
26 | }
|
---|
27 |
|
---|
28 | #region IMouseEventListener Members
|
---|
29 |
|
---|
30 | public event SetNewClippingAreaHandler SetNewClippingArea;
|
---|
31 | public event MouseEventHandler OnMouseMove;
|
---|
32 | public event MouseEventHandler OnMouseUp;
|
---|
33 |
|
---|
34 | public void MouseMove(object sender, MouseEventArgs e) {
|
---|
35 | PointD worldStartPoint = Transform.ToWorld(startPoint, viewPort, clippingArea);
|
---|
36 | PointD worldActualPoint = Transform.ToWorld(e.Location, viewPort, clippingArea);
|
---|
37 |
|
---|
38 | double xDiff = worldActualPoint.X - worldStartPoint.X;
|
---|
39 | double yDiff = worldActualPoint.Y - worldStartPoint.Y;
|
---|
40 |
|
---|
41 | RectangleD newClippingArea = new RectangleD();
|
---|
42 | newClippingArea.X1 = clippingArea.X1 - xDiff;
|
---|
43 | newClippingArea.X2 = clippingArea.X2 - xDiff;
|
---|
44 | newClippingArea.Y1 = clippingArea.Y1 - yDiff;
|
---|
45 | newClippingArea.Y2 = clippingArea.Y2 - yDiff;
|
---|
46 |
|
---|
47 | if (SetNewClippingArea != null) {
|
---|
48 | SetNewClippingArea(newClippingArea);
|
---|
49 | }
|
---|
50 |
|
---|
51 | if (OnMouseMove != null) {
|
---|
52 | OnMouseMove(sender, e);
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public void MouseUp(object sender, MouseEventArgs e) {
|
---|
57 | if (OnMouseUp != null) {
|
---|
58 | OnMouseUp(sender, e);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | #endregion
|
---|
63 | }
|
---|
64 |
|
---|
65 | public class ZoomListener : IMouseEventListener {
|
---|
66 | private readonly Point startPoint;
|
---|
67 |
|
---|
68 | public event DrawRectangleHandler DrawRectangle;
|
---|
69 |
|
---|
70 | public ZoomListener(Point startPoint) {
|
---|
71 | this.startPoint = startPoint;
|
---|
72 | }
|
---|
73 |
|
---|
74 | #region IMouseEventListener Members
|
---|
75 |
|
---|
76 | public event MouseEventHandler OnMouseMove;
|
---|
77 | public event MouseEventHandler OnMouseUp;
|
---|
78 |
|
---|
79 | public void MouseMove(object sender, MouseEventArgs e) {
|
---|
80 | Rectangle r = new Rectangle();
|
---|
81 | Point actualPoint = e.Location;
|
---|
82 |
|
---|
83 | if (startPoint.X < actualPoint.X) {
|
---|
84 | r.X = startPoint.X;
|
---|
85 | r.Width = actualPoint.X - startPoint.X;
|
---|
86 | } else {
|
---|
87 | r.X = actualPoint.X;
|
---|
88 | r.Width = startPoint.X - actualPoint.X;
|
---|
89 | }
|
---|
90 |
|
---|
91 | if (startPoint.Y < actualPoint.Y) {
|
---|
92 | r.Y = startPoint.Y;
|
---|
93 | r.Height = actualPoint.Y - startPoint.Y;
|
---|
94 | } else {
|
---|
95 | r.Y = actualPoint.Y;
|
---|
96 | r.Height = startPoint.Y - actualPoint.Y;
|
---|
97 | }
|
---|
98 |
|
---|
99 | if(DrawRectangle != null) {
|
---|
100 | DrawRectangle(r);
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (OnMouseMove != null) {
|
---|
104 | OnMouseMove(sender, e);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public void MouseUp(object sender, MouseEventArgs e) {
|
---|
109 | if (OnMouseUp != null) {
|
---|
110 | OnMouseUp(sender, e);
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | #endregion
|
---|
115 | }
|
---|
116 | } |
---|