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 |
|
---|
16 | public Canvas MainCanvas {
|
---|
17 | get { return mainCanvas; }
|
---|
18 | }
|
---|
19 |
|
---|
20 | public MouseEventListener MouseEventListener {
|
---|
21 | get { return mouseEventListener; }
|
---|
22 | set { mouseEventListener = value; }
|
---|
23 | }
|
---|
24 |
|
---|
25 | protected override void OnPaint(PaintEventArgs pe) {
|
---|
26 | try {
|
---|
27 | Graphics g = pe.Graphics;
|
---|
28 |
|
---|
29 | g.SmoothingMode = SmoothingMode.AntiAlias;
|
---|
30 |
|
---|
31 | g.FillRectangle(Brushes.White, ClientRectangle);
|
---|
32 |
|
---|
33 | mainCanvas.Draw(g, ClientRectangle);
|
---|
34 |
|
---|
35 | g.DrawRectangle(Pens.Black, 0, 0, Width - 1, Height - 1);
|
---|
36 |
|
---|
37 | base.OnPaint(pe);
|
---|
38 | } catch (Exception e) {
|
---|
39 | Debug.WriteLine(e);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void OnResize(EventArgs e) {
|
---|
44 | Invalidate();
|
---|
45 |
|
---|
46 | base.OnResize(e);
|
---|
47 | }
|
---|
48 |
|
---|
49 | private void CanvasUI_MouseMove(object sender, MouseEventArgs e) {
|
---|
50 | if (mouseEventListener != null) {
|
---|
51 | mouseEventListener.MouseMove(e.Location);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | private void CanvasUI_MouseUp(object sender, MouseEventArgs e) {
|
---|
56 | if (mouseEventListener != null) {
|
---|
57 | mouseEventListener.MouseUp(e.Location);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 | } |
---|