Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted fixes from getting example code running #11

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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