diff --git a/src/tempe/font.py b/src/tempe/font.py index 4140398..07e1a20 100644 --- a/src/tempe/font.py +++ b/src/tempe/font.py @@ -41,7 +41,7 @@ def __init__(self, mod): self.height = mod.height self.baseline = mod.baseline self.monospaced = mod.monospaced - self.memory = len(mod._font) + len(mod._sparse) + #self.memory = len(mod._font) + len(mod._sparse) def measure(self, text): width = 0 diff --git a/src/tempe/shapes.py b/src/tempe/shapes.py index 59f9c44..0b87acf 100644 --- a/src/tempe/shapes.py +++ b/src/tempe/shapes.py @@ -17,6 +17,9 @@ def draw(self, buffer, x=0, y=0): # draw nothing pass + def draw_raster(self, raster): + self.draw(raster.fbuf, raster.x, raster.y) + def update(self): if self.clip is None: self.clip = self._bounds() @@ -87,7 +90,6 @@ def _bounds(self): return (min_x, min_y, max_x - min_x, max_y - min_y) - class HLines(ColoredGeometry): """Render multiple colored horizontal line segments with line-width 1. @@ -158,6 +160,7 @@ def _bounds(self): max_y = -0x7fff min_y = 0x7fff for geometry in self.geometry: + geometry = list(geometry) max_x = max(max_x, max(geometry[::2])) min_x = min(min_x, min(geometry[::2])) max_y = max(max_y, max(geometry[1::2])) @@ -213,6 +216,20 @@ def draw(self, buffer, x=0, y=0): r = geometry[2] buffer.ellipse(px, py, r, r, color, self.fill) + def _bounds(self): + max_x = -0x7fff + min_x = 0x7fff + max_y = -0x7fff + min_y = 0x7fff + for geometry in self.geometry: + max_x = max(max_x, geometry[0] + abs(geometry[2])) + min_x = min(min_x, geometry[0] - abs(geometry[2])) + max_y = max(max_y, geometry[1] + abs(geometry[2])) + min_y = min(min_y, geometry[1] - abs(geometry[2])) + + return (min_x - 1, min_y - 1, max_x - min_x + 2, max_y - min_y + 2) + + class Ellipses(FillableGeometry): """Render multiple ellipses. @@ -227,3 +244,16 @@ def draw(self, buffer, x=0, y=0): rx = geometry[2] ry = geometry[3] buffer.ellipse(px, py, rx, ry, color, self.fill) + + def _bounds(self): + max_x = -0x7fff + min_x = 0x7fff + max_y = -0x7fff + min_y = 0x7fff + for geometry in self.geometry: + max_x = max(max_x, geometry[0] + abs(geometry[2])) + min_x = min(min_x, geometry[0] - abs(geometry[2])) + max_y = max(max_y, geometry[1] + abs(geometry[3])) + min_y = min(min_y, geometry[1] - abs(geometry[3])) + + return (min_x, min_y, max_x - min_x, max_y - min_y) diff --git a/src/tempe/surface.py b/src/tempe/surface.py index 139415a..57814ac 100644 --- a/src/tempe/surface.py +++ b/src/tempe/surface.py @@ -26,7 +26,7 @@ def draw(self, raster): clip = raster.clip(*object.clip) if clip is None: continue - object.draw(clip.fbuf, clip.x, clip.y) + object.draw_raster(clip) def refresh(self, display, working_buffer): for rect in self._damage: diff --git a/src/tempe/text.py b/src/tempe/text.py index 32303eb..f745900 100644 --- a/src/tempe/text.py +++ b/src/tempe/text.py @@ -1,7 +1,7 @@ from array import array import framebuf -from .font import BitmapFont, AlrightFont +from .font import BitmapFont from .shapes import ColoredGeometry, BLIT_KEY_RGB565