Mercurial > boomslang
annotate tools/rect_drawer.py @ 521:d143947690d9
Add list_scenes to rect_drawer
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Wed, 08 Sep 2010 00:41:23 +0200 |
parents | d274cc414178 |
children | 08dbb7f3a34d |
rev | line source |
---|---|
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
1 # Quickly hacked together helper for working out |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
2 # interactive regions in Suspended Sentence |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
3 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
4 import sys |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
5 import os.path |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
6 |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
7 script_path = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
8 sys.path.append(script_path) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
9 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
10 from albow.root import RootWidget |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
11 from albow.utils import frame_rect |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
12 from albow.widget import Widget |
509 | 13 from albow.controls import Button, Image, Label |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
14 from albow.palette_view import PaletteView |
199 | 15 from albow.file_dialogs import request_old_filename |
243
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
16 from albow.resource import get_font |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
17 from pygame.locals import SWSURFACE, K_LEFT, K_RIGHT, K_UP, K_DOWN, \ |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
18 K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z, \ |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
19 BLEND_RGBA_MIN, SRCALPHA |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
20 import pygame |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
21 from pygame.colordict import THECOLORS |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
22 |
250 | 23 from gamelib import constants |
24 constants.DEBUG = True | |
506 | 25 MENU_WIDTH = 200 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
26 MENU_BUTTON_HEIGHT = 25 |
506 | 27 ZOOM = 4 |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
28 ZOOM_STEP = 100 |
250 | 29 |
286
776bcf563ea0
Re-enable thing rects by default in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
279
diff
changeset
|
30 from gamelib import state |
776bcf563ea0
Re-enable thing rects by default in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
279
diff
changeset
|
31 state.DEBUG_RECTS = True |
243
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
32 from gamelib.widgets import BoomLabel |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
33 |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
34 |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
35 class AppPalette(PaletteView): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
36 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
37 sel_width = 5 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
38 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
39 colors = [ |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
40 'red', 'maroon1', 'palevioletred1', 'moccasin', 'orange', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
41 'honeydew', 'yellow', 'gold', 'goldenrod', 'brown', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
42 'blue', 'purple', 'darkorchid4', 'thistle', 'skyblue1', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
43 'green', 'palegreen1', 'darkgreen', 'aquamarine', 'darkolivegreen', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
44 ] |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
45 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
46 def __init__(self, app_image): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
47 self.image = app_image |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
48 super(AppPalette, self).__init__((35, 35), 4, 5, margin=2) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
49 self.selection = 0 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
50 self.image.rect_color = pygame.color.Color(self.colors[self.selection]) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
51 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
52 def num_items(self): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
53 return len(self.colors) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
54 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
55 def draw_item(self, surface, item_no, rect): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
56 d = -2 * self.sel_width |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
57 r = rect.inflate(d, d) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
58 surface.fill(pygame.color.Color(self.colors[item_no]), r) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
59 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
60 def click_item(self, item_no, event): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
61 self.selection = item_no |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
62 self.image.rect_color = pygame.color.Color(self.colors[item_no]) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
63 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
64 def item_is_selected(self, item_no): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
65 return self.selection == item_no |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
66 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
67 |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
68 class AppImage(Widget): |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
69 |
181
f98bc17f5e67
Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents:
179
diff
changeset
|
70 rect_thick = 3 |
f98bc17f5e67
Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents:
179
diff
changeset
|
71 draw_thick = 1 |
f98bc17f5e67
Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents:
179
diff
changeset
|
72 |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
73 def __init__(self, state): |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
74 self.state = state |
506 | 75 super(AppImage, self).__init__(pygame.rect.Rect(0, 0, constants.SCREEN[0], constants.SCREEN[1])) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
76 self.mode = 'draw' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
77 self.rects = [] |
200 | 78 self.images = [] |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
79 self.start_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
80 self.end_pos = None |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
81 self.rect_color = pygame.color.Color('white') |
200 | 82 self.current_image = None |
199 | 83 self.place_image_menu = None |
243
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
84 self.close_button = BoomLabel('Close', font=get_font(20, 'Vera.ttf')) |
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
85 self.close_button.fg_color = (0, 0, 0) |
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
86 self.close_button.bg_color = (0, 0, 0) |
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
87 if self.state.current_detail: |
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
88 w, h = self.state.current_detail.get_detail_size() |
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
89 rect = pygame.rect.Rect(0, 0, w, h) |
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
90 self.close_button.rect.midbottom = rect.midbottom |
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
91 self.add(self.close_button) |
279
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
92 self.offset = (0, 0) |
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
93 else: |
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
94 self.offset = (-self.state.current_scene.OFFSET[0], - self.state.current_scene.OFFSET[1]) |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
95 self.draw_rects = True |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
96 self.draw_things = True |
312
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
97 self.draw_thing_rects = True |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
98 self.draw_images = True |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
99 self.trans_images = False |
275
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
100 self.draw_toolbar = True |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
101 self.old_mouse_pos = None |
506 | 102 self.zoom_display = False |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
103 self.draw_anim = False |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
104 self.zoom_offset = (600, 600) |
323
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
105 self.find_existing_intersects() |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
106 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
107 def _get_scene(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
108 if self.state.current_detail: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
109 return self.state.current_detail |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
110 else: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
111 return self.state.current_scene |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
112 |
323
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
113 def find_existing_intersects(self): |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
114 """Parse the things in the scene for overlaps""" |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
115 scene = self._get_scene() |
323
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
116 # Pylint hates this function |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
117 for thing in scene.things.itervalues(): |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
118 for interact_name in thing.interacts: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
119 thing.set_interact(interact_name) |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
120 if hasattr(thing.rect, 'collidepoint'): |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
121 thing_rects = [thing.rect] |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
122 else: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
123 thing_rects = thing.rect |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
124 for thing2 in scene.things.itervalues(): |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
125 if thing is thing2: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
126 continue |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
127 for interact2_name in thing2.interacts: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
128 thing2.set_interact(interact2_name) |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
129 if hasattr(thing2.rect, 'collidepoint'): |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
130 thing2_rects = [thing2.rect] |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
131 else: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
132 thing2_rects = thing2.rect |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
133 for my_rect in thing_rects: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
134 for other_rect in thing2_rects: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
135 if my_rect.colliderect(other_rect): |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
136 print 'Existing Intersecting rects' |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
137 print " Thing1 %s Interact %s" % (thing.name, interact_name) |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
138 print " Thing2 %s Interact %s" % (thing2.name, interact2_name) |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
139 print " Rects", my_rect, other_rect |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
140 print |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
141 |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
142 def find_intersecting_rects(self, d): |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
143 """Find if any rect collections intersect""" |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
144 # I loath N^X brute search algorithm's, but whatever, hey |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
145 scene = self._get_scene() |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
146 for (num, col) in enumerate(d): |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
147 rect_list = d[col] |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
148 for thing in scene.things.itervalues(): |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
149 for interact_name in thing.interacts: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
150 thing.set_interact(interact_name) |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
151 if hasattr(thing.rect, 'collidepoint'): |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
152 thing_rects = [thing.rect] |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
153 else: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
154 thing_rects = thing.rect |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
155 for other_rect in thing_rects: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
156 for my_rect in rect_list: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
157 if my_rect.colliderect(other_rect): |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
158 print 'Intersecting rects' |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
159 print " Object %s" % num |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
160 print " Thing %s Interact %s" % (thing.name, interact_name) |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
161 print " Rects", my_rect, other_rect |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
162 if thing.INITIAL: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
163 thing.set_interact(thing.INITIAL) |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
164 print |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
165 for (num2, col2) in enumerate(d): |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
166 if num2 == num: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
167 continue |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
168 other_list = d[col2] |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
169 for my_rect in rect_list: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
170 for other_rect in other_list: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
171 if my_rect.colliderect(other_rect): |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
172 print 'Intersecting rects', |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
173 print ' Object %s and %s' % (num, num2) |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
174 print " Rects", my_rect, other_rect |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
175 print |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
176 print |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
177 |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
178 def toggle_things(self): |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
179 self.draw_things = not self.draw_things |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
180 |
312
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
181 def toggle_thing_rects(self): |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
182 self.draw_thing_rects = not self.draw_thing_rects |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
183 scene = self._get_scene() |
312
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
184 for thing in scene.things.itervalues(): |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
185 if not self.draw_thing_rects: |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
186 if not hasattr(thing, 'old_colour'): |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
187 thing.old_colour = thing._interact_hilight_color |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
188 thing._interact_hilight_color = None |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
189 else: |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
190 thing._interact_hilight_color = thing.old_colour |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
191 |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
192 def toggle_images(self): |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
193 self.draw_images = not self.draw_images |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
194 |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
195 def toggle_trans_images(self): |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
196 self.trans_images = not self.trans_images |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
197 self.invalidate() |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
198 |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
199 def toggle_rects(self): |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
200 self.draw_rects = not self.draw_rects |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
201 |
275
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
202 def toggle_toolbar(self): |
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
203 self.draw_toolbar = not self.draw_toolbar |
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
204 |
506 | 205 def toggle_zoom(self): |
206 self.zoom_display = not self.zoom_display | |
207 | |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
208 def toggle_anim(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
209 self.draw_anim = not self.draw_anim |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
210 |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
211 def draw_mode(self): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
212 self.mode = 'draw' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
213 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
214 def del_mode(self): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
215 self.mode = 'del' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
216 self.start_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
217 self.end_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
218 |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
219 def draw_sub_image(self, image, surface, cropped_rect): |
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
220 """Tweaked image drawing to avoid albow's centring the image in the |
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
221 subsurface""" |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
222 surf = pygame.surface.Surface((cropped_rect.w, cropped_rect.h), SRCALPHA).convert_alpha() |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
223 frame = surf.get_rect() |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
224 imsurf = image.get_image().convert_alpha() |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
225 r = imsurf.get_rect() |
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
226 r.topleft = frame.topleft |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
227 if self.trans_images: |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
228 surf.fill(pygame.color.Color(255, 255, 255, 96)) |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
229 surf.blit(imsurf, r, None, BLEND_RGBA_MIN) |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
230 else: |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
231 surf.blit(imsurf, r, None) |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
232 surface.blit(surf, cropped_rect) |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
233 |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
234 def draw(self, surface): |
506 | 235 if self.zoom_display: |
236 base_surface = surface.copy() | |
237 self.do_unzoomed_draw(base_surface) | |
238 zoomed = pygame.transform.scale(base_surface, (ZOOM * constants.SCREEN[0], ZOOM * constants.SCREEN[1])) | |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
239 area = pygame.rect.Rect(self.zoom_offset[0], self.zoom_offset[1], self.zoom_offset[0] + constants.SCREEN[0], self.zoom_offset[1] + constants.SCREEN[1]) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
240 surface.blit(zoomed, (0, 0), area) |
506 | 241 else: |
242 self.do_unzoomed_draw(surface) | |
243 | |
244 def do_unzoomed_draw(self, surface): | |
238
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
245 if self.state.current_detail: |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
246 if self.draw_things: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
247 self.state.draw_detail(surface, None) |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
248 else: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
249 self.state.current_detail.draw_background(surface) |
238
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
250 else: |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
251 if self.draw_things: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
252 self.state.draw(surface, None) |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
253 else: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
254 self.state.current_scene.draw_background(surface) |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
255 if self.mode == 'draw' and self.start_pos and self.draw_rects: |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
256 rect = pygame.rect.Rect(self.start_pos[0], self.start_pos[1], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
257 self.end_pos[0] - self.start_pos[0], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
258 self.end_pos[1] - self.start_pos[1]) |
321 | 259 rect.normalize() |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
260 frame_rect(surface, self.rect_color, rect, self.draw_thick) |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
261 if self.draw_rects: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
262 for (col, rect) in self.rects: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
263 frame_rect(surface, col, rect, self.rect_thick) |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
264 if self.draw_images: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
265 for image in self.images: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
266 if image.rect.colliderect(surface.get_rect()): |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
267 cropped_rect = image.rect.clip(surface.get_rect()) |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
268 self.draw_sub_image(image, surface, cropped_rect) |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
269 else: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
270 print 'image outside surface', image |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
271 if self.current_image and self.mode == 'image': |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
272 if self.current_image.rect.colliderect(surface.get_rect()): |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
273 cropped_rect = self.current_image.rect.clip(surface.get_rect()) |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
274 self.draw_sub_image(self.current_image, surface, cropped_rect) |
275
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
275 if self.draw_toolbar: |
506 | 276 toolbar_rect = pygame.rect.Rect(0, constants.SCREEN[1] - constants.BUTTON_SIZE, constants.SCREEN[0], constants.BUTTON_SIZE) |
277 tb_surf = surface.subsurface(0, constants.SCREEN[1] - constants.BUTTON_SIZE, constants.SCREEN[0], constants.BUTTON_SIZE).convert_alpha() | |
276
75f4ee46ac58
Better (and fixed) rect tool with toolbar overlay.
Jeremy Thurgood <firxen@gmail.com>
parents:
275
diff
changeset
|
278 tb_surf.fill(pygame.color.Color(127, 0, 0, 191)) |
506 | 279 surface.blit(tb_surf, (0, constants.SCREEN[1] - constants.BUTTON_SIZE)) |
276
75f4ee46ac58
Better (and fixed) rect tool with toolbar overlay.
Jeremy Thurgood <firxen@gmail.com>
parents:
275
diff
changeset
|
280 # frame_rect(surface, (127, 0, 0), toolbar_rect, 2) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
281 |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
282 def _make_dict(self): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
283 d = {} |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
284 for col, rect in self.rects: |
213
20998c650ce1
Fixed rect_drawer tool and adjusted JIM message background.
Jeremy Thurgood <firxen@gmail.com>
parents:
200
diff
changeset
|
285 col = (col.r, col.g, col.b) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
286 d.setdefault(col, []) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
287 d[col].append(rect) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
288 return d |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
289 |
198
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
290 def print_objs(self): |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
291 d = self._make_dict() |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
292 self.find_intersecting_rects(d) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
293 for (num, col) in enumerate(d): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
294 print 'Rect %d : ' % num |
279
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
295 for rect in d[col]: |
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
296 r = rect.move(self.offset) |
179
39f75faf16cb
Add trailing , for copy-n-paste
Neil Muller <neil@dip.sun.ac.za>
parents:
174
diff
changeset
|
297 print ' (%d, %d, %d, %d),' % (r.x, r.y, r.w, r.h) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
298 print |
200 | 299 for i, image in enumerate(self.images): |
300 print 'Image %d' % i | |
279
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
301 rect = image.rect |
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
302 r = rect.move(self.offset) |
200 | 303 print ' (%d, %d, %d, %d),' % (r.x, r.y, r.w, r.h) |
304 print | |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
305 print |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
306 |
199 | 307 def image_load(self): |
308 image_path= '%s/Resources/images/%s' % (script_path, self.state.current_scene.FOLDER) | |
309 imagename = request_old_filename(directory=image_path) | |
310 try: | |
200 | 311 image_data = pygame.image.load(imagename) |
312 self.current_image = Image(image_data) | |
199 | 313 self.place_image_menu.enabled = True |
200 | 314 # ensure we're off screen to start |
506 | 315 self.current_image.rect = image_data.get_rect().move(constants.SCREEN[0] + MENU_WIDTH, constants.SCREEN[1]) |
199 | 316 except pygame.error, e: |
317 print 'Unable to load image %s' % e | |
198
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
318 |
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
319 def image_mode(self): |
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
320 self.mode = 'image' |
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
321 self.start_pos = None |
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
322 self.end_pos = None |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
323 # So we do the right thing for off screen images |
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
324 self.old_mouse_pos = None |
198
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
325 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
326 def cycle_mode(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
327 self.mode = 'cycle' |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
328 |
506 | 329 def _conv_pos(self, mouse_pos): |
330 if self.zoom_display: | |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
331 pos = ((mouse_pos[0] + self.zoom_offset[0]) / ZOOM, (mouse_pos[1] + self.zoom_offset[1]) / ZOOM) |
506 | 332 else: |
333 pos = mouse_pos | |
334 return pos | |
335 | |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
336 def _check_limits(self, offset): |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
337 if offset[0] < 0: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
338 offset[0] = 0 |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
339 if offset[1] < 0: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
340 offset[1] = 0 |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
341 if offset[0] > ZOOM * constants.SCREEN[0] - constants.SCREEN[0]: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
342 offset[0] = ZOOM * constants.SCREEN[0] - constants.SCREEN[0] |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
343 if offset[1] > ZOOM * constants.SCREEN[1] - constants.SCREEN[1]: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
344 offset[1] = ZOOM * constants.SCREEN[1] - constants.SCREEN[1] |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
345 |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
346 def _make_zoom_offset(self, pos): |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
347 zoom_pos = (pos[0] * ZOOM, pos[1] * ZOOM) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
348 offset = [zoom_pos[0] - constants.SCREEN[0] / 2, |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
349 zoom_pos[1] - constants.SCREEN[1] / 2] |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
350 self._check_limits(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
351 self.zoom_offset = tuple(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
352 |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
353 def _move_zoom(self, x, y): |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
354 offset = list(self.zoom_offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
355 offset[0] += ZOOM_STEP * x |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
356 offset[1] += ZOOM_STEP * y |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
357 self._check_limits(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
358 self.zoom_offset = tuple(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
359 |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
360 def do_mouse_move(self, e): |
506 | 361 pos = self._conv_pos(e.pos) |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
362 if not self.zoom_display: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
363 # Construct zoom offset from mouse pos |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
364 self._make_zoom_offset(e.pos) |
200 | 365 if self.mode == 'image' and self.current_image: |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
366 if self.old_mouse_pos: |
506 | 367 delta = (pos[0] - self.old_mouse_pos[0], pos[1] - self.old_mouse_pos[1]) |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
368 self.current_image.rect.center = (self.current_image.rect.center[0] + delta[0], self.current_image.rect.center[1] + delta[1]) |
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
369 else: |
506 | 370 self.current_image.rect.center = pos |
200 | 371 self.invalidate() |
506 | 372 self.old_mouse_pos = pos |
200 | 373 |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
374 def key_down(self, e): |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
375 if self.mode == 'image' and self.current_image: |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
376 # Move the image by 1 pixel |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
377 cur_pos = self.current_image.rect.center |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
378 if e.key == K_LEFT: |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
379 self.current_image.rect.center = (cur_pos[0] - 1, cur_pos[1]) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
380 elif e.key == K_RIGHT: |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
381 self.current_image.rect.center = (cur_pos[0] + 1, cur_pos[1]) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
382 elif e.key == K_UP: |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
383 self.current_image.rect.center = (cur_pos[0], cur_pos[1] - 1) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
384 elif e.key == K_DOWN: |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
385 self.current_image.rect.center = (cur_pos[0], cur_pos[1] + 1) |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
386 elif self.zoom_display: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
387 if e.key == K_LEFT: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
388 self._move_zoom(-1, 0) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
389 elif e.key == K_RIGHT: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
390 self._move_zoom(1, 0) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
391 elif e.key == K_UP: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
392 self._move_zoom(0, -1) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
393 elif e.key == K_DOWN: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
394 self._move_zoom(0, 1) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
395 |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
396 if e.key == K_o: |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
397 self.toggle_trans_images() |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
398 elif e.key == K_t: |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
399 self.toggle_things() |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
400 elif e.key == K_r: |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
401 self.toggle_thing_rects() |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
402 elif e.key == K_i: |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
403 self.toggle_images() |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
404 elif e.key == K_d: |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
405 self.toggle_rects() |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
406 elif e.key == K_b: |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
407 self.toggle_toolbar() |
506 | 408 elif e.key == K_z: |
409 self.toggle_zoom() | |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
410 elif e.key == K_a: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
411 self.toggle_anim() |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
412 |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
413 def mouse_down(self, e): |
506 | 414 pos = self._conv_pos(e.pos) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
415 if self.mode == 'del': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
416 cand = None |
200 | 417 # Images are drawn above rectangles, so search those first |
418 for image in self.images: | |
419 if image.rect.collidepoint(pos): | |
420 cand = image | |
421 break | |
422 if cand: | |
423 self.images.remove(cand) | |
424 self.invalidate() | |
425 return | |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
426 for (col, rect) in self.rects: |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
427 if rect.collidepoint(pos): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
428 cand = (col, rect) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
429 break |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
430 if cand: |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
431 self.rects.remove(cand) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
432 self.invalidate() |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
433 elif self.mode == 'cycle': |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
434 scene = self._get_scene() |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
435 cand = None |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
436 for thing in scene.things.itervalues(): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
437 if thing.contains(pos): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
438 cand = thing |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
439 break |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
440 if cand: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
441 # Find current interacts in this thing |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
442 cur_interact = cand.current_interact |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
443 j = cand.interacts.values().index(cur_interact) |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
444 if j + 1< len(cand.interacts): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
445 next_name = cand.interacts.keys()[j+1] |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
446 else: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
447 next_name = cand.interacts.keys()[0] |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
448 if cand.interacts[next_name] != cur_interact: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
449 cand.set_interact(next_name) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
450 elif self.mode == 'draw': |
506 | 451 self.start_pos = pos |
452 self.end_pos = pos | |
200 | 453 elif self.mode == 'image': |
454 if self.current_image: | |
455 self.images.append(self.current_image) | |
456 self.current_image = None | |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
457 self.old_mouse_pos = None |
200 | 458 self.invalidate() |
459 else: | |
460 cand = None | |
461 for image in self.images: | |
462 if image.rect.collidepoint(e.pos): | |
463 cand = image | |
464 break | |
465 if cand: | |
466 self.images.remove(cand) | |
467 self.current_image = cand | |
502
f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents:
482
diff
changeset
|
468 # We want to move relative to the current mouse pos, so |
506 | 469 self.old_mouse_pos = pos |
200 | 470 self.invalidate() |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
471 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
472 def mouse_up(self, e): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
473 if self.mode == 'draw': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
474 rect = pygame.rect.Rect(self.start_pos[0], self.start_pos[1], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
475 self.end_pos[0] - self.start_pos[0], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
476 self.end_pos[1] - self.start_pos[1]) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
477 rect.normalize() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
478 self.rects.append((self.rect_color, rect)) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
479 self.start_pos = self.end_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
480 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
481 def mouse_drag(self, e): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
482 if self.mode == 'draw': |
506 | 483 self.end_pos = self._conv_pos(e.pos) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
484 self.invalidate() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
485 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
486 def animate(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
487 if self.draw_anim: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
488 if self.state.animate(): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
489 self.invalidate() |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
490 |
509 | 491 |
492 class ModeLabel(BoomLabel): | |
493 | |
494 def __init__(self, app_image): | |
495 self.app_image = app_image | |
496 super(ModeLabel, self).__init__('Mode : ', 200, | |
497 font=get_font(15, 'VeraBd.ttf'), | |
498 fg_color = pygame.color.Color(128, 0, 255)) | |
499 self.rect.move_ip(805, 0) | |
500 | |
501 def draw_all(self, surface): | |
502 self.set_text('Mode : %s' % self.app_image.mode) | |
503 super(ModeLabel, self).draw_all(surface) | |
504 | |
505 | |
197 | 506 def make_button(text, action, ypos): |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
507 button = Button(text, action=action, font=get_font(15, 'VeraBd.ttf')) |
197 | 508 button.align = 'l' |
506 | 509 button.rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) |
197 | 510 button.rect.move_ip(805, ypos) |
511 return button | |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
512 |
509 | 513 |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
514 class RectApp(RootWidget): |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
515 """Handle the app stuff for the rect drawer""" |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
516 |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
517 def __init__(self, display): |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
518 super(RectApp, self).__init__(display) |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
519 self.image = AppImage(state) |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
520 self.add(self.image) |
509 | 521 mode_label = ModeLabel(self.image) |
522 self.add(mode_label) | |
523 y = mode_label.get_rect().h | |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
524 draw = make_button('Draw Rect', self.image.draw_mode, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
525 self.add(draw) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
526 y += draw.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
527 load_image = make_button("Load image", self.image.image_load, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
528 self.add(load_image) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
529 y += load_image.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
530 add_image = make_button("Place/Move images", self.image.image_mode, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
531 add_image.enabled = False |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
532 self.add(add_image) |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
533 self.image.place_image_menu = add_image |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
534 y += add_image.get_rect().h |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
535 cycle = make_button("Cycle interacts", self.image.cycle_mode, y) |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
536 self.add(cycle) |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
537 y += cycle.get_rect().h |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
538 delete = make_button('Delete Objects', self.image.del_mode, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
539 self.add(delete) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
540 y += delete.get_rect().h |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
541 palette = AppPalette(self.image) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
542 palette.rect.move_ip(810, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
543 self.add(palette) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
544 y += palette.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
545 print_rects = make_button("Print objects", self.image.print_objs, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
546 self.add(print_rects) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
547 y += print_rects.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
548 toggle_things = make_button("Show Things (t)", self.image.toggle_things, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
549 self.add(toggle_things) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
550 y += toggle_things.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
551 toggle_thing_rects = make_button("Show Thing Rects (r)", self.image.toggle_thing_rects, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
552 self.add(toggle_thing_rects) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
553 y += toggle_thing_rects.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
554 toggle_images = make_button("Show Images (i)", self.image.toggle_images, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
555 self.add(toggle_images) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
556 y += toggle_images.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
557 trans_images = make_button("Opaque Images (o)", self.image.toggle_trans_images, y) |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
558 self.add(trans_images) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
559 y += trans_images.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
560 toggle_rects = make_button("Show Drawn Rects (d)", self.image.toggle_rects, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
561 self.add(toggle_rects) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
562 y += toggle_rects.get_rect().h |
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
563 toggle_toolbar = make_button("Show Toolbar (b)", self.image.toggle_toolbar, y) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
564 self.add(toggle_toolbar) |
506 | 565 y += toggle_toolbar.get_rect().h |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
566 toggle_anim = make_button("Show Animations (a)", self.image.toggle_anim, y) |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
567 self.add(toggle_anim) |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
568 y += toggle_anim.get_rect().h |
506 | 569 toggle_zoom = make_button("Zoom (z)", self.image.toggle_zoom, y) |
570 self.add(toggle_zoom) | |
571 y += toggle_zoom.get_rect().h | |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
572 quit_but = make_button("Quit", self.quit, 570) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
573 self.add(quit_but) |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
574 self.set_timer(constants.FRAME_RATE) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
575 |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
576 def key_down(self, event): |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
577 # Dispatch to image widget |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
578 self.image.key_down(event) |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
579 |
503
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
580 def mouse_delta(self, event): |
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
581 # We propogate mouse move from here to draw region, so images move |
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
582 # off-screen |
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
583 self.image.do_mouse_move(event) |
65e17aba12c5
Tweak various aspects of image drawing/mouse code to handle edge cases better
Neil Muller <neil@dip.sun.ac.za>
parents:
502
diff
changeset
|
584 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
585 def begin_frame(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
586 self.image.animate() |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
587 |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
588 |
521
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
589 def list_scenes(state): |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
590 """List the scenes in the state""" |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
591 print 'Available scenes are : ' |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
592 for scene in state.scenes: |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
593 print ' ',scene |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
594 print 'Available details are : ' |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
595 for detail in state.detail_views: |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
596 print ' ',detail |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
597 |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
598 if __name__ == "__main__": |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
599 pygame.display.init() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
600 pygame.font.init() |
521
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
601 display = pygame.display.set_mode((constants.SCREEN[0] + MENU_WIDTH, constants.SCREEN[1])) |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
602 state = state.initial_state() |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
603 if len(sys.argv) < 2: |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
604 print 'Please provide a scene name or scene and detail names' |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
605 list_scenes(state) |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
606 sys.exit(0) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
607 # enable key repeating |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
608 pygame.key.set_repeat(200, 100) |
238
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
609 if len(sys.argv) < 3: |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
610 try: |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
611 state.set_current_scene(sys.argv[1]) |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
612 state.do_check = None |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
613 except KeyError: |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
614 print 'Invalid scene name' |
521
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
615 list_scenes(state) |
238
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
616 sys.exit(1) |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
617 else: |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
618 try: |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
619 state.set_current_scene(sys.argv[1]) |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
620 state.set_current_detail(sys.argv[2]) |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
621 state.do_check = None |
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
622 except KeyError: |
521
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
623 print 'Invalid scene or detail name' |
d143947690d9
Add list_scenes to rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
510
diff
changeset
|
624 list_scenes(state) |
238
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
625 sys.exit(1) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
626 app = RectApp(display) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
627 app.run() |