changeset 10:771db7d6e862

Basic widget layout (won't work
author Stefano Rivera <stefano@rivera.za.net>
date Sun, 11 Sep 2011 13:03:45 +0200
parents be8412c77e7b
children 447311ee028c
files mamba/widgets/__init__.py mamba/widgets/text.py
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mamba/widgets/__init__.py	Sun Sep 11 13:03:45 2011 +0200
@@ -0,0 +1,12 @@
+class Widget(object):
+    def __init__(self, pos):
+        pass
+
+    def dispatch(self, event):
+        pass
+
+    def add(self, widget):
+        pass
+
+    def draw(self, surface):
+        surface.blit(self.surface, self.pos)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mamba/widgets/text.py	Sun Sep 11 13:03:45 2011 +0200
@@ -0,0 +1,16 @@
+import pygame
+
+from mamba.widgets import Widget
+from mamba.data import filepath
+
+class Text(Widget):
+    fontcache = {}
+    def __init__(self, text, pos, size=16, color='black'):
+        self.text = text
+        self.pos = pos
+        font = 'DejaVuSans.ttf'
+        if (font, size) not in Text.fontcache:
+            fontfn = filepath('fonts/' + font)
+            Text.fontcache[(font, size)] = pygame.font.Font(fontfn, size)
+        self.font = Text.fontcache[(font, size)]
+        self.surface = self.font.render(text, True, color)