public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) { Point p = dataPoint.GetPoint(chartControl, chartPanel, chartScale); switch (DrawingState) { case DrawingState.Building: if (ChartAnchors.Count == 0) { ChartAnchors.Add(new ChartAnchor { DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this }); } foreach (ChartAnchor ca in ChartAnchors) { if (ca.IsEditing) { dataPoint.CopyDataValues(ca); ca.IsEditing = false; } } ChartAnchor clickTestAnchor = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, p); if (ChartAnchors.Count > 1 && doubleClickTimer.IsEnabled && clickTestAnchor != null && clickTestAnchor != ChartAnchors[ChartAnchors.Count - 1]) { // ChartAnchors[ChartAnchors.Count - 1] is the 'temp anchor' ChartAnchors.Remove(ChartAnchors[ChartAnchors.Count - 1]); PathToolSegments.Remove(PathToolSegments[PathToolSegments.Count - 1]); doubleClickTimer.Stop(); DrawingState = DrawingState.Normal; IsSelected = false; } else { ChartAnchor ca = new ChartAnchor { DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this }; dataPoint.CopyDataValues(ca); ChartAnchors.Add(ca); if (ChartAnchors.Count > 1) { PathToolSegments.Add(new PathToolSegment(ChartAnchors[ChartAnchors.Count - 2], ChartAnchors[ChartAnchors.Count - 1], string.Format("{0} {1}", Custom.Resource.NinjaScriptDrawingToolPathSegment, PathToolSegments.Count + 1))); if (!doubleClickTimer.IsEnabled) { doubleClickTimer.Start(); } } } break; case DrawingState.Normal: editingAnchor = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, p); if (editingAnchor != null) { editingAnchor.IsEditing = true; DrawingState = DrawingState.Editing; } else { if (GetCursor(chartControl, chartPanel, chartScale, p) != null) { DrawingState = DrawingState.Moving; } } break; } }
public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) { Point p = dataPoint.GetPoint(chartControl, chartPanel, chartScale); switch (DrawingState) { case DrawingState.Building: if (ChartAnchors.Count == 0) { ChartAnchors.Add(new ChartAnchor { DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this }); } foreach (ChartAnchor ca in ChartAnchors) { if (ca.IsEditing) { dataPoint.CopyDataValues(ca); ca.IsEditing = false; } } if (ChartAnchors.Count > 2 && (GetCursor(chartControl, chartPanel, chartScale, p) == Cursors.Cross || DateTime.Now.Subtract(lastClick).TotalMilliseconds <= 200)) { ChartAnchors.Remove(ChartAnchors[ChartAnchors.Count - 1]); DrawingState = DrawingState.Normal; IsSelected = false; } else { ChartAnchor ca = new ChartAnchor { DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchor, IsEditing = true, DrawingTool = this }; dataPoint.CopyDataValues(ca); ChartAnchors.Add(ca); } lastClick = DateTime.Now; break; case DrawingState.Normal: editingAnchor = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, p); if (editingAnchor != null) { editingAnchor.IsEditing = true; DrawingState = DrawingState.Editing; } else { if (GetCursor(chartControl, chartPanel, chartScale, p) != null) { DrawingState = DrawingState.Moving; } else if (!IsPointInsidePolygon(chartControl, chartPanel, chartScale, p)) { IsSelected = false; } } break; } }