[1055] | 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 |
|
---|
[1249] | 8 | public event RectangleHandler DrawRectangle;
|
---|
| 9 | public event RectangleHandler SetClippingArea;
|
---|
[1055] | 10 |
|
---|
| 11 | public ZoomListener(Point startPoint) {
|
---|
| 12 | this.startPoint = startPoint;
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | #region IMouseEventListener Members
|
---|
| 16 |
|
---|
| 17 | public void MouseMove(object sender, MouseEventArgs e) {
|
---|
[1249] | 18 | if(DrawRectangle != null) {
|
---|
| 19 | DrawRectangle(CalcRectangle(e.Location));
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
[1055] | 22 |
|
---|
[1249] | 23 | public void MouseUp(object sender, MouseEventArgs e) {
|
---|
| 24 | if(SetClippingArea != null) {
|
---|
| 25 | SetClippingArea(CalcRectangle(e.Location));
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | #endregion
|
---|
| 30 |
|
---|
| 31 | private Rectangle CalcRectangle(Point actualPoint) {
|
---|
| 32 | Rectangle rectangle = new Rectangle();
|
---|
| 33 |
|
---|
[1055] | 34 | if (startPoint.X < actualPoint.X) {
|
---|
[1249] | 35 | rectangle.X = startPoint.X;
|
---|
| 36 | rectangle.Width = actualPoint.X - startPoint.X;
|
---|
[1055] | 37 | } else {
|
---|
[1249] | 38 | rectangle.X = actualPoint.X;
|
---|
| 39 | rectangle.Width = startPoint.X - actualPoint.X;
|
---|
[1055] | 40 | }
|
---|
| 41 |
|
---|
| 42 | if (startPoint.Y < actualPoint.Y) {
|
---|
[1249] | 43 | rectangle.Y = startPoint.Y;
|
---|
| 44 | rectangle.Height = actualPoint.Y - startPoint.Y;
|
---|
[1055] | 45 | } else {
|
---|
[1249] | 46 | rectangle.Y = actualPoint.Y;
|
---|
| 47 | rectangle.Height = startPoint.Y - actualPoint.Y;
|
---|
[1055] | 48 | }
|
---|
| 49 |
|
---|
[1249] | 50 | return rectangle;
|
---|
[1055] | 51 | }
|
---|
| 52 |
|
---|
[1058] | 53 | public static RectangleD ZoomClippingArea(RectangleD clippingArea, double zoomFactor) {
|
---|
| 54 | double x1, x2, y1, y2, width, height;
|
---|
| 55 |
|
---|
| 56 | width = clippingArea.Width * zoomFactor;
|
---|
| 57 | height = clippingArea.Height * zoomFactor;
|
---|
| 58 |
|
---|
| 59 | x1 = clippingArea.X1 - (width - clippingArea.Width) / 2;
|
---|
| 60 | y1 = clippingArea.Y1 - (height - clippingArea.Height) / 2;
|
---|
| 61 | x2 = width + x1;
|
---|
| 62 | y2 = height + y1;
|
---|
| 63 |
|
---|
| 64 | return new RectangleD(x1, y1, x2, y2);
|
---|
| 65 | }
|
---|
[1055] | 66 | }
|
---|
| 67 | } |
---|