protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // Calculate the position of the click Vector2 po = new Vector2(m_Camera.x + e.X, m_Camera.y - e.Y); // Create the new mouse event SplineMouseEventArgs me = new SplineMouseEventArgs(e, po, BezierMode, Radius, Thickness, Thickness); // Set the selected knot me.Selected = m_Selected; // Call knots move function SplineMouseMove(this, me); // Set the selected knot m_Selected = me.Selected; // Is there a selected spline? if (m_Selected != null) { // Invalide the graphics Invalidate(); } }
// Events relating to the mouse #region Mouse Events protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); // Calculate the position of the click Vector2 po = new Vector2(m_Camera.x + e.X, m_Camera.y - e.Y); // Create the new mouse event SplineMouseEventArgs me = new SplineMouseEventArgs(e, po, BezierMode, Radius, Thickness, Thickness); // Set the selected knot me.Selected = m_Selected; // Was left button clicked? if (e.Button == MouseButtons.Left) { // Call knots move function SplineMouseClick(this, me); // Set the selected knot m_Selected = me.Selected; // Was no knot selected? if (m_Selected == null) { // Was the knot successfully added? if (AddKnot(po)) { // Call the on knot added event SplineKnotInserted(this, new SplineEventArgs(BezierMode, Radius, Thickness, Thickness)); // Invalidate the graphics Invalidate(); } else { // Set mouse to down Capture = true; } } } // Was the remove button clicked? else if (e.Button == MouseButtons.Right) { // Was the knot successfully removed? if (RemoveKnot(po)) { // Reset interpolation time InterpolationTime = 0f; // Call the on knot removed event SplineKnotRemoved(this, new SplineEventArgs(BezierMode, Radius, Thickness, Thickness)); // Invalidate the graphics Invalidate(); } } }
private void MouseMove_Hermite(Vector2 p, SplineMouseEventArgs e) { // Switch based on knots selection switch (SelControl) { case SelectedControl.Point: { // Set the points position Position = p; // Re-calculate control points m_Front = m_Point - m_In / 3f; m_After = m_Point + m_Out / 3f; // Break from this case break; } case SelectedControl.In: { // Keep tangents equal Before = p; After = m_Point + (m_Point - m_Front); // Break from this case break; } case SelectedControl.Out: { // Keep tangents equal After = p; Before = m_Point - (m_After - m_Point); // Break from this case break; } default: { break; } } }
private void MouseMove_Bezier(Vector2 p, SplineMouseEventArgs e) { // Switch based on knots selection switch (SelControl) { case SelectedControl.Point: { // Set the points position Position = p; // Re-calculate tangents m_In = 3f * (m_Point - m_Front); m_Out = 3f * (m_After - m_Point); // Break from this case break; } case SelectedControl.In: { // Set the points in tangent Before = p; // Break from this case break; } case SelectedControl.Out: { // Set the points out tangent After = p; // Break from this case break; } default: { break; } } }
public void MouseMove(object sender, SplineMouseEventArgs e) { // Get sender as a spline tab SplineTab tb = sender as SplineTab; // Assure sender was a spline tab if (tb == null) { throw new Exception("Sender for knots must be spline tab"); } // Is bezier being constructed? if (e.Bezier) { // Move bezier tools MouseMove_Bezier(e.Point, e); } else { // Move hermite tools MouseMove_Hermite(e.Point, e); } }
// Functions related to the mouse #region Mouse Functions public void MouseClick(object sender, SplineMouseEventArgs e) { // Get sender as a spline tab SplineTab tb = sender as SplineTab; // Assure sender was a spline tab if (tb == null) { throw new Exception("Sender for knots must be spline tab"); } // Check if point was clicked first if ((e.Point - m_Point).Magnitude() <= e.Radius) { // Set this knot to being selected e.Selected = this; // Set the selected control to the point SelControl = SelectedControl.Point; // End this function return; } // Create booleans to capture result bool hasFront = false; bool hasAfter = false; // Is bezier mode active? if (e.Bezier) { // Create bound rectangle Vector2 BU = new Vector2(e.Radius, e.Radius); // Calculate fronts bounding box Vector2 FLL = m_Front - BU; Vector2 FUR = m_Front + BU; // Calculate afters bounding box Vector2 ALL = m_After - BU; Vector2 AUR = m_After + BU; // Set if mouse is contained in either hasFront = (e.Point.x >= FLL.x && e.Point.x <= FUR.x) && (e.Point.y >= FLL.y && e.Point.y <= FUR.y); hasAfter = (e.Point.x >= ALL.x && e.Point.x <= AUR.x) && (e.Point.y >= ALL.y && e.Point.y <= AUR.y); } else { // Set if mouse is contained in either hasFront = (e.Point - m_Front).Magnitude() <= e.Radius; hasAfter = (e.Point - m_After).Magnitude() <= e.Radius; } // Was mouse contained by the in tangent? if (hasFront) { // Set this knot to being selected e.Selected = this; // Set the selected control to the in tangent SelControl = SelectedControl.In; // End this function return; } // Was the mouse contained by the out tangent? if (hasAfter) { // Set this knot to being selected e.Selected = this; // Set the selected control to the out tangent SelControl = SelectedControl.Out; // End this function return; } // Set no control to being selected SelControl = SelectedControl.None; }