private void Draw(ScreenDrawingSurface 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()) { 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(); }
public void RightClick(ScreenDrawingSurface surface, System.Drawing.Point location) { Click(surface, location); ContextMenuStrip menu = new ContextMenuStrip(); if (heldEntity != null) { var deleteMenu = new ToolStripMenuItem( String.Format("Delete {0}", heldEntity.entity), Properties.Resources.Remove, (s, e) => { surface.Screen.RemoveEntity(heldEntity); surface.ReDrawEntities(); } ); menu.Items.Add(deleteMenu); menu.Items.Add(new ToolStripSeparator()); } var testMenu = new ToolStripMenuItem( "Test From Here", Properties.Resources.protoman, (s, e) => { MainForm.Instance.RunTestFromStage(surface.Screen, location); } ); menu.Items.Add(testMenu); menu.Show(surface, location); }
private void Flood(ScreenDrawingSurface surface, int tile_x, int tile_y, int tile_id, int brush_x, int brush_y) { var selection = surface.Selection; if (selection != null) { // only paint inside selection if (!selection.Value.Contains(tile_x, tile_y)) { return; } } var old = surface.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 == cells[brush_x, brush_y].Id) { return; } surface.Screen.ChangeTile(tile_x, tile_y, cells[brush_x, brush_y].Id); changes.Add(new TileChange(tile_x, tile_y, tile_id, cells[brush_x, brush_y].Id, surface)); Flood(surface, tile_x - 1, tile_y, tile_id, (brush_x == 0)? width - 1 : brush_x - 1, brush_y); Flood(surface, tile_x + 1, tile_y, tile_id, (brush_x == width - 1) ? 0 : brush_x + 1, brush_y); Flood(surface, tile_x, tile_y - 1, tile_id, brush_x, (brush_y == 0) ? height - 1 : brush_y - 1); Flood(surface, tile_x, tile_y + 1, tile_id, brush_x, (brush_y == height - 1) ? 0 : brush_y + 1); }
public void Click(ScreenDrawingSurface surface, Point location) { var selection = surface.Selection; if (selection != null) { // only paint inside selection if (!selection.Value.Contains(location)) { return; } } int tile_x = location.X / surface.Screen.Tileset.TileSize; int tile_y = location.Y / surface.Screen.Tileset.TileSize; var old = surface.Screen.TileAt(tile_x, tile_y); Flood(surface, tile_x, tile_y, old.Id, 0, 0); // need to manually inform the screen surface that I messed with it if (changes.Count > 0) { surface.EditedWithAction(new DrawAction("Fill", changes, surface)); surface.ReDrawTiles(); } changes.Clear(); }
public void Release(ScreenDrawingSurface surface) { if (startTiles == null) { return; } held = false; var changes = new List <TileChange>(); for (int y = 0; y < surface.Screen.Height; y++) { for (int x = 0; x < surface.Screen.Width; x++) { if (startTiles[x, y].HasValue && endTiles[x, y].HasValue && startTiles[x, y].Value != endTiles[x, y].Value) { changes.Add(new TileChange(x, y, startTiles[x, y].Value, endTiles[x, y].Value, surface)); } } } if (changes.Count > 0) { surface.EditedWithAction(new DrawAction("Brush", changes, surface)); } changes.Clear(); }
private static void EditJoin(ScreenDrawingSurface surface, Join join) { JoinForm form = new JoinForm(join, surface.Screen.Stage.Screens); form.OK += () => surface.Screen.Stage.RaiseJoinChange(join); form.Show(); }
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); } } }
public void Click(ScreenDrawingSurface surface, Point location) { var info = surface.Screen.AddEntity(entity, location); var action = new AddEntityAction(info, surface); surface.EditedWithAction(action); surface.ReDrawEntities(); }
public void RightClick(ScreenDrawingSurface surface, System.Drawing.Point location) { var zoomPoint = new Point(surface.Location.X + location.X, surface.Location.Y + location.Y); var form = (StageForm)(surface.Parent); form.ZoomOut(zoomPoint); }
public TileChange(int tx, int ty, int oldId, int newId, ScreenDrawingSurface surface) { tileX = tx; tileY = ty; oldTileId = oldId; newTileId = newId; Surface = surface; }
public void Move(ScreenDrawingSurface surface, System.Drawing.Point location) { if (heldEntity != null) { heldEntity.screenX = location.X - entityAnchor.X; heldEntity.screenY = location.Y - entityAnchor.Y; surface.ReDrawEntities(); } }
public void Release(ScreenDrawingSurface surface) { surface.SetSelection( Math.Min(tx1, tx2), Math.Min(ty1, ty2), Math.Abs(tx2 - tx1), Math.Abs(ty2 - ty1) ); }
public void Click(ScreenDrawingSurface surface, Point location) { int px = (location.X / surface.Screen.Tileset.TileSize) * surface.Screen.Tileset.TileSize + 4; int py = (location.Y / surface.Screen.Tileset.TileSize) * surface.Screen.Tileset.TileSize + 4; surface.Screen.Stage.StartScreen = surface.Screen.Name; surface.Screen.Stage.StartPoint = new Point(px, py); surface.ReDrawEntities(); }
// behaves as eyedropper public void RightClick(ScreenDrawingSurface surface, Point location) { int tile_x = location.X / surface.Screen.Tileset.TileSize; int tile_y = location.Y / surface.Screen.Tileset.TileSize; var tile = surface.Screen.TileAt(tile_x, tile_y); MainForm.Instance.TileStrip.SelectTile(tile); }
public void Move(ScreenDrawingSurface surface, System.Drawing.Point location) { if (held) { tx2 = location.X / surface.Screen.Tileset.TileSize; ty2 = location.Y / surface.Screen.Tileset.TileSize; Release(surface); } }
private static void NewJoin(ScreenDrawingSurface surface, string s1, string s2, JoinType type, int offset) { Join newjoin = new Join { screenTwo = s2, screenOne = s1, type = type, Size = 1 }; newjoin.offsetOne = newjoin.offsetTwo = offset; JoinForm form = new JoinForm(newjoin, surface.Screen.Stage.Screens); form.OK += () => surface.Screen.Stage.AddJoin(newjoin); form.Show(); }
public void Click(ScreenDrawingSurface surface, Point location) { Point tilePos = new Point(location.X / surface.Screen.Tileset.TileSize, location.Y / surface.Screen.Tileset.TileSize); var selection = surface.Selection; if (selection != null) { // only paint inside selection if (!selection.Value.Contains(tilePos)) { startTiles = null; endTiles = null; return; } } startTiles = new int?[surface.Screen.Width, surface.Screen.Height]; endTiles = new int?[surface.Screen.Width, surface.Screen.Height]; // check for line drawing if ((Control.ModifierKeys & Keys.Shift) != Keys.None) { var xdist = Math.Abs(tilePos.X - currentTilePos.X); var ydist = Math.Abs(tilePos.Y - currentTilePos.Y); if (xdist >= ydist) { var min = Math.Min(currentTilePos.X, tilePos.X); var max = Math.Max(currentTilePos.X, tilePos.X); for (int i = min; i <= max; i += brush.Width) { Draw(surface, i, currentTilePos.Y); } } else { var min = Math.Min(currentTilePos.Y, tilePos.Y); var max = Math.Max(currentTilePos.Y, tilePos.Y); for (int i = min; i <= max; i += brush.Height) { Draw(surface, currentTilePos.X, i); } } } else { Draw(surface, tilePos.X, tilePos.Y); held = true; } currentTilePos = tilePos; }
private ScreenDrawingSurface CreateScreenSurface(ScreenDocument screen) { var surface = new ScreenDrawingSurface(screen); surfaces.Add(screen.Name, surface); screen.Renamed += this.RenameSurface; screen.Resized += (w, h) => this.AlignScreenSurfaces(); surface.Edited += new EventHandler <ScreenEditEventArgs>(surface_Edited); surface.Activated += () => { ActiveSurface = surface; }; this.Controls.Add(surface); joinOverlay.Add(surface); return(surface); }
public void Move(ScreenDrawingSurface surface, Point location) { if (!held) { return; } Point pos = new Point(location.X / surface.Screen.Tileset.TileSize, location.Y / surface.Screen.Tileset.TileSize); if (pos == currentTilePos) { return; // don't keep drawing on the same spot } Draw(surface, pos.X, pos.Y); }
private static Join NearestJoin(ScreenDrawingSurface surface, Point location) { Join nearest = null; foreach (var join in surface.Screen.Stage.Joins) { if (join.screenOne == surface.Screen.Name) { int begin = join.offsetOne * surface.Screen.Tileset.TileSize; int end = (join.offsetOne + join.Size) * surface.Screen.Tileset.TileSize; if (join.type == JoinType.Vertical) { if (location.X > surface.Width - surface.Screen.Tileset.TileSize && location.Y >= begin && location.Y <= end) { nearest = join; } } else { if (location.Y > surface.Height - surface.Screen.Tileset.TileSize && location.X >= begin && location.X <= end) { nearest = join; } } } else if (join.screenTwo == surface.Screen.Name) { int begin = join.offsetTwo * surface.Screen.Tileset.TileSize; int end = (join.offsetTwo + join.Size) * surface.Screen.Tileset.TileSize; if (join.type == JoinType.Vertical) { if (location.X < surface.Screen.Tileset.TileSize && location.Y >= begin && location.Y <= end) { nearest = join; } } else { if (location.Y < surface.Screen.Tileset.TileSize && location.X >= begin && location.X <= end) { nearest = join; } } } } return(nearest); }
public void Release(ScreenDrawingSurface surface) { held = false; var g = surface.GetToolLayerGraphics(); if (g != null) { g.Clear(Color.Transparent); surface.ReturnToolLayerGraphics(g); } 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; startTiles = new int?[surface.Screen.Width, surface.Screen.Height]; endTiles = new int?[surface.Screen.Width, surface.Screen.Height]; for (int y = y_start; y <= y_end; y += brush.Height) { for (int x = x_start; x <= x_end; x += brush.Width) { Draw(surface, x, y); } } var changes = new List <TileChange>(); for (int y = 0; y < surface.Screen.Height; y++) { for (int x = 0; x < surface.Screen.Width; x++) { if (startTiles[x, y].HasValue && endTiles[x, y].HasValue && startTiles[x, y].Value != endTiles[x, y].Value) { changes.Add(new TileChange(x, y, startTiles[x, y].Value, endTiles[x, y].Value, surface)); } } } if (changes.Count > 0) { surface.EditedWithAction(new DrawAction("Rectangle", changes, surface)); } }
public void Click(ScreenDrawingSurface surface, System.Drawing.Point location) { // select nearest entity var index = surface.Screen.FindEntityAt(location); surface.Screen.SelectEntity(index); surface.ReDrawEntities(); heldEntity = surface.Screen.GetEntity(index); if (heldEntity != null) { entityAnchor = new Point(location.X - (int)heldEntity.screenX, location.Y - (int)heldEntity.screenY); } else { entityAnchor = Point.Empty; } }
public void Click(ScreenDrawingSurface surface, System.Drawing.Point location) { if (currentSurface != null) { var g = surface.GetToolLayerGraphics(); if (g != null) { g.Clear(Color.Transparent); } } currentSurface = surface; tx1 = location.X / surface.Screen.Tileset.TileSize; ty1 = location.Y / surface.Screen.Tileset.TileSize; tx2 = tx1; ty2 = ty1; held = true; }
private void LayoutNextScreen(ScreenDrawingSurface surface, Point location, Join join, bool one) { int offsetX = location.X; int offsetY = location.Y; int mag = one ? 1 : -1; if (join.type == JoinType.Horizontal) { offsetX += (join.offsetOne - join.offsetTwo) * stage.Tileset.TileSize * mag; offsetY += surfaces[join.screenOne].Screen.PixelHeight * mag; } else { offsetX += surfaces[join.screenOne].Screen.PixelWidth * mag; offsetY += (join.offsetOne - join.offsetTwo) * stage.Tileset.TileSize * mag; } LayoutFromScreen(surface, new Point(offsetX, offsetY)); }
public void Click(ScreenDrawingSurface surface, Point location) { ContextMenu menu = new ContextMenu(); // find a join to modify var nearest = NearestJoin(surface, location); if (nearest != null) { string typeText = (nearest.type == JoinType.Vertical)? "Left-Right" : "Up-Down"; menu.MenuItems.Add("Modify " + typeText + " Join from " + nearest.screenOne + " to " + nearest.screenTwo, (s, e) => EditJoin(surface, nearest)); menu.MenuItems.Add("Delete " + typeText + " Join from " + nearest.screenOne + " to " + nearest.screenTwo, (s, e) => DeleteJoin(surface, nearest)); } else { if (location.X > surface.Width - surface.Screen.Tileset.TileSize) { menu.MenuItems.Add(new MenuItem("New Rightward Join from " + surface.Screen.Name, (s, e) => NewJoin(surface, surface.Screen.Name, "", JoinType.Vertical, location.Y / surface.Screen.Tileset.TileSize))); } if (location.X < surface.Screen.Tileset.TileSize) { menu.MenuItems.Add(new MenuItem("New Leftward Join from " + surface.Screen.Name, (s, e) => NewJoin(surface, "", surface.Screen.Name, JoinType.Vertical, location.Y / surface.Screen.Tileset.TileSize))); } if (location.Y > surface.Height - surface.Screen.Tileset.TileSize) { menu.MenuItems.Add(new MenuItem("New Downward Join from " + surface.Screen.Name, (s, e) => NewJoin(surface, surface.Screen.Name, "", JoinType.Horizontal, location.X / surface.Screen.Tileset.TileSize))); } if (location.Y < surface.Screen.Tileset.TileSize) { menu.MenuItems.Add(new MenuItem("New Upward Join from " + surface.Screen.Name, (s, e) => NewJoin(surface, "", surface.Screen.Name, JoinType.Horizontal, location.X / surface.Screen.Tileset.TileSize))); } } menu.Show(surface, location); }
private void LayoutFromScreen(ScreenDrawingSurface surface, Point location) { surface.Location = location; surface.Placed = true; var myJoins = stage.Joins.Where(j => j.screenOne == surface.Screen.Name || j.screenTwo == surface.Screen.Name); var joinedScreens = surfaces.Values.Where(s => myJoins.Any(j => j.screenOne == s.Screen.Name || j.screenTwo == s.Screen.Name)); var placed = surfaces.Values.Where(s => s.Placed && s != surface && !joinedScreens.Contains(s)); var collision = SurfaceCollides(placed, surface); while (collision != Rectangle.Empty) { TryToFixCollision(surface, collision); collision = SurfaceCollides(placed, surface); } foreach (var join in stage.Joins.Where(j => j.screenOne == surface.Screen.Name)) { var nextScreen = surfaces[join.screenTwo]; if (nextScreen.Placed) { continue; } LayoutNextScreen(nextScreen, surface.Location, join, true); } foreach (var join in stage.Joins.Where(j => j.screenTwo == surface.Screen.Name)) { var nextScreen = surfaces[join.screenOne]; if (nextScreen.Placed) { continue; } LayoutNextScreen(nextScreen, surface.Location, join, false); } }
private void TryToFixCollision(ScreenDrawingSurface surface, Rectangle collision) { Point collCenter = collision.Location; collCenter.Offset(collision.Width / 2, collision.Height / 2); Point surfCenter = surface.Location; surfCenter.Offset(surface.Width / 2, surface.Height / 2); int off_y = surfCenter.Y - collCenter.Y; int off_x = surfCenter.X - collCenter.X; if (Math.Abs(off_y) > Math.Abs(off_x)) { surface.Location = new Point(surface.Location.X, surface.Location.Y + surface.Screen.Tileset.TileSize); } else { surface.Location = new Point(surface.Location.X + surface.Screen.Tileset.TileSize, surface.Location.Y); } }
private static void NewJoin(ScreenDrawingSurface surface, string s1, string s2, JoinType type, int offset) { Join newjoin = new Join {screenTwo = s2, screenOne = s1, type = type, Size = 1}; newjoin.offsetOne = newjoin.offsetTwo = offset; JoinForm form = new JoinForm(newjoin, surface.Screen.Stage.Screens); form.OK += () => surface.Screen.Stage.AddJoin(newjoin); form.Show(); }
private static Join NearestJoin(ScreenDrawingSurface surface, Point location) { Join nearest = null; foreach (var join in surface.Screen.Stage.Joins) { if (join.screenOne == surface.Screen.Name) { int begin = join.offsetOne * surface.Screen.Tileset.TileSize; int end = (join.offsetOne + join.Size) * surface.Screen.Tileset.TileSize; if (join.type == JoinType.Vertical) { if (location.X > surface.Width - surface.Screen.Tileset.TileSize && location.Y >= begin && location.Y <= end) { nearest = join; } } else { if (location.Y > surface.Height - surface.Screen.Tileset.TileSize && location.X >= begin && location.X <= end) { nearest = join; } } } else if (join.screenTwo == surface.Screen.Name) { int begin = join.offsetTwo * surface.Screen.Tileset.TileSize; int end = (join.offsetTwo + join.Size) * surface.Screen.Tileset.TileSize; if (join.type == JoinType.Vertical) { if (location.X < surface.Screen.Tileset.TileSize && location.Y >= begin && location.Y <= end) { nearest = join; } } else { if (location.Y < surface.Screen.Tileset.TileSize && location.X >= begin && location.X <= end) { nearest = join; } } } } return nearest; }
public DrawAction(string name, IEnumerable<TileChange> changes, ScreenDrawingSurface surface) { this.name = name; this.changes = new List<TileChange>(changes); this.surface = surface; }
private ScreenDrawingSurface CreateScreenSurface(ScreenDocument screen) { var surface = new ScreenDrawingSurface(screen); surfaces.Add(screen.Name, surface); screen.Renamed += this.RenameSurface; screen.Resized += (w, h) => this.AlignScreenSurfaces(); surface.Edited += new EventHandler<ScreenEditEventArgs>(surface_Edited); surface.Activated += () => { ActiveSurface = surface; }; this.Controls.Add(surface); joinOverlay.Add(surface); return surface; }
public void Release(ScreenDrawingSurface surface) { }
private static void DeleteJoin(ScreenDrawingSurface surface, Join join) { surface.Screen.Stage.RemoveJoin(join); }
private void LayoutFromScreen(ScreenDrawingSurface surface, Point location) { surface.Location = location; surface.Placed = true; var myJoins = stage.Joins.Where(j => j.screenOne == surface.Screen.Name || j.screenTwo == surface.Screen.Name); var joinedScreens = surfaces.Values.Where(s => myJoins.Any(j => j.screenOne == s.Screen.Name || j.screenTwo == s.Screen.Name)); var placed = surfaces.Values.Where(s => s.Placed && s != surface && !joinedScreens.Contains(s)); var collision = SurfaceCollides(placed, surface); while (collision != Rectangle.Empty) { TryToFixCollision(surface, collision); collision = SurfaceCollides(placed, surface); } foreach (var join in stage.Joins.Where(j => j.screenOne == surface.Screen.Name)) { var nextScreen = surfaces[join.screenTwo]; if (nextScreen.Placed) continue; LayoutNextScreen(nextScreen, surface.Location, join, true); } foreach (var join in stage.Joins.Where(j => j.screenTwo == surface.Screen.Name)) { var nextScreen = surfaces[join.screenOne]; if (nextScreen.Placed) continue; LayoutNextScreen(nextScreen, surface.Location, join, false); } }
public void ApplyToSurface(ScreenDrawingSurface surface) { surface.Screen.ChangeTile(tileX, tileY, newTileId); }
private Rectangle SurfaceCollides(IEnumerable<ScreenDrawingSurface> placedAlready, ScreenDrawingSurface next) { Rectangle collisions = Rectangle.Empty; Rectangle nextRect = new Rectangle(next.Location, next.Size); foreach (ScreenDrawingSurface surface in placedAlready) { Rectangle inter = Rectangle.Intersect(new Rectangle(surface.Location, surface.Size), nextRect); if (inter.Width > 0 && inter.Height > 0) { if (collisions.Height > 0 && collisions.Width > 0) collisions = Rectangle.Union(collisions, inter); else collisions = inter; } } return collisions; }
public AddEntityAction(EntityPlacement entity, ScreenDrawingSurface surface) { this.entity = entity; this.surface = surface; }
public SurfaceCollision(ScreenDrawingSurface surface, Rectangle collision) { Surface = surface; Collision = collision; }
public void Move(ScreenDrawingSurface surface, Point location) { }
public void RightClick(ScreenDrawingSurface surface, Point location) { }
private void Flood(ScreenDrawingSurface surface, int tile_x, int tile_y, int tile_id, int brush_x, int brush_y) { var selection = surface.Selection; if (selection != null) { // only paint inside selection if (!selection.Value.Contains(tile_x, tile_y)) { return; } } var old = surface.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 == cells[brush_x, brush_y].Id) return; surface.Screen.ChangeTile(tile_x, tile_y, cells[brush_x, brush_y].Id); changes.Add(new TileChange(tile_x, tile_y, tile_id, cells[brush_x, brush_y].Id, surface)); Flood(surface, tile_x - 1, tile_y, tile_id, (brush_x == 0)? width-1 : brush_x - 1, brush_y); Flood(surface, tile_x + 1, tile_y, tile_id, (brush_x == width - 1) ? 0 : brush_x + 1, brush_y); Flood(surface, tile_x, tile_y - 1, tile_id, brush_x, (brush_y == 0) ? height - 1 : brush_y - 1); Flood(surface, tile_x, tile_y + 1, tile_id, brush_x, (brush_y == height - 1) ? 0 : brush_y + 1); }