Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ZoomToolBase.cs @ 2868

Last change on this file since 2868 was 2868, checked in by mkommend, 14 years ago

finished mapping from OperatorGraph to GraphVisualizationInfo (ticket #867)

File size: 3.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Drawing;
5
6namespace Netron.Diagramming.Core
7{
8    // ----------------------------------------------------------------------
9    /// <summary>
10    /// The base class for zooming tools.  Zoom tools allow the user to
11    /// incrementally adjust (increase or decrease) the View's magnification.
12    /// </summary>
13    // ----------------------------------------------------------------------
14    public class ZoomToolBase : AbstractTool
15    {
16        // ------------------------------------------------------------------
17        /// <summary>
18        /// Used to multiply the current magnification by.
19        /// </summary>
20        // ------------------------------------------------------------------
21        protected float myZoomFactor = 0.9F;
22
23        // ------------------------------------------------------------------
24        /// <summary>
25        /// Gets or sets the multiplier used to adjust the View's
26        /// Magnification by.  The default is 0.9.
27        /// </summary>
28        // ------------------------------------------------------------------
29        public float ZoomFactor
30        {
31            get
32            {
33                return myZoomFactor;
34            }
35            set
36            {
37                myZoomFactor = value;
38            }
39        }
40
41        // ------------------------------------------------------------------
42        /// <summary>
43        /// Constructor.
44        /// </summary>
45        /// <param name="toolName">string: The  name of the tool.</param>
46        // ------------------------------------------------------------------
47        public ZoomToolBase(string toolName)
48            : base(toolName)
49        {
50        }
51
52        // ------------------------------------------------------------------
53        /// <summary>
54        /// Activates this tool - the View's current magnification is
55        /// mulitiplied by 'ZoomFactor'.
56        /// </summary>
57        // ------------------------------------------------------------------
58        protected override void OnActivateTool()
59        {
60            base.OnActivateTool();
61
62            SizeF size = Controller.View.Magnification;
63            SizeF autoScrollMinSize =
64                Controller.ParentControl.AutoScrollMinSize;
65            Point origin = Controller.View.Origin;
66            Point parentAutoScrollPosition =
67                Controller.ParentControl.AutoScrollPosition;
68
69            Controller.View.Magnification = new SizeF(
70                size.Width * myZoomFactor,
71                size.Height * myZoomFactor);
72
73            // Remember to also adjust the diagram's scroll bars.
74            size = new SizeF(
75                autoScrollMinSize.Width * myZoomFactor,
76                autoScrollMinSize.Height * myZoomFactor);
77            Controller.ParentControl.AutoScrollMinSize = Size.Round(size);
78
79            // Should we set the Origin to the location of the selected items
80            // if there are any?  This will allow the user to zoom in on
81            // a selection.
82            if (this.Controller.Model.Selection.SelectedItems.Count > 0)
83            {
84              Bundle bundle = new Bundle(this.Controller.Model.Selection.SelectedItems);
85                Point bundleLocation = bundle.Rectangle.Location;
86
87                // Don't move the origin *exactly* to the bundle's location.
88                // Offset it a little so the bundle is butted-up with the
89                // upper-right hand corner of the screen.
90                bundleLocation.Offset(-20, -20);
91                origin.Offset(Point.Round(Controller.View.WorldToView(
92                    bundleLocation)));
93
94                Controller.View.Origin = origin;
95            }
96
97            Controller.ParentControl.AutoScrollPosition =
98                Controller.View.Origin;
99
100            DeactivateTool();
101        }
102    }
103}
Note: See TracBrowser for help on using the repository browser.