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