private static void DrawGridQuad(Graphics g, TmxMap tmxMap, float scale) { HashSet <Point> points = new HashSet <Point>(); for (int x = 0; x < GetMaxTilesWide(tmxMap); ++x) { for (int y = 0; y < GetMaxTilesHigh(tmxMap); ++y) { // Add the "top-left" corner of a tile points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y)); // Add all other corners of the tile to our list of grid points // This is complicated by different map types (espcially staggered isometric) if (tmxMap.Orientation == TmxMap.MapOrientation.Orthogonal || tmxMap.Orientation == TmxMap.MapOrientation.Isometric) { points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x + 1, y)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x + 1, y + 1)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y + 1)); } else if (tmxMap.Orientation == TmxMap.MapOrientation.Staggered) { bool sx = TmxMath.DoStaggerX(tmxMap, x); bool sy = TmxMath.DoStaggerY(tmxMap, y); if (sx) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x + 1, y + 1)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y + 1)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x - 1, y + 1)); } else if (sy) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x + 1, y + 1)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y + 2)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y + 1)); } else if (tmxMap.StaggerAxis == TmxMap.MapStaggerAxis.X) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x + 1, y)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y + 1)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x - 1, y)); } else if (tmxMap.StaggerAxis == TmxMap.MapStaggerAxis.Y) { // top-right, bottom-right, and bottom-left points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y + 1)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x, y + 2)); points.Add(TmxMath.TileCornerInGridCoordinates(tmxMap, x - 1, y + 1)); } } } } // Can take for granted that background is always white float invScale = 1.0f / scale; List <RectangleF> rectangles = new List <RectangleF>(points.Count); foreach (var p in points) { RectangleF rc = new RectangleF(p.X, p.Y, PreviewImage.GridSize * invScale, PreviewImage.GridSize * invScale); rc.Offset(-PreviewImage.GridSize * 0.5f * invScale, -PreviewImage.GridSize * 0.5f * invScale); rectangles.Add(rc); } using (Pen pen = new Pen(Brushes.Black, invScale)) { g.DrawRectangles(pen, rectangles.ToArray()); } }