Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/PanListener.cs @ 1122

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

#424
Did some code refactoring (created concrete MouseEventListeners)

File size: 1.6 KB
Line 
1using System.Drawing;
2using System.Windows.Forms;
3
4namespace HeuristicLab.Visualization {
5  public class PanListener : IMouseEventListener {
6    private readonly Rectangle viewPort;
7    private readonly RectangleD clippingArea;
8    private readonly Point startPoint;
9
10    public PanListener(Rectangle viewPort, RectangleD clippingArea, Point startPoint) {
11      this.viewPort = viewPort;
12      this.clippingArea = clippingArea;
13      this.startPoint = startPoint;
14    }
15
16    #region IMouseEventListener Members
17
18    public event SetNewClippingAreaHandler SetNewClippingArea;
19    public event MouseEventHandler OnMouseMove;
20    public event MouseEventHandler OnMouseUp;
21
22    public void MouseMove(object sender, MouseEventArgs e) {
23      PointD worldStartPoint = Transform.ToWorld(startPoint, viewPort, clippingArea);
24      PointD worldActualPoint = Transform.ToWorld(e.Location, viewPort, clippingArea);
25
26      double xDiff = worldActualPoint.X - worldStartPoint.X;
27      double yDiff = worldActualPoint.Y - worldStartPoint.Y;
28
29      RectangleD newClippingArea = new RectangleD();
30      newClippingArea.X1 = clippingArea.X1 - xDiff;
31      newClippingArea.X2 = clippingArea.X2 - xDiff;
32      newClippingArea.Y1 = clippingArea.Y1 - yDiff;
33      newClippingArea.Y2 = clippingArea.Y2 - yDiff;
34
35      if (SetNewClippingArea != null) {
36        SetNewClippingArea(newClippingArea);
37      }
38
39      if (OnMouseMove != null) {
40        OnMouseMove(sender, e);
41      }
42    }
43
44    public void MouseUp(object sender, MouseEventArgs e) {
45      if (OnMouseUp != null) {
46        OnMouseUp(sender, e);
47      }
48    }
49
50    #endregion
51  }
52}
Note: See TracBrowser for help on using the repository browser.