Changeset 1045
- Timestamp:
- 12/21/08 18:42:03 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization.Test/MainForm.Designer.cs
r865 r1045 37 37 this.canvasUI.TabIndex = 3; 38 38 this.canvasUI.Text = "canvasUI"; 39 this.canvasUI.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI_MouseDown);40 39 // 41 40 // label2 -
trunk/sources/HeuristicLab.Visualization.Test/MainForm.cs
r1038 r1045 4 4 namespace HeuristicLab.Visualization.Test { 5 5 public partial class MainForm : Form { 6 private MouseEventListener dragDropListener;7 8 6 public MainForm() { 9 7 InitializeComponent(); 10 11 CreateMouseEventListeners();12 8 13 9 canvasUI.MainCanvas.WorldShape = new WorldShape(new RectangleD(0, 0, 800, 600), new RectangleD(0, 0, 800, 600)); … … 19 15 20 16 canvasUI.Invalidate(); 21 }22 23 private void CreateMouseEventListeners() {24 dragDropListener = new MouseEventListener();25 dragDropListener.OnMouseMove += DragDrop_OnMouseMove;26 dragDropListener.OnMouseUp += DragDrop_OnMouseUp;27 17 } 28 18 … … 92 82 } 93 83 94 private void canvasUI_MouseDown(object sender, MouseEventArgs e) {95 mouseEventDemonstrationGraphics = canvasUI.CreateGraphics();96 97 dragDropListener.StartPoint = e.Location;98 lastActualPoint = e.Location;99 100 canvasUI.MouseEventListener = dragDropListener;101 }102 103 private Point lastActualPoint;104 private Graphics mouseEventDemonstrationGraphics;105 106 private void DragDrop_OnMouseUp(Point startPoint, Point actualPoint) {107 canvasUI.MouseEventListener = null;108 109 canvasUI.Invalidate();110 mouseEventDemonstrationGraphics.Dispose();111 }112 113 private void DragDrop_OnMouseMove(Point startPoint, Point actualPoint) {114 mouseEventDemonstrationGraphics.DrawLine(Pens.Blue, lastActualPoint, actualPoint);115 lastActualPoint = actualPoint;116 }117 118 84 private void legendButton_Click(object sender, System.EventArgs e) { 119 85 LegendForm form = new LegendForm(); -
trunk/sources/HeuristicLab.Visualization/CanvasUI.cs
r1038 r1045 8 8 public partial class CanvasUI : Control { 9 9 private readonly Canvas mainCanvas = new Canvas(); 10 private MouseEventListener mouseEventListener;10 private IMouseEventListener mouseEventListener; 11 11 12 12 public CanvasUI() { … … 20 20 } 21 21 22 public MouseEventListener MouseEventListener {22 public IMouseEventListener MouseEventListener { 23 23 get { return mouseEventListener; } 24 24 set { mouseEventListener = value; } … … 51 51 private void CanvasUI_MouseMove(object sender, MouseEventArgs e) { 52 52 if (mouseEventListener != null) { 53 mouseEventListener.MouseMove( e.Location);53 mouseEventListener.MouseMove(sender, e); 54 54 } 55 55 } … … 57 57 private void CanvasUI_MouseUp(object sender, MouseEventArgs e) { 58 58 if (mouseEventListener != null) { 59 mouseEventListener.MouseUp( e.Location);59 mouseEventListener.MouseUp(sender, e); 60 60 } 61 61 } -
trunk/sources/HeuristicLab.Visualization/LineChart.cs
r1038 r1045 49 49 /// <param name="model">Referenz to the model, for data</param> 50 50 public LineChart(IChartDataRowsModel model) : this() { 51 if (model == null) 51 if (model == null) { 52 52 throw new NullReferenceException("Model cannot be null."); 53 } 53 54 54 55 //TODO: correct Rectangle to fit … … 71 72 72 73 UpdateLayout(); 73 74 CreateMouseEventListeners();75 74 76 75 this.model = model; … … 117 116 model.ModelChanged += OnModelChanged; 118 117 119 foreach (IDataRow row in model.Rows) 118 foreach (IDataRow row in model.Rows) { 120 119 OnDataRowAdded(row); 120 } 121 121 } 122 122 … … 132 132 row.ValueChanged += OnRowValueChanged; 133 133 row.ValuesChanged += OnRowValuesChanged; 134 if (row.Count > maxDataRowCount) 134 if (row.Count > maxDataRowCount) { 135 135 maxDataRowCount = row.Count; 136 } 136 137 137 138 InitLineShapes(row); … … 139 140 140 141 private void ZoomToFullView() { 141 if (!zoomFullView) 142 if (!zoomFullView) { 142 143 return; 144 } 143 145 RectangleD newClippingArea = new RectangleD(-0.1, 144 146 minDataValue - ((maxDataValue - minDataValue)*0.05), … … 164 166 List<LineShape> lineShapes = new List<LineShape>(); 165 167 if (row.Count > 0) { 166 maxDataValue = Math.Max(row[0], this.maxDataValue);168 maxDataValue = Math.Max(row[0], maxDataValue); 167 169 minDataValue = Math.Min(row[0], minDataValue); 168 170 } … … 197 199 minDataValue = Math.Min(value, minDataValue); 198 200 199 if (index > lineShapes.Count + 1) 201 if (index > lineShapes.Count + 1) { 200 202 throw new NotImplementedException(); 203 } 201 204 202 205 // new value was added 203 206 if (index > 0 && index == lineShapes.Count + 1) { 204 if (maxDataRowCount < row.Count) 207 if (maxDataRowCount < row.Count) { 205 208 maxDataRowCount = row.Count; 209 } 206 210 LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], 0, row.Color, row.Thickness, row.Style); 207 211 lineShapes.Add(lineShape); … … 211 215 212 216 // not the first value 213 if (index > 0) 217 if (index > 0) { 214 218 lineShapes[index - 1].Y2 = value; 219 } 215 220 216 221 // not the last value 217 if (index > 0 && index < row.Count - 1) 222 if (index > 0 && index < row.Count - 1) { 218 223 lineShapes[index].Y1 = value; 224 } 219 225 ZoomToFullView(); 220 226 … … 224 230 // TODO use action parameter 225 231 private void OnRowValuesChanged(IDataRow row, double[] values, int index, Action action) { 226 foreach (double value in values) 232 foreach (double value in values) { 227 233 OnRowValueChanged(row, value, index++, action); 234 } 228 235 } 229 236 … … 241 248 242 249 public void EndUpdate() { 243 if (beginUpdateCount == 0) 250 if (beginUpdateCount == 0) { 244 251 throw new InvalidOperationException("Too many EndUpdates."); 252 } 245 253 246 254 beginUpdateCount--; 247 255 248 if (beginUpdateCount == 0) 256 if (beginUpdateCount == 0) { 249 257 canvas.Invalidate(); 258 } 250 259 } 251 260 252 261 #endregion 253 262 254 private MouseEventListener panListener; 255 private MouseEventListener zoomListener; 256 257 private void CreateMouseEventListeners() { 258 panListener = new MouseEventListener(); 259 panListener.OnMouseMove += Pan_OnMouseMove; 260 panListener.OnMouseUp += Pan_OnMouseUp; 261 262 zoomListener = new MouseEventListener(); 263 zoomListener.OnMouseMove += Zoom_OnMouseMove; 264 zoomListener.OnMouseUp += Zoom_OnMouseUp; 265 } 266 267 private RectangleD startClippingArea; 263 private RectangleShape rectangleShape; 268 264 269 265 private void canvasUI1_MouseDown(object sender, MouseEventArgs e) { 270 266 if (ModifierKeys == Keys.Control) { 271 zoomListener.StartPoint = e.Location; 272 canvas.MouseEventListener = zoomListener; 273 274 r = Rectangle.Empty; 275 rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, Color.Blue); 276 rectangleShape.Opacity = 50; 277 278 linesShape.AddShape(rectangleShape); 267 CreateZoomListener(e); 279 268 } else { 280 panListener.StartPoint = e.Location; 281 canvas.MouseEventListener = panListener; 282 283 startClippingArea = linesShape.ClippingArea; 284 } 285 } 286 287 private void Pan_OnMouseUp(Point startPoint, Point actualPoint) { 269 CreatePanListener(e); 270 } 271 } 272 273 private void CreateZoomListener(MouseEventArgs e) { 274 ZoomListener zoomListener = new ZoomListener(e.Location); 275 zoomListener.DrawRectangle += DrawRectangle; 276 zoomListener.OnMouseUp += OnZoom_MouseUp; 277 278 canvas.MouseEventListener = zoomListener; 279 280 rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, Color.Blue); 281 rectangleShape.Opacity = 50; 282 283 linesShape.AddShape(rectangleShape); 284 } 285 286 private void OnZoom_MouseUp(object sender, MouseEventArgs e) { 288 287 canvas.MouseEventListener = null; 289 } 290 291 private void Pan_OnMouseMove(Point startPoint, Point actualPoint) { 292 Rectangle viewPort = canvas.ClientRectangle; 293 294 PointD worldStartPoint = Transform.ToWorld(startPoint, viewPort, startClippingArea); 295 PointD worldActualPoint = Transform.ToWorld(actualPoint, viewPort, startClippingArea); 296 297 double xDiff = worldActualPoint.X - worldStartPoint.X; 298 double yDiff = worldActualPoint.Y - worldStartPoint.Y; 299 300 RectangleD newClippingArea = new RectangleD(); 301 newClippingArea.X1 = startClippingArea.X1 - xDiff; 302 newClippingArea.X2 = startClippingArea.X2 - xDiff; 303 newClippingArea.Y1 = startClippingArea.Y1 - yDiff; 304 newClippingArea.Y2 = startClippingArea.Y2 - yDiff; 305 288 289 SetLineClippingArea(rectangleShape.Rectangle); 290 linesShape.RemoveShape(rectangleShape); 291 292 zoomFullView = false; //user wants to zoom => no full view 293 294 canvas.Invalidate(); 295 } 296 297 private void DrawRectangle(Rectangle rectangle) { 298 rectangleShape.Rectangle = Transform.ToWorld(rectangle, canvas.ClientRectangle, linesShape.ClippingArea); 299 canvas.Invalidate(); 300 } 301 302 private void CreatePanListener(MouseEventArgs e) { 303 PanListener panListener = new PanListener(canvas.ClientRectangle, linesShape.ClippingArea, e.Location); 304 305 panListener.SetNewClippingArea += SetNewClippingArea; 306 panListener.OnMouseUp += delegate { canvas.MouseEventListener = null; }; 307 308 canvas.MouseEventListener = panListener; 309 } 310 311 private void SetNewClippingArea(RectangleD newClippingArea) { 306 312 SetLineClippingArea(newClippingArea); 307 panListener.StartPoint = startPoint; 308 309 zoomFullView = false; //user wants to pan => no full view 310 311 canvas.Invalidate(); 312 } 313 314 private void Zoom_OnMouseUp(Point startPoint, Point actualPoint) { 315 canvas.MouseEventListener = null; 316 317 RectangleD newClippingArea = Transform.ToWorld(r, canvas.ClientRectangle, linesShape.ClippingArea); 318 SetLineClippingArea(newClippingArea); 319 linesShape.RemoveShape(rectangleShape); 320 321 zoomFullView = false; //user wants to pan => no full view 322 323 canvas.Invalidate(); 324 } 325 326 private Rectangle r; 327 private RectangleShape rectangleShape; 328 329 private void Zoom_OnMouseMove(Point startPoint, Point actualPoint) { 330 r = new Rectangle(); 331 332 if (startPoint.X < actualPoint.X) { 333 r.X = startPoint.X; 334 r.Width = actualPoint.X - startPoint.X; 335 } else { 336 r.X = actualPoint.X; 337 r.Width = startPoint.X - actualPoint.X; 338 } 339 340 if (startPoint.Y < actualPoint.Y) { 341 r.Y = startPoint.Y; 342 r.Height = actualPoint.Y - startPoint.Y; 343 } else { 344 r.Y = actualPoint.Y; 345 r.Height = startPoint.Y - actualPoint.Y; 346 } 347 348 rectangleShape.Rectangle = Transform.ToWorld(r, canvas.ClientRectangle, linesShape.ClippingArea); 349 313 314 zoomFullView = false; 350 315 canvas.Invalidate(); 351 316 } -
trunk/sources/HeuristicLab.Visualization/MouseEventListener.cs
r863 r1045 1 1 using System.Drawing; 2 using System.Windows.Forms; 2 3 3 4 namespace HeuristicLab.Visualization { 4 /// <summary> 5 /// Helper class for different OnMouseMove and OnMouseUp implementations. 6 /// </summary> 7 public class MouseEventListener { 8 /// <summary> 9 /// Fired when the MouseMove method was called. 10 /// </summary> 11 public event MouseEventListenerHandler OnMouseMove; 5 public interface IMouseEventListener { 6 void MouseMove(object sender, MouseEventArgs e); 7 void MouseUp(object sender, MouseEventArgs e); 12 8 13 /// <summary> 14 /// Fired when the MouseUp method was called. 15 /// </summary> 16 public event MouseEventListenerHandler OnMouseUp; 9 event MouseEventHandler OnMouseMove; 10 event MouseEventHandler OnMouseUp; 11 } 17 12 18 private Point startPoint;13 public delegate void SetNewClippingAreaHandler(RectangleD newClippingArea); 19 14 20 /// <summary> 21 /// Call this method to fire the OnMouseMove event. 22 /// </summary> 23 /// <param name="actualPoint"></param> 24 public void MouseMove(Point actualPoint) { 15 public delegate void DrawRectangleHandler(Rectangle rectangle); 16 17 public class PanListener : IMouseEventListener { 18 private readonly Rectangle viewPort; 19 private readonly RectangleD clippingArea; 20 private readonly Point startPoint; 21 22 public PanListener(Rectangle viewPort, RectangleD clippingArea, Point startPoint) { 23 this.viewPort = viewPort; 24 this.clippingArea = clippingArea; 25 this.startPoint = startPoint; 26 } 27 28 #region IMouseEventListener Members 29 30 public event SetNewClippingAreaHandler SetNewClippingArea; 31 public event MouseEventHandler OnMouseMove; 32 public event MouseEventHandler OnMouseUp; 33 34 public void MouseMove(object sender, MouseEventArgs e) { 35 PointD worldStartPoint = Transform.ToWorld(startPoint, viewPort, clippingArea); 36 PointD worldActualPoint = Transform.ToWorld(e.Location, viewPort, clippingArea); 37 38 double xDiff = worldActualPoint.X - worldStartPoint.X; 39 double yDiff = worldActualPoint.Y - worldStartPoint.Y; 40 41 RectangleD newClippingArea = new RectangleD(); 42 newClippingArea.X1 = clippingArea.X1 - xDiff; 43 newClippingArea.X2 = clippingArea.X2 - xDiff; 44 newClippingArea.Y1 = clippingArea.Y1 - yDiff; 45 newClippingArea.Y2 = clippingArea.Y2 - yDiff; 46 47 if (SetNewClippingArea != null) { 48 SetNewClippingArea(newClippingArea); 49 } 50 25 51 if (OnMouseMove != null) { 26 OnMouseMove(s tartPoint, actualPoint);52 OnMouseMove(sender, e); 27 53 } 28 54 } 29 55 30 /// <summary> 31 /// Call this method to fire the OnMouseUp event. 32 /// </summary> 33 /// <param name="actualPoint">Actual point of the mouse</param> 34 public void MouseUp(Point actualPoint) { 56 public void MouseUp(object sender, MouseEventArgs e) { 35 57 if (OnMouseUp != null) { 36 OnMouseUp(s tartPoint, actualPoint);58 OnMouseUp(sender, e); 37 59 } 38 60 } 39 61 40 /// <summary> 41 /// Gets or sets the starting point of the mouse. 42 /// </summary> 43 public Point StartPoint { 44 get { return startPoint; } 45 set { startPoint = value; } 46 } 62 #endregion 47 63 } 48 64 49 /// <summary> 50 /// Handler for the MouseEventListener events. 51 /// </summary> 52 /// <param name="startPoint">Starting point of the mouse.</param> 53 /// <param name="actualPoint">Actual point of the mouse.</param> 54 public delegate void MouseEventListenerHandler(Point startPoint, Point actualPoint); 65 public class ZoomListener : IMouseEventListener { 66 private readonly Point startPoint; 67 68 public event DrawRectangleHandler DrawRectangle; 69 70 public ZoomListener(Point startPoint) { 71 this.startPoint = startPoint; 72 } 73 74 #region IMouseEventListener Members 75 76 public event MouseEventHandler OnMouseMove; 77 public event MouseEventHandler OnMouseUp; 78 79 public void MouseMove(object sender, MouseEventArgs e) { 80 Rectangle r = new Rectangle(); 81 Point actualPoint = e.Location; 82 83 if (startPoint.X < actualPoint.X) { 84 r.X = startPoint.X; 85 r.Width = actualPoint.X - startPoint.X; 86 } else { 87 r.X = actualPoint.X; 88 r.Width = startPoint.X - actualPoint.X; 89 } 90 91 if (startPoint.Y < actualPoint.Y) { 92 r.Y = startPoint.Y; 93 r.Height = actualPoint.Y - startPoint.Y; 94 } else { 95 r.Y = actualPoint.Y; 96 r.Height = startPoint.Y - actualPoint.Y; 97 } 98 99 if(DrawRectangle != null) { 100 DrawRectangle(r); 101 } 102 103 if (OnMouseMove != null) { 104 OnMouseMove(sender, e); 105 } 106 } 107 108 public void MouseUp(object sender, MouseEventArgs e) { 109 if (OnMouseUp != null) { 110 OnMouseUp(sender, e); 111 } 112 } 113 114 #endregion 115 } 55 116 }
Note: See TracChangeset
for help on using the changeset viewer.