예제 #1
0
        public override void Draw(System.Drawing.Graphics g)
        {
            if (Fill == 254)
            {
                g.FillRectangle(Selected ? Brushes.Red : Brushes.Black, DrawRect);
            }
            else if (Fill == 0)
            {
                Pen p = new Pen(Selected ? System.Drawing.Color.Red : System.Drawing.Color.Black);
                p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                g.DrawRectangle(p, DrawRect);
            }
            else
            {
                // bitmap texture
                Bitmap   textureBitmap   = new Bitmap(8, 2);
                Graphics textureGraphics = Graphics.FromImage(textureBitmap);
                string   s = HexHelper.HexToBin(Fill.ToString("X").PadLeft(2, '0'));
                for (int i = 0; i < 8; i++)
                {
                    if (s[i] == '0')
                    {
                        textureBitmap.SetPixel(i, 0, Color.White);
                        textureBitmap.SetPixel(i, 1, Selected ? Color.Red : Color.Black);
                    }
                    else
                    {
                        textureBitmap.SetPixel(i, 1, Color.White);
                        textureBitmap.SetPixel(i, 0, Selected ? Color.Red : Color.Black);
                    }
                }

                TextureBrush texturedBrush = new TextureBrush(textureBitmap);
                g.FillRectangle(texturedBrush, DrawRect);
            }
        }