Hook up shift glyph
[naja.git] / naja / widgets / text.py
index 02de03fd955be7f9b45324077df7390daa6a8dcd..302d2370f3fdf7d85d11c88c754f57c3b9e72102 100644 (file)
@@ -3,7 +3,7 @@ import pygame.locals as pgl
 
 from naja.constants import FONT, FONT_SIZE, EIGHT_BIT_SCALE, PALETTE, KEYS
 from naja.resources import resources
-from naja.resources.mutators import EIGHT_BIT, blender
+from naja.resources.mutators import EIGHT_BIT, R180, blender
 from naja.utils import convert_colour
 from naja.widgets.base import Widget
 
@@ -22,6 +22,8 @@ MARKUP_MAP = {
     'BLUE': ('glyphs/key.png', PALETTE.BLUE),
     'CLOCKWISE': ('glyphs/clockwise.png', None),
     'ANTICLOCKWISE': ('glyphs/anticlockwise.png', None),
+    'SHIFT_LEFT': ('glyphs/shift_left.png', None),
+    'SHIFT_RIGHT': ('glyphs/shift_right.png', None),
 
     'HEALTH_NOCOLOUR': ('glyphs/health.png', None),
     'WINTOKEN_NOCOLOUR': ('glyphs/win.png', None),
@@ -104,6 +106,23 @@ class TextWidget(Widget):
             rect = self.pos
             area = self.view_port
         surface.blit(self.surface, rect, area)
+        if self.view_port is not None:
+            self.draw_arrows(surface)
+
+    def draw_arrows(self, surface):
+        if self.view_port.top > 0:
+            up = resources.get_image('bits', 'arrow_on.png',
+                                     transforms=(EIGHT_BIT,))
+            icon_size = up.get_rect().height
+            pos = (self.pos[0] + self.view_port.width - icon_size, self.pos[1])
+            surface.blit(up, pos)
+        if self.view_port.bottom < self.surface.get_rect().bottom:
+            down = resources.get_image('bits', 'arrow_on.png',
+                                       transforms=(R180, EIGHT_BIT))
+            icon_size = down.get_rect().height
+            pos = (self.pos[0] + self.view_port.width - icon_size,
+                   self.pos[1] + self.view_port.height - icon_size)
+            surface.blit(down, pos)
 
 
 class TextBoxWidget(TextWidget):
@@ -116,6 +135,8 @@ class TextBoxWidget(TextWidget):
                                                        PALETTE.BLACK))
         self.box_width = kwargs.pop('box_width', 0)
 
+        self.full_width = kwargs.pop('full_width', True)
+
         super(TextBoxWidget, self).__init__(*args, **kwargs)
 
     def lines(self, image_map):
@@ -153,7 +174,7 @@ class TextBoxWidget(TextWidget):
     def _wrapped_lines(self, image_map):
         def words_fit(words):
             words_line = ' '.join(words)
-            width = self.font.size(words_line)[0]
+            width = self.font.size(words_line)[0] * EIGHT_BIT_SCALE
             if width < self.box_width:
                 return True
             elif len(words) == 1:
@@ -202,6 +223,9 @@ class TextBoxWidget(TextWidget):
             width = max(width, line_rect.width + self.padding * 2)
             height += line_rect.height
 
+        if self.full_width:
+            width = max(width, self.box_width)
+
         self.surface = pygame.surface.Surface((width, height),
                                               pygame.locals.SRCALPHA)
         self.surface.fill(self.bg_colour)
@@ -209,6 +233,9 @@ class TextBoxWidget(TextWidget):
 
         x, y = self.padding, self.padding
         for line_surface in rendered_lines:
+            if self.centre:
+                x = (width - line_surface.get_rect().width) / 2
+                x += self.padding
             self.surface.blit(line_surface, (x, y))
             y += line_surface.get_rect().height
         for pos, img in image_map.items():