Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ZoomToolBase.cs @ 16462

Last change on this file since 16462 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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