diff --git a/rewrite/screens/components/out.py b/rewrite/screens/components/out.py index 6975db33..5e1169fc 100644 --- a/rewrite/screens/components/out.py +++ b/rewrite/screens/components/out.py @@ -1,5 +1,3 @@ -from driver import graphics - from utils.graphics import DrawRect class Out: @@ -17,15 +15,17 @@ def render(self): self.__render_outline(coords, color) + # TODO: The size coordinates for these boxes are off-by-one because they fail to account for endpoints. + # i.e. `size` config of 2 renders a 3x3 box instead of 2x2 because endpoints for graphics.DrawLine are inclusive. def __render_outline(self, coords, color): x, y, size = coords.x, coords.y, coords.size - DrawRect(self.canvas, x, y, size, size, color, filled=False) + DrawRect(self.canvas, x, y, size + 1, size + 1, color, filled=False) def __render_out(self, coords, color): x, y, size = coords.x, coords.y, coords.size - DrawRect(self.canvas, x, y, size, size, color, filled=True) + DrawRect(self.canvas, x, y, size + 1, size + 1, color, filled=True) @property def game(self): diff --git a/rewrite/utils/graphics.py b/rewrite/utils/graphics.py index ab81ec3d..255f6009 100644 --- a/rewrite/utils/graphics.py +++ b/rewrite/utils/graphics.py @@ -2,6 +2,10 @@ def DrawRect(canvas, x, y, width, height, color, filled=True): + # Account for graphics.DrawLine rendering endpoints inclusive + width -= 1 + height -= 1 + if filled: _DrawFilledRect(canvas, x, y, width, height, color) else: @@ -14,11 +18,11 @@ def _DrawFilledRect(canvas, x, y, width, height, color): Chooses the smallest dimension as the render direction to prevent extra draw calls. """ if width > height: - for offset in range(0, height): - graphics.DrawLine(canvas, x, y + offset, x + width - 1, y + offset, color) + for offset in range(0, height + 1): + graphics.DrawLine(canvas, x, y + offset, x + width, y + offset, color) else: - for offset in range(0, width): - graphics.DrawLine(canvas, x + offset, y, x + offset, y + height - 1, color) + for offset in range(0, width + 1): + graphics.DrawLine(canvas, x + offset, y, x + offset, y + height, color) def _DrawUnfilledRect(canvas, x, y, width, height, color): # Top horizontal