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