Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/HeuristicLab.Netron-3.0.2672.12446/NetronVisualization.cs @ 6593

Last change on this file since 6593 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

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