Beispiel #1
0
        public static void Initialize(GraphicsDevice device)
        {
            if (!_init) {
                _init = true;

                Black = new SolidColorBrush(device, Color.Black);
                Blue = new SolidColorBrush(device, Color.Blue);
                Cyan = new SolidColorBrush(device, Color.Cyan);
                Green = new SolidColorBrush(device, Color.Green);
                Magenta = new SolidColorBrush(device, Color.Magenta);
                Red = new SolidColorBrush(device, Color.Red);
                White = new SolidColorBrush(device, Color.White);
                Yellow = new SolidColorBrush(device, Color.Yellow);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Draws a rectangle with the thickness provided
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="location">Where to draw</param>
 /// <param name="size">The size of the rectangle</param>
 /// <param name="color">The color to draw the rectangle in</param>
 /// <param name="thickness">The thickness of the line</param>
 public static void DrawRectangle(SpriteBatch spriteBatch, Vector2 location, Vector2 size, Brush brush, float thickness)
 {
     DrawRectangle(spriteBatch, new Rectangle((int)location.X, (int)location.Y, (int)size.X, (int)size.Y), brush, thickness, 0.0f, location);
 }
Beispiel #3
0
        /// <summary>
        /// Draws a rectangle with the thickness provided
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="rect">The rectangle to draw</param>
        /// <param name="color">The color to draw the rectangle in</param>
        /// <param name="thickness">The thickness of the lines</param>
        /// <param name="angle">The angle to draw the rectangle at</param>
        /// <param name="rotateAround">The location to rotate the rectangle around</param>
        public static void DrawRectangle(SpriteBatch spriteBatch, Rectangle rect, Brush brush, float thickness, float angle, Vector2 rotateAround)
        {
            // TODO: Handle rotations
            // TODO: Figure out the pattern for the offsets required and then handle it in the line instead of here

            DrawHLine(spriteBatch, new Vector2(rect.Left, rect.Top), rect.Width, brush);
            DrawHLine(spriteBatch, new Vector2(rect.Left, rect.Bottom), rect.Width, brush);
            DrawVLine(spriteBatch, new Vector2(rect.Left, rect.Top), rect.Height, brush);
            DrawVLine(spriteBatch, new Vector2(rect.Right, rect.Top), rect.Height, brush);

            /*DrawLine(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Right, rect.Y), brush, thickness); // top
            DrawLine(spriteBatch, new Vector2(rect.X + 1f, rect.Y), new Vector2(rect.X + 1f, rect.Bottom + 1f), brush, thickness); // left
            DrawLine(spriteBatch, new Vector2(rect.X, rect.Bottom), new Vector2(rect.Right, rect.Bottom), brush, thickness); // bottom
            DrawLine(spriteBatch, new Vector2(rect.Right + 1f, rect.Y), new Vector2(rect.Right + 1f, rect.Bottom + 1f), brush, thickness); // right
             */
            /*
            DrawLine(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.X + rect.Width, rect.Y), Color.White, thickness); // top
            DrawLine(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.X, rect.Y + rect.Height + 1f), Color.Red, thickness); // left
            DrawLine(spriteBatch, new Vector2(rect.X, rect.Y + rect.Height), new Vector2(rect.X + rect.Width, rect.Y + rect.Height), Color.Blue, thickness); // bottom
            DrawLine(spriteBatch, new Vector2(rect.X + rect.Width, rect.Y), new Vector2(rect.X + rect.Width, rect.Y + rect.Height), Color.Green, thickness); // right
            //*/

            /* Gary's method:
            p2.X += 1;
            p2.Y += 1;
            float offset = thickness;
            Line(new Vector2(p1.X, p1.Y), new Vector2(p2.X, p1.Y), thickness, color);
            Line(new Vector2(p1.X + offset, p1.Y), new Vector2(p1.X + offset, p2.Y), thickness, color);
            Line(new Vector2(p1.X, p2.Y - offset), new Vector2(p2.X, p2.Y - offset), thickness, color);
            Line(new Vector2(p2.X, p1.Y), new Vector2(p2.X, p2.Y), thickness, color);
            //*/
        }
Beispiel #4
0
 public Pen(Brush brush)
     : this(brush, 1)
 {
 }
Beispiel #5
0
        /// <summary>
        /// Draws a list of connecting points
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="position">Where to position the points</param>
        /// <param name="points">The points to connect with lines</param>
        /// <param name="color">The color to use</param>
        /// <param name="color">The thickness to use</param>
        /// <param name="thickness">The thickness of the lines</param>
        private static void DrawPoints(SpriteBatch spriteBatch, Vector2 position, List<Vector2> points, Brush brush, float thickness)
        {
            if (points.Count < 2)
                return;

            for (int i = 1; i < points.Count; i++) {
                DrawLine(spriteBatch, points[i - 1] + position, points[i] + position, brush, thickness);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Draws a filled rectangle
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="x1">The X coord of the left side</param>
        /// <param name="y1">The Y coord of the upper side</param>
        /// <param name="x2">The X coord of the right side</param>
        /// <param name="y2">The Y coord of the bottom side</param>
        /// <param name="color">The color to draw the rectangle in</param>
        /// <param name="thickness">The thickness of the line</param>
        public static void FillRectangle(SpriteBatch spriteBatch, float x1, float y1, float x2, float y2, Brush brush, float thickness)
        {
            //if (m_pixel == null) { CreateThePixel(spriteBatch); }

            // Simply use the function already there
            FillRectangle(spriteBatch, new Vector2(x1, y1), new Vector2(x2, y2), brush, thickness);
        }
Beispiel #7
0
 /// <summary>
 /// Draws a filled rectangle
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="location">Where to draw</param>
 /// <param name="size">The size of the rectangle</param>
 /// <param name="color">The color to draw the rectangle in</param>
 public static void FillRectangle(SpriteBatch spriteBatch, Vector2 location, Vector2 size, Brush brush)
 {
     FillRectangle(spriteBatch, location, size, brush, 0.0f);
 }
Beispiel #8
0
        /// <summary>
        /// Draws a filled rectangle
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="rect">The rectangle to draw</param>
        /// <param name="color">The color to draw the rectangle in</param>
        public static void FillRectangle(SpriteBatch spriteBatch, Rectangle rect, Brush brush)
        {
            //if (m_pixel == null) { CreateThePixel(spriteBatch); }

            // Simply use the function already there
            spriteBatch.Draw(brush.Texture, rect, Color.White * brush.Alpha);
        }
Beispiel #9
0
 /// <summary>
 /// Draws a line from point1 to point2 with an offset
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="point1">The first point</param>
 /// <param name="point2">The second point</param>
 /// <param name="color">The color to use</param>
 public static void DrawLine(SpriteBatch spriteBatch, Vector2 point1, Vector2 point2, Brush brush)
 {
     DrawLine(spriteBatch, point1, point2, brush, 1.0f);
 }
Beispiel #10
0
 /// <summary>
 /// Draws a line from point1 to point2 with an offset
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="x1">The X coord of the first point</param>
 /// <param name="y1">The Y coord of the first point</param>
 /// <param name="x2">The X coord of the second point</param>
 /// <param name="y2">The Y coord of the second point</param>
 /// <param name="color">The color to use</param>
 /// <param name="thickness">The thickness of the line</param>
 public static void DrawLine(SpriteBatch spriteBatch, float x1, float y1, float x2, float y2, Brush brush, float thickness)
 {
     DrawLine(spriteBatch, new Vector2(x1, y1), new Vector2(x2, y2), brush, thickness);
 }
Beispiel #11
0
 public static void DrawCircle(SpriteBatch spriteBatch, float x, float y, float radius, int sides, Brush brush, float thickness)
 {
     DrawPoints(spriteBatch, new Vector2(x, y), CreateCircle(radius, sides), brush, thickness);
 }
Beispiel #12
0
 /// <summary>
 /// Draw a circle
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="center">The center of the circle</param>
 /// <param name="radius">The radius of the circle</param>
 /// <param name="sides">The number of sides to generate</param>
 /// <param name="color">The color of the circle</param>
 public static void DrawCircle(SpriteBatch spriteBatch, Vector2 center, float radius, int sides, Brush brush, float thickness)
 {
     DrawPoints(spriteBatch, center, CreateCircle(radius, sides), brush, thickness);
 }
Beispiel #13
0
 /// <summary>
 /// Draw a arc
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="center">The center of the arc</param>
 /// <param name="radius">The radius of the arc</param>
 /// <param name="sides">The number of sides to generate</param>
 /// <param name="startingAngle">The starting angle of arc, 0 being to the east, 90 being south</param>
 /// <param name="degrees">The number of degrees to draw, clockwise from the starting angle</param>
 /// <param name="color">The color of the arc</param>
 /// <param name="thickness">The thickness of the arc</param>
 public static void DrawArc(SpriteBatch spriteBatch, Vector2 center, float radius, int sides, float startingAngle, float degrees, Brush brush, float thickness)
 {
     List<Vector2> arc = CreateArc(radius, sides, startingAngle, degrees);
     //List<Vector2> arc = CreateArc2(radius, sides, startingAngle, degrees);
     DrawPoints(spriteBatch, center, arc, brush, thickness);
 }
Beispiel #14
0
 /// <summary>
 /// Draw a arc
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="center">The center of the arc</param>
 /// <param name="radius">The radius of the arc</param>
 /// <param name="sides">The number of sides to generate</param>
 /// <param name="startingAngle">The starting angle of arc, 0 being to the east, 90 being south</param>
 /// <param name="degrees">The number of degrees to draw, clockwise from the starting angle</param>
 /// <param name="color">The color of the arc</param>
 public static void DrawArc(SpriteBatch spriteBatch, Vector2 center, float radius, int sides, float startingAngle, float degrees, Brush brush)
 {
     DrawArc(spriteBatch, center, radius, sides, startingAngle, degrees, brush, 1.0f);
 }
Beispiel #15
0
 /// <summary>
 /// Draws a rectangle with the thickness provided
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="location">Where to draw</param>
 /// <param name="size">The size of the rectangle</param>
 /// <param name="color">The color to draw the rectangle in</param>
 /// <param name="thickness">The thickness of the line</param>
 /// <param name="angle">The angle to draw the rectangle at</param>
 /// <param name="rotateAround">Rotate around this point</param>
 public static void DrawRectangle(SpriteBatch spriteBatch, Vector2 location, Vector2 size, Brush brush, float thickness, float angle, Vector2 rotateAround)
 {
     DrawRectangle(spriteBatch, new Rectangle((int)location.X, (int)location.Y, (int)size.X, (int)size.Y), brush, thickness, angle, rotateAround);
 }
Beispiel #16
0
 public static void DrawVLine(SpriteBatch spriteBatch, Vector2 point, float length, Brush brush)
 {
     spriteBatch.Draw(brush.Texture, new Rectangle((int)point.X, (int)point.Y, 1, (int)length), Color.White * brush.Alpha);
 }
Beispiel #17
0
        /// <summary>
        /// Draws a line from point1 to point2 with an offset
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="point1">The first point</param>
        /// <param name="point2">The second point</param>
        /// <param name="color">The color to use</param>
        /// <param name="thickness">The thickness of the line</param>
        public static void DrawLine(SpriteBatch spriteBatch, Vector2 point1, Vector2 point2, Brush brush, float thickness)
        {
            // calculate the distance between the two vectors
            float distance = Vector2.Distance(point1, point2);

            // calculate the angle between the two vectors
            float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);

            DrawLine(spriteBatch, point1, distance, angle, brush, thickness);
        }
Beispiel #18
0
        /// <summary>
        /// Draws a filled rectangle
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="rect">The rectangle to draw</param>
        /// <param name="angle">The angle to draw the rectangle at</param>
        /// <param name="color">The color to draw the rectangle in</param>
        public static void FillRectangle(SpriteBatch spriteBatch, Rectangle rect, Brush brush, float angle)
        {
            //if (m_pixel == null) { CreateThePixel(spriteBatch); }

            spriteBatch.Draw(brush.Texture, rect, null, Color.White * brush.Alpha, angle, Vector2.Zero, SpriteEffects.None, 0);
        }
Beispiel #19
0
 /// <summary>
 /// Draws a line from point1 to point2 with an offset
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="point">The starting point</param>
 /// <param name="length">The length of the line</param>
 /// <param name="angle">The angle of this line from the starting point</param>
 /// <param name="color">The color to use</param>
 public static void DrawLine(SpriteBatch spriteBatch, Vector2 point, float length, float angle, Brush brush)
 {
     DrawLine(spriteBatch, point, length, angle, brush, 1.0f);
 }
Beispiel #20
0
        /// <summary>
        /// Draws a filled rectangle
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="location">Where to draw</param>
        /// <param name="size">The size of the rectangle</param>
        /// <param name="angle">The angle to draw the rectangle at</param>
        /// <param name="color">The color to draw the rectangle in</param>
        public static void FillRectangle(SpriteBatch spriteBatch, Vector2 location, Vector2 size, Brush brush, float angle)
        {
            //if (m_pixel == null) { CreateThePixel(spriteBatch); }

            // stretch the pixel between the two vectors
            spriteBatch.Draw(brush.Texture,
                             location,
                             null,
                             Color.White * brush.Alpha,
                             angle,
                             Vector2.Zero,
                             size,
                             SpriteEffects.None,
                             0);
        }
Beispiel #21
0
        /// <summary>
        /// Draws a line from point1 to point2 with an offset
        /// </summary>
        /// <param name="spriteBatch">The destination drawing surface</param>
        /// <param name="point">The starting point</param>
        /// <param name="length">The length of the line</param>
        /// <param name="angle">The angle of this line from the starting point</param>
        /// <param name="color">The color to use</param>
        /// <param name="thickness">The thickness of the line</param>
        public static void DrawLine(SpriteBatch spriteBatch, Vector2 point, float length, float angle, Brush brush, float thickness)
        {
            if (m_pixel == null) { CreateThePixel(spriteBatch); }

            float width = length * (float)Math.Cos(angle);
            float height = length * (float)Math.Sin(angle);
            Vector2 point2 = new Vector2(point.X + width, point.Y + height);

            int steps = (int)(length / brush.Texture.Width);
            float stepX = brush.Texture.Width * (float)Math.Cos(angle);
            float stepY = brush.Texture.Width * (float)Math.Sin(angle);

            Vector2 stepPoint = point;
            for (int i = 0; i < steps; i++) {
                spriteBatch.Draw(brush.Texture,
                             stepPoint,
                             null,
                             Color.White * brush.Alpha,
                             angle,
                             Vector2.Zero,
                             Vector2.One,
                             SpriteEffects.None,
                             0);
                stepPoint.X += stepX;
                stepPoint.Y += stepY;
            }

            int rem = (int)(length - steps * brush.Texture.Width);

            if (rem > 0) {
                spriteBatch.Draw(brush.Texture,
                             stepPoint,
                             new Rectangle(0, 0, rem, brush.Texture.Height),
                             Color.White * brush.Alpha,
                             angle,
                             Vector2.Zero,
                             Vector2.One,
                             SpriteEffects.None,
                             0);
            }
        }
Beispiel #22
0
 /// <summary>
 /// Draws a list of connecting points
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="position">Where to position the points</param>
 /// <param name="points">The points to connect with lines</param>
 /// <param name="color">The color to use</param>
 private static void DrawPoints(SpriteBatch spriteBatch, Vector2 position, List<Vector2> points, Brush brush)
 {
     DrawPoints(spriteBatch, position, points, brush, 1.0f);
 }
Beispiel #23
0
 /// <summary>
 /// Draws a rectangle with the thickness provided
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="rect">The rectangle to draw</param>
 /// <param name="color">The color to draw the rectangle in</param>
 public static void DrawRectangle(SpriteBatch spriteBatch, Rectangle rect, Brush brush)
 {
     DrawRectangle(spriteBatch, rect, brush, 1.0f, 0.0f, new Vector2(rect.X, rect.Y));
 }
Beispiel #24
0
 /// <summary>
 /// Draws a rectangle with the thickness provided
 /// </summary>
 /// <param name="spriteBatch">The destination drawing surface</param>
 /// <param name="rect">The rectangle to draw</param>
 /// <param name="color">The color to draw the rectangle in</param>
 /// <param name="thickness">The thickness of the lines</param>
 /// <param name="angle">The angle to draw the rectangle at, this will rotate around the top-left of the rectangle by default</param>
 public static void DrawRectangle(SpriteBatch spriteBatch, Rectangle rect, Brush brush, float thickness, float angle)
 {
     DrawRectangle(spriteBatch, rect, brush, thickness, angle, new Vector2(rect.X, rect.Y));
 }
Beispiel #25
0
 public Pen(Brush brush, int width)
 {
     Brush = brush;
     Width = width;
 }