1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Windows.Forms;
|
---|
26 |
|
---|
27 | using Netron.Diagramming.Core;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Netron {
|
---|
30 | [ToolboxItem(true)]
|
---|
31 | public partial class NetronVisualization : DiagramControlBase {
|
---|
32 | private static Size INVALID_SIZE = new Size(-1, -1);
|
---|
33 | private Size oldSize;
|
---|
34 | public NetronVisualization()
|
---|
35 | : base() {
|
---|
36 | InitializeComponent();
|
---|
37 | this.oldSize = INVALID_SIZE;
|
---|
38 |
|
---|
39 | SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
---|
40 | SetStyle(ControlStyles.DoubleBuffer, true);
|
---|
41 | SetStyle(ControlStyles.UserPaint, true);
|
---|
42 | SetStyle(ControlStyles.ResizeRedraw, true);
|
---|
43 |
|
---|
44 | AutoScroll = true;
|
---|
45 |
|
---|
46 | if (!DesignMode) {
|
---|
47 | this.Controller = new Controller(this);
|
---|
48 | this.Document = new Document();
|
---|
49 | this.Document.Model.Selection = new Selection(this.Controller, this.Document.Model);
|
---|
50 | this.View = new View(this);
|
---|
51 | this.AttachToDocument(Document);
|
---|
52 | this.Controller.View = View;
|
---|
53 |
|
---|
54 | View.OnCursorChange += new EventHandler<CursorEventArgs>(mView_OnCursorChange);
|
---|
55 | View.OnBackColorChange += new EventHandler<ColorEventArgs>(View_OnBackColorChange);
|
---|
56 |
|
---|
57 | this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
|
---|
58 | this.UpdateView();
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public Size PageSize {
|
---|
63 | get { return this.View.PageSize; }
|
---|
64 | set {
|
---|
65 | this.View.PageSize = value;
|
---|
66 | this.UpdateView();
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void UpdateView() {
|
---|
71 | //zoom in to show scrollbars - code taken from ControllerBase line 1082
|
---|
72 | SizeF s = this.View.Magnification;
|
---|
73 | float alpha = 1.1F;
|
---|
74 | View.Magnification = new SizeF(
|
---|
75 | s.Width * alpha,
|
---|
76 | s.Height * alpha);
|
---|
77 |
|
---|
78 | float w = (float)this.AutoScrollPosition.X /
|
---|
79 | (float)this.AutoScrollMinSize.Width;
|
---|
80 |
|
---|
81 | float h = (float)this.AutoScrollPosition.Y /
|
---|
82 | (float)this.AutoScrollMinSize.Height;
|
---|
83 |
|
---|
84 | RectangleF pageBounds = this.Controller.Model.CurrentPage.Bounds;
|
---|
85 | pageBounds.Inflate(s);
|
---|
86 | SizeF deltaSize = new SizeF(
|
---|
87 | pageBounds.Width - this.ClientRectangle.Width,
|
---|
88 | pageBounds.Height - this.ClientRectangle.Height);
|
---|
89 |
|
---|
90 | if ((deltaSize.Width > 0) && (deltaSize.Height > 0)) {
|
---|
91 | this.AutoScrollMinSize = Size.Round(deltaSize);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
|
---|
96 | //if (this.oldSize == INVALID_SIZE) {
|
---|
97 | //this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
|
---|
98 | // if (!this.DesignMode)
|
---|
99 | // oldSize = this.Size;
|
---|
100 | // return;
|
---|
101 | //}
|
---|
102 |
|
---|
103 | //SizeF magnificationChanges = new SizeF();
|
---|
104 | //magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
|
---|
105 | //magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
|
---|
106 |
|
---|
107 | //SizeF newMagnification = new SizeF();
|
---|
108 | //newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
|
---|
109 | //newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
|
---|
110 |
|
---|
111 | //this.Magnification = newMagnification;
|
---|
112 | //this.oldSize = this.Size;
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | protected override void OnMouseWheel(MouseEventArgs e) {
|
---|
117 | //inserted to disable scrolling by the mousewheel
|
---|
118 | //base.OnMouseWheel(e);
|
---|
119 | }
|
---|
120 |
|
---|
121 | protected override void OnScroll(ScrollEventArgs se) {
|
---|
122 | //base.OnScroll(se);
|
---|
123 | if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
|
---|
124 | Origin = new Point(se.NewValue, Origin.Y);
|
---|
125 | } else {
|
---|
126 | Origin = new Point(Origin.X, se.NewValue);
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | private void mView_OnCursorChange(object sender, CursorEventArgs e) {
|
---|
131 | this.Cursor = e.Cursor;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|