Put the menu screen background in place.
authorSimon Cross <hodgestar@gmail.com>
Fri, 16 May 2014 22:40:23 +0000 (00:40 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 16 May 2014 22:41:22 +0000 (00:41 +0200)
naja/scenes/menu.py
naja/widgets/image_box.py [new file with mode: 0644]

index adc42df5b366d32a972244afcf1f7043462907e5..750d2ce06457051109146cbeb798199c0d06a3d3 100644 (file)
@@ -15,11 +15,17 @@ from naja.scenes.load_save import LoadGameScene, SaveGameScene
 from naja.scenes.new_game import NewGameScene
 from naja.widgets.selector import SelectorWidget
 from naja.widgets.text import TextWidget
+from naja.widgets.image_box import ImageBox
 
 
 class MenuScene(Scene):
     def __init__(self, state):
         super(MenuScene, self).__init__(state)
+
+        background = ImageBox(
+            (0, 0), "screens/splash.png")
+        self.add(background)
+
         selector = SelectorWidget()
         self.add(selector)
         y_offset = 0
diff --git a/naja/widgets/image_box.py b/naja/widgets/image_box.py
new file mode 100644 (file)
index 0000000..5709cec
--- /dev/null
@@ -0,0 +1,22 @@
+"""Widget to draw an image"""
+
+from naja.resources import resources
+from naja.resources.mutators import EIGHT_BIT
+from naja.widgets.base import Widget
+
+
+class ImageBox(Widget):
+    """Widget which holds an image."""
+
+    def __init__(self, pos, image, transforms=(EIGHT_BIT,)):
+        super(ImageBox, self).__init__(pos)
+        self.image = image
+        self.transforms = transforms
+
+    def prepare(self):
+        self.surface = resources.get_image(
+            self.image, transforms=self.transforms)
+        self.size = self.surface.get_rect().size
+
+    def draw(self, surface):
+        surface.blit(self.surface, self.rect)