1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 | if (!DesignMode) {
|
---|
45 | this.Controller = new Controller(this);
|
---|
46 | this.Document = new Document();
|
---|
47 | this.Document.Model.Selection = new Selection(this.Controller, this.Document.Model);
|
---|
48 | this.View = new View(this);
|
---|
49 | this.AttachToDocument(Document);
|
---|
50 | this.Controller.View = View;
|
---|
51 |
|
---|
52 | View.OnCursorChange += new EventHandler<CursorEventArgs>(mView_OnCursorChange);
|
---|
53 | View.OnBackColorChange += new EventHandler<ColorEventArgs>(View_OnBackColorChange);
|
---|
54 |
|
---|
55 | this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
|
---|
56 | this.UpdateView();
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | public Size PageSize {
|
---|
61 | get { return this.View.PageSize; }
|
---|
62 | set {
|
---|
63 | this.View.PageSize = value;
|
---|
64 | this.UpdateView();
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | private void UpdateView() {
|
---|
69 | //zoom in to show scrollbars - code taken from ControllerBase line 1082
|
---|
70 | SizeF s = this.View.Magnification;
|
---|
71 | float alpha = 1.1F;
|
---|
72 | View.Magnification = new SizeF(
|
---|
73 | s.Width * alpha,
|
---|
74 | s.Height * alpha);
|
---|
75 |
|
---|
76 | float w = (float)this.AutoScrollPosition.X /
|
---|
77 | (float)this.AutoScrollMinSize.Width;
|
---|
78 |
|
---|
79 | float h = (float)this.AutoScrollPosition.Y /
|
---|
80 | (float)this.AutoScrollMinSize.Height;
|
---|
81 |
|
---|
82 | RectangleF pageBounds = this.Controller.Model.CurrentPage.Bounds;
|
---|
83 | pageBounds.Inflate(s);
|
---|
84 | SizeF deltaSize = new SizeF(
|
---|
85 | pageBounds.Width - this.ClientRectangle.Width,
|
---|
86 | pageBounds.Height - this.ClientRectangle.Height);
|
---|
87 |
|
---|
88 | if ((deltaSize.Width > 0) && (deltaSize.Height > 0)) {
|
---|
89 | this.AutoScrollMinSize = Size.Round(deltaSize);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
|
---|
94 | //if (this.oldSize == INVALID_SIZE) {
|
---|
95 | //this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
|
---|
96 | // if (!this.DesignMode)
|
---|
97 | // oldSize = this.Size;
|
---|
98 | // return;
|
---|
99 | //}
|
---|
100 |
|
---|
101 | //SizeF magnificationChanges = new SizeF();
|
---|
102 | //magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
|
---|
103 | //magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
|
---|
104 |
|
---|
105 | //SizeF newMagnification = new SizeF();
|
---|
106 | //newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
|
---|
107 | //newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
|
---|
108 |
|
---|
109 | //this.Magnification = newMagnification;
|
---|
110 | //this.oldSize = this.Size;
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | protected override void OnMouseWheel(MouseEventArgs e) {
|
---|
115 | //inserted to disable scrolling by the mousewheel
|
---|
116 | //base.OnMouseWheel(e);
|
---|
117 | }
|
---|
118 |
|
---|
119 | protected override void OnScroll(ScrollEventArgs se) {
|
---|
120 | //base.OnScroll(se);
|
---|
121 | if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
|
---|
122 | Origin = new Point(se.NewValue, Origin.Y);
|
---|
123 | } else {
|
---|
124 | Origin = new Point(Origin.X, se.NewValue);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | private void mView_OnCursorChange(object sender, CursorEventArgs e) {
|
---|
129 | this.Cursor = e.Cursor;
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|