Exemplo n.º 1
0
 public void SetBackgroundColor(Pixel backColor)
 {
     this.BackgroundColor = new Color4(backColor.r, backColor.g, backColor.b, backColor.a);
 }
        // Draws a line from (x1,y1) to (x2,y2)
        public void DrawLine(int x1, int y1, int x2, int y2, Pixel p, uint pattern = 0xFFFFFFFF)
        {
            if (p == default(Pixel))
            {
                p = Pixel.WHITE;
            }

            int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;

            dx = x2 - x1; dy = y2 - y1;

            Func <uint, uint> rol = (pat) =>
            {
                pat = (pat << 1) | (pat >> 31);
                return(pat);
            };

            // straight lines idea by gurkanctn
            if (dx == 0) // Line is vertical
            {
                if (y2 < y1)
                {
                    swap(ref y1, ref y2);
                }
                for (y = y1; y <= y2; y++)
                {
                    pattern = rol(pattern);
                    if ((pattern & 1) == 1)
                    {
                        Draw((uint)x1, (uint)y, p);
                    }
                }
                return;
            }

            if (dy == 0) // Line is horizontal
            {
                if (x2 < x1)
                {
                    swap(ref x1, ref x2);
                }
                for (x = x1; x <= x2; x++)
                {
                    pattern = rol(pattern);
                    if ((pattern & 1) == 1)
                    {
                        Draw((uint)x, (uint)y1, p);
                    }
                }
                return;
            }

            // Line is Funk-aye
            dx1 = Math.Abs(dx);
            dy1 = Math.Abs(dy);
            px  = 2 * dy1 - dx1;
            py  = 2 * dx1 - dy1;
            if (dy1 <= dx1)
            {
                if (dx >= 0)
                {
                    x = x1; y = y1; xe = x2;
                }
                else
                {
                    x = x2; y = y2; xe = x1;
                }

                pattern = rol(pattern);
                if ((pattern & 1) == 1)
                {
                    Draw((uint)x, (uint)y, p);
                }

                for (i = 0; x < xe; i++)
                {
                    x = x + 1;
                    if (px < 0)
                    {
                        px = px + 2 * dy1;
                    }
                    else
                    {
                        if ((dx < 0 && dy < 0) || (dx > 0 && dy > 0))
                        {
                            y = y + 1;
                        }
                        else
                        {
                            y = y - 1;
                        }
                        px = px + 2 * (dy1 - dx1);
                    }
                    pattern = rol(pattern);
                    if ((pattern & 1) == 1)
                    {
                        Draw((uint)x, (uint)y, p);
                    }
                }
            }
            else
            {
                if (dy >= 0)
                {
                    x = x1; y = y1; ye = y2;
                }
                else
                {
                    x = x2; y = y2; ye = y1;
                }

                pattern = rol(pattern);
                if ((pattern & 1) == 1)
                {
                    Draw((uint)x, (uint)y, p);
                }

                for (i = 0; y < ye; i++)
                {
                    y = y + 1;
                    if (py <= 0)
                    {
                        py = py + 2 * dx1;
                    }
                    else
                    {
                        if ((dx < 0 && dy < 0) || (dx > 0 && dy > 0))
                        {
                            x = x + 1;
                        }
                        else
                        {
                            x = x - 1;
                        }
                        py = py + 2 * (dx1 - dy1);
                    }
                    pattern = rol(pattern);
                    if ((pattern & 1) == 1)
                    {
                        Draw((uint)x, (uint)y, p);
                    }
                }
            }
        }
        // Draws a single line of text
        public void DrawString(int x, int y, string sText, Pixel col, uint scale = 1)
        {
            if (col == default(Pixel))
            {
                col = Pixel.WHITE;
            }

            int       sx = 0;
            int       sy = 0;
            BlendMode m  = this.PixelBlendMode;

            if (col.a != 255)
            {
                this.PixelBlendMode = BlendMode.ALPHA;
            }
            else
            {
                this.PixelBlendMode = BlendMode.MASK;
            }

            foreach (var c in sText)
            {
                if (c == '\n')
                {
                    sx  = 0;
                    sy += (int)(8 * scale);
                }
                else
                {
                    int ox = (c - 32) % 16;
                    int oy = (c - 32) / 16;

                    if (scale > 1)
                    {
                        for (uint i = 0; i < 8; i++)
                        {
                            for (uint j = 0; j < 8; j++)
                            {
                                if (fontSprite.GetPixel((uint)(i + ox * 8), (uint)(j + oy * 8)).r > 0)
                                {
                                    for (uint is_ = 0; is_ < scale; is_++)
                                    {
                                        for (uint js = 0; js < scale; js++)
                                        {
                                            Draw((uint)(x + sx + (i * scale) + is_), (uint)(y + sy + (j * scale) + js), col);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        for (uint i = 0; i < 8; i++)
                        {
                            for (uint j = 0; j < 8; j++)
                            {
                                if (fontSprite.GetPixel((uint)(i + ox * 8), (uint)(j + oy * 8)).r > 0)
                                {
                                    Draw((uint)(x + sx + i), (uint)(y + sy + j), col);
                                }
                            }
                        }
                    }
                    sx += (int)(8 * scale);
                }
            }
            this.PixelBlendMode = m;
        }
Exemplo n.º 4
0
 public Triangle()
 {
     this.p   = new vec3d[3];
     this.t   = new vec2d[3];
     this.col = new Pixel();
 }