Mercurial > pyntnclick
comparison tools/rect_drawer.py @ 504:f3dbe35b6e4b
Add 'translucent image mode'
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Thu, 02 Sep 2010 11:43:51 +0200 |
parents | 65e17aba12c5 |
children | 4c8aa01b606c |
comparison
equal
deleted
inserted
replaced
503:65e17aba12c5 | 504:f3dbe35b6e4b |
---|---|
12 from albow.widget import Widget | 12 from albow.widget import Widget |
13 from albow.controls import Button, Image | 13 from albow.controls import Button, Image |
14 from albow.palette_view import PaletteView | 14 from albow.palette_view import PaletteView |
15 from albow.file_dialogs import request_old_filename | 15 from albow.file_dialogs import request_old_filename |
16 from albow.resource import get_font | 16 from albow.resource import get_font |
17 from pygame.locals import SWSURFACE, K_LEFT, K_RIGHT, K_UP, K_DOWN | 17 from pygame.locals import SWSURFACE, K_LEFT, K_RIGHT, K_UP, K_DOWN, BLEND_RGBA_MIN, SRCALPHA |
18 import pygame | 18 import pygame |
19 from pygame.colordict import THECOLORS | 19 from pygame.colordict import THECOLORS |
20 | 20 |
21 from gamelib import constants | 21 from gamelib import constants |
22 constants.DEBUG = True | 22 constants.DEBUG = True |
88 self.offset = (-self.state.current_scene.OFFSET[0], - self.state.current_scene.OFFSET[1]) | 88 self.offset = (-self.state.current_scene.OFFSET[0], - self.state.current_scene.OFFSET[1]) |
89 self.draw_rects = True | 89 self.draw_rects = True |
90 self.draw_things = True | 90 self.draw_things = True |
91 self.draw_thing_rects = True | 91 self.draw_thing_rects = True |
92 self.draw_images = True | 92 self.draw_images = True |
93 self.trans_images = False | |
93 self.draw_toolbar = True | 94 self.draw_toolbar = True |
94 self.old_mouse_pos = None | 95 self.old_mouse_pos = None |
95 self.find_existing_intersects() | 96 self.find_existing_intersects() |
96 | 97 |
97 def find_existing_intersects(self): | 98 def find_existing_intersects(self): |
183 thing._interact_hilight_color = thing.old_colour | 184 thing._interact_hilight_color = thing.old_colour |
184 | 185 |
185 def toggle_images(self): | 186 def toggle_images(self): |
186 self.draw_images = not self.draw_images | 187 self.draw_images = not self.draw_images |
187 | 188 |
189 def toggle_trans_images(self): | |
190 self.trans_images = not self.trans_images | |
191 self.invalidate() | |
192 | |
188 def toggle_rects(self): | 193 def toggle_rects(self): |
189 self.draw_rects = not self.draw_rects | 194 self.draw_rects = not self.draw_rects |
190 | 195 |
191 def toggle_toolbar(self): | 196 def toggle_toolbar(self): |
192 self.draw_toolbar = not self.draw_toolbar | 197 self.draw_toolbar = not self.draw_toolbar |
200 self.end_pos = None | 205 self.end_pos = None |
201 | 206 |
202 def draw_sub_image(self, image, surface, cropped_rect): | 207 def draw_sub_image(self, image, surface, cropped_rect): |
203 """Tweaked image drawing to avoid albow's centring the image in the | 208 """Tweaked image drawing to avoid albow's centring the image in the |
204 subsurface""" | 209 subsurface""" |
205 surf = surface.subsurface(cropped_rect) | 210 surf = pygame.surface.Surface((cropped_rect.w, cropped_rect.h), SRCALPHA).convert_alpha() |
206 frame = surf.get_rect() | 211 frame = surf.get_rect() |
207 imsurf = image.get_image() | 212 imsurf = image.get_image().convert_alpha() |
208 r = imsurf.get_rect() | 213 r = imsurf.get_rect() |
209 r.topleft = frame.topleft | 214 r.topleft = frame.topleft |
210 surf.blit(imsurf, r) | 215 if self.trans_images: |
216 surf.fill(pygame.color.Color(255, 255, 255, 96)) | |
217 surf.blit(imsurf, r, None, BLEND_RGBA_MIN) | |
218 else: | |
219 surf.blit(imsurf, r, None) | |
220 surface.blit(surf, cropped_rect) | |
211 | 221 |
212 def draw(self, surface): | 222 def draw(self, surface): |
213 if self.state.current_detail: | 223 if self.state.current_detail: |
214 if self.draw_things: | 224 if self.draw_things: |
215 self.state.draw_detail(surface, None) | 225 self.state.draw_detail(surface, None) |
403 self.add(toggle_things) | 413 self.add(toggle_things) |
404 toggle_thing_rects = make_button("Toggle Thing Rects", self.image.toggle_thing_rects, 370) | 414 toggle_thing_rects = make_button("Toggle Thing Rects", self.image.toggle_thing_rects, 370) |
405 self.add(toggle_thing_rects) | 415 self.add(toggle_thing_rects) |
406 toggle_images = make_button("Toggle Images", self.image.toggle_images, 405) | 416 toggle_images = make_button("Toggle Images", self.image.toggle_images, 405) |
407 self.add(toggle_images) | 417 self.add(toggle_images) |
408 toggle_rects = make_button("Toggle Rects", self.image.toggle_rects, 440) | 418 trans_images = make_button("Translucent Images", self.image.toggle_trans_images, 440) |
419 self.add(trans_images) | |
420 toggle_rects = make_button("Toggle Drawn Rects", self.image.toggle_rects, 475) | |
409 self.add(toggle_rects) | 421 self.add(toggle_rects) |
410 toggle_toolbar = make_button("Toggle Toolbar", self.image.toggle_toolbar, 475) | 422 toggle_toolbar = make_button("Toggle Toolbar", self.image.toggle_toolbar, 510) |
411 self.add(toggle_toolbar) | 423 self.add(toggle_toolbar) |
412 quit_but = make_button("Quit", self.quit, 565) | 424 quit_but = make_button("Quit", self.quit, 565) |
413 self.add(quit_but) | 425 self.add(quit_but) |
414 | 426 |
415 def key_down(self, event): | 427 def key_down(self, event): |