Main menu scene.
"""
-from .scene import Scene
+from naja.scenes.scene import Scene
+from naja.widgets.text import TextWidget
class MenuScene(Scene):
- """
- Main menu.
- """
+
+ def __init__(self):
+ self.tw = TextWidget((10, 10), 'Haai', colour=(255, 255, 255))
+
+ def render(self, surface):
+ self.tw.draw(surface)
+
+ def handle_event(self, ev):
+ pass
--- /dev/null
+import pygame
+
+
+class Widget(object):
+ def __init__(self, pos, size=None):
+ self.pos = pos
+ self.size = size or (0, 0)
+ self._prepared = False
+
+ @property
+ def rect(self):
+ return pygame.Rect(self.pos, self.size)
+
+ def draw(self, surface):
+ raise NotImplemented()
+
+ def prepare(self):
+ if not self._prepared:
+ self._prepare()
+ self._prepared = True
+
+ def _prepare(self):
+ raise NotImplemented()
--- /dev/null
+from naja.constants import FONT, FONT_SIZE
+from naja.widgets.base import Widget
+from naja.resources import resources
+
+
+class TextWidget(Widget):
+ def __init__(self, pos, text, size=None, fontname=None, fontsize=None,
+ colour=None):
+ super(TextWidget, self).__init__(pos, size)
+
+ self.text = text
+ self.fontname = fontname or FONT
+ self.fontsize = fontsize or FONT_SIZE
+ self.colour = colour or (0, 0, 0)
+
+ def _prepare(self):
+ self.font = resources.get_font(self.fontname, self.fontsize)
+ self.surface = self.font.render(self.text, True, self.colour)
+ self.size = self.surface.get_rect().size
+
+ def draw(self, surface):
+ self.prepare()
+ surface.blit(self.surface, self.rect)