1 | using System;
|
---|
2 | using System.Diagnostics;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Drawing.Drawing2D;
|
---|
5 | using System.Windows.Forms;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Visualization {
|
---|
8 | public partial class CanvasUI : Control {
|
---|
9 | private readonly Canvas mainCanvas = new Canvas();
|
---|
10 | private MouseEventListener mouseEventListener;
|
---|
11 |
|
---|
12 | public CanvasUI() {
|
---|
13 | InitializeComponent();
|
---|
14 |
|
---|
15 | DoubleBuffered = true;
|
---|
16 | }
|
---|
17 |
|
---|
18 | public Canvas MainCanvas {
|
---|
19 | get { return mainCanvas; }
|
---|
20 | }
|
---|
21 |
|
---|
22 | public MouseEventListener MouseEventListener {
|
---|
23 | get { return mouseEventListener; }
|
---|
24 | set { mouseEventListener = value; }
|
---|
25 | }
|
---|
26 |
|
---|
27 | protected override void OnPaint(PaintEventArgs pe) {
|
---|
28 | try {
|
---|
29 | Graphics g = pe.Graphics;
|
---|
30 |
|
---|
31 | g.SmoothingMode = SmoothingMode.AntiAlias;
|
---|
32 |
|
---|
33 | g.FillRectangle(Brushes.White, ClientRectangle);
|
---|
34 |
|
---|
35 | mainCanvas.Draw(g, ClientRectangle);
|
---|
36 |
|
---|
37 | g.DrawRectangle(Pens.Black, 0, 0, Width - 1, Height - 1);
|
---|
38 |
|
---|
39 | base.OnPaint(pe);
|
---|
40 | } catch (Exception e) {
|
---|
41 | Debug.WriteLine(e);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void OnResize(EventArgs e) {
|
---|
46 | Invalidate();
|
---|
47 |
|
---|
48 | base.OnResize(e);
|
---|
49 | }
|
---|
50 |
|
---|
51 | private void CanvasUI_MouseMove(object sender, MouseEventArgs e) {
|
---|
52 | if (mouseEventListener != null) {
|
---|
53 | mouseEventListener.MouseMove(e.Location);
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | private void CanvasUI_MouseUp(object sender, MouseEventArgs e) {
|
---|
58 | if (mouseEventListener != null) {
|
---|
59 | mouseEventListener.MouseUp(e.Location);
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | } |
---|