Ejemplo n.º 1
0
        // important Note: Do not cause Console Output while drawing
        // otherwise, a stack overflow will occur!
        private unsafe void DrawChar(int screenX, int screenY, int charIdx)
        {
            if (screenX >= Columns || screenY >= Rows)
            {
                return;
            }

            // TODO: Improve
            var fontSec     = KernelElf.Main.GetSectionHeader("consolefont.regular");
            var fontSecAddr = KernelElf.Main.GetSectionPhysAddr(fontSec);

            var fontHeader = (PSF1Header *)fontSecAddr;

            var rows        = (int)fontHeader->Charsize;
            var bytesPerRow = 1; //14 bits --> 2 bytes + 2fill bits
            int columns     = 8;

            var charSize = bytesPerRow * rows;

            var charMem = (byte *)(fontSecAddr + sizeof(PSF1Header));

            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < columns; x++)
                {
                    var bt = BitHelper.IsBitSet(charMem[(charSize * charIdx) + (y * bytesPerRow) + (x / 8)], (byte)(7 - (x % 8)));
                    if (bt)
                    {
                        dev.SetPixel((screenX * columns) + x, (screenY * rows) + y, int.MaxValue / 2);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>Draws the string.</summary>
        public void DrawString(IFrameBuffer frameBuffer, uint color, uint x, uint y, string text)
        {
            int size8 = size / 8;

            string[] lines = text.Split('\n');

            for (int l = 0; l < lines.Length; l++)
            {
                int usedX = 0;
                for (int i = 0; i < lines[l].Length; i++)
                {
                    char c     = lines[l][i];
                    int  index = charset.IndexOf(c);

                    if (index < 0)
                    {
                        usedX += size / 2;
                        continue;
                    }

                    int maxX = 0, sizePerFont = size * size8 * index, X = usedX + (int)x, Y = (int)y + size * l;

                    for (int h = 0; h < size; h++)
                    {
                        for (int aw = 0; aw < size8; aw++)
                        {
                            for (int ww = 0; ww < 8; ww++)
                            {
                                if ((buffer[sizePerFont + (h * size8) + aw] & (0x80 >> ww)) != 0)
                                {
                                    int max = (aw * 8) + ww;

                                    int xx = X + max;
                                    int yy = Y + h;

                                    frameBuffer.SetPixel(color, (uint)xx, (uint)yy);

                                    if (max > maxX)
                                    {
                                        maxX = max;
                                    }
                                }
                            }
                        }
                    }

                    usedX += maxX + 2;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>Draws the string.</summary>
        public void DrawString(IFrameBuffer frameBuffer, uint color, uint x, uint y, string text)
        {
            for (uint c = 0; c < text.Length; c++)
            {
                int    offset  = ((byte)text[(int)c] & 0xFF) * 16;
                byte[] fontbuf = new byte[16];

                for (int k = 0; k < fontbuf.Length; k++)
                {
                    fontbuf[k] = Buffer[offset + k];
                }

                for (uint i = 0; i < 16; i++)
                {
                    for (uint j = 0; j < 8; j++)
                    {
                        if ((fontbuf[i] & (0x80 >> (int)j)) != 0)
                        {
                            frameBuffer.SetPixel(color, x + j + (c * 8), y + i);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Writes the pixel.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 void IPixelGraphicsDevice.WritePixel(Color color, ushort x, ushort y)
 {
     frameBuffer.SetPixel(ConvertColor(color), x, y);
     UpdateFrame(x, y, 1, 1);
 }
Ejemplo n.º 5
0
 public void SetPixel(int x, int y, uint nativeColor)
 {
     Dev.SetPixel(x, y, nativeColor);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Writes the pixel.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 public void WritePixel(Color color, ushort x, ushort y)
 {
     frameBuffer.SetPixel(ConvertColor(color), x, y);
     UpdateFrame(x, y, 1, 1);
 }
Ejemplo n.º 7
0
        //ToDo: fix draw line
        public static void DrawLine(this IFrameBuffer buffer, int x, int y, int x2, int y2, Color c)
        {
            int w = x2 - x;
            int h = y2 - y;
            int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;

            if (w < 0)
            {
                dx1 = -1;
            }
            else if (w > 0)
            {
                dx1 = 1;
            }
            if (h < 0)
            {
                dy1 = -1;
            }
            else if (h > 0)
            {
                dy1 = 1;
            }
            if (w < 0)
            {
                dx2 = -1;
            }
            else if (w > 0)
            {
                dx2 = 1;
            }
            int longest  = Math.Abs(w);
            int shortest = Math.Abs(h);

            if (!(longest > shortest))
            {
                longest  = Math.Abs(h);
                shortest = Math.Abs(w);
                if (h < 0)
                {
                    dy2 = -1;
                }
                else if (h > 0)
                {
                    dy2 = 1;
                }
                dx2 = 0;
            }
            int numerator = longest >> 1;

            for (int i = 0; i <= longest; i++)
            {
                buffer.SetPixel(c, (uint)x, (uint)y);

                numerator += shortest;
                if (!(numerator < longest))
                {
                    numerator -= longest;
                    x         += dx1;
                    y         += dy1;
                }
                else
                {
                    x += dx2;
                    y += dy2;
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>Writes a single pixel.</summary>
 /// <param name="color">The color.</param>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 public void WritePixel(Color color, ushort x, ushort y)
 {
     frameBuffer.SetPixel(ConvertColorToUInt(color), x, y);
 }