Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ZoomToolBase.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ZoomToolBase.cs
r2868 r4068 1 using System;2 using System.Collections.Generic;3 using System.Text;4 1 using System.Drawing; 5 2 6 namespace Netron.Diagramming.Core 7 { 8 // ---------------------------------------------------------------------- 3 namespace 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 // ------------------------------------------------------------------ 9 12 /// <summary> 10 /// The base class for zooming tools. Zoom tools allow the user to 11 /// incrementally adjust (increase or decrease) the View's magnification. 13 /// Used to multiply the current magnification by. 12 14 /// </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; 15 // ------------------------------------------------------------------ 16 protected float myZoomFactor = 0.9F; 22 17 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 } 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 } 40 32 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 } 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 } 51 42 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(); 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(); 61 51 62 63 64 65 66 Point parentAutoScrollPosition =67 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; 68 58 69 70 71 59 Controller.View.Magnification = new SizeF( 60 size.Width * myZoomFactor, 61 size.Height * myZoomFactor); 72 62 73 74 75 76 77 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); 78 68 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; 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; 86 75 87 88 89 90 91 92 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))); 93 82 94 95 83 Controller.View.Origin = origin; 84 } 96 85 97 98 86 Controller.ParentControl.AutoScrollPosition = 87 Controller.View.Origin; 99 88 100 DeactivateTool(); 101 } 89 DeactivateTool(); 102 90 } 91 } 103 92 }
Note: See TracChangeset
for help on using the changeset viewer.