############################################################################# ## This file is part of the Ostendo Resource Manager. ## ##-------------------------------------------------------------------------## ## Copyright 2007-2008 Bryce Schroeder ## ## bryce.schroeder@gmail.com ## ## http://www.ferazelhosting.net/~bryce/ ## ##-------------------------------------------------------------------------## ## This program is free software: you can redistribute it and/or modify ## ## it under the terms of the GNU General Public License as published by ## ## the Free Software Foundation, either version 3 of the License, or ## ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## ## along with this program. If not, see . ## ############################################################################# from .standard_interpreters import Resource, R import pygame, time from pygame.locals import * class Scroller: def __init__(self, text): self.text = text self.g = text.g def show(self): """Show the text of the scroller. Takes over the display.""" finished = False text=self.text font=text['font'].pygame_font(text['font_size']) if text['music']: text['music'].play() lines=str(text).split('\n') rendered_lines = [] i = 0 for line in lines: surf = font.render(line, True, text['fg_color'], text['bg_color']) surf.set_alpha(1 + 254*(i < text['inital_lines'])) rendered_lines.append(surf) i += 1 screen_height = self.g.screen.get_height() fontheight = font.get_height() frame = 0 offset = 0 last = None while not finished and self.g.unfinished: if text['bg_image']: text['bg_image'].blit(self.g.screen, 0,0) elif text['bg_color']: self.g.screen.fill(text['bg_color']) py = offset finished = True first = True for line in rendered_lines: if py > -fontheight and py + text['v_bottom'] < screen_height - text['v_top']: self.g.screen.blit(line, (32,py+text['v_bottom'])) finished = False if first and frame > text['start_delay']: line.set_alpha(line.get_alpha()/2 + 1) first = False last = line py += fontheight if last: last.set_alpha(last.get_alpha()*2) frame += 1 for evt in pygame.event.get(): if evt.type is QUIT: print "Goodbye." self.g.unfinished = False elif evt.type is MOUSEBUTTONUP or evt.type is KEYDOWN: finished = True time.sleep(0.05) if frame > text['start_delay']: offset -= 1 pygame.display.flip() if text['music']: text['music'].fadeout(100) class Text(Resource): MANDATORY = ['text'] #OPTIONAL = ['meta'] def init(self): self.meta = {} if self.parts.has_key('meta'): self.meta = self.process_meta(self.parts['meta']) def __str__(self): return self.parts['text'] def __getitem__(self, key): try: return self.meta[key] except KeyError: return None def scroller(self): return Scroller(self)