Example #1
0
 /// <summary>
 /// Draws a pixel.
 /// </summary>
 /// <param name="x">Starting X coordinate.</param>
 /// <param name="y">Starting Y coordinate.</param>
 /// <param name="color">The color to use.</param>
 public static void SetPixel(int x, int y, Color.Palette color)
 {
     SetClip(x, y, 1, 1);
     b2[0] = (byte)((ushort)color >> 8);
     b2[1] = (byte)((ushort)color >> 0);
     DrawImage(b2);
 }
Example #2
0
 /// <summary>
 /// Draws a string in small font.
 /// </summary>
 /// <param name="x">Starting X coordinate.</param>
 /// <param name="y">Starting Y coordinate.</param>
 /// <param name="str">The string to draw.</param>
 /// <param name="color">The color to use.</param>
 public static void DrawString(int x, int y, string str, Color.Palette color)
 {
     for (int i = 0; i < str.Length; i++)
     {
         DrawCharacter(x + i * 6, y, str[i], color);
     }
 }
Example #3
0
        /// <summary>
        /// Get the Red, Green and Blue values from a Palette color.
        /// </summary>
        /// <param name="color">Palette color.</param>
        /// <returns>The Red, Green and Blue values.</returns>
        public static byte[] RgbFromPalette(Color.Palette color)
        {
            var ushortColor = (ushort)color;
            var red         = (byte)(((ushortColor & 0xF800) >> 11) * 8);
            var green       = (byte)(((ushortColor & 0x7E0) >> 5) * 4);
            var blue        = (byte)((ushortColor & 0x1F) * 8);

            return(new byte[3] {
                red, green, blue
            });
        }
Example #4
0
        /// <summary>
        /// Draws a filled rectangle.
        /// </summary>
        /// <param name="x">Starting X coordinate.</param>
        /// <param name="y">Starting Y coordinate.</param>
        /// <param name="w">Width</param>
        /// <param name="h">Height</param>
        /// <param name="color">The color to use.</param>
        public static void DrawFillRect(int x, int y, int w, int h, Color.Palette color)
        {
            SetClip(x, y, w, h);

            byte[] colors = new byte[w * h * 2];
            for (int i = 0; i < colors.Length; i += 2)
            {
                colors[i]     = (byte)(((ushort)color >> 8) & 0xFF);
                colors[i + 1] = (byte)(((ushort)color >> 0) & 0xFF);
            }

            DrawImage(colors);
        }
Example #5
0
            public void SetPixel(int x, int y, Color.Palette color)
            {
                if (x > _width || x < 0)
                {
                    return;
                }
                if (y > _height || y < 0)
                {
                    return;
                }

                Pixels[(x * _width + y) * 2 + 0] = (byte)((ushort)color >> 8);
                Pixels[(x * _width + y) * 2 + 1] = (byte)color;
            }
Example #6
0
        /// <summary>
        /// Draws a character in small font.
        /// </summary>
        /// <param name="x">Starting X coordinate.</param>
        /// <param name="y">Starting Y coordinate.</param>
        /// <param name="c">The character to draw.</param>
        /// <param name="color">The color to use.</param>
        public static void DrawCharacter(int x, int y, char c, Color.Palette color)
        {
            if (c > 126 || c < 32)
            {
                return;
            }

            c = (char)(c - 32);

            for (int i = 0; i < 5; i++)
            {
                Draw8Pixels(x + i, y, font[5 * c + i], (ushort)color);
            }
        }
Example #7
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="x">Starting X coordinate.</param>
        /// <param name="y">Starting Y coordinate.</param>
        /// <param name="w">Width</param>
        /// <param name="h">Height</param>
        /// <param name="color">The color to use.</param>
        public static void DrawRect(int x, int y, int w, int h, Color.Palette color)
        {
            // chnage to be like the fill rect for speed
            for (int i = x; i < x + w; i++)
            {
                SetPixel(i, y, color);
                SetPixel(i, y + h - 1, color);
            }

            for (int i = y; i < y + h; i++)
            {
                SetPixel(x, i, color);
                SetPixel(x + w - 1, i, color);
            }
        }
Example #8
0
        /// <summary>
        /// Draws a circle.
        /// </summary>
        /// <param name="x0">Starting X coordinate.</param>
        /// <param name="y0">Starting Y coordinate.</param>
        /// <param name="r">The radius.</param>
        /// <param name="color">The color to use.</param>
        public static void DrawCircle(int x0, int y0, int r, Color.Palette color)
        {
            int f     = 1 - r;
            int ddF_x = 1;
            int ddF_y = -2 * r;
            int x     = 0;
            int y     = r;

            SetPixel(x0, y0 + r, color);
            SetPixel(x0, y0 - r, color);
            SetPixel(x0 + r, y0, color);
            SetPixel(x0 - r, y0, color);

            while (x < y)
            {
                if (f >= 0)
                {
                    y--;
                    ddF_y += 2;
                    f     += ddF_y;
                }
                x++;
                ddF_x += 2;
                f     += ddF_x;

                SetPixel(x0 + x, y0 + y, color);
                SetPixel(x0 - x, y0 + y, color);
                SetPixel(x0 + x, y0 - y, color);
                SetPixel(x0 - x, y0 - y, color);

                SetPixel(x0 + y, y0 + x, color);
                SetPixel(x0 - y, y0 + x, color);
                SetPixel(x0 + y, y0 - x, color);
                SetPixel(x0 - y, y0 - x, color);
            }
        }
Example #9
0
 /// <summary>
 /// Sets the color of the Light Bulb.
 /// </summary>
 /// <param name="color">The <see cref="Palette" /> color to use.</param>
 public static void SetColor(Color.Palette color)
 {
     byte[] rgb = Color.RgbFromPalette(color);
     SetColor(rgb[0] / 255.0, rgb[1] / 255.0, rgb[2] / 255.0);
 }
Example #10
0
        /// <summary>
        /// Draws a line.
        /// </summary>
        /// <param name="x0">Starting X coordinate.</param>
        /// <param name="y0">Starting Y coordinate.</param>
        /// <param name="x1">Ending X coordinate.</param>
        /// <param name="y1">Ending Y coordinate.</param>
        /// <param name="color">The color to use.</param>
        public static void DrawLine(int x0, int y0, int x1, int y1, Color.Palette color)
        {
            int  t;
            bool steep = System.Math.Abs(y1 - y0) > System.Math.Abs(x1 - x0);

            if (steep)
            {
                t  = x0;
                x0 = y0;
                y0 = t;
                t  = x1;
                x1 = y1;
                y1 = t;
            }

            if (x0 > x1)
            {
                t  = x0;
                x0 = x1;
                x1 = t;

                t  = y0;
                y0 = y1;
                y1 = t;
            }

            int dx, dy;

            dx = x1 - x0;
            dy = System.Math.Abs(y1 - y0);

            int err = (dx / 2);
            int ystep;

            if (y0 < y1)
            {
                ystep = 1;
            }
            else
            {
                ystep = -1;
            }

            for (; x0 < x1; x0++)
            {
                if (steep)
                {
                    SetPixel(y0, x0, color);
                }
                else
                {
                    SetPixel(x0, y0, color);
                }
                err -= dy;
                if (err < 0)
                {
                    y0  += (byte)ystep;
                    err += dx;
                }
            }
        }