Free cookie consent management tool by TermsFeed Policy Generator

Changeset 984


Ignore:
Timestamp:
12/12/08 18:48:01 (15 years ago)
Author:
bspisic
Message:

#424
Implemented zooming

Location:
trunk/sources/HeuristicLab.Visualization
Files:
3 edited

Legend:

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

    r983 r984  
    192192
    193193    private MouseEventListener panListener;
     194    private MouseEventListener zoomListener;
    194195
    195196    private void CreateMouseEventListeners() {
     
    197198      panListener.OnMouseMove += Pan_OnMouseMove;
    198199      panListener.OnMouseUp += Pan_OnMouseUp;
    199     }
    200 
     200
     201      zoomListener = new MouseEventListener();
     202      zoomListener.OnMouseMove += Zoom_OnMouseMove;
     203      zoomListener.OnMouseUp += Zoom_OnMouseUp;
     204    }
    201205
    202206    private RectangleD startClippingArea;
    203207
    204208    private void canvasUI1_MouseDown(object sender, MouseEventArgs e) {
    205       panListener.StartPoint = e.Location;
    206       canvasUI1.MouseEventListener = panListener;
    207 
    208       startClippingArea = root.ClippingArea;
     209      if (ModifierKeys == Keys.Control) {
     210        zoomListener.StartPoint = e.Location;
     211        canvasUI1.MouseEventListener = zoomListener;
     212
     213        r = Rectangle.Empty;
     214        rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, 1000, Color.Blue);
     215
     216        root.AddShape(rectangleShape);
     217      } else {
     218        panListener.StartPoint = e.Location;
     219        canvasUI1.MouseEventListener = panListener;
     220
     221        startClippingArea = root.ClippingArea;
     222      }
    209223    }
    210224
    211225    private void Pan_OnMouseUp(Point startPoint, Point actualPoint) {
    212        canvasUI1.MouseEventListener = null;
     226      canvasUI1.MouseEventListener = null;
    213227    }
    214228
     
    231245      panListener.StartPoint = startPoint;
    232246
    233       this.zoomFullView = false; //user wants to pan => no full view
    234 
     247      zoomFullView = false; //user wants to pan => no full view
     248
     249      canvasUI1.Invalidate();
     250    }
     251
     252    private void Zoom_OnMouseUp(Point startPoint, Point actualPoint) {
     253      canvasUI1.MouseEventListener = null;
     254
     255      RectangleD newClippingArea = Transform.ToWorld(r, canvasUI1.ClientRectangle, root.ClippingArea);
     256      root.ClippingArea = newClippingArea;
     257      root.RemoveShape(rectangleShape);
     258
     259      zoomFullView = false; //user wants to pan => no full view
     260
     261      canvasUI1.Invalidate();
     262    }
     263
     264    private Rectangle r;
     265    private RectangleShape rectangleShape;
     266
     267    private void Zoom_OnMouseMove(Point startPoint, Point actualPoint) {
     268      r = new Rectangle();
     269
     270      if (startPoint.X < actualPoint.X) {
     271        r.X = startPoint.X;
     272        r.Width = actualPoint.X - startPoint.X;
     273      } else {
     274        r.X = actualPoint.X;
     275        r.Width = startPoint.X - actualPoint.X;
     276      }
     277
     278      if (startPoint.Y < actualPoint.Y) {
     279        r.Y = startPoint.Y;
     280        r.Height = actualPoint.Y - startPoint.Y;
     281      } else {
     282        r.Y = actualPoint.Y;
     283        r.Height = startPoint.Y - actualPoint.Y;
     284      }
     285
     286      rectangleShape.Rectangle = Transform.ToWorld(r, canvasUI1.ClientRectangle, root.ClippingArea);
    235287      canvasUI1.Invalidate();
    236288    }
  • trunk/sources/HeuristicLab.Visualization/RectangleShape.cs

    r635 r984  
    33namespace HeuristicLab.Visualization {
    44  public class RectangleShape : IShape {
    5     private RectangleD rect;
     5    private RectangleD rectangle;
    66    private double z;
    77    private Color color;
     8    private int opacity = 100;
    89
    910    public RectangleShape(double x1, double y1, double x2, double y2, double z, Color color) {
    10       this.rect = new RectangleD(x1, y1, x2, y2);
     11      rectangle = new RectangleD(x1, y1, x2, y2);
    1112      this.z = z;
    1213      this.color = color;
     
    1415
    1516    public RectangleD BoundingBox {
    16       get { return rect; }
     17      get { return rectangle; }
    1718    }
    1819
    1920    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
     21      Color brushColor = Color.FromArgb(50, color);
     22
    2023      using (Pen pen = new Pen(color, 1))
    21       using (Brush brush = new SolidBrush(color)) {
    22         Rectangle screenRect = Transform.ToScreen(rect, viewport, clippingArea);
     24      using (Brush brush = new SolidBrush(brushColor)) {
     25        Rectangle screenRect = Transform.ToScreen(rectangle, viewport, clippingArea);
    2326
    2427        graphics.DrawRectangle(pen, screenRect);
     
    3134      set { z = value; }
    3235    }
     36
     37    public RectangleD Rectangle {
     38      get { return rectangle; }
     39      set { rectangle = value; }
     40    }
    3341  }
    3442}
  • trunk/sources/HeuristicLab.Visualization/WorldShape.cs

    r928 r984  
    2121
    2222      graphics.SetClip(innerViewport);
    23      
     23
    2424      foreach (IShape shape in shapes) {
    2525        shape.Draw(graphics, innerViewport, this.clippingArea);
    2626      }
    27      
     27
    2828      graphics.Restore(gstate);
    2929    }
     
    4848      shapes.Add(shape);
    4949    }
     50
     51    public bool RemoveShape(IShape shape) {
     52      return shapes.Remove(shape);
     53    }
    5054  }
    5155}
Note: See TracChangeset for help on using the changeset viewer.