Skip to content

Commit 57938f9

Browse files
authored
Merge pull request #13 from Tasm-Devil/master
implemented scroll method to framebuf (2nd attempt)
2 parents d0e9028 + b2827a2 commit 57938f9

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

adafruit_framebuf.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,31 @@ def blit(self):
252252
"""blit is not yet implemented"""
253253
raise NotImplementedError()
254254

255-
def scroll(self):
256-
"""scroll is not yet implemented"""
257-
raise NotImplementedError()
255+
def scroll(self, delta_x, delta_y):
256+
"""shifts framebuf in x and y direction"""
257+
if delta_x < 0:
258+
shift_x = 0
259+
xend = self.width + delta_x
260+
dt_x = 1
261+
else:
262+
shift_x = self.width - 1
263+
xend = delta_x - 1
264+
dt_x = -1
265+
if delta_y < 0:
266+
y = 0
267+
yend = self.height + delta_y
268+
dt_y = 1
269+
else:
270+
y = self.height - 1
271+
yend = delta_y - 1
272+
dt_y = -1
273+
while y != yend:
274+
x = shift_x
275+
while x != xend:
276+
self.format.set_pixel(
277+
self, x, y, self.format.get_pixel(self, x - delta_x, y - delta_y))
278+
x += dt_x
279+
y += dt_y
258280

259281
def text(self, string, x, y, color, *,
260282
font_name="font5x8.bin"):

0 commit comments

Comments
 (0)