Mercurial > boomslang
annotate pyntnclick/tools/rect_drawer.py @ 673:f67bc162d69e pyntnclick
Working resume button
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 12 Feb 2012 18:44:41 +0200 |
parents | b27b5c6c54e8 |
children | 32e554adf538 |
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 |
636
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
4 # XXX: Threw away albow |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
5 #from albow.utils import frame_rect |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
6 #from albow.widget import Widget |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
7 #from albow.controls import Button, Image |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
8 #from albow.palette_view import PaletteView |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
9 #from albow.file_dialogs import request_old_filename |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
10 #from albow.resource import get_font |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
11 frame_rect = None |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
12 Button = object |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
13 Image = object |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
14 request_old_filename = None |
2748d3afcae5
Excise albow. Really.
Stefano Rivera <stefano@rivera.za.net>
parents:
589
diff
changeset
|
15 get_font = None |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
16 |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
17 from pygame.locals import (K_LEFT, K_RIGHT, K_UP, K_DOWN, |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
18 K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z, |
648
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
19 BLEND_RGBA_MIN, SRCALPHA, QUIT) |
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 |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
22 import pyntnclick.constants |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
23 from pyntnclick.widgets.text import LabelWidget, TextButton |
648
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
24 from pyntnclick.widgets.base import Container |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
25 |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
26 |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
27 class RectDrawerConstants(pyntnclick.constants.GameConstants): |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
28 debug = True |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
29 menu_width = 200 |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
30 menu_button_height = 25 |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
31 zoom = 4 |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
32 zoom_step = 100 |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
33 |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
34 constants = RectDrawerConstants() |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
35 |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
36 |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
37 class AppPalette(object): |
165
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 sel_width = 5 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
40 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
41 colors = [ |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
42 '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
|
43 '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
|
44 '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
|
45 '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
|
46 ] |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
47 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
48 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
|
49 self.image = app_image |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
50 #super(AppPalette, self).__init__((35, 35), 4, 5, margin=2) |
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
51 #self.selection = 0 |
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
52 #self.image.rect_color = pygame.color.Color(self.colors[self.selection]) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
53 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
54 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
|
55 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
|
56 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 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
|
61 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
66 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
|
67 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
|
68 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
69 |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
70 class AppImage(Container): |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
71 |
181
f98bc17f5e67
Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents:
179
diff
changeset
|
72 rect_thick = 3 |
f98bc17f5e67
Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents:
179
diff
changeset
|
73 draw_thick = 1 |
f98bc17f5e67
Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents:
179
diff
changeset
|
74 |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
75 def __init__(self, gd, state): |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
76 self.state = state |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
77 super(AppImage, self).__init__(pygame.rect.Rect(0, 0, |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
78 constants.screen[0], constants.screen[1]), gd) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
79 self.mode = 'draw' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
80 self.rects = [] |
200 | 81 self.images = [] |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
82 self.start_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
83 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
|
84 self.rect_color = pygame.color.Color('white') |
200 | 85 self.current_image = None |
199 | 86 self.place_image_menu = None |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
87 self.close_button = LabelWidget(pygame.Rect((0, 0), (200, 100)), |
671
b27b5c6c54e8
Use constants for font location
Stefano Rivera <stefano@rivera.za.net>
parents:
664
diff
changeset
|
88 gd, 'Close', fontname=constants.bold_font, fontsize=20) |
243
0ea4661d134c
Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents:
238
diff
changeset
|
89 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
|
90 self.close_button.bg_color = (0, 0, 0) |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
91 self.draw_rects = True |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
92 self.draw_things = True |
312
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
93 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
|
94 self.draw_images = True |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
95 self.trans_images = False |
275
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
96 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
|
97 self.old_mouse_pos = None |
506 | 98 self.zoom_display = False |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
99 self.draw_anim = False |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
100 self.zoom_offset = (600, 600) |
524
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
101 if self.state.current_detail: |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
102 w, h = self.state.current_detail.get_detail_size() |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
103 rect = pygame.rect.Rect(0, 0, w, h) |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
104 self.close_button.rect.midbottom = rect.midbottom |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
105 self.offset = (0, 0) |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
106 else: |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
107 self.offset = (-self.state.current_scene.OFFSET[0], |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
108 -self.state.current_scene.OFFSET[1]) |
323
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
109 self.find_existing_intersects() |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
110 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
111 def _get_scene(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
112 if self.state.current_detail: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
113 return self.state.current_detail |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
114 else: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
115 return self.state.current_scene |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
116 |
323
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
117 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
|
118 """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
|
119 scene = self._get_scene() |
323
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
120 # Pylint hates this function |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
121 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
|
122 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
|
123 thing.set_interact(interact_name) |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
124 if hasattr(thing.rect, 'collidepoint'): |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
125 thing_rects = [thing.rect] |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
126 else: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
127 thing_rects = thing.rect |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
128 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
|
129 if thing is thing2: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
130 continue |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
131 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
|
132 thing2.set_interact(interact2_name) |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
133 if hasattr(thing2.rect, 'collidepoint'): |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
134 thing2_rects = [thing2.rect] |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
135 else: |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
136 thing2_rects = thing2.rect |
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 print 'Existing Intersecting rects' |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
141 print (" Thing1 %s Interact %s" |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
142 % (thing.name, interact_name)) |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
143 print (" Thing2 %s Interact %s" |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
144 % (thing2.name, interact2_name)) |
323
0630a37cb371
Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents:
321
diff
changeset
|
145 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
|
146 print |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
147 |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
148 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
|
149 """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
|
150 # 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 else: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 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
|
164 print 'Intersecting rects' |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
165 print " Object %s" % num |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
166 print (" Thing %s Interact %s" |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
167 % (thing.name, interact_name)) |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
168 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
|
169 if thing.INITIAL: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
170 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
|
171 print |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
172 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
|
173 if num2 == num: |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
174 continue |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 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
|
179 print 'Intersecting rects', |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
180 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
|
181 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
|
182 print |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
183 print |
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
184 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
185 def toggle_things(self, ev, widget): |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
186 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
|
187 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
188 def toggle_thing_rects(self, ev, widget): |
312
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
189 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
|
190 scene = self._get_scene() |
312
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
191 for thing in scene.things.itervalues(): |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
192 if not self.draw_thing_rects: |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
193 if not hasattr(thing, 'old_colour'): |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
194 thing.old_colour = thing._interact_hilight_color |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
195 thing._interact_hilight_color = None |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
196 else: |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
197 thing._interact_hilight_color = thing.old_colour |
a0d66c0f5a89
Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents:
286
diff
changeset
|
198 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
199 def toggle_images(self, ev, widget): |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
200 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
|
201 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
202 def toggle_trans_images(self, ev, widget): |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
203 self.trans_images = not self.trans_images |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
204 self.invalidate() |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
205 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
206 def toggle_rects(self, ev, widget): |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
207 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
|
208 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
209 def toggle_toolbar(self, ev, widget): |
275
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
210 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
|
211 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
212 def toggle_zoom(self, ev, widget): |
506 | 213 self.zoom_display = not self.zoom_display |
214 | |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
215 def toggle_anim(self, ev, widget): |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
216 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
|
217 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
218 def draw_mode(self, ev, widget): |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
219 self.mode = 'draw' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
220 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
221 def del_mode(self, ev, widget): |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
222 self.mode = 'del' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
223 self.start_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
224 self.end_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
225 |
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
|
226 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
|
227 """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
|
228 subsurface""" |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
229 surf = pygame.surface.Surface((cropped_rect.w, cropped_rect.h), |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
230 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
|
231 frame = surf.get_rect() |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
232 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
|
233 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
|
234 r.topleft = frame.topleft |
504
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
235 if self.trans_images: |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
236 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
|
237 surf.blit(imsurf, r, None, BLEND_RGBA_MIN) |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
238 else: |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
239 surf.blit(imsurf, r, None) |
f3dbe35b6e4b
Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents:
503
diff
changeset
|
240 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
|
241 |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
242 def draw(self, surface): |
506 | 243 if self.zoom_display: |
244 base_surface = surface.copy() | |
245 self.do_unzoomed_draw(base_surface) | |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
246 zoomed = pygame.transform.scale(base_surface, |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
247 (constants.zoom * constants.screen[0], |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
248 constants.zoom * constants.screen[1])) |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
249 area = pygame.rect.Rect(self.zoom_offset[0], self.zoom_offset[1], |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
250 self.zoom_offset[0] + constants.screen[0], |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
251 self.zoom_offset[1] + constants.screen[1]) |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
252 surface.blit(zoomed, (0, 0), area) |
506 | 253 else: |
254 self.do_unzoomed_draw(surface) | |
255 | |
256 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
|
257 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
|
258 if self.draw_things: |
523
08dbb7f3a34d
Fix calls to draw to match recent changes
Neil Muller <neil@dip.sun.ac.za>
parents:
521
diff
changeset
|
259 self.state.current_detail.draw(surface, None) |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
260 else: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
261 self.state.current_detail.draw_background(surface) |
524
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
262 # We duplicate Albow's draw logic here, so we zoom the close |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
263 # button correctly |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
264 r = self.close_button.get_rect() |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
265 surf_rect = surface.get_rect() |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
266 sub_rect = surf_rect.clip(r) |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
267 try: |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
268 sub = surface.subsurface(sub_rect) |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
269 self.close_button.draw_all(sub) |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
270 except ValueError, e: |
a91cb4bffd5d
Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents:
523
diff
changeset
|
271 print 'Error, failed to draw close button', e |
238
2510e0b0e901
Add detail view support to helper
Neil Muller <neil@dip.sun.ac.za>
parents:
213
diff
changeset
|
272 else: |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
273 if self.draw_things: |
523
08dbb7f3a34d
Fix calls to draw to match recent changes
Neil Muller <neil@dip.sun.ac.za>
parents:
521
diff
changeset
|
274 self.state.current_scene.draw(surface, None) |
268
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
275 else: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 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
|
280 self.end_pos[1] - self.start_pos[1]) |
321 | 281 rect.normalize() |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
282 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
|
283 if self.draw_rects: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
284 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
|
285 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
|
286 if self.draw_images: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
287 for image in self.images: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 else: |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
292 print 'image outside surface', image |
e4ea9def56b2
Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents:
250
diff
changeset
|
293 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
|
294 if self.current_image.rect.colliderect(surface.get_rect()): |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
295 cropped_rect = self.current_image.rect.clip( |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
296 surface.get_rect()) |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
297 self.draw_sub_image(self.current_image, surface, |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
298 cropped_rect) |
275
d78ce15bccc8
Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
299 if self.draw_toolbar: |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
300 tb_surf = surface.subsurface(0, constants.screen[1] |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
301 - constants.button_size, |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
302 constants.screen[0], |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
303 constants.button_size).convert_alpha() |
276
75f4ee46ac58
Better (and fixed) rect tool with toolbar overlay.
Jeremy Thurgood <firxen@gmail.com>
parents:
275
diff
changeset
|
304 tb_surf.fill(pygame.color.Color(127, 0, 0, 191)) |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
305 surface.blit(tb_surf, (0, constants.screen[1] |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
306 - constants.button_size)) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
307 |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
308 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
|
309 d = {} |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
310 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
|
311 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
|
312 d.setdefault(col, []) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
313 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
|
314 return d |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
315 |
198
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 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
|
320 print 'Rect %d : ' % num |
279
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
321 for rect in d[col]: |
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
322 r = rect.move(self.offset) |
179
39f75faf16cb
Add trailing , for copy-n-paste
Neil Muller <neil@dip.sun.ac.za>
parents:
174
diff
changeset
|
323 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
|
324 print |
200 | 325 for i, image in enumerate(self.images): |
326 print 'Image %d' % i | |
279
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
327 rect = image.rect |
c67a4a4d78f6
Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents:
276
diff
changeset
|
328 r = rect.move(self.offset) |
200 | 329 print ' (%d, %d, %d, %d),' % (r.x, r.y, r.w, r.h) |
330 print | |
320
c295b06b27f8
Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents:
312
diff
changeset
|
331 print |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
332 |
199 | 333 def image_load(self): |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
334 image_path = ('%s/Resources/images/%s' |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
335 % (script_path, self.state.current_scene.FOLDER)) |
199 | 336 imagename = request_old_filename(directory=image_path) |
337 try: | |
200 | 338 image_data = pygame.image.load(imagename) |
339 self.current_image = Image(image_data) | |
199 | 340 self.place_image_menu.enabled = True |
200 | 341 # ensure we're off screen to start |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
342 self.current_image.rect = image_data.get_rect() \ |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
343 .move(constants.screen[0] + constants.menu_width, |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
344 constants.screen[1]) |
199 | 345 except pygame.error, e: |
346 print 'Unable to load image %s' % e | |
198
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
347 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
348 def image_mode(self, ev, widget): |
198
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
349 self.mode = 'image' |
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
350 self.start_pos = None |
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
351 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
|
352 # 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
|
353 self.old_mouse_pos = None |
198
e73d78d6dd83
Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents:
197
diff
changeset
|
354 |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
355 def cycle_mode(self, ev, widget): |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
356 self.mode = 'cycle' |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
357 |
506 | 358 def _conv_pos(self, mouse_pos): |
359 if self.zoom_display: | |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
360 pos = ((mouse_pos[0] + self.zoom_offset[0]) / constants.zoom, |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
361 (mouse_pos[1] + self.zoom_offset[1]) / constants.zoom) |
506 | 362 else: |
363 pos = mouse_pos | |
364 return pos | |
365 | |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
366 def _check_limits(self, offset): |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
367 if offset[0] < 0: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
368 offset[0] = 0 |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
369 if offset[1] < 0: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
370 offset[1] = 0 |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
371 width, height = constants.screen |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
372 if offset[0] > constants.zoom * width - width: |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
373 offset[0] = constants.zoom * width - width |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
374 if offset[1] > constants.zoom * height - height: |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
375 offset[1] = constants.zoom * height - height |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
376 |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
377 def _make_zoom_offset(self, pos): |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
378 zoom_pos = (pos[0] * constants.zoom, pos[1] * constants.zoom) |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
379 offset = [zoom_pos[0] - constants.screen[0] / 2, |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
380 zoom_pos[1] - constants.screen[1] / 2] |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
381 self._check_limits(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
382 self.zoom_offset = tuple(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
383 |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
384 def _move_zoom(self, x, y): |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
385 offset = list(self.zoom_offset) |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
386 offset[0] += constants.zoom_step * x |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
387 offset[1] += constants.zoom_step * y |
507
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
388 self._check_limits(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
389 self.zoom_offset = tuple(offset) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
390 |
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
|
391 def do_mouse_move(self, e): |
506 | 392 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
|
393 if not self.zoom_display: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
394 # Construct zoom offset from mouse pos |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
395 self._make_zoom_offset(e.pos) |
200 | 396 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
|
397 if self.old_mouse_pos: |
537
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
398 delta = (pos[0] - self.old_mouse_pos[0], |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
399 pos[1] - self.old_mouse_pos[1]) |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
400 self.current_image.rect.center = ( |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
401 self.current_image.rect.center[0] + delta[0], |
5b9f371c2bb8
PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents:
524
diff
changeset
|
402 self.current_image.rect.center[1] + delta[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
|
403 else: |
506 | 404 self.current_image.rect.center = pos |
200 | 405 self.invalidate() |
506 | 406 self.old_mouse_pos = pos |
200 | 407 |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
408 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
|
409 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
|
410 # 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
|
411 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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 elif self.zoom_display: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
421 if e.key == K_LEFT: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
422 self._move_zoom(-1, 0) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
423 elif e.key == K_RIGHT: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
424 self._move_zoom(1, 0) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
425 elif e.key == K_UP: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
426 self._move_zoom(0, -1) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
427 elif e.key == K_DOWN: |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
428 self._move_zoom(0, 1) |
caec319a4ae3
Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents:
506
diff
changeset
|
429 |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
430 if e.key == K_o: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
431 self.toggle_trans_images(None, None) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
432 elif e.key == K_t: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
433 self.toggle_things(None, None) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
434 elif e.key == K_r: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
435 self.toggle_thing_rects(None, None) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
436 elif e.key == K_i: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
437 self.toggle_images(None, None) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
438 elif e.key == K_d: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
439 self.toggle_rects(None, None) |
505
4c8aa01b606c
Tweak menu layout. Add keys for toggle options
Neil Muller <neil@dip.sun.ac.za>
parents:
504
diff
changeset
|
440 elif e.key == K_b: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
441 self.toggle_toolbar(None, None) |
506 | 442 elif e.key == K_z: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
443 self.toggle_zoom(None, None) |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
444 elif e.key == K_a: |
664
d1c1253fcd77
Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
663
diff
changeset
|
445 self.toggle_anim(None, None) |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
446 |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
447 def mouse_down(self, e): |
506 | 448 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
|
449 if self.mode == 'del': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
450 cand = None |
200 | 451 # Images are drawn above rectangles, so search those first |
452 for image in self.images: | |
453 if image.rect.collidepoint(pos): | |
454 cand = image | |
455 break | |
456 if cand: | |
457 self.images.remove(cand) | |
458 self.invalidate() | |
459 return | |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
460 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
|
461 if rect.collidepoint(pos): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
462 cand = (col, rect) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
463 break |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
464 if cand: |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
465 self.rects.remove(cand) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
466 self.invalidate() |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
467 elif self.mode == 'cycle': |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
468 scene = self._get_scene() |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
469 cand = None |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
470 for thing in scene.things.itervalues(): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
471 if thing.contains(pos): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
472 cand = thing |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
473 break |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
474 if cand: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
475 # Find current interacts in this thing |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
476 cur_interact = cand.current_interact |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
477 j = cand.interacts.values().index(cur_interact) |
538 | 478 if j + 1 < len(cand.interacts): |
479 next_name = cand.interacts.keys()[j + 1] | |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
480 else: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
481 next_name = cand.interacts.keys()[0] |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
482 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
|
483 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
|
484 elif self.mode == 'draw': |
506 | 485 self.start_pos = pos |
486 self.end_pos = pos | |
200 | 487 elif self.mode == 'image': |
488 if self.current_image: | |
489 self.images.append(self.current_image) | |
490 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
|
491 self.old_mouse_pos = None |
200 | 492 self.invalidate() |
493 else: | |
494 cand = None | |
495 for image in self.images: | |
496 if image.rect.collidepoint(e.pos): | |
497 cand = image | |
498 break | |
499 if cand: | |
500 self.images.remove(cand) | |
501 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
|
502 # We want to move relative to the current mouse pos, so |
506 | 503 self.old_mouse_pos = pos |
200 | 504 self.invalidate() |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
505 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
506 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
|
507 if self.mode == 'draw': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 rect.normalize() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
512 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
|
513 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
|
514 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
515 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
|
516 if self.mode == 'draw': |
506 | 517 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
|
518 self.invalidate() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
519 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
520 def animate(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
521 if self.draw_anim: |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
522 if self.state.animate(): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
523 self.invalidate() |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
524 |
509 | 525 |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
526 class ModeLabel(LabelWidget): |
509 | 527 |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
528 def __init__(self, rect, gd, app_image): |
509 | 529 self.app_image = app_image |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
530 super(ModeLabel, self).__init__(rect, |
671
b27b5c6c54e8
Use constants for font location
Stefano Rivera <stefano@rivera.za.net>
parents:
664
diff
changeset
|
531 gd, 'Mode : ', fontname=constants.bold_font, |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
532 fontsize=15, color=pygame.color.Color(128, 0, 255)) |
509 | 533 |
534 def draw_all(self, surface): | |
535 self.set_text('Mode : %s' % self.app_image.mode) | |
536 super(ModeLabel, self).draw_all(surface) | |
537 | |
538 | |
663
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
539 def make_button(text, gd, action, ypos): |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
540 rect = pygame.rect.Rect(0, 0, constants.menu_width, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
541 constants.menu_button_height) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
542 rect.move_ip(805, ypos) |
671
b27b5c6c54e8
Use constants for font location
Stefano Rivera <stefano@rivera.za.net>
parents:
664
diff
changeset
|
543 button = TextButton(rect, gd, text, fontname=constants.font, fontsize=12, |
663
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
544 color=pygame.color.Color(255, 255, 0), border=1, padding=3) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
545 button.add_callback('clicked', action) |
197 | 546 return button |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
547 |
509 | 548 |
648
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
549 class RectApp(Container): |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
550 """The actual rect drawer main app""" |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
551 def __init__(self, rect, gd): |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
552 super(RectApp, self).__init__(rect, gd) |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
553 |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
554 state = gd.initial_state() |
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
555 |
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
556 self.image = AppImage(gd, state) |
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
557 self.add(self.image) |
663
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
558 mode_label = ModeLabel(pygame.Rect((805, 0), (200, 25)), |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
559 self.gd, self.image) |
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
560 self.add(mode_label) |
663
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
561 y = mode_label.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
562 draw = make_button('Draw Rect', gd, self.image.draw_mode, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
563 self.add(draw) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
564 y += draw.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
565 load_image = make_button("Load image", gd, self.image.image_load, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
566 self.add(load_image) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
567 y += load_image.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
568 add_image = make_button("Place/Move images", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
569 self.image.image_mode, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
570 add_image.enabled = False |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
571 self.add(add_image) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
572 self.image.place_image_menu = add_image |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
573 y += add_image.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
574 cycle = make_button("Cycle interacts", gd, self.image.cycle_mode, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
575 self.add(cycle) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
576 y += cycle.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
577 delete = make_button("Delete Objects", gd, self.image.del_mode, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
578 self.add(delete) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
579 y += delete.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
580 #palette = AppPalette(self.image) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
581 #palette.rect.move_ip(810, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
582 #self.add(palette) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
583 #y += palette.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
584 print_rects = make_button("Print objects", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
585 self.image.print_objs, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
586 self.add(print_rects) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
587 y += print_rects.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
588 toggle_things = make_button("Show Things (t)", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
589 self.image.toggle_things, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
590 self.add(toggle_things) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
591 y += toggle_things.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
592 toggle_thing_rects = make_button("Show Thing Rects (r)", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
593 self.image.toggle_thing_rects, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
594 self.add(toggle_thing_rects) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
595 y += toggle_thing_rects.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
596 toggle_images = make_button("Show Images (i)", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
597 self.image.toggle_images, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
598 self.add(toggle_images) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
599 y += toggle_images.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
600 trans_images = make_button("Opaque Images (o)", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
601 self.image.toggle_trans_images, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
602 self.add(trans_images) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
603 y += trans_images.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
604 toggle_rects = make_button("Show Drawn Rects (d)", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
605 self.image.toggle_rects, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
606 self.add(toggle_rects) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
607 y += toggle_rects.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
608 toggle_toolbar = make_button("Show Toolbar (b)", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
609 self.image.toggle_toolbar, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
610 self.add(toggle_toolbar) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
611 y += toggle_toolbar.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
612 toggle_anim = make_button("Show Animations (a)", gd, |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
613 self.image.toggle_anim, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
614 self.add(toggle_anim) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
615 y += toggle_anim.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
616 toggle_zoom = make_button("Zoom (z)", gd, self.image.toggle_zoom, y) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
617 self.add(toggle_zoom) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
618 y += toggle_zoom.rect.height |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
619 quit_but = make_button("Quit", gd, self.quit, 570) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
620 self.add(quit_but) |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
621 |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
622 def quit(self, ev, widget): |
b67fdd4a152d
Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents:
662
diff
changeset
|
623 pygame.event.post(pygame.event.Event(QUIT)) |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
624 |
648
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
625 |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
626 class RectEngine(object): |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
627 """Engine for the rect drawer.""" |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
628 |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
629 def __init__(self, gd, get_initial_state, scene, detail): |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
630 self.state = None |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
631 self._gd = gd |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
632 rect = pygame.display.get_surface().get_rect() |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
633 self.app = RectApp(rect, self._gd) |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
634 |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
635 def run(self): |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
636 """App loop""" |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
637 clock = pygame.time.Clock() |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
638 while True: |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
639 events = pygame.event.get() |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
640 for ev in events: |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
641 if ev.type == QUIT: |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
642 return |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
643 else: |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
644 self.app.event(ev) |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
645 surface = pygame.display.get_surface() |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
646 self.app.draw(surface) |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
647 pygame.display.flip() |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
648 clock.tick(self._gd.constants.frame_rate) |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
649 |
b2c2b6f56291
baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents:
636
diff
changeset
|
650 |
662
6daaeffb37d1
The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents:
661
diff
changeset
|
651 class RectAppOld(object): |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
652 """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
|
653 |
589
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
654 def __init__(self, display, get_initial_state, scene, detail): |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
655 super(RectApp, self).__init__(display) |
589
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
656 pygame.key.set_repeat(200, 100) |
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
657 state = get_initial_state() |
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
658 state.set_current_scene(scene) |
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
659 state.set_current_detail(detail) |
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
660 state.do_check = None |
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
661 |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
550
diff
changeset
|
662 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
|
663 |
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
664 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
|
665 # 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
|
666 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
|
667 |
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
|
668 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
|
669 # 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
|
670 # 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
|
671 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
|
672 |
510
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
673 def begin_frame(self): |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
674 self.image.animate() |
d274cc414178
Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents:
509
diff
changeset
|
675 |
482
2bef605a0ef2
Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents:
323
diff
changeset
|
676 |
589
ebc48b397fd5
Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents:
576
diff
changeset
|
677 def make_rect_display(): |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
678 pygame.display.init() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
679 pygame.font.init() |
661
5dc866e1d71d
Misc pep8 and pyflakes fixes
Neil Muller <neil@dip.sun.ac.za>
parents:
648
diff
changeset
|
680 pygame.display.set_mode((constants.screen[0] |
5dc866e1d71d
Misc pep8 and pyflakes fixes
Neil Muller <neil@dip.sun.ac.za>
parents:
648
diff
changeset
|
681 + constants.menu_width, constants.screen[1])) |