comparison pyntnclick/tools/rect_drawer.py @ 662:6daaeffb37d1 pyntnclick

The rect drawer becomes less black
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 12 Feb 2012 15:17:36 +0200
parents 5dc866e1d71d
children b67fdd4a152d
comparison
equal deleted inserted replaced
661:5dc866e1d71d 662:6daaeffb37d1
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 4 # XXX: Threw away albow
5 #from albow.root import RootWidget
6 #from albow.utils import frame_rect 5 #from albow.utils import frame_rect
7 #from albow.widget import Widget 6 #from albow.widget import Widget
8 #from albow.controls import Button, Image 7 #from albow.controls import Button, Image
9 #from albow.palette_view import PaletteView 8 #from albow.palette_view import PaletteView
10 #from albow.file_dialogs import request_old_filename 9 #from albow.file_dialogs import request_old_filename
11 #from albow.resource import get_font 10 #from albow.resource import get_font
12 RootWidget = object
13 frame_rect = None 11 frame_rect = None
14 Widget = object
15 Button = object 12 Button = object
16 Image = object 13 Image = object
17 PaletteView = object
18 request_old_filename = None 14 request_old_filename = None
19 get_font = None 15 get_font = None
20 16
21 from pygame.locals import (K_LEFT, K_RIGHT, K_UP, K_DOWN, 17 from pygame.locals import (K_LEFT, K_RIGHT, K_UP, K_DOWN,
22 K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z, 18 K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z,
23 BLEND_RGBA_MIN, SRCALPHA, QUIT) 19 BLEND_RGBA_MIN, SRCALPHA, QUIT)
24 import pygame 20 import pygame
25 21
26 import pyntnclick.constants 22 import pyntnclick.constants
27 from pyntnclick import state 23 from pyntnclick.widgets.text import LabelWidget, TextButton
28 state.DEBUG_RECTS = True
29 from pyntnclick.widgets import BoomLabel
30 from pyntnclick.widgets.base import Container 24 from pyntnclick.widgets.base import Container
31 25
32 26
33 class RectDrawerConstants(pyntnclick.constants.GameConstants): 27 class RectDrawerConstants(pyntnclick.constants.GameConstants):
34 debug = True 28 debug = True
38 zoom_step = 100 32 zoom_step = 100
39 33
40 constants = RectDrawerConstants() 34 constants = RectDrawerConstants()
41 35
42 36
43 class AppPalette(PaletteView): 37 class AppPalette(object):
44 38
45 sel_width = 5 39 sel_width = 5
46 40
47 colors = [ 41 colors = [
48 'red', 'maroon1', 'palevioletred1', 'moccasin', 'orange', 42 'red', 'maroon1', 'palevioletred1', 'moccasin', 'orange',
51 'green', 'palegreen1', 'darkgreen', 'aquamarine', 'darkolivegreen', 45 'green', 'palegreen1', 'darkgreen', 'aquamarine', 'darkolivegreen',
52 ] 46 ]
53 47
54 def __init__(self, app_image): 48 def __init__(self, app_image):
55 self.image = app_image 49 self.image = app_image
56 super(AppPalette, self).__init__((35, 35), 4, 5, margin=2) 50 #super(AppPalette, self).__init__((35, 35), 4, 5, margin=2)
57 self.selection = 0 51 #self.selection = 0
58 self.image.rect_color = pygame.color.Color(self.colors[self.selection]) 52 #self.image.rect_color = pygame.color.Color(self.colors[self.selection])
59 53
60 def num_items(self): 54 def num_items(self):
61 return len(self.colors) 55 return len(self.colors)
62 56
63 def draw_item(self, surface, item_no, rect): 57 def draw_item(self, surface, item_no, rect):
71 65
72 def item_is_selected(self, item_no): 66 def item_is_selected(self, item_no):
73 return self.selection == item_no 67 return self.selection == item_no
74 68
75 69
76 class AppImage(Widget): 70 class AppImage(Container):
77 71
78 rect_thick = 3 72 rect_thick = 3
79 draw_thick = 1 73 draw_thick = 1
80 74
81 def __init__(self, state): 75 def __init__(self, gd, state):
82 self.state = state 76 self.state = state
83 super(AppImage, self).__init__(pygame.rect.Rect(0, 0, 77 super(AppImage, self).__init__(pygame.rect.Rect(0, 0,
84 constants.screen[0], 78 constants.screen[0], constants.screen[1]), gd)
85 constants.screen[1]))
86 self.mode = 'draw' 79 self.mode = 'draw'
87 self.rects = [] 80 self.rects = []
88 self.images = [] 81 self.images = []
89 self.start_pos = None 82 self.start_pos = None
90 self.end_pos = None 83 self.end_pos = None
91 self.rect_color = pygame.color.Color('white') 84 self.rect_color = pygame.color.Color('white')
92 self.current_image = None 85 self.current_image = None
93 self.place_image_menu = None 86 self.place_image_menu = None
94 self.close_button = BoomLabel('Close', font=get_font(20, 'Vera.ttf')) 87 self.close_button = LabelWidget(pygame.Rect((0, 0), (200, 100)),
88 gd, 'Close', fontname='Vera.ttf', fontsize=20)
95 self.close_button.fg_color = (0, 0, 0) 89 self.close_button.fg_color = (0, 0, 0)
96 self.close_button.bg_color = (0, 0, 0) 90 self.close_button.bg_color = (0, 0, 0)
97 self.draw_rects = True 91 self.draw_rects = True
98 self.draw_things = True 92 self.draw_things = True
99 self.draw_thing_rects = True 93 self.draw_thing_rects = True
527 if self.draw_anim: 521 if self.draw_anim:
528 if self.state.animate(): 522 if self.state.animate():
529 self.invalidate() 523 self.invalidate()
530 524
531 525
532 class ModeLabel(BoomLabel): 526 class ModeLabel(LabelWidget):
533 527
534 def __init__(self, app_image): 528 def __init__(self, rect, gd, app_image):
535 self.app_image = app_image 529 self.app_image = app_image
536 super(ModeLabel, self).__init__('Mode : ', 200, 530 super(ModeLabel, self).__init__(rect,
537 font=get_font(15, 'VeraBd.ttf'), 531 gd, 'Mode : ', fontname='VeraBd.ttf',
538 fg_color=pygame.color.Color(128, 0, 255)) 532 fontsize=15, color=pygame.color.Color(128, 0, 255))
539 self.rect.move_ip(805, 0)
540 533
541 def draw_all(self, surface): 534 def draw_all(self, surface):
542 self.set_text('Mode : %s' % self.app_image.mode) 535 self.set_text('Mode : %s' % self.app_image.mode)
543 super(ModeLabel, self).draw_all(surface) 536 super(ModeLabel, self).draw_all(surface)
544 537
554 547
555 class RectApp(Container): 548 class RectApp(Container):
556 """The actual rect drawer main app""" 549 """The actual rect drawer main app"""
557 def __init__(self, rect, gd): 550 def __init__(self, rect, gd):
558 super(RectApp, self).__init__(rect, gd) 551 super(RectApp, self).__init__(rect, gd)
552
553 state = gd.initial_state()
554
555 self.image = AppImage(gd, state)
556 self.add(self.image)
557 mode_label = ModeLabel(pygame.Rect((805, 0), (200, 100)),
558 self.gd, self.image)
559 self.add(mode_label)
559 560
560 561
561 class RectEngine(object): 562 class RectEngine(object):
562 """Engine for the rect drawer.""" 563 """Engine for the rect drawer."""
563 564
581 self.app.draw(surface) 582 self.app.draw(surface)
582 pygame.display.flip() 583 pygame.display.flip()
583 clock.tick(self._gd.constants.frame_rate) 584 clock.tick(self._gd.constants.frame_rate)
584 585
585 586
586 class RectAppOld(RootWidget): 587 class RectAppOld(object):
587 """Handle the app stuff for the rect drawer""" 588 """Handle the app stuff for the rect drawer"""
588 589
589 def __init__(self, display, get_initial_state, scene, detail): 590 def __init__(self, display, get_initial_state, scene, detail):
590 super(RectApp, self).__init__(display) 591 super(RectApp, self).__init__(display)
591 pygame.key.set_repeat(200, 100) 592 pygame.key.set_repeat(200, 100)
592 state = get_initial_state() 593 state = get_initial_state()
593 state.set_current_scene(scene) 594 state.set_current_scene(scene)
594 state.set_current_detail(detail) 595 state.set_current_detail(detail)
595 state.do_check = None 596 state.do_check = None
596 597
597 self.image = AppImage(state) 598 mode_label = ModeLabel(pygame.Rect((805, 0), (200, 100)),
598 self.add(self.image) 599 self.gd, self.image)
599 mode_label = ModeLabel(self.image)
600 self.add(mode_label) 600 self.add(mode_label)
601 y = mode_label.get_rect().h 601 y = mode_label.get_rect().h
602 draw = make_button('Draw Rect', self.image.draw_mode, y) 602 draw = make_button('Draw Rect', self.image.draw_mode, y)
603 self.add(draw) 603 self.add(draw)
604 y += draw.get_rect().h 604 y += draw.get_rect().h