Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization.Test/MainForm.cs @ 781

Last change on this file since 781 was 725, checked in by bspisic, 16 years ago

#319

MouseEventListener implemented
dragDrop MouseEventListener example implemented

File size: 3.9 KB
Line 
1using System.Drawing;
2using System.Windows.Forms;
3
4namespace HeuristicLab.Visualization.Test {
5  public partial class MainForm : Form {
6    private MouseEventListener dragDropListener;
7
8    public MainForm() {
9      InitializeComponent();
10
11      CreateMouseEventListeners();
12
13      canvasUI.MainCanvas.WorldShape = new WorldShape(new RectangleD(0, 0, 800, 600), new RectangleD(0, 0, 800, 600));
14
15      CreateLeftWorldShape();
16      CreateMiddleCompositeShape();
17      CreateRightWorldShape();
18      CreateSimpleRectangleShape();
19
20      canvasUI.Invalidate();
21    }
22
23    private void CreateMouseEventListeners() {
24      dragDropListener = new MouseEventListener();
25      dragDropListener.OnMouseMove += DragDrop_OnMouseMove;
26      dragDropListener.OnMouseUp += DragDrop_OnMouseUp;
27    }
28
29    private void CreateSimpleRectangleShape() {
30      WorldShape mainWorld = canvasUI.MainCanvas.WorldShape;
31      // simple rectangle shape
32      RectangleShape rect7 = new RectangleShape(5, 5, 50, 50, 0, Color.Black);
33      mainWorld.AddShape(rect7);
34    }
35
36    private void CreateRightWorldShape() {
37      WorldShape mainWorld = canvasUI.MainCanvas.WorldShape;
38      // right world shape
39      WorldShape rightWorld = new WorldShape(new RectangleD(-1, -1, 1, 1), new RectangleD(600, 10, 780, 600));
40
41      double x1 = -3;
42      double y1 = -3;
43
44      for (int i = 0; i < 10000; i++) {
45        RectangleShape rect = new RectangleShape(x1, y1, x1 + 0.3, y1 + 0.3, 0, Color.Maroon);
46        x1 += 0.4;
47        y1 += 0.4;
48        rightWorld.AddShape(rect);
49      }
50
51      mainWorld.AddShape(rightWorld);
52    }
53
54    private void CreateMiddleCompositeShape() {
55      WorldShape mainWorld = canvasUI.MainCanvas.WorldShape;
56      // middle composite shape
57      CompositeShape middleComp = new CompositeShape();
58
59      RectangleShape rect5 = new RectangleShape(400, 10, 500, 300, 0, Color.Navy);
60      RectangleShape rect6 = new RectangleShape(510, 310, 580, 590, 0, Color.Magenta);
61
62      middleComp.AddShape(rect5);
63      middleComp.AddShape(rect6);
64
65      mainWorld.AddShape(middleComp);
66    }
67
68    private void CreateLeftWorldShape() {
69      WorldShape mainWorld = canvasUI.MainCanvas.WorldShape;
70      // left world shape
71      WorldShape leftWorld = new WorldShape(new RectangleD(0, 0, 1000, 1000), new RectangleD(10, 10, 380, 590));
72
73      RectangleShape fillRect = new RectangleShape(0, 0, 1000, 1000, 0, Color.LightBlue);
74
75      RectangleShape rect1 = new RectangleShape(100, 100, 500, 500, 0, Color.Red);
76      RectangleShape rect2 = new RectangleShape(800, -200, 1200, 500, 0, Color.Green);
77
78      CompositeShape comp1 = new CompositeShape();
79
80      RectangleShape rect3 = new RectangleShape(510, 580, 590, 700, 0, Color.Blue);
81      RectangleShape rect4 = new RectangleShape(600, 710, 800, 900, 0, Color.Orange);
82
83      comp1.AddShape(rect3);
84      comp1.AddShape(rect4);
85
86      leftWorld.AddShape(fillRect);
87      leftWorld.AddShape(rect1);
88      leftWorld.AddShape(rect2);
89      leftWorld.AddShape(comp1);
90
91      mainWorld.AddShape(leftWorld);
92    }
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    }
117  }
118}
Note: See TracBrowser for help on using the repository browser.