Esempio n. 1
0
        public Bitmap Render(byte scale = 1)
        {
            var result = scale <= 1 ? new Bitmap(Width, Height) : new Bitmap(Width * scale, Height * scale);

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    if (scale <= 1)
                    {
                        result.SetPixel(x, y, PaletteUtility.GetColour(Data[x, y]));
                    }
                    else
                    {
                        using (var g = Graphics.FromImage(result))
                        {
                            var brush = new SolidBrush(PaletteUtility.GetColour(Data[x, y]));

                            g.FillRectangle(brush, (x * scale), (y * scale), scale, scale);
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
 public void SetTile(Tile value)
 {
     for (byte x = 0; x < Width; x++)
     {
         for (byte y = 0; y < Height; y++)
         {
             pixels[x, y].BackColor = PaletteUtility.GetColor((Palette)value.Data[x, y]);
         }
     }
 }
Esempio n. 3
0
        public Tile GetTile()
        {
            var result = new Tile();

            for (byte x = 0; x < Width; x++)
            {
                for (byte y = 0; y < Height; y++)
                {
                    result.Set(x, y, PaletteUtility.GetPalette(pixels[x, y].BackColor));
                }
            }

            return(result);
        }
Esempio n. 4
0
        void Init(byte pixelWidth)
        {
            tiles = new TileList();
            //pre-populate the list with the number of tiles we defined slots for
            byte x = 0;
            byte y = 0;

            for (byte i = 0; i < (Height * Width); i++)
            {
                var tile = new Tile();

                var pixel = pixels[x, y];
                var scale = 3f;

                pixel.Paint += (s, e) =>
                {
                    var panel = (CellPanel)s;

                    var ptile = GetTile(panel.X, panel.Y, false);

                    for (var ix = 0; ix < ptile.Width; ix++)
                    {
                        for (var iy = 0; iy < ptile.Height; iy++)
                        {
                            var brush = new SolidBrush(PaletteUtility.GetColour(ptile.Data[ix, iy]));

                            e.Graphics.FillRectangle(brush, (ix * scale), (iy * scale), scale, scale);
                        }
                    }

                    var index = (panel.Y * Width) + panel.X;
                    if ((byte)index == selectedIndex)
                    {
                        e.Graphics.DrawRectangle(Pens.Red, 1, 1, pixelWidth - 5, pixelWidth - 5);
                    }

                    e.Graphics.DrawString($"({panel.Y},{panel.X})", SystemFonts.DialogFont, Brushes.Gray, 0, 0, StringFormat.GenericDefault);
                };

                tiles.Add(tile);

                x++;
                if (x == Width)
                {
                    x = 0;
                    y++;
                }
            }
        }
Esempio n. 5
0
        void Init()
        {
            byte c = 0;

            //set the colours
            for (byte x = 0; x < Width; x++)
            {
                for (byte y = 0; y < Height; y++)
                {
                    pixels[x, y].BackColor = PaletteUtility.GetColor((Palette)(c++));
                }
            }

            var p = pixels[0, 0];

            p.ForeColor = Color.Red;
            p.Paint    += (s, e) =>
            {
                e.Graphics.DrawLine(Pens.Red, 0, 0, p.Width, p.Height);
                e.Graphics.DrawLine(Pens.Red, p.Width - 2, 0, 0, p.Height - 2);
            };
        }