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
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):
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):
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:
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)
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():