public void RenderMap() { // render map if (isIsometric) { pbMap.Width = (tile_width * map_width) + 270; pbMap.Height = (tile_height * map_height); } else { pbMap.Width = tile_width * map_width; pbMap.Height = tile_height * map_height; } Bitmap bmp = new Bitmap(pbMap.Width, pbMap.Height); pbMap.Image = bmp; pbMapSmall.Image = bmp; Graphics gfx = Graphics.FromImage(bmp); gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; if (isIsometric) { Point startLocation = new Point(270, -100); Point location = startLocation; for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map[x, y] != -1) { Model.TileType tileType = (Model.TileType)map[x, y]; Model.LevelTile levelTile = new Model.LevelTile(location, tileType, (Bitmap)tile_library[map[x, y]].TilePictureBox.Image); location.X += 20; levelTile.Draw(gfx); } } location.Y += 20; location.X = startLocation.X; } } else { for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map[x, y] != -1) { if (tile_library != null && tile_library.Length > map[x, y]) { PictureBox tile = tile_library[map[x, y]].TilePictureBox; if (tile != null) { gfx.DrawImage(tile.Image, x * tile_width, y * tile_height, tile_width, tile_height); if (show_walkable_on && !tile_library[map[x, y]].TileWalkable) { // show walkble tile gfx.FillRectangle(new SolidBrush(Color.FromArgb(128, 50, 50, 255)), x * tile_width + 2, y * tile_height + 2, tile_width - 4, tile_height - 4); } } } } } } } if (map_width > map_height) { int mh = map_height * 150 / map_width; pbMapSmall.Width = 150; pbMapSmall.Height = mh; } else if (map_width < map_height) { int mw = map_width * 150 / map_height; pbMapSmall.Width = mw; pbMapSmall.Height = 150; } else { pbMapSmall.Width = 150; pbMapSmall.Height = 150; } pbMapSmall.Refresh(); if (grid_on) { // draw grids for (int a = 1; a < map_width; a++) { // draw vertical lines gfx.DrawLine(Pens.Gray, a * tile_width, 0, a * tile_width, map_height * tile_height); } for (int b = 1; b < map_height; b++) { // draw horizontal lines gfx.DrawLine(Pens.Gray, 0, b * tile_height, map_width * tile_width, b * tile_height); } } if (selection.BottomRightX > map_width) { selection.BottomRightX = map_width; } if (selection.BottomRightY > map_height) { selection.BottomRightY = map_height; } Rectangle marquee = new Rectangle(selection.TopLeftX * tile_width, selection.TopLeftY * tile_height, (selection.BottomRightX - selection.TopLeftX) * tile_width, (selection.BottomRightY - selection.TopLeftY) * tile_height); Pen mypen = new Pen(new SolidBrush(Color.Blue)); mypen.Color = Color.Blue; mypen.Width = 2; mypen.DashCap = System.Drawing.Drawing2D.DashCap.Flat; mypen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; gfx.DrawRectangle(mypen, marquee); gfx.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Aqua)), marquee); gfx.Dispose(); pbMap.Refresh(); }
public void RenderMap() { // render map if (isIsometric) { pbMap.Width = (tile_width * map_width) + 270; pbMap.Height = (tile_height * map_height); } else { pbMap.Width = tile_width * map_width; pbMap.Height = tile_height * map_height; } Bitmap bmp = new Bitmap(pbMap.Width, pbMap.Height); pbMap.Image = bmp; pbMapSmall.Image = bmp; Graphics gfx = Graphics.FromImage(bmp); gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; if (isIsometric) { Point startLocation = new Point(270, -100); Point location = startLocation; for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map[x, y] != -1) { Model.TileType tileType = (Model.TileType)map[x, y]; Model.LevelTile levelTile = new Model.LevelTile(location, tileType, (Bitmap)tile_library[map[x, y]].TilePictureBox.Image); location.X += 20; levelTile.Draw(gfx); } } location.Y += 20; location.X = startLocation.X; } } else { for (int x = 0; x < map_width; x++) { for (int y = 0; y < map_height; y++) { if (map[x, y] != -1) { if (tile_library != null && tile_library.Length > map[x, y]) { PictureBox tile = tile_library[map[x, y]].TilePictureBox; if (tile != null) { gfx.DrawImage(tile.Image, x * tile_width, y * tile_height, tile_width, tile_height); if (show_walkable_on && !tile_library[map[x, y]].TileWalkable) { // show walkble tile gfx.FillRectangle(new SolidBrush(Color.FromArgb(128, 50, 50, 255)), x * tile_width + 2, y * tile_height + 2, tile_width - 4, tile_height - 4); } } } } } } } if (map_width > map_height) { int mh = map_height * 150 / map_width; pbMapSmall.Width = 150; pbMapSmall.Height = mh; } else if (map_width < map_height) { int mw = map_width * 150 / map_height; pbMapSmall.Width = mw; pbMapSmall.Height = 150; } else { pbMapSmall.Width = 150; pbMapSmall.Height = 150; } pbMapSmall.Refresh(); if (grid_on) { // draw grids for (int a = 1; a < map_width; a++) { // draw vertical lines gfx.DrawLine(Pens.Gray, a * tile_width, 0, a * tile_width, map_height * tile_height); } for (int b = 1; b < map_height; b++) { // draw horizontal lines gfx.DrawLine(Pens.Gray, 0, b * tile_height, map_width * tile_width, b * tile_height); } } if (selection.BottomRightX > map_width) selection.BottomRightX = map_width; if (selection.BottomRightY > map_height) selection.BottomRightY = map_height; Rectangle marquee = new Rectangle(selection.TopLeftX * tile_width, selection.TopLeftY * tile_height, (selection.BottomRightX - selection.TopLeftX) * tile_width, (selection.BottomRightY - selection.TopLeftY) * tile_height); Pen mypen = new Pen(new SolidBrush(Color.Blue)); mypen.Color = Color.Blue; mypen.Width = 2; mypen.DashCap = System.Drawing.Drawing2D.DashCap.Flat; mypen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; gfx.DrawRectangle(mypen, marquee); gfx.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Aqua)), marquee); gfx.Dispose(); pbMap.Refresh(); }