Skip to content

Commit

Permalink
fix tileset display bug
Browse files Browse the repository at this point in the history
  • Loading branch information
php42 committed Sep 24, 2021
1 parent 180d842 commit d05fd4c
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions editor/TilesetDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public void SetBitmap(Bitmap bmp)
}
}

g.DrawImage(bmp, 0, 0);
var rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
g.DrawImage(bmp, rect, rect, GraphicsUnit.Pixel);
}

SetClientSizeCore(bmp_.Width * Zoom, bmp_.Height * Zoom);
Expand All @@ -96,25 +97,9 @@ protected override void OnPaint(PaintEventArgs e)
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

// align to tile boundary
var tile_sz = 16 * Zoom;
var dst = e.ClipRectangle;
var dx = dst.X % tile_sz;
var dy = dst.Y % tile_sz;
dst.X -= dx;
dst.Y -= dy;
dst.Width += dx;
dst.Height += dy;
if((dst.Width % tile_sz) != 0)
dst.Width += tile_sz - (dst.Width % tile_sz);
if((dst.Height % tile_sz) != 0)
dst.Height += tile_sz - (dst.Height % tile_sz);

var src = dst;
src.X /= Zoom;
src.Y /= Zoom;
src.Width /= Zoom;
src.Height /= Zoom;
var dst = new Rectangle(0, 0, bmp_.Width * Zoom, bmp_.Height * Zoom);
var src = new Rectangle(0, 0, bmp_.Width, bmp_.Height);

e.Graphics.DrawImage(bmp_, dst, src, GraphicsUnit.Pixel);

Expand Down

0 comments on commit d05fd4c

Please sign in to comment.