Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/movableobject.py
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2009-04-06 11:23:08 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2009-04-06 11:23:08 (GMT)
commit06a8fac4cb75a5d047a6002045a73b19c8e755e0 (patch)
tree4a855575ca35332c4e34a0a25d3ea5d49881b795 /movableobject.py
parentaba7e1f7a4964132bd27c53cbd84ffd28d10245b (diff)
Tidy up grid code a bit.
Diffstat (limited to 'movableobject.py')
-rw-r--r--movableobject.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/movableobject.py b/movableobject.py
index 40fc9b7..76bba15 100644
--- a/movableobject.py
+++ b/movableobject.py
@@ -19,21 +19,9 @@ from vector import Vector
import gtk, math
-# The global grid unit size, in pixels. Objects will snap to multiples of this value.
-#GRID_SIZE = 50
-
-# Width and height of region within which we can drag objects.
-#DRAGGING_RECT_WIDTH = 24*GRID_SIZE
-#DRAGGING_RECT_HEIGHT = 16*GRID_SIZE
-
-# The global grid angle size, in radians.
-#RADIAL_GRID_SIZE = math.pi/4
-
class MovableObject(Object):
"""
Extends Objects with the ability to move.
- Derived classes must implement:
- get_bounds() - Returns min, max bounds of the Object.
"""
def __init__(self):
Object.__init__(self)
@@ -218,13 +206,12 @@ class MovableObject(Object):
self.container.select_object(self)
def on_key(self, event):
- GRID_SIZE = 50
if self.container:
GRID_SIZE = self.container.GRID_SIZE
-
- RADIAL_GRID_SIZE = math.pi/4
- if self.container:
RADIAL_GRID_SIZE = self.container.RADIAL_GRID_SIZE
+ else:
+ GRID_SIZE = 50
+ RADIAL_GRID_SIZE = math.pi/4
if not self.selectable or not self.draggable:
return
@@ -255,3 +242,13 @@ class MovableObject(Object):
self.drop_origin.remove_object(self)
return
+ # Default implementation which may be overridden by derived objects.
+ def is_in_container(self):
+ if not self.container:
+ return False
+
+ mn, mx = self.get_bounds()
+ if mn.x < -2 or mx.x > self.container.DRAGGING_RECT_WIDTH + 2 or \
+ mn.y < -1 or mx.y > self.container.DRAGGING_RECT_HEIGHT:
+ return False
+ return True