Free cookie consent management tool by TermsFeed Policy Generator

Changeset 725


Ignore:
Timestamp:
11/09/08 16:30:24 (16 years ago)
Author:
bspisic
Message:

#319

MouseEventListener implemented
dragDrop MouseEventListener example implemented

Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/MainForm.Designer.cs

    r724 r725  
    3636      this.canvasUI.TabIndex = 3;
    3737      this.canvasUI.Text = "canvasUI";
     38      this.canvasUI.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI_MouseDown);
    3839      //
    3940      // label2
  • trunk/sources/HeuristicLab.Visualization.Test/MainForm.cs

    r636 r725  
    11using System.Drawing;
    22using System.Windows.Forms;
    3 using HeuristicLab.Visualization;
    43
    54namespace HeuristicLab.Visualization.Test {
    65  public partial class MainForm : Form {
     6    private MouseEventListener dragDropListener;
     7
    78    public MainForm() {
    89      InitializeComponent();
     10
     11      CreateMouseEventListeners();
    912
    1013      canvasUI.MainCanvas.WorldShape = new WorldShape(new RectangleD(0, 0, 800, 600), new RectangleD(0, 0, 800, 600));
     
    1619
    1720      canvasUI.Invalidate();
     21    }
     22
     23    private void CreateMouseEventListeners() {
     24      dragDropListener = new MouseEventListener();
     25      dragDropListener.OnMouseMove += DragDrop_OnMouseMove;
     26      dragDropListener.OnMouseUp += DragDrop_OnMouseUp;
    1827    }
    1928
     
    3443
    3544      for (int i = 0; i < 10000; i++) {
    36         RectangleShape rect = new RectangleShape(x1, y1, x1+0.3, y1+0.3, 0, Color.Maroon);
    37         x1 += 0.4; y1 += 0.4;
     45        RectangleShape rect = new RectangleShape(x1, y1, x1 + 0.3, y1 + 0.3, 0, Color.Maroon);
     46        x1 += 0.4;
     47        y1 += 0.4;
    3848        rightWorld.AddShape(rect);
    3949      }
     
    8191      mainWorld.AddShape(leftWorld);
    8292    }
     93
     94    private void canvasUI_MouseDown(object sender, MouseEventArgs e) {
     95      mouseEventDemonstrationGraphics = canvasUI.CreateGraphics();
     96
     97      dragDropListener.StartPoint = e.Location;
     98      lastActualPoint = e.Location;
     99
     100      canvasUI.MouseEventListener = dragDropListener;
     101    }
     102
     103    private Point lastActualPoint;
     104    private Graphics mouseEventDemonstrationGraphics;
     105
     106    private void DragDrop_OnMouseUp(Point startPoint, Point actualPoint) {
     107      canvasUI.MouseEventListener = null;
     108
     109      canvasUI.Invalidate();
     110      mouseEventDemonstrationGraphics.Dispose();
     111    }
     112
     113    private void DragDrop_OnMouseMove(Point startPoint, Point actualPoint) {
     114      mouseEventDemonstrationGraphics.DrawLine(Pens.Blue, lastActualPoint, actualPoint);
     115      lastActualPoint = actualPoint;
     116    }
    83117  }
    84118}
  • trunk/sources/HeuristicLab.Visualization/CanvasUI.cs

    r724 r725  
    3939
    4040    private void CanvasUI_MouseMove(object sender, MouseEventArgs e) {
    41       if (mouseEventListener != null) {}
     41      if (mouseEventListener != null) {
     42        mouseEventListener.MouseMove(e.Location);
     43      }
    4244    }
    4345
    4446    private void CanvasUI_MouseUp(object sender, MouseEventArgs e) {
    45       if (mouseEventListener != null) {}
     47      if (mouseEventListener != null) {
     48        mouseEventListener.MouseUp(e.Location);
     49      }
    4650    }
    4751  }
  • trunk/sources/HeuristicLab.Visualization/MouseEventListener.cs

    r724 r725  
    1 namespace HeuristicLab.Visualization {
    2   public class MouseEventListener {}
     1using System.Drawing;
     2
     3namespace HeuristicLab.Visualization {
     4  public class MouseEventListener {
     5    public event MouseEventListenerHandler OnMouseMove;
     6    public event MouseEventListenerHandler OnMouseUp;
     7
     8    private Point startPoint;
     9
     10    public void MouseMove(Point actualPoint) {
     11      if (OnMouseMove != null) {
     12        OnMouseMove(startPoint, actualPoint);
     13      }
     14    }
     15
     16    public void MouseUp(Point actualPoint) {
     17      if (OnMouseUp != null) {
     18        OnMouseUp(startPoint, actualPoint);
     19      }
     20    }
     21
     22    public Point StartPoint {
     23      get { return startPoint; }
     24      set { startPoint = value; }
     25    }
     26  }
     27
     28  public delegate void MouseEventListenerHandler(Point startPoint, Point actualPoint);
    329}
Note: See TracChangeset for help on using the changeset viewer.