Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/HeuristicLab.Netron-3.0.2672.12446/NetronVisualization.cs @ 11552

Last change on this file since 11552 was 11171, checked in by ascheibe, 10 years ago

#2115 merged r11170 (copyright update) into trunk

File size: 4.6 KB
RevLine 
[2801]1#region License Information
2/* HeuristicLab
[11171]3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2801]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;
[2781]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 {
[2801]32    private static Size INVALID_SIZE = new Size(-1, -1);
[2782]33    private Size oldSize;
[2781]34    public NetronVisualization()
35      : base() {
36      InitializeComponent();
[2782]37      this.oldSize = INVALID_SIZE;
[2781]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);
[2868]46        this.Document = new Document();
[2909]47        this.Document.Model.Selection = new Selection(this.Controller, this.Document.Model);
[2781]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
[2782]55        this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
[2909]56        this.UpdateView();
[2781]57      }
58    }
59
[2909]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
[2782]93    private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
[2801]94      //if (this.oldSize == INVALID_SIZE) {
[2909]95      //this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
[2801]96      //  if (!this.DesignMode)
97      //    oldSize = this.Size;
98      //  return;
99      //}
[2782]100
[2801]101      //SizeF magnificationChanges = new SizeF();
102      //magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
103      //magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
[2782]104
[2801]105      //SizeF newMagnification = new SizeF();
106      //newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
107      //newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
[2782]108
[2801]109      //this.Magnification = newMagnification;
110      //this.oldSize = this.Size;
[2781]111    }
112
[3167]113
114    protected override void OnMouseWheel(MouseEventArgs e) {
115      //inserted to disable scrolling by the mousewheel
116      //base.OnMouseWheel(e);
117    }
118
[2781]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);
[2782]125      }
[2781]126    }
127
128    private void mView_OnCursorChange(object sender, CursorEventArgs e) {
129      this.Cursor = e.Cursor;
130    }
131  }
132}
Note: See TracBrowser for help on using the repository browser.