changeset 690:4a933444c99b pyntnclick

The return of the rects to the rect drawer
author Neil Muller <neil@dip.sun.ac.za>
date Tue, 14 Feb 2012 12:24:33 +0200
parents 929b63589c96
children 60bf20849231
files pyntnclick/tools/rect_drawer.py pyntnclick/tools/utils.py
diffstat 2 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/tools/rect_drawer.py	Mon Feb 13 18:24:08 2012 +0200
+++ b/pyntnclick/tools/rect_drawer.py	Tue Feb 14 12:24:33 2012 +0200
@@ -1,9 +1,6 @@
 # Quickly hacked together helper for working out
 # interactive regions in Suspended Sentence
 
-def frame_rect(*args):
-    pass
-
 Image = object
 request_old_filename = None
 
@@ -17,6 +14,7 @@
 import pyntnclick.constants
 from pyntnclick.widgets.text import LabelWidget, TextButton
 from pyntnclick.widgets.base import Container
+from pyntnclick.tools.utils import draw_rect_image
 
 
 class RectDrawerConstants(pyntnclick.constants.GameConstants):
@@ -103,7 +101,7 @@
                            -self.state.current_scene.OFFSET[1])
         self.find_existing_intersects()
         self.add_callback(MOUSEBUTTONDOWN, self.mouse_down)
-        self.add_callback(MOUSEBUTTONUP, self.mouse_down)
+        self.add_callback(MOUSEBUTTONUP, self.mouse_up)
         self.add_callback(MOUSEMOTION, self.mouse_move)
 
     def _get_scene(self):
@@ -277,10 +275,10 @@
                     self.end_pos[0] - self.start_pos[0],
                     self.end_pos[1] - self.start_pos[1])
             rect.normalize()
-            frame_rect(surface, self.rect_color, rect, self.draw_thick)
+            draw_rect_image(surface, self.rect_color, rect, self.draw_thick)
         if self.draw_rects:
             for (col, rect) in self.rects:
-                frame_rect(surface, col, rect, self.rect_thick)
+                draw_rect_image(surface, col, rect, self.rect_thick)
         if self.draw_images:
             for image in self.images:
                 if image.rect.colliderect(surface.get_rect()):
--- a/pyntnclick/tools/utils.py	Mon Feb 13 18:24:08 2012 +0200
+++ b/pyntnclick/tools/utils.py	Tue Feb 14 12:24:33 2012 +0200
@@ -10,3 +10,17 @@
     print 'Available details are : '
     for detail in state.detail_views:
         print '    ', detail
+
+def draw_rect_image(surface, color, rect, thickness):
+    """Draw a rectangle with lines thickness wide"""
+    # top
+    surface.fill(color, (rect.left, rect.top, rect.width, thickness))
+    # bottom
+    surface.fill(color, (rect.left, rect.bottom - thickness, rect.width,
+        thickness))
+    # left
+    surface.fill(color, (rect.left, rect.top, thickness, rect.height))
+    # right
+    surface.fill(color, (rect.right - thickness, rect.top, thickness,
+        rect.height))
+