Browse Source

Basic support for selection between multiple fonts. Attempt to add heading to QR code, not yet finished.

Thomas Buck 1 year ago
parent
commit
3e0c60902b
6 changed files with 10439 additions and 22 deletions
  1. 2
    2
      camp_small.py
  2. 16
    12
      draw.py
  3. 10405
    0
      fonts/ib8x8u.bdf
  4. 4
    4
      manager.py
  5. 2
    2
      net.py
  6. 10
    2
      qr.py

+ 2
- 2
camp_small.py View File

30
     success = Manager(t)
30
     success = Manager(t)
31
     success.add(ImageScreen(t, "drinka.gif", 0.2, 2, 20.0))
31
     success.add(ImageScreen(t, "drinka.gif", 0.2, 2, 20.0))
32
     success.add(Solid(t, 1.0))
32
     success.add(Solid(t, 1.0))
33
-    success.add(QRScreen(t, url, 30.0))
33
+    success.add(QRScreen(t, url, 30.0, "Order:"))
34
     success.add(Solid(t, 1.0))
34
     success.add(Solid(t, 1.0))
35
 
35
 
36
     fail = Manager(t)
36
     fail = Manager(t)
37
     fail.add(ImageScreen(t, "attention.gif", 0.2, 2, 20.0, (0, 0, 0)))
37
     fail.add(ImageScreen(t, "attention.gif", 0.2, 2, 20.0, (0, 0, 0)))
38
-    fail.add(ScrollText(t, "The UbaBot Cocktail machine is currently closed. Please come back later for more drinks!", 2))
38
+    fail.add(ScrollText(t, "The UbaBot Cocktail machine is currently closed. Please come back later for more drinks!", "ib8x8u", 2))
39
     fail.add(Solid(t, 2.0))
39
     fail.add(Solid(t, 2.0))
40
     fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
40
     fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
41
     fail.add(Solid(t, 2.0))
41
     fail.add(Solid(t, 2.0))

+ 16
- 12
draw.py View File

18
 
18
 
19
         scriptDir = os.path.dirname(os.path.realpath(__file__))
19
         scriptDir = os.path.dirname(os.path.realpath(__file__))
20
         fontDir = os.path.join(scriptDir, "fonts")
20
         fontDir = os.path.join(scriptDir, "fonts")
21
-        self.fonts = []
21
+        self.fonts = {}
22
         for f in os.listdir(os.fsencode(fontDir)):
22
         for f in os.listdir(os.fsencode(fontDir)):
23
             filename = os.fsdecode(f)
23
             filename = os.fsdecode(f)
24
 
24
 
34
             offset = 0
34
             offset = 0
35
             if filename == "iv18x16u.bdf":
35
             if filename == "iv18x16u.bdf":
36
                 offset = 6
36
                 offset = 6
37
+            elif filename == "ib8x8u.bdf":
38
+                offset = 10
37
 
39
 
38
             data = (font, offset, {})
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
         # only render glyphs once, cache resulting image data
46
         # only render glyphs once, cache resulting image data
45
         if not c in cache:
47
         if not c in cache:
70
                 p = g.getpixel((x, y))
72
                 p = g.getpixel((x, y))
71
                 self.gui.set_pixel(xTarget, yOff + y, p)
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
         w = 0
76
         w = 0
75
         for c in s:
77
         for c in s:
76
             xOff = -offset + w
78
             xOff = -offset + w
78
                 if xOff >= self.gui.width:
80
                 if xOff >= self.gui.width:
79
                     break
81
                     break
80
 
82
 
81
-            g, y = self.getGlyph(c)
83
+            g, y = self.getGlyph(c, f)
82
             w += g.width
84
             w += g.width
83
 
85
 
84
             if xOff >= -10: # some wiggle room so chars dont disappear
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
         return w
88
         return w
87
-import sys
89
+
88
 class ScrollText:
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
         self.gui = g
92
         self.gui = g
91
         self.drawer = DrawText(self.gui)
93
         self.drawer = DrawText(self.gui)
92
         self.text = t
94
         self.text = t
95
+        self.font = f
93
         self.iterations = i
96
         self.iterations = i
94
         self.speed = 1.0 / s
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
         self.restart()
100
         self.restart()
98
 
101
 
99
     def restart(self):
102
     def restart(self):
113
                 self.offset = -self.gui.width
116
                 self.offset = -self.gui.width
114
                 self.count += 1
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
 if __name__ == "__main__":
121
 if __name__ == "__main__":
119
     import util
122
     import util
120
     t = util.getTarget()
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
     t.debug_loop(d.draw)
127
     t.debug_loop(d.draw)

+ 10405
- 0
fonts/ib8x8u.bdf
File diff suppressed because it is too large
View File


+ 4
- 4
manager.py View File

63
 
63
 
64
     m = Manager(t)
64
     m = Manager(t)
65
 
65
 
66
-    m.add(ScrollText(t, "This appears once"))
66
+    m.add(ScrollText(t, "This appears once", "ib8x8u"))
67
     m.add(Solid(t, 1.0))
67
     m.add(Solid(t, 1.0))
68
 
68
 
69
-    m.add(ScrollText(t, "And this twice...", 2))
69
+    m.add(ScrollText(t, "And this twice...", "ib8x8u", 2))
70
     m.add(Solid(t, 1.0))
70
     m.add(Solid(t, 1.0))
71
 
71
 
72
     m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0, True))
72
     m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0, True))
73
     m.add(Solid(t, 1.0))
73
     m.add(Solid(t, 1.0))
74
 
74
 
75
     sub = Manager(t)
75
     sub = Manager(t)
76
-    sub.add(ScrollText(t, "Hello"))
76
+    sub.add(ScrollText(t, "Hello", "ib8x8u"))
77
     sub.add(Solid(t, 1.0, (0, 255, 0)))
77
     sub.add(Solid(t, 1.0, (0, 255, 0)))
78
-    sub.add(ScrollText(t, "World"))
78
+    sub.add(ScrollText(t, "World", "ib8x8u"))
79
     sub.add(Solid(t, 1.0, (0, 0, 255)))
79
     sub.add(Solid(t, 1.0, (0, 0, 255)))
80
     m.add(sub)
80
     m.add(sub)
81
     m.add(Solid(t, 1.0))
81
     m.add(Solid(t, 1.0))

+ 2
- 2
net.py View File

63
     t = util.getTarget()
63
     t = util.getTarget()
64
 
64
 
65
     d = CheckHTTP("http://xythobuz.de")
65
     d = CheckHTTP("http://xythobuz.de")
66
-    d.success(ScrollText(t, "Success"))
67
-    d.fail(ScrollText(t, "Failure"))
66
+    d.success(ScrollText(t, "Success", "ib8x8u"))
67
+    d.fail(ScrollText(t, "Failure", "ib8x8u"))
68
 
68
 
69
     t.debug_loop(d.draw)
69
     t.debug_loop(d.draw)

+ 10
- 2
qr.py View File

10
 import time
10
 import time
11
 import qrcode
11
 import qrcode
12
 import util
12
 import util
13
+from draw import DrawText
13
 
14
 
14
 class QRScreen:
15
 class QRScreen:
15
-    def __init__(self, g, d, t = 10.0, c1 = (0, 0, 0), c2 = (255, 255, 255)):
16
+    def __init__(self, g, d, t = 10.0, h = None, c1 = (0, 0, 0), c2 = (255, 255, 255)):
16
         self.gui = g
17
         self.gui = g
17
         self.time = t
18
         self.time = t
19
+        self.heading = h
18
         self.c1 = c1
20
         self.c1 = c1
19
         self.c2 = c2
21
         self.c2 = c2
20
 
22
 
33
         else:
35
         else:
34
             self.image = qr.make_image(fill_color = self.c1, back_color = self.c2)
36
             self.image = qr.make_image(fill_color = self.c1, back_color = self.c2)
35
 
37
 
38
+        if self.heading != None:
39
+            self.text = DrawText(self.gui)
40
+
36
         self.xOff = int((self.gui.width - self.image.width) / 2)
41
         self.xOff = int((self.gui.width - self.image.width) / 2)
37
         self.yOff = int((self.gui.height - self.image.height) / 2)
42
         self.yOff = int((self.gui.height - self.image.height) / 2)
38
 
43
 
65
                     v = (v, v, v)
70
                     v = (v, v, v)
66
                 self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
71
                 self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
67
 
72
 
73
+        if self.heading != None:
74
+            self.text.text(self.heading, "ib8x8u", 0, True, -10)
75
+
68
 if __name__ == "__main__":
76
 if __name__ == "__main__":
69
     import util
77
     import util
70
     t = util.getTarget()
78
     t = util.getTarget()
71
 
79
 
72
-    d = QRScreen(t, "Hello World")
80
+    d = QRScreen(t, "Hello World", 10.0, "Test")
73
     t.debug_loop(d.draw)
81
     t.debug_loop(d.draw)

Loading…
Cancel
Save