Skip to content

Commit

Permalink
Assorted fixes from getting example code running.
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster committed Oct 17, 2024
1 parent 5bcc456 commit 7b1ca2d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/tempe/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion src/tempe/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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.
Expand All @@ -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)
2 changes: 1 addition & 1 deletion src/tempe/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/tempe/text.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down

0 comments on commit 7b1ca2d

Please sign in to comment.