public void Move(ScreenDrawingSurface surface, Point location) { if (held) { tx2 = location.X / surface.Screen.Tileset.TileSize; ty2 = location.Y / surface.Screen.Tileset.TileSize; var g = surface.GetToolLayerGraphics(); if (g != null) { g.Clear(Color.Transparent); // draw rectangle preview int x_start = Math.Min(tx1, tx2); int x_end = Math.Max(tx1, tx2) - 1; int y_start = Math.Min(ty1, ty2); int y_end = Math.Max(ty1, ty2) - 1; for (int y = y_start; y <= y_end; y += brush.Height) { for (int x = x_start; x <= x_end; x += brush.Width) { brush.DrawOn(g, x * brush.CellSize, y * brush.CellSize); } } surface.ReturnToolLayerGraphics(g); } } }
private void Flood(ScreenCanvas canvas, int tile_x, int tile_y, int tile_id, int brush_x, int brush_y) { var selection = canvas.Screen.Selection; if (selection != null) { // only paint inside selection if (!selection.Value.Contains(tile_x, tile_y)) { return; } } var old = canvas.Screen.TileAt(tile_x, tile_y); // checking whether this is already the new tile prevents infinite recursion, but // it can prevent filling a solid area with a brush that uses that same tile if (old == null || old.Id != tile_id || old.Id == _brush.Cells[brush_x][brush_y].tile.Id) { return; } _brush.DrawOn(canvas.Screen, tile_x, tile_y); changes.Add(new TileChange(canvas.Screen, tile_x, tile_y, tile_id, _brush.Cells[brush_x][brush_y].tile.Id)); Flood(canvas, tile_x - 1, tile_y, tile_id, (brush_x == 0) ? width - 1 : brush_x - 1, brush_y); Flood(canvas, tile_x + 1, tile_y, tile_id, (brush_x == width - 1) ? 0 : brush_x + 1, brush_y); Flood(canvas, tile_x, tile_y - 1, tile_id, brush_x, (brush_y == 0) ? height - 1 : brush_y - 1); Flood(canvas, tile_x, tile_y + 1, tile_id, brush_x, (brush_y == height - 1) ? 0 : brush_y + 1); }
public BrushTool(ITileBrush brush) { this.brush = brush; held = false; Icon = new Bitmap(brush.Width * brush.CellSize, brush.Height * brush.CellSize); using (Graphics g = Graphics.FromImage(Icon)) { brush.DrawOn(g, 0, 0); } }
public Bucket(ITileBrush brush) { width = brush.Width; height = brush.Height; cells = new Tile[width, height]; foreach (TileBrushCell cell in brush.Cells()) { cells[cell.x, cell.y] = cell.tile; } Icon = new Bitmap(brush.Width * brush.CellSize, brush.Height * brush.CellSize); using (Graphics g = Graphics.FromImage(Icon)) { brush.DrawOn(g, 0, 0); } changes = new List <TileChange>(); }
public Bucket(ITileBrush brush) { width = brush.Width; height = brush.Height; cells = new Tile[width, height]; foreach (TileBrushCell cell in brush.Cells()) { cells[cell.x, cell.y] = cell.tile; } Icon = new Bitmap(brush.Width * brush.CellSize, brush.Height * brush.CellSize); using (Graphics g = Graphics.FromImage(Icon)) { brush.DrawOn(g, 0, 0); } changes = new List<TileChange>(); }
private void AddBrushPanel(ITileBrush brush) { PictureBox brushPict = new PictureBox(); if (Tileset != null) { brushPict.Image = new Bitmap(brush.Width * Tileset.TileSize, brush.Height * Tileset.TileSize); brushPict.Size = brushPict.Image.Size; using (Graphics g = Graphics.FromImage(brushPict.Image)) { brush.DrawOn(g, 0, 0); } } Panel border = new Panel { BackColor = brushPanel.BackColor, Width = brushPict.Width + 8, Height = brushPict.Height + 8 }; border.Controls.Add(brushPict); brushPict.Top = 4; brushPict.Left = 4; brushPict.Click += (snd, args) => { ChangeBrush(brush); foreach (Control c in brushPanel.Controls) { c.BackColor = brushPanel.BackColor; } border.BackColor = Color.Orange; }; brushPanels.Add(brush, border); brushPanel.Controls.Add(border); }
private void Draw(ScreenCanvas surface, int tile_x, int tile_y) { // first track the changes i'm going to make for undo purposes foreach (TileBrushCell cell in brush.Cells.SelectMany(c => c)) { int tx = cell.x + tile_x; int ty = cell.y + tile_y; if (tx < 0 || tx >= surface.Screen.Width || ty < 0 || ty >= surface.Screen.Height) { continue; } if (startTiles[tx, ty] == null) // don't overwrite existing data { startTiles[tx, ty] = surface.Screen.TileAt(tx, ty).Id; } endTiles[tx, ty] = cell.tile.Id; } brush.DrawOn(surface.Screen, tile_x, tile_y); }
private void Draw(ScreenDrawingSurface surface, int tile_x, int tile_y) { var selection = surface.Selection; if (selection != null) { // only paint inside selection if (!selection.Value.Contains(tile_x, tile_y)) { return; } } // first track the changes i'm going to make for undo purposes foreach (TileBrushCell cell in brush.Cells()) { int tx = cell.x + tile_x; int ty = cell.y + tile_y; if (tx < 0 || tx >= surface.Screen.Width || ty < 0 || ty >= surface.Screen.Height) { continue; } if (startTiles[tx, ty] == null) // don't overwrite existing data { startTiles[tx, ty] = surface.Screen.TileAt(tx, ty).Id; } endTiles[tx, ty] = cell.tile.Id; } brush.DrawOn(surface.Screen, tile_x, tile_y); surface.ReDrawTiles(); }
private void Draw(ScreenDocument screen, int tile_x, int tile_y) { var changed = _brush.DrawOn(screen, tile_x, tile_y); changes.AddRange(changed); }
private void AddBrushPanel(ITileBrush brush) { PictureBox brushPict = new PictureBox(); if (Tileset != null) { brushPict.Image = new Bitmap(brush.Width * Tileset.TileSize, brush.Height * Tileset.TileSize); brushPict.Size = brushPict.Image.Size; using (Graphics g = Graphics.FromImage(brushPict.Image)) { brush.DrawOn(g, 0, 0); } } Panel border = new Panel { BackColor = brushPanel.BackColor, Width = brushPict.Width + 8, Height = brushPict.Height + 8 }; border.Controls.Add(brushPict); brushPict.Top = 4; brushPict.Left = 4; brushPict.Click += (snd, args) => { ChangeBrush(brush); foreach (Control c in brushPanel.Controls) c.BackColor = brushPanel.BackColor; border.BackColor = Color.Orange; }; brushPanels.Add(brush, border); brushPanel.Controls.Add(border); }