Example #1
0
 public void FillScreen(Color666 color)
 {
     lock (this)
     {
         DrawRect(0, Width - 1, 0, Height - 1, color);
     }
 }
Example #2
0
        public void DrawString(int x, int y, string s, Font font, Color666 foreground, Color666 background = Color666.Black)
        {
            var currentX = x;

            char[] chars = s.ToCharArray();

            foreach (char c in chars)
            {
                var character = font.GetFontData(c);

                if (c == '\n') //line feed
                {
                    y += character.Height;
                }
                else if (c == '\r') //carriage return
                {
                    currentX = x;
                }
                else
                {
                    if (currentX + character.Width > Width)
                    {
                        currentX = x; //start over at the left and go to a new line.
                        y       += character.Height;
                    }
                    if (character.Data != null)
                    {
                        DrawChar(currentX, y, character, foreground, background);
                    }
                    currentX += character.Width + character.Space;
                }
            }
        }
Example #3
0
        public void DrawPixel(UInt16 x, UInt16 y, Color666 color)
        {
            lock (this)
            {
                var b = (byte)((UInt32)color & 0xff);
                var g = (byte)(((UInt32)color >> 8) & 0xff);
                var r = (byte)(((UInt32)color >> 16) & 0xff);

                SetWindow(x, x, y, y);
                SendData(b, g, r);
            }
        }
Example #4
0
 public void DrawCircle(UInt16 x0, UInt16 y0, UInt16 radius, Color666 color)
 {
     for (int y = -radius; y <= radius; y++)
     {
         for (int x = -radius; x <= radius; x++)
         {
             if (x * x + y * y <= radius * radius)
             {
                 DrawPixel((UInt16)(x + x0), (UInt16)(y + y0), color);
             }
         }
     }
 }
Example #5
0
        public void DrawRect(int left, int right, int top, int bottom, Color666 color)
        {
            var b = (byte)((UInt32)color & 0xff);
            var g = (byte)(((UInt32)color >> 8) & 0xff);
            var r = (byte)(((UInt32)color >> 16) & 0xff);

            DrawRect(left, right, top, bottom, r, g, b);

            //lock (this)
            //{
            //    SetWindow(left, right, top, bottom);

            //    var buffer = new byte[Width * 3];
            //    _spi.ConnectionSettings.DataBitLength = 23;

            //    var b = (byte)((UInt32)color & 0xff);
            //    var g = (byte)(((UInt32)color >> 8) & 0xff);
            //    var r = (byte)(((UInt32)color >> 16) & 0xff);

            //    if (r != 0 || g != 0 || b != 0)
            //    {
            //        for (var i = 0; i < Width * 3; i = i + 3)
            //        {
            //            buffer[i] = r;
            //            buffer[i + 1] = g;
            //            buffer[i + 2] = b;
            //        }
            //    }

            //    for (int y = 0; y < Height; y++)
            //    {
            //        SendData(buffer);
            //    }
            //    _spi.ConnectionSettings.DataBitLength = 8;
            //}
        }
Example #6
0
        public void DrawChar(int x, int y, FontCharacter character, Color666 color, Color666 background = Color666.Black, bool isDebug = false)
        {
            lock (this)
            {
                SetWindow(x, x + character.Width - 1, y, y + character.Height - 1);

                var pixels        = new byte[character.Width * character.Height * 3];
                var pixelPosition = 0;

                var b = (byte)((UInt32)color & 0xff);
                var g = (byte)(((UInt32)color >> 8) & 0xff);
                var r = (byte)(((UInt32)color >> 16) & 0xff);

                var bb = (byte)((UInt32)background & 0xff);
                var bg = (byte)(((UInt32)background >> 8) & 0xff);
                var br = (byte)(((UInt32)background >> 16) & 0xff);

                for (var segmentIndex = 0; segmentIndex < character.Data.Length; segmentIndex++)
                {
                    var segment = character.Data[segmentIndex];
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x80) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x80) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x80) != 0 ? b : bb; pixelPosition++;
                    }
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x40) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x40) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x40) != 0 ? b : bb; pixelPosition++;
                    }
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x20) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x20) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x20) != 0 ? b : bb; pixelPosition++;
                    }
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x10) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x10) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x10) != 0 ? b : bb; pixelPosition++;
                    }
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x8) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x8) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x8) != 0 ? b : bb; pixelPosition++;
                    }
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x4) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x4) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x4) != 0 ? b : bb; pixelPosition++;
                    }
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x2) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x2) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x2) != 0 ? b : bb; pixelPosition++;
                    }
                    if (pixelPosition < pixels.Length)
                    {
                        pixels[pixelPosition] = (segment & 0x1) != 0 ? r : br; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x1) != 0 ? g : bg; pixelPosition++;
                        pixels[pixelPosition] = (segment & 0x1) != 0 ? b : bb; pixelPosition++;
                    }
                }

                if (isDebug)
                {
                    var currentBuffer = string.Empty;
                    for (var pixel = 0; pixel < pixels.Length; pixel++)
                    {
                        if (pixels[pixel] > 0)
                        {
                            currentBuffer += "X";
                        }
                        else
                        {
                            currentBuffer += "-";
                        }
                        if (currentBuffer.Length >= character.Width)
                        {
                            Console.WriteLine(currentBuffer);
                            currentBuffer = string.Empty;
                        }
                    }
                }

                SendData(pixels);
            }
        }