Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/RectangleTool.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/RectangleTool.cs
r2768 r4068 1 using System;2 1 using System.Drawing; 3 2 using System.Windows.Forms; 4 3 5 namespace Netron.Diagramming.Core 6 { 7 // ---------------------------------------------------------------------- 4 namespace Netron.Diagramming.Core { 5 // ---------------------------------------------------------------------- 6 /// <summary> 7 /// Tool to draw rectangles on the canvas. 8 /// </summary> 9 // ---------------------------------------------------------------------- 10 public class RectangleTool : AbstractDrawingTool { 11 #region Fields 12 13 #endregion 14 15 #region Properties 16 17 #endregion 18 19 #region Constructor 20 public RectangleTool() 21 : base("Rectangle Tool") { 22 } 23 public RectangleTool(string name) 24 : base(name) { 25 26 } 27 #endregion 28 29 #region Methods 30 31 // ------------------------------------------------------------------ 8 32 /// <summary> 9 /// Tool to draw rectangles on the canvas.33 /// Activates the tool - the cursor is set to the Icons.DrawRectangle. 10 34 /// </summary> 11 // ---------------------------------------------------------------------- 12 public class RectangleTool : AbstractDrawingTool 13 { 14 #region Fields 35 // ------------------------------------------------------------------ 36 protected override void OnActivateTool() { 37 base.OnActivateTool(); 38 Cursor = CursorPalette.DrawRectangle; 39 } 15 40 16 #endregion 41 // ------------------------------------------------------------------ 42 /// <summary> 43 /// Draws a ghost rectangle on the canvas if 'IsActive' and 'started' 44 /// is true. 45 /// </summary> 46 /// <param name="e">MouseEventArgs</param> 47 // ------------------------------------------------------------------ 48 protected override void OnMouseMove(MouseEventArgs e) { 49 base.OnMouseMove(e); 50 if (IsActive && started) { 51 Point point = new Point(e.X, e.Y); 17 52 18 #region Properties53 Controller.View.PaintGhostRectangle(startingPoint, point); 19 54 20 #endregion 55 Controller.View.Invalidate(System.Drawing.Rectangle.Inflate( 56 Controller.View.Ghost.Rectangle, 20, 20)); 57 } 58 } 21 59 22 #region Constructor 23 public RectangleTool() : base("Rectangle Tool") 24 { 25 } 26 public RectangleTool(string name): base(name) 27 { 60 // ------------------------------------------------------------------ 61 /// <summary> 62 /// This method will be called when the user has finished drawing a 63 /// ghost rectangle or bundle and initiates the actual creation of a 64 /// bundle and the addition to the model via the appropriate command. 65 /// </summary> 66 // ------------------------------------------------------------------ 67 protected override void GhostDrawingComplete() { 68 if ((IsActive == false) || 69 (started == false)) { 70 return; 71 } 28 72 29 } 30 #endregion 73 try { 74 SimpleRectangle shape = new SimpleRectangle(this.Controller.Model); 75 shape.Width = (int)Rectangle.Width; 76 shape.Height = (int)Rectangle.Height; 77 AddShapeCommand cmd = new AddShapeCommand( 78 this.Controller, 79 shape, 80 new Point((int)Rectangle.X, (int)Rectangle.Y)); 31 81 32 #region Methods 82 this.Controller.UndoManager.AddUndoCommand(cmd); 83 cmd.Redo(); 84 } 85 catch { 86 base.Controller.DeactivateTool(this); 87 Controller.View.Invalidate(); 88 throw; 89 } 33 90 34 // ------------------------------------------------------------------ 35 /// <summary> 36 /// Activates the tool - the cursor is set to the Icons.DrawRectangle. 37 /// </summary> 38 // ------------------------------------------------------------------ 39 protected override void OnActivateTool() 40 { 41 base.OnActivateTool(); 42 Cursor = CursorPalette.DrawRectangle; 43 } 44 45 // ------------------------------------------------------------------ 46 /// <summary> 47 /// Draws a ghost rectangle on the canvas if 'IsActive' and 'started' 48 /// is true. 49 /// </summary> 50 /// <param name="e">MouseEventArgs</param> 51 // ------------------------------------------------------------------ 52 protected override void OnMouseMove(MouseEventArgs e) 53 { 54 base.OnMouseMove(e); 55 if (IsActive && started) 56 { 57 Point point = new Point(e.X, e.Y); 58 59 Controller.View.PaintGhostRectangle(startingPoint, point); 60 61 Controller.View.Invalidate(System.Drawing.Rectangle.Inflate( 62 Controller.View.Ghost.Rectangle, 20, 20)); 63 } 64 } 65 66 // ------------------------------------------------------------------ 67 /// <summary> 68 /// This method will be called when the user has finished drawing a 69 /// ghost rectangle or bundle and initiates the actual creation of a 70 /// bundle and the addition to the model via the appropriate command. 71 /// </summary> 72 // ------------------------------------------------------------------ 73 protected override void GhostDrawingComplete() 74 { 75 if ((IsActive == false) || 76 (started == false)) 77 { 78 return; 79 } 80 81 try 82 { 83 SimpleRectangle shape = new SimpleRectangle(this.Controller.Model); 84 shape.Width = (int) Rectangle.Width; 85 shape.Height = (int) Rectangle.Height; 86 AddShapeCommand cmd = new AddShapeCommand( 87 this.Controller, 88 shape, 89 new Point((int) Rectangle.X, (int)Rectangle.Y)); 90 91 this.Controller.UndoManager.AddUndoCommand(cmd); 92 cmd.Redo(); 93 } 94 catch 95 { 96 base.Controller.DeactivateTool(this); 97 Controller.View.Invalidate(); 98 throw; 99 } 100 101 //base.Controller.DeactivateTool(this); 102 } 91 //base.Controller.DeactivateTool(this); 92 } 103 93 104 94 105 106 95 #endregion 96 } 107 97 108 98 }
Note: See TracChangeset
for help on using the changeset viewer.