public void PaintTools(object sender, SplinePaintEventArgs 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 drawn? if (e.Bezier) { // Draw bezier tools PaintTools_Bezier(tb.Camera, e); } else { // Draw hermite tools PaintTools_Hermite(tb.Camera, e); } }
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 drawing #region Paint Functions public void PaintCurve(object sender, SplinePaintEventArgs 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"); } // Get the graphics from the event Graphics g = e.PaintEvent.Graphics; // Create a red brush Brush rBrush = new SolidBrush(SelControl == SelectedControl.None ? Color.Red : e.Bezier ? Color.Blue : Color.Green); // Get the camera as a vector Vector2 cam = tb.Camera; // Draw a circle to represent this knot g.FillEllipse(rBrush, (m_Point.x - cam.x) - e.Radius, (-(m_Point.y - cam.y)) - e.Radius, e.Radius * 2f, e.Radius * 2f); // Create a white pen Pen wPen = new Pen(Color.White, e.Thickness); // Is this knot not the last knot? if (m_Next != null) { // Draw the curve g.DrawBezier(wPen, GetPos(m_Point, cam), GetPos(m_After, cam), GetPos(Next.Before, cam), GetPos(Next.Position, cam)); } // Dispose of pens and brushes rBrush.Dispose(); wPen.Dispose(); }
// 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; }