Mercurial > boomslang
comparison pyntnclick/tools/rect_drawer.py @ 686:48f68ae7d454 pyntnclick
Throw out more old stuff. Fix animation support
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Mon, 13 Feb 2012 11:36:32 +0200 |
parents | 32e554adf538 |
children | 929b63589c96 |
comparison
equal
deleted
inserted
replaced
685:32e554adf538 | 686:48f68ae7d454 |
---|---|
1 # Quickly hacked together helper for working out | 1 # Quickly hacked together helper for working out |
2 # interactive regions in Suspended Sentence | 2 # interactive regions in Suspended Sentence |
3 | 3 |
4 # XXX: Threw away albow | |
5 #from albow.utils import frame_rect | |
6 #from albow.widget import Widget | |
7 #from albow.controls import Button, Image | |
8 #from albow.palette_view import PaletteView | |
9 #from albow.file_dialogs import request_old_filename | |
10 #from albow.resource import get_font | |
11 frame_rect = None | 4 frame_rect = None |
12 Button = object | |
13 Image = object | 5 Image = object |
14 request_old_filename = None | 6 request_old_filename = None |
15 get_font = None | |
16 | 7 |
17 from pygame.locals import (K_LEFT, K_RIGHT, K_UP, K_DOWN, | 8 from pygame.locals import (K_LEFT, K_RIGHT, K_UP, K_DOWN, |
18 K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z, | 9 K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z, |
19 BLEND_RGBA_MIN, SRCALPHA, QUIT) | 10 BLEND_RGBA_MIN, SRCALPHA, QUIT) |
20 import pygame | 11 import pygame |
517 self.end_pos = self._conv_pos(e.pos) | 508 self.end_pos = self._conv_pos(e.pos) |
518 self.invalidate() | 509 self.invalidate() |
519 | 510 |
520 def animate(self): | 511 def animate(self): |
521 if self.draw_anim: | 512 if self.draw_anim: |
522 if self.state.animate(): | 513 self.state.animate() |
523 self.invalidate() | |
524 | 514 |
525 | 515 |
526 class ModeLabel(LabelWidget): | 516 class ModeLabel(LabelWidget): |
527 | 517 |
528 def __init__(self, rect, gd, app_image): | 518 def __init__(self, rect, gd, app_image): |
550 """The actual rect drawer main app""" | 540 """The actual rect drawer main app""" |
551 def __init__(self, rect, gd): | 541 def __init__(self, rect, gd): |
552 super(RectApp, self).__init__(rect, gd) | 542 super(RectApp, self).__init__(rect, gd) |
553 | 543 |
554 state = gd.initial_state() | 544 state = gd.initial_state() |
545 gd.sound.disable_sound() # No sound here | |
546 | |
547 # Handle any setup that needs to happen | |
548 # We start in leave, so do this twice | |
549 # FIXME: Screen parameter to check_enter_leave | |
550 # should go away | |
551 state.check_enter_leave(None) | |
552 state.check_enter_leave(None) | |
555 | 553 |
556 self.image = AppImage(gd, state) | 554 self.image = AppImage(gd, state) |
557 self.add(self.image) | 555 self.add(self.image) |
558 mode_label = ModeLabel(pygame.Rect((805, 0), (200, 25)), | 556 mode_label = ModeLabel(pygame.Rect((805, 0), (200, 25)), |
559 self.gd, self.image) | 557 self.gd, self.image) |
620 self.add(quit_but) | 618 self.add(quit_but) |
621 | 619 |
622 def quit(self, ev, widget): | 620 def quit(self, ev, widget): |
623 pygame.event.post(pygame.event.Event(QUIT)) | 621 pygame.event.post(pygame.event.Event(QUIT)) |
624 | 622 |
623 def animate(self): | |
624 self.image.animate() | |
625 | |
625 | 626 |
626 class RectEngine(object): | 627 class RectEngine(object): |
627 """Engine for the rect drawer.""" | 628 """Engine for the rect drawer.""" |
628 | 629 |
629 def __init__(self, gd, get_initial_state, scene, detail): | 630 def __init__(self, gd, get_initial_state, scene, detail): |
640 for ev in events: | 641 for ev in events: |
641 if ev.type == QUIT: | 642 if ev.type == QUIT: |
642 return | 643 return |
643 else: | 644 else: |
644 self.app.event(ev) | 645 self.app.event(ev) |
646 self.app.animate() | |
645 surface = pygame.display.get_surface() | 647 surface = pygame.display.get_surface() |
646 self.app.draw(surface) | 648 self.app.draw(surface) |
647 pygame.display.flip() | 649 pygame.display.flip() |
648 clock.tick(self._gd.constants.frame_rate) | 650 clock.tick(self._gd.constants.frame_rate) |
649 | |
650 | |
651 class RectAppOld(object): | |
652 """Handle the app stuff for the rect drawer""" | |
653 | |
654 def __init__(self, display, get_initial_state, scene, detail): | |
655 super(RectApp, self).__init__(display) | |
656 pygame.key.set_repeat(200, 100) | |
657 state = get_initial_state() | |
658 state.set_current_scene(scene) | |
659 state.set_current_detail(detail) | |
660 state.do_check = None | |
661 | |
662 self.set_timer(constants.frame_rate) | |
663 | |
664 def key_down(self, event): | |
665 # Dispatch to image widget | |
666 self.image.key_down(event) | |
667 | |
668 def mouse_delta(self, event): | |
669 # We propogate mouse move from here to draw region, so images move | |
670 # off-screen | |
671 self.image.do_mouse_move(event) | |
672 | |
673 def begin_frame(self): | |
674 self.image.animate() | |
675 | 651 |
676 | 652 |
677 def make_rect_display(): | 653 def make_rect_display(): |
678 pygame.display.init() | 654 pygame.display.init() |
679 pygame.font.init() | 655 pygame.font.init() |