Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // Create the new event
            SplinePaintEventArgs se = new SplinePaintEventArgs(e, BezierMode, Radius, Thickness, Thickness);

            // Is interpolation active?
            if (InterpolationActive)
            {
                // Get a yellow coloured brush
                Brush yBrush = new SolidBrush(Color.Yellow);

                // Draw a circle to represent the current interpolation
                e.Graphics.FillEllipse(yBrush, (m_InterPos.x - m_Camera.x) - Radius, (-(m_InterPos.y - m_Camera.y)) - Radius, Radius * 2f, Radius * 2f);

                // Dispose of the brush
                yBrush.Dispose();
            }

            // Draw each knot
            SplinePaintCurve(this, se);

            // Draw the knots tools
            SplinePaintTools(this, se);
        }
Ejemplo n.º 2
0
        private void PaintTools_Hermite(Vector2 c, SplinePaintEventArgs e)
        {
            // Get the graphics from the event
            Graphics g = e.PaintEvent.Graphics;

            // Get a green brush and pen
            Brush gBrush = new SolidBrush(Color.Green);
            Pen   gPen   = new Pen(Color.Green, e.Radius / 2f);

            // Does this knot have a previous?
            if (m_Prev != null)
            {
                // Draw a circle to represent the in tangent
                g.FillEllipse(gBrush, (m_Front.x - c.x) - e.Radius, (-(m_Front.y - c.y)) - e.Radius, e.Radius * 2f, e.Radius * 2f);

                // Draw a line from the in tangent to the knots point
                g.DrawLine(gPen, GetPos(m_Front, c), GetPos(m_Point, c));
            }

            // Does this knot have a next?
            if (m_Next != null)
            {
                // Draw a circle to represent the out tangent
                g.FillEllipse(gBrush, (m_After.x - c.x) - e.Radius, (-(m_After.y - c.y)) - e.Radius, e.Radius * 2f, e.Radius * 2f);

                // Draw a line from the out tangent to the knots point
                g.DrawLine(gPen, GetPos(m_Point, c), GetPos(m_After, c));
            }

            // Dispose of pens and brushes
            gPen.Dispose();
            gBrush.Dispose();
        }
Ejemplo n.º 3
0
        private void PaintTools_Bezier(Vector2 c, SplinePaintEventArgs e)
        {
            // Get the graphics from the event
            Graphics g = e.PaintEvent.Graphics;

            // Get a blue brush and pen
            Brush bBrush = new SolidBrush(Color.Blue);
            Pen   bPen   = new Pen(Color.Blue, e.Radius / 2f);

            // Create the common size
            SizeF BS = new SizeF(e.Radius * 2f, e.Radius * 2f);

            // Does this knot have a previous?
            if (m_Prev != null)
            {
                // Get the front point as a rectangle
                RectangleF Fr = new RectangleF(GetPos(m_Front, c), BS);

                Fr.X -= e.Radius;
                Fr.Y -= e.Radius;

                // Draw the front control point
                g.FillRectangle(bBrush, Fr);

                // Draw a line from front point to the knots point
                g.DrawLine(bPen, GetPos(m_Front, c), GetPos(m_Point, c));

                // Draw a line from the nexts after point to this knots front point
                g.DrawLine(bPen, GetPos(Previous.After, c), GetPos(m_Front, c));
            }

            // Does this knot have a next?
            if (m_Next != null)
            {
                // Get the after point as a rectangle
                RectangleF Af = new RectangleF(GetPos(m_After, c), BS);

                Af.X -= e.Radius;
                Af.Y -= e.Radius;

                // Draw the after control point
                g.FillRectangle(bBrush, Af);

                // Draw a line from the knots point to the after point
                g.DrawLine(bPen, GetPos(m_Point, c), GetPos(m_After, c));
            }

            // Dispose of pens and brushes
            bPen.Dispose();
            bBrush.Dispose();
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        // 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();
        }