public void Update(float dt) { if (this.m_spline.IsValid) { this.m_spline.Draw(0.005f, this.m_splineController); } ToolSpline.State state = this.m_state; if (state != ToolSpline.State.Dragging) { return; } RectangleF dragRectangle = this.DragRectangle; if (this.IsDragRectangle(dragRectangle)) { Render.DrawScreenRectangleOutlined(dragRectangle, 1f, 0.00125f, Color.White); } }
protected void StartDrag(SplineController.SelectMode dragMode) { this.m_state = ToolSpline.State.Dragging; this.m_dragStart = Editor.Viewport.NormalizedMousePos; this.m_dragMode = dragMode; }
public bool OnMouseEvent(Editor.MouseEvent mouseEvent, MouseEventArgs mouseEventArgs) { switch (mouseEvent) { case Editor.MouseEvent.MouseDown: if (this.m_spline.IsValid) { UndoManager.RecordUndo(); switch (this.m_paramEditTool.Value) { case ToolSpline.EditTool.Select: if ((Control.ModifierKeys & Keys.Control) != Keys.None) { this.StartDrag(SplineController.SelectMode.Toggle); } else { if ((Control.ModifierKeys & Keys.Shift) != Keys.None) { this.StartDrag(SplineController.SelectMode.Add); } else { if (this.TestPoints()) { if (!this.m_splineController.IsSelected(this.m_hitPoint)) { this.m_splineController.ClearSelection(); this.m_splineController.SetSelected(this.m_hitPoint, true); } this.m_state = ToolSpline.State.Moving; } else { this.StartDrag(SplineController.SelectMode.Replace); } } } break; case ToolSpline.EditTool.Paint: case ToolSpline.EditTool.Add: { this.m_hitPoint = -1; this.m_hitDelta = new Vec2(0f, 0f); Vec3 vec; if (this.m_spline.Count < 100 && Editor.RayCastTerrainFromMouse(out vec)) { if (this.m_spline.Count <= 1) { if (this.m_spline.Count < 1) { this.m_spline.AddPoint(vec.XY); } this.m_spline.AddPoint(vec.XY); this.m_hitPoint = 1; } else { if (this.TestPoints()) { if (this.m_hitPoint == 0) { this.m_spline.InsertPoint(vec.XY, 0); } else { if (this.m_hitPoint == this.m_spline.Count - 1) { this.m_spline.InsertPoint(vec.XY, this.m_hitPoint + 1); this.m_hitPoint++; } } } else { if (this.TestSegments()) { this.m_hitPoint++; this.m_spline.InsertPoint(vec.XY, this.m_hitPoint); } } } if (this.m_hitPoint != -1) { this.m_splineController.ClearSelection(); this.m_splineController.SetSelected(this.m_hitPoint, true); this.m_spline.UpdateSpline(); if (this.m_paramEditTool.Value == ToolSpline.EditTool.Paint) { this.m_state = ToolSpline.State.Drawing; if (this.m_hitPoint == 0) { this.m_forward = false; } else { if (this.m_hitPoint == this.m_spline.Count - 1) { this.m_forward = true; } else { this.m_state = ToolSpline.State.Moving; } } } else { this.m_state = ToolSpline.State.Moving; } } } break; } case ToolSpline.EditTool.Remove: this.RemovePointUnderMouse(); this.m_state = ToolSpline.State.Removing; break; } if (this.m_state != ToolSpline.State.None) { MainForm.Instance.EnableShortcuts = false; } else { UndoManager.CommitUndo(); } } break; case Editor.MouseEvent.MouseUp: if (this.m_spline.IsValid && this.m_state != ToolSpline.State.None) { UndoManager.CommitUndo(); switch (this.m_state) { case ToolSpline.State.Dragging: { RectangleF dragRectangle = this.DragRectangle; this.m_splineController.SelectFromScreenRect(dragRectangle, 0.015f, this.m_dragMode); break; } case ToolSpline.State.Drawing: { bool flag = false; if (this.m_forward && this.m_hitPoint >= 1) { flag = this.m_spline.OptimizePoint(this.m_hitPoint - 1); } else { if (!this.m_forward && this.m_hitPoint < this.m_spline.Count - 1) { flag = this.m_spline.OptimizePoint(this.m_hitPoint + 1); } } if (flag) { this.m_spline.UpdateSpline(); } break; } } if (this.m_spline.RemoveSimilarPoints()) { this.m_spline.UpdateSpline(); this.m_splineController.ClearSelection(); } if (this.m_state != ToolSpline.State.None) { this.m_spline.FinalizeSpline(); MainForm.Instance.EnableShortcuts = true; } this.m_hitPoint = -1; this.m_state = ToolSpline.State.None; } break; case Editor.MouseEvent.MouseMove: if (this.m_spline.IsValid) { switch (this.m_state) { case ToolSpline.State.Moving: this.MovePointsToMouse(false); break; case ToolSpline.State.Drawing: this.MovePointsToMouse(true); break; case ToolSpline.State.Removing: this.RemovePointUnderMouse(); break; } } break; } return false; }
public bool OnMouseEvent(Editor.MouseEvent mouseEvent, MouseEventArgs mouseEventArgs) { switch (mouseEvent) { case Editor.MouseEvent.MouseDown: if (this.m_spline.IsValid) { UndoManager.RecordUndo(); switch (this.m_paramEditTool.Value) { case ToolSpline.EditTool.Select: if ((Control.ModifierKeys & Keys.Control) != Keys.None) { this.StartDrag(SplineController.SelectMode.Toggle); } else { if ((Control.ModifierKeys & Keys.Shift) != Keys.None) { this.StartDrag(SplineController.SelectMode.Add); } else { if (this.TestPoints()) { if (!this.m_splineController.IsSelected(this.m_hitPoint)) { this.m_splineController.ClearSelection(); this.m_splineController.SetSelected(this.m_hitPoint, true); } this.m_state = ToolSpline.State.Moving; } else { this.StartDrag(SplineController.SelectMode.Replace); } } } break; case ToolSpline.EditTool.Paint: case ToolSpline.EditTool.Add: { this.m_hitPoint = -1; this.m_hitDelta = new Vec2(0f, 0f); Vec3 vec; if (this.m_spline.Count < 100 && Editor.RayCastTerrainFromMouse(out vec)) { if (this.m_spline.Count <= 1) { if (this.m_spline.Count < 1) { this.m_spline.AddPoint(vec.XY); } this.m_spline.AddPoint(vec.XY); this.m_hitPoint = 1; } else { if (this.TestPoints()) { if (this.m_hitPoint == 0) { this.m_spline.InsertPoint(vec.XY, 0); } else { if (this.m_hitPoint == this.m_spline.Count - 1) { this.m_spline.InsertPoint(vec.XY, this.m_hitPoint + 1); this.m_hitPoint++; } } } else { if (this.TestSegments()) { this.m_hitPoint++; this.m_spline.InsertPoint(vec.XY, this.m_hitPoint); } } } if (this.m_hitPoint != -1) { this.m_splineController.ClearSelection(); this.m_splineController.SetSelected(this.m_hitPoint, true); this.m_spline.UpdateSpline(); if (this.m_paramEditTool.Value == ToolSpline.EditTool.Paint) { this.m_state = ToolSpline.State.Drawing; if (this.m_hitPoint == 0) { this.m_forward = false; } else { if (this.m_hitPoint == this.m_spline.Count - 1) { this.m_forward = true; } else { this.m_state = ToolSpline.State.Moving; } } } else { this.m_state = ToolSpline.State.Moving; } } } break; } case ToolSpline.EditTool.Remove: this.RemovePointUnderMouse(); this.m_state = ToolSpline.State.Removing; break; } if (this.m_state != ToolSpline.State.None) { MainForm.Instance.EnableShortcuts = false; } else { UndoManager.CommitUndo(); } } break; case Editor.MouseEvent.MouseUp: if (this.m_spline.IsValid && this.m_state != ToolSpline.State.None) { UndoManager.CommitUndo(); switch (this.m_state) { case ToolSpline.State.Dragging: { RectangleF dragRectangle = this.DragRectangle; this.m_splineController.SelectFromScreenRect(dragRectangle, 0.015f, this.m_dragMode); break; } case ToolSpline.State.Drawing: { bool flag = false; if (this.m_forward && this.m_hitPoint >= 1) { flag = this.m_spline.OptimizePoint(this.m_hitPoint - 1); } else { if (!this.m_forward && this.m_hitPoint < this.m_spline.Count - 1) { flag = this.m_spline.OptimizePoint(this.m_hitPoint + 1); } } if (flag) { this.m_spline.UpdateSpline(); } break; } } if (this.m_spline.RemoveSimilarPoints()) { this.m_spline.UpdateSpline(); this.m_splineController.ClearSelection(); } if (this.m_state != ToolSpline.State.None) { this.m_spline.FinalizeSpline(); MainForm.Instance.EnableShortcuts = true; } this.m_hitPoint = -1; this.m_state = ToolSpline.State.None; } break; case Editor.MouseEvent.MouseMove: if (this.m_spline.IsValid) { switch (this.m_state) { case ToolSpline.State.Moving: this.MovePointsToMouse(false); break; case ToolSpline.State.Drawing: this.MovePointsToMouse(true); break; case ToolSpline.State.Removing: this.RemovePointUnderMouse(); break; } } break; } return(false); }
protected void StartDrag(SplineController.SelectMode dragMode) { this.m_state = ToolSpline.State.Dragging; this.m_dragStart = Editor.Viewport.NormalizedMousePos; this.m_dragMode = dragMode; }