/// <summary> /// What to do when click mouse button /// </summary> /// <param name="e"></param> protected override void OnMouseClick(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (this.CurrentEditorTool is RulerTool) { RulerTool ruler = (RulerTool)this.CurrentEditorTool; if (ruler.Initial == null) { ruler.Initial = transform.GetWorldPoint(new PointF(e.X, e.Y)); if (this.SecondaryEditorTool != null && this.SecondaryEditorTool is PointAnalysisTool) { PointAnalysisTool pat = ((PointAnalysisTool)this.SecondaryEditorTool); pat.Save = new List <Coordinates>(); pat.Save.Add(ruler.Initial.Value); } } else if (ruler.Current != null) { ruler.Initial = null; ruler.Current = null; if (this.SecondaryEditorTool != null && this.SecondaryEditorTool is PointAnalysisTool) { PointAnalysisTool pat = ((PointAnalysisTool)this.SecondaryEditorTool); pat.Save = null; } } } } }
public ToolManager() { rulerTool = new RulerTool(this); angleTool = new AngleTool(this); selectTool = new SelectTool(this); pathTool = new PathTool(this); sketchTool = new SketchTool(this); contextMenuTool = new ContextMenuTool(this); pointInspectTool = new PointInspectTool(this); }
/// <summary> /// What to do when mouse moves /// </summary> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { #region Left if (e.Button == MouseButtons.Left) { if (isDragging) { // Get the offset. Point point = (Point)controlTag; // Calculate change in position double deltaX = e.X - point.X; double deltaY = e.Y - point.Y; // Update the world Coordinates tempCenter = WorldTransform.CenterPoint; tempCenter.X -= deltaX / WorldTransform.Scale; tempCenter.Y += deltaY / WorldTransform.Scale; WorldTransform.CenterPoint = tempCenter; // update control controlTag = new Point(e.X, e.Y); } // redraw this.Invalidate(); } #endregion #region Right else if (e.Button == MouseButtons.Right) { } #endregion // check if this is a ruler tool if (this.CurrentEditorTool is RulerTool) { RulerTool ruler = (RulerTool)this.CurrentEditorTool; if (ruler.Initial != null) { KeyStateInfo shiftKey = KeyboardInfo.GetKeyState(Keys.ShiftKey); Coordinates current = transform.GetWorldPoint(new PointF(e.X, e.Y)); if (!shiftKey.IsPressed) { ruler.Current = current; } else { Coordinates rulerOrig = ruler.Initial.Value; Coordinates xVec = new Coordinates(current.X - rulerOrig.X, 0.0); Coordinates yVec = new Coordinates(0.0, current.Y - rulerOrig.Y); if (xVec.Length > yVec.Length) { ruler.Current = rulerOrig + xVec; } else { ruler.Current = rulerOrig + yVec; } } } // redraw this.Invalidate(); } // check if point analysis tool if (this.SecondaryEditorTool is PointAnalysisTool) { // update ((PointAnalysisTool)this.SecondaryEditorTool).Current = transform.GetWorldPoint(new PointF(e.X, e.Y)); // redraw this.Invalidate(); } base.OnMouseMove(e); }