|
@@ -18,7 +18,7 @@ class DrawText:
|
18
|
18
|
|
19
|
19
|
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
20
|
20
|
fontDir = os.path.join(scriptDir, "fonts")
|
21
|
|
- self.fonts = []
|
|
21
|
+ self.fonts = {}
|
22
|
22
|
for f in os.listdir(os.fsencode(fontDir)):
|
23
|
23
|
filename = os.fsdecode(f)
|
24
|
24
|
|
|
@@ -34,12 +34,14 @@ class DrawText:
|
34
|
34
|
offset = 0
|
35
|
35
|
if filename == "iv18x16u.bdf":
|
36
|
36
|
offset = 6
|
|
37
|
+ elif filename == "ib8x8u.bdf":
|
|
38
|
+ offset = 10
|
37
|
39
|
|
38
|
40
|
data = (font, offset, {})
|
39
|
|
- self.fonts.append(data)
|
|
41
|
+ self.fonts[filename[:-4]] = data
|
40
|
42
|
|
41
|
|
- def getGlyph(self, c):
|
42
|
|
- f, o, cache = self.fonts[0] # TODO selection of fonts
|
|
43
|
+ def getGlyph(self, c, font):
|
|
44
|
+ f, o, cache = self.fonts[font]
|
43
|
45
|
|
44
|
46
|
# only render glyphs once, cache resulting image data
|
45
|
47
|
if not c in cache:
|
|
@@ -70,7 +72,7 @@ class DrawText:
|
70
|
72
|
p = g.getpixel((x, y))
|
71
|
73
|
self.gui.set_pixel(xTarget, yOff + y, p)
|
72
|
74
|
|
73
|
|
- def text(self, s, offset = 0, earlyAbort = True):
|
|
75
|
+ def text(self, s, f, offset = 0, earlyAbort = True, yOff = 0):
|
74
|
76
|
w = 0
|
75
|
77
|
for c in s:
|
76
|
78
|
xOff = -offset + w
|
|
@@ -78,22 +80,23 @@ class DrawText:
|
78
|
80
|
if xOff >= self.gui.width:
|
79
|
81
|
break
|
80
|
82
|
|
81
|
|
- g, y = self.getGlyph(c)
|
|
83
|
+ g, y = self.getGlyph(c, f)
|
82
|
84
|
w += g.width
|
83
|
85
|
|
84
|
86
|
if xOff >= -10: # some wiggle room so chars dont disappear
|
85
|
|
- self.drawGlyph(g, xOff, y)
|
|
87
|
+ self.drawGlyph(g, xOff, y + yOff)
|
86
|
88
|
return w
|
87
|
|
-import sys
|
|
89
|
+
|
88
|
90
|
class ScrollText:
|
89
|
|
- def __init__(self, g, t, i = 1, s = 75):
|
|
91
|
+ def __init__(self, g, t, f, i = 1, s = 75):
|
90
|
92
|
self.gui = g
|
91
|
93
|
self.drawer = DrawText(self.gui)
|
92
|
94
|
self.text = t
|
|
95
|
+ self.font = f
|
93
|
96
|
self.iterations = i
|
94
|
97
|
self.speed = 1.0 / s
|
95
|
98
|
|
96
|
|
- self.width = self.drawer.text(self.text, 0, False)
|
|
99
|
+ self.width = self.drawer.text(self.text, self.font, 0, False)
|
97
|
100
|
self.restart()
|
98
|
101
|
|
99
|
102
|
def restart(self):
|
|
@@ -113,11 +116,12 @@ class ScrollText:
|
113
|
116
|
self.offset = -self.gui.width
|
114
|
117
|
self.count += 1
|
115
|
118
|
|
116
|
|
- self.drawer.text(self.text, self.offset, True)
|
|
119
|
+ self.drawer.text(self.text, self.font, self.offset, True)
|
117
|
120
|
|
118
|
121
|
if __name__ == "__main__":
|
119
|
122
|
import util
|
120
|
123
|
t = util.getTarget()
|
121
|
124
|
|
122
|
|
- d = ScrollText(t, "This is a long scrolling text. Is it too fast or maybe too slow?")
|
|
125
|
+ #d = ScrollText(t, "This is a long scrolling text. Is it too fast or maybe too slow?", "iv18x16u")
|
|
126
|
+ d = ScrollText(t, "This is a long scrolling text. Is it too fast or maybe too slow?", "ib8x8u")
|
123
|
127
|
t.debug_loop(d.draw)
|