private void DrawRegion(MapPen mapPen, MapBrush mapBrush, GeoPolygon region) { Pen pen = new Pen(Color.FromArgb((int)(mapPen.Color | 0xFF000000)), mapPen.Width); Brush brush = GetBrush(mapBrush); GeoBounds bounds = new GeoBounds(118.808451, 31.907395, 0.003907, 0.0035); ArrayList clippedPts = _sutherlandHodgman.ClipRegion(region.GetPoints()); GeoPoint[] screenPts = FromLatLngToMapPixel(clippedPts); if (screenPts.Length > 2) { { int[] xpoints = new int[screenPts.Length]; int[] ypoints = new int[screenPts.Length]; for (int i = 0; i < screenPts.Length; i++) { xpoints[i] = (int)screenPts[i].X; ypoints[i] = (int)screenPts[i].Y; } Point[] points = new Point[xpoints.Length]; for (int i = 0; i < points.Length; i++) { points[i] = new Point(xpoints[i], ypoints[i]); } SharedGraphics2D.Graphics.DrawPolygon(pen, points); SharedGraphics2D.Graphics.FillPolygon(brush, points); } } }
private void toolStripButton_ellipse_Click(object sender, EventArgs e) { toolStripButton_pencil.Checked = false; toolStripButton_fill.Checked = false; toolStripButton_select.Checked = false; toolStripButton_rectangle.Checked = false; toolStripButton_ellipse.Checked = true; mapBrush = MapBrush.ellipse; }
public void DrawMapWithBrush(MapBrush brush, Coordinate pos) { if (CheckPosValid(pos)) { _map.SetMapCell(pos, ConvertBrushTypeToMapCellType(brush.curBrushType)); RefreshMapCell(pos); } else { Debug.LogError("Invalid pos " + pos); } }
private void InitData() { var jsonText = File.ReadAllText("Resources/res.txt"); var jsonDo = JsonConvert.DeserializeObject <RawJsonData>(jsonText); foreach (int imageId in jsonDo.Images.Keys) { var path = jsonDo.Images[imageId]; var bitmap = LoadBitmap("Resources/" + path); _imageBitmaps.Add(imageId, bitmap); } foreach (string name in jsonDo.Brushes.Keys) { int[] imageIds = jsonDo.Brushes[name]; int background = -1; int terrain = -1; int vegetation = -1; int feature = -1; foreach (int imageId in imageIds) { var imageType = (ResourceImageType)(imageId / 1000); //Get the first two numbers of our 5-digit number switch (imageType) { case ResourceImageType.Background: background = imageId; break; case ResourceImageType.Terrain: terrain = imageId; break; case ResourceImageType.Vegetation: vegetation = imageId; break; case ResourceImageType.Feature: feature = imageId; break; default: throw new InvalidDataException("No ImageType exists matching the given id"); } } var brush = new MapBrush(name, background, terrain, vegetation, feature); _brushes.Add(brush); } }
public void DrawMapOverlayPencil(Point pos, MapBrush brush) { int posx = pos.X / tile_width; int posy = pos.Y / tile_height; if (posx >= map_tile_count_x) { posx = map_tile_count_x - 1; } else if (posx < 0) { posx = 0; } if (posy >= map_tile_count_y) { posy = map_tile_count_y - 1; } else if (posy < 0) { posy = 0; } if (map_cursor_pos_x_hover == posx && map_cursor_pos_y_hover == posy) { return; } else { map_cursor_pos_x_hover = posx; map_cursor_pos_y_hover = posy; } graphics = Graphics.FromImage(map_overlay); graphics.Clear(Color.Transparent); graphics.DrawRectangle(new Pen(Color.Red, 2.0f), new Rectangle(posx * tile_width + 1, posy * tile_height + 1, tile_select_width - 2, tile_select_height - 2)); graphics.Dispose(); CombineOverlayMapOutput(); pictureBox_map.Image = map_output; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * draw a region. * @param mapPen pen for the border of the region. * @param mapBrush brush to fill the region. * @param region the polygon object. */ private void DrawRegion(MapPen mapPen, MapBrush mapBrush, GeoPolygon region) { Pen pen = new Pen(new Color(mapPen.Color, false), mapPen.Width); TextureBrush brush = GetImagePatternBrush(mapBrush); ArrayList clippedPts = _sutherlandHodgman.ClipRegion(region.GetPoints()); GeoPoint[] screenPts = FromLatLngToMapPixel(clippedPts); if (screenPts.Length > 2) { { int[] xpoints = new int[screenPts.Length]; int[] ypoints = new int[screenPts.Length]; for (int i = 0; i < screenPts.Length; i++) { xpoints[i] = (int)screenPts[i].X; ypoints[i] = (int)screenPts[i].Y; } Polygon polygon = new Polygon { Xpoints = xpoints, Ypoints = ypoints, NumOfNpoints = xpoints.Length }; if (mapBrush.Pattern == 2) { SharedGraphics2D.SetPenAndBrush(pen, brush); SharedGraphics2D.DrawPolygon(null, polygon); SharedGraphics2D.FillPolygon(null, polygon); } else { SharedGraphics2D.SetDefaultPen(pen); SharedGraphics2D.DrawPolygon(null, polygon); } } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get a texture brush based on region's brush attributes. * @param brush the map brush object. * @return the texture brush to used for the map brush. */ private TextureBrush GetImagePatternBrush(MapBrush brush) { switch (brush.Pattern) { case 1: break; case 2: _imagePatternGraphics.SetColor(brush.ForeColor); _imagePatternGraphics.FillRect( 0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); break; case 3: case 19: case 20: case 21: case 22: case 23: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect( 0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); for (int i = 0; i < 4; i++) { _imagePatternGraphics.DrawLine(0, i * 4, IMAGE_PATERN_WIDTH, i * 4); } break; case 4: case 24: case 25: case 26: case 27: case 28: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect( 0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 4; i++) { _imagePatternGraphics.DrawLine(i * 4, 0, i * 4, IMAGE_PATERN_WIDTH); } break; case 5: case 29: case 30: case 31: case 32: case 33: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect( 0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 8; i++) { _imagePatternGraphics.DrawLine(0, i * 4, i * 4, 0); } break; case 6: case 34: case 35: case 36: case 37: case 38: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 8; i++) { _imagePatternGraphics.DrawLine(0, IMAGE_PATERN_WIDTH - i * 4, i * 4, 0); } break; case 15: case 16: case 17: case 18: case 48: case 49: case 50: case 51: case 53: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { _imagePatternGraphics.FillRect(i * 4, j * 4, 1, 1); } } break; default: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 4; i++) { _imagePatternGraphics.DrawLine(0, i * 4, IMAGE_PATERN_WIDTH, i * 4); _imagePatternGraphics.DrawLine(i * 4, 0, i * 4, IMAGE_PATERN_WIDTH); } break; } int[] rgbData = _imagePattern.GetRGB(); TextureBrush textureBrush = new TextureBrush(rgbData, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); return textureBrush; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * draw a region. * @param mapPen pen for the border of the region. * @param mapBrush brush to fill the region. * @param region the polygon object. */ private void DrawRegion(MapPen mapPen, MapBrush mapBrush, GeoPolygon region) { Pen pen = new Pen(new Color(mapPen.Color,false), mapPen.Width); TextureBrush brush = GetImagePatternBrush(mapBrush); ArrayList clippedPts = _sutherlandHodgman.ClipRegion(region.GetPoints()); GeoPoint[] screenPts = FromLatLngToMapPixel(clippedPts); if (screenPts.Length > 2) { { int[] xpoints = new int[screenPts.Length]; int[] ypoints = new int[screenPts.Length]; for (int i = 0; i < screenPts.Length; i++) { xpoints[i] = (int)screenPts[i].X; ypoints[i] = (int)screenPts[i].Y; } Polygon polygon = new Polygon { Xpoints = xpoints, Ypoints = ypoints, NumOfNpoints = xpoints.Length }; if (mapBrush.Pattern == 2) { SharedGraphics2D.SetPenAndBrush(pen, brush); SharedGraphics2D.DrawPolygon(null, polygon); SharedGraphics2D.FillPolygon(null, polygon); } else { SharedGraphics2D.SetDefaultPen(pen); SharedGraphics2D.DrawPolygon(null, polygon); } } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get a texture brush based on region's brush attributes. * @param brush the map brush object. * @return the texture brush to used for the map brush. */ private TextureBrush GetImagePatternBrush(MapBrush brush) { switch (brush.Pattern) { case 1: break; case 2: _imagePatternGraphics.SetColor(brush.ForeColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); break; case 3: case 19: case 20: case 21: case 22: case 23: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); for (int i = 0; i < 4; i++) { _imagePatternGraphics.DrawLine(0, i * 4, IMAGE_PATERN_WIDTH, i * 4); } break; case 4: case 24: case 25: case 26: case 27: case 28: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 4; i++) { _imagePatternGraphics.DrawLine(i * 4, 0, i * 4, IMAGE_PATERN_WIDTH); } break; case 5: case 29: case 30: case 31: case 32: case 33: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 8; i++) { _imagePatternGraphics.DrawLine(0, i * 4, i * 4, 0); } break; case 6: case 34: case 35: case 36: case 37: case 38: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 8; i++) { _imagePatternGraphics.DrawLine(0, IMAGE_PATERN_WIDTH - i * 4, i * 4, 0); } break; case 15: case 16: case 17: case 18: case 48: case 49: case 50: case 51: case 53: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { _imagePatternGraphics.FillRect(i * 4, j * 4, 1, 1); } } break; default: _imagePatternGraphics.SetColor(brush.BackColor); _imagePatternGraphics.FillRect(0, 0, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); _imagePatternGraphics.SetColor(brush.ForeColor); for (int i = 0; i < 4; i++) { _imagePatternGraphics.DrawLine(0, i * 4, IMAGE_PATERN_WIDTH, i * 4); _imagePatternGraphics.DrawLine(i * 4, 0, i * 4, IMAGE_PATERN_WIDTH); } break; } int[] rgbData = _imagePattern.GetRGB(); TextureBrush textureBrush = new TextureBrush(rgbData, IMAGE_PATERN_WIDTH, IMAGE_PATERN_WIDTH); return(textureBrush); }
public MapDrawer(MapData data, string name = "__terrainDrawer") { CreateLineMaterial(); this.data = data; InitMesh(name); brush = new MapBrush("__brush", gameObject, GetOffset, flag); brush.ChangeColor(notReachableColor); wayPointBrush = new MapBrush("__WayPointBrush", gameObject, GetOffset, flag); currentBrush = null; SetHideFlags(gameObject, flag); }
private static Brush GetBrush(MapBrush mapBrush) { int imageIndex = 0; switch (mapBrush.Pattern) { case 0: case 9: case 1: case 10: case 11: return(new SolidBrush(Color.Empty)); break; case 2: imageIndex = 1; break; case 3: imageIndex = 12; break; case 4: imageIndex = 16; break; case 5: imageIndex = 19; break; case 6: imageIndex = 24; break; case 7: imageIndex = 31; break; case 8: imageIndex = 34; break; case 12: imageIndex = 2; break; case 13: imageIndex = 3; break; default: imageIndex = mapBrush.Pattern - 10; break; } string imgIndex = string.Empty; if (imageIndex < 10) { imgIndex = "0" + imageIndex.ToString(); } else { imgIndex = imageIndex.ToString(); } string filename = @"C:\CVSMapDigit\MapTileDownloader\MapDigit\brushpatterns\fill" + imgIndex + ".bmp"; Bitmap bitmap = (Bitmap)Image.FromFile(filename); Color foreColor = Color.FromArgb((int)(mapBrush.ForeColor | 0xE0000000)); Bitmap newBitmap = new Bitmap(bitmap.Width, bitmap.Height); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { Color getColor = bitmap.GetPixel(i, j); if (getColor.R == 0 && getColor.G == 0 && getColor.B == 0) { newBitmap.SetPixel(i, j, foreColor); } else { newBitmap.SetPixel(i, j, Color.Empty); } } } return(new TextureBrush(newBitmap)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy Constructor. * @param brush the map object copied from */ public MapBrush(MapBrush brush) { Pattern = brush.Pattern; ForeColor = brush.ForeColor; BackColor = brush.BackColor; }
private void DrawRegion(MapPen mapPen, MapBrush mapBrush, GeoPolygon region) { Pen pen = new Pen(Color.FromArgb((int)(mapPen.Color | 0xFF000000)), mapPen.Width); Brush brush = GetBrush(mapBrush); GeoBounds bounds = new GeoBounds(118.808451, 31.907395, 0.003907, 0.0035); ArrayList clippedPts = _sutherlandHodgman.ClipRegion(region.GetPoints()); GeoPoint[] screenPts = FromLatLngToMapPixel(clippedPts); if (screenPts.Length > 2) { { int[] xpoints = new int[screenPts.Length]; int[] ypoints = new int[screenPts.Length]; for (int i = 0; i < screenPts.Length; i++) { xpoints[i] = (int)screenPts[i].X; ypoints[i] = (int)screenPts[i].Y; } Point[] points = new Point[xpoints.Length]; for (int i = 0; i < points.Length; i++) { points[i] = new Point(xpoints[i], ypoints[i]); } SharedGraphics2D.Graphics.DrawPolygon(pen, points); SharedGraphics2D.Graphics.FillPolygon(brush, points); } } }
private static Brush GetBrush(MapBrush mapBrush) { int imageIndex = 0; switch (mapBrush.Pattern) { case 0: case 9: case 1: case 10: case 11: return new SolidBrush(Color.Empty); break; case 2: imageIndex = 1; break; case 3: imageIndex = 12; break; case 4: imageIndex = 16; break; case 5: imageIndex = 19; break; case 6: imageIndex = 24; break; case 7: imageIndex = 31; break; case 8: imageIndex = 34; break; case 12: imageIndex = 2; break; case 13: imageIndex = 3; break; default: imageIndex = mapBrush.Pattern - 10; break; } string imgIndex = string.Empty; if(imageIndex<10) { imgIndex = "0" + imageIndex.ToString(); }else { imgIndex = imageIndex.ToString(); } string filename = @"C:\CVSMapDigit\MapTileDownloader\MapDigit\brushpatterns\fill" + imgIndex + ".bmp"; Bitmap bitmap = (Bitmap)Image.FromFile(filename); Color foreColor = Color.FromArgb((int) (mapBrush.ForeColor | 0xE0000000)); Bitmap newBitmap = new Bitmap(bitmap.Width, bitmap.Height); for(int i=0;i<bitmap.Width;i++) { for(int j=0;j<bitmap.Height;j++) { Color getColor = bitmap.GetPixel(i, j); if (getColor.R == 0 && getColor.G == 0 && getColor.B==0) { newBitmap.SetPixel(i, j, foreColor); }else { newBitmap.SetPixel(i, j, Color.Empty); } } } return new TextureBrush(newBitmap); }
public void DrawTiles(Point pos, MapBrush brush) { if (map_layer_index == 0) { return; } int posx = pos.X / tile_width; int posy = pos.Y / tile_height; if (posx >= map_tile_count_x) { posx = map_tile_count_x - 1; } else if (posx < 0) { posx = 0; } if (posy >= map_tile_count_y) { posy = map_tile_count_y - 1; } else if (posy < 0) { posy = 0; } if (map_cursor_pos_x_down == posx && map_cursor_pos_y_down == posy && !newTileSelected && !layerChanged) { return; } else { map_cursor_pos_x_down = posx; map_cursor_pos_y_down = posy; newTileSelected = false; layerChanged = false; } if (brush == MapBrush.pencil) { graphics = Graphics.FromImage(map_layer[map_layer_index - 1]); for (int x = 0; x < tile_select_width_count; x++) { for (int y = 0; y < tile_select_height_count; y++) { graphics.SetClip(new Rectangle(tile_width * (posx + x), tile_height * (posy + y), tile_width, tile_height), System.Drawing.Drawing2D.CombineMode.Replace); graphics.Clear(Color.Transparent); graphics.DrawImage(tile[tile_select_start_x + x, tile_select_start_y + y], tile_width * (posx + x), tile_height * (posy + y)); if (posx + x < map_tile_count_x && posy + y < map_tile_count_y) { map_layer_tileinfo[map_layer_index - 1][(posy + y) * map_tile_count_x + x + posx] = (tile_select_start_y + y) * tile_count_x + tile_select_start_x + x; if (tile_select_start_x + x == 0 && tile_select_start_y + y == 1) { map_layer_tileinfo[map_layer_index - 1][(posy + y) * map_tile_count_x + posx + x] = -1; } } //Console.WriteLine("index: " + ((posy + y) * map_tile_count_x + posx + x) + "value: " + map_layer_tileinfo[layer - 1][(posy + y) * map_tile_count_x + x+posx]); } } graphics.Dispose(); CombineInnerMapOutput(); CombineOverlayMapOutput(); pictureBox_map.Image = map_output; } else if (brush == MapBrush.rectangle) { } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy Constructor. * @param brush the map object copied from */ public MapBrush(MapBrush brush) { Pattern = brush.Pattern; ForeColor = brush.ForeColor; BackColor = brush.BackColor; }