1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 |
|
---|
10 | using Netron.Diagramming.Core;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Netron {
|
---|
13 | [ToolboxItem(true)]
|
---|
14 | public partial class NetronVisualization : DiagramControlBase {
|
---|
15 | private static Size INVALID_SIZE = new Size(-1,-1);
|
---|
16 | private Size oldSize;
|
---|
17 | public NetronVisualization()
|
---|
18 | : base() {
|
---|
19 | InitializeComponent();
|
---|
20 | this.oldSize = INVALID_SIZE;
|
---|
21 |
|
---|
22 | SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
---|
23 | SetStyle(ControlStyles.DoubleBuffer, true);
|
---|
24 | SetStyle(ControlStyles.UserPaint, true);
|
---|
25 | SetStyle(ControlStyles.ResizeRedraw, true);
|
---|
26 |
|
---|
27 | if (!DesignMode) {
|
---|
28 | this.Controller = new Controller(this);
|
---|
29 | this.View = new View(this);
|
---|
30 |
|
---|
31 | this.Document = new Document();
|
---|
32 | this.AttachToDocument(Document);
|
---|
33 | this.Controller.View = View;
|
---|
34 | TextEditor.Init(this);
|
---|
35 |
|
---|
36 | View.OnCursorChange += new EventHandler<CursorEventArgs>(mView_OnCursorChange);
|
---|
37 | View.OnBackColorChange += new EventHandler<ColorEventArgs>(View_OnBackColorChange);
|
---|
38 |
|
---|
39 | this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
|
---|
40 | this.AllowDrop = true;
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
|
---|
45 | if (this.oldSize == INVALID_SIZE) {
|
---|
46 | this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
|
---|
47 | oldSize = this.Size;
|
---|
48 | return;
|
---|
49 | }
|
---|
50 |
|
---|
51 | SizeF magnificationChanges = new SizeF();
|
---|
52 | magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
|
---|
53 | magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
|
---|
54 |
|
---|
55 | SizeF newMagnification = new SizeF();
|
---|
56 | newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
|
---|
57 | newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
|
---|
58 |
|
---|
59 | this.Magnification = newMagnification;
|
---|
60 | this.oldSize = this.Size;
|
---|
61 | }
|
---|
62 |
|
---|
63 | protected override void OnScroll(ScrollEventArgs se) {
|
---|
64 | //base.OnScroll(se);
|
---|
65 | if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
|
---|
66 | Origin = new Point(se.NewValue, Origin.Y);
|
---|
67 | //System.Diagnostics.Trace.WriteLine(se.NewValue);
|
---|
68 | } else {
|
---|
69 | Origin = new Point(Origin.X, se.NewValue);
|
---|
70 | //System.Diagnostics.Trace.WriteLine(se.NewValue);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | private void mView_OnCursorChange(object sender, CursorEventArgs e) {
|
---|
75 | this.Cursor = e.Cursor;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|