Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/04/09 21:35:43 (15 years ago)
Author:
bspisic
Message:

reimplemented panning and zooming (#424)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/ZoomListener.cs

    r1058 r1249  
    66    private readonly Point startPoint;
    77
    8     public event DrawRectangleHandler DrawRectangle;
     8    public event RectangleHandler DrawRectangle;
     9    public event RectangleHandler SetClippingArea;
    910
    1011    public ZoomListener(Point startPoint) {
     
    1415    #region IMouseEventListener Members
    1516
    16     public event MouseEventHandler OnMouseMove;
    17     public event MouseEventHandler OnMouseUp;
    18 
    1917    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 
    3918      if(DrawRectangle != null) {
    40         DrawRectangle(r);
    41       }
    42 
    43       if (OnMouseMove != null) {
    44         OnMouseMove(sender, e);
     19        DrawRectangle(CalcRectangle(e.Location));
    4520      }
    4621    }
    4722
    4823    public void MouseUp(object sender, MouseEventArgs e) {
    49       if (OnMouseUp != null) {
    50         OnMouseUp(sender, e);
    51       }
     24     if(SetClippingArea != null) {
     25       SetClippingArea(CalcRectangle(e.Location));
     26     }
    5227    }
    5328
    5429    #endregion
     30
     31    private Rectangle CalcRectangle(Point actualPoint) {
     32      Rectangle rectangle = new Rectangle();
     33
     34      if (startPoint.X < actualPoint.X) {
     35        rectangle.X = startPoint.X;
     36        rectangle.Width = actualPoint.X - startPoint.X;
     37      } else {
     38        rectangle.X = actualPoint.X;
     39        rectangle.Width = startPoint.X - actualPoint.X;
     40      }
     41
     42      if (startPoint.Y < actualPoint.Y) {
     43        rectangle.Y = startPoint.Y;
     44        rectangle.Height = actualPoint.Y - startPoint.Y;
     45      } else {
     46        rectangle.Y = actualPoint.Y;
     47        rectangle.Height = startPoint.Y - actualPoint.Y;
     48      }
     49
     50      return rectangle;
     51    }
    5552
    5653    public static RectangleD ZoomClippingArea(RectangleD clippingArea, double zoomFactor) {
Note: See TracChangeset for help on using the changeset viewer.