Changeset 13045 for branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/LinearPrimitiveBase.cs
- Timestamp:
- 10/21/15 14:18:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/LinearPrimitiveBase.cs
r12535 r13045 20 20 #endregion 21 21 22 using System; 22 23 using System.Drawing; 23 24 using System.Drawing.Drawing2D; … … 26 27 namespace HeuristicLab.Visualization { 27 28 public abstract class LinearPrimitiveBase : PrimitiveBase { 28 protected IGroup selectionRectangles;29 protected IGroup SelectionRectangles; 29 30 30 31 private PointD myStart; … … 45 46 protected LinearPrimitiveBase(IChart chart, PointD start, PointD end) 46 47 : base(chart) { 47 selectionRectangles = new Group(chart);48 SelectionRectangles = new Group(chart); 48 49 myStart = start; 49 50 myEnd = end; 50 51 } 51 protected LinearPrimitiveBase(IChart chart, double x1, double y1, double x2, double y2)52 : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {53 }54 52 protected LinearPrimitiveBase(IChart chart, PointD start, PointD end, Pen pen, Brush brush) 55 53 : base(chart, pen, brush) { 56 selectionRectangles = new Group(chart);54 SelectionRectangles = new Group(chart); 57 55 myStart = start; 58 56 myEnd = end; 59 }60 protected LinearPrimitiveBase(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)61 : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {62 57 } 63 58 … … 65 60 myStart = start; 66 61 myEnd = end; 67 On Update();62 OnRedrawRequired(); 68 63 } 69 public void SetPosition(double x1, double y1, double x2, double y2) { 70 SetPosition(new PointD(x1, y1), new PointD(x2, y2)); 71 } 64 72 65 public override void Move(Offset delta) { 73 66 SetPosition(Start + delta, End + delta); 74 67 } 75 68 76 public override bool ContainsPoint(PointD point) { 77 if (Selected) { 78 if (selectionRectangles.GetPrimitive(point) != null) return true; 79 } 80 return false; 69 public override void Move(PointD point, Offset delta) { 70 if (Selected && SelectionRectangles.ContainsPoint(point)) { 71 var rect = (SelectionRectangle)SelectionRectangles.GetPrimitive(point); 72 if (rect.Point == Start) { 73 SetPosition(Start + delta, End); 74 } else if (rect.Point == End) { 75 SetPosition(Start, End + delta); 76 } 77 } else SetPosition(Start + delta, End + delta); 81 78 } 82 79 83 public override void MouseDrag(PointD point, Offset offset, MouseButtons button) { 84 if (button == MouseButtons.Left) { 85 if (Selected) { 86 if (selectionRectangles.ContainsPoint(point)) { 87 SelectionRectangle rect = (SelectionRectangle)selectionRectangles.GetPrimitive(point); 88 if (rect.Point == Start) { 89 SetPosition(Start + offset, End); 90 } else if (rect.Point == End) { 91 SetPosition(Start, End + offset); 92 } 93 } else { 94 base.MouseDrag(point, offset, button); 95 } 80 public override void SnapToGrid(IGrid grid) { 81 var bl = grid.GetBottomLeftGridPoint(Start); 82 var ur = grid.GetUpperRightGridPoint(Start); 83 var sx = Math.Abs(bl.X - Start.X) <= Math.Abs(ur.X - Start.X) ? bl.X : ur.X; 84 var sy = Math.Abs(bl.Y - Start.Y) <= Math.Abs(ur.Y - Start.Y) ? bl.Y : ur.Y; 85 86 var end = new PointD(End.X + (sx - Start.X), End.Y + (sy - Start.Y)); 87 88 bl = grid.GetBottomLeftGridPoint(end); 89 ur = grid.GetUpperRightGridPoint(end); 90 var ex = Math.Abs(bl.X - end.X) <= Math.Abs(ur.X - end.X) ? bl.X : ur.X; 91 var ey = Math.Abs(bl.Y - end.Y) <= Math.Abs(ur.Y - end.Y) ? bl.Y : ur.Y; 92 93 SetPosition(new PointD(sx, sy), new PointD(ex, ey)); 94 } 95 96 public override void SnapToGrid(PointD point, IGrid grid) { 97 if (Selected && SelectionRectangles.ContainsPoint(point)) { 98 var rect = (SelectionRectangle)SelectionRectangles.GetPrimitive(point); 99 if (rect.Point == Start) { 100 var bl = grid.GetBottomLeftGridPoint(Start); 101 var ur = grid.GetUpperRightGridPoint(Start); 102 var sx = Math.Abs(bl.X - Start.X) <= Math.Abs(ur.X - Start.X) ? bl.X : ur.X; 103 var sy = Math.Abs(bl.Y - Start.Y) <= Math.Abs(ur.Y - Start.Y) ? bl.Y : ur.Y; 104 SetPosition(new PointD(sx, sy), End); 105 } else if (rect.Point == End) { 106 var bl = grid.GetBottomLeftGridPoint(End); 107 var ur = grid.GetUpperRightGridPoint(End); 108 var ex = Math.Abs(bl.X - End.X) <= Math.Abs(ur.X - End.X) ? bl.X : ur.X; 109 var ey = Math.Abs(bl.Y - End.Y) <= Math.Abs(ur.Y - End.Y) ? bl.Y : ur.Y; 110 SetPosition(Start, new PointD(ex, ey)); 96 111 } 97 } 112 } else SnapToGrid(grid); 113 } 114 115 public override bool ContainsPoint(PointD point) { 116 if (Selected && SelectionRectangles.GetPrimitive(point) != null) return true; 117 return false; 98 118 } 99 119 100 120 public override Cursor GetCursor(PointD point) { 101 121 if (Selected) { 102 Cursor cursor = selectionRectangles.GetCursor(point);122 var cursor = SelectionRectangles.GetCursor(point); 103 123 if (cursor != null) return cursor; 104 124 } … … 107 127 108 128 public override void PostDraw(Graphics graphics) { 109 selectionRectangles.Clear();129 SelectionRectangles.Clear(); 110 130 if (Selected) { 111 Pen pen = new Pen(Color.LightGray, 3); 112 pen.DashStyle = DashStyle.Dash; 131 var pen = new Pen(Color.LightGray, 3) { DashStyle = DashStyle.Dash }; 113 132 graphics.DrawLine(pen, 114 133 Chart.TransformWorldToPixel(Start), 115 134 Chart.TransformWorldToPixel(End)); 116 selectionRectangles.Add(new SelectionRectangle(Chart, Start, Cursors.SizeAll));117 selectionRectangles.Add(new SelectionRectangle(Chart, End, Cursors.SizeAll));135 SelectionRectangles.Add(new SelectionRectangle(Chart, Start, Cursors.SizeAll)); 136 SelectionRectangles.Add(new SelectionRectangle(Chart, End, Cursors.SizeAll)); 118 137 119 selectionRectangles.Draw(graphics);138 SelectionRectangles.Draw(graphics); 120 139 } 121 140 }
Note: See TracChangeset
for help on using the changeset viewer.