Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/objectarea.py
diff options
context:
space:
mode:
Diffstat (limited to 'objectarea.py')
-rw-r--r--objectarea.py56
1 files changed, 55 insertions, 1 deletions
diff --git a/objectarea.py b/objectarea.py
index f2c7640..0b53fad 100644
--- a/objectarea.py
+++ b/objectarea.py
@@ -15,7 +15,7 @@
# along with Math. If not, see <http://www.gnu.org/licenses/>.
from vector import Vector
-import gtk, math
+import gtk, gobject, math
GRID_VISIBLE = False
@@ -53,6 +53,8 @@ class Object:
self.container = None
+ self.animating = False
+
self.GRID_SIZE = 50
self.DRAGGING_RECT_WIDTH = 24*self.GRID_SIZE
self.DRAGGING_RECT_HEIGHT = 16*self.GRID_SIZE
@@ -103,6 +105,17 @@ class Object:
self.scale = scale
self.queue_draw()
+ def start_animating(self):
+ self.container.start_animating_object(self)
+ self.animating = True
+
+ def stop_animating(self):
+ self.container.stop_animating_object(self)
+ self.animating = False
+
+ def animate(self):
+ pass
+
def on_key(self, event):
pass
@@ -119,6 +132,9 @@ class ObjectArea(gtk.Layout):
self.objects = []
+ # Sub-list of objects that are currently animating.
+ self.animating_objects = []
+
# Object currently selected.
self.selected_object = None
@@ -149,6 +165,8 @@ class ObjectArea(gtk.Layout):
self.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#ffffff'))
self.connect('expose-event', self.expose_cb)
+ self.timer_id = None
+
def check_problem_solved(self):
pass
@@ -197,6 +215,30 @@ class ObjectArea(gtk.Layout):
old_selected_object.queue_draw()
object.queue_draw()
+ def start_animating_object(self, object):
+ if self.animating_objects.count(object) == 0:
+ self.animating_objects.append(object)
+
+ if self.timer_id is None:
+ self.timer_id = gobject.timeout_add(50, self.timer_cb)
+ self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
+
+ def stop_animating_object(self, object):
+ self.animating_objects.remove(object)
+
+ if len(self.animating_objects) == 0:
+ if self.timer_id is not None:
+ gobject.source_remove(self.timer_id)
+ self.timer_id = None
+
+ self.window.set_cursor(gtk.gdk.Cursor(self.cursor))
+
+ # Give a chance to solve the problem when animation finishes.
+ self.check_problem_solved()
+
+ def is_animating(self):
+ return len(self.animating_objects) > 0
+
def configure_dragging_area(self, grid_size, dragging_rect_width, dragging_rect_height, radial_grid_size):
self.GRID_SIZE = grid_size
self.DRAGGING_RECT_WIDTH = dragging_rect_width * self.GRID_SIZE
@@ -225,6 +267,10 @@ class ObjectArea(gtk.Layout):
self.queued_cursor = cursor
def on_mouse(self, widget, event):
+ # Wait for animation to finish before accepting input.
+ if self.is_animating():
+ return
+
# Any mouse movement over the canvas grabs focus, so we can receive keyboard events.
if not widget.is_focus():
widget.grab_focus()
@@ -263,6 +309,10 @@ class ObjectArea(gtk.Layout):
gtk.gdk.event_request_motions(event)
def on_key(self, widget, event):
+ # Wait for animation to finish before accepting input.
+ if self.is_animating():
+ return
+
key_name = gtk.gdk.keyval_name(event.keyval)
# Useful print for determining the names of keys.
@@ -359,5 +409,9 @@ class ObjectArea(gtk.Layout):
o.draw(cr)
cr.restore()
+ def timer_cb(self):
+ for o in self.animating_objects:
+ o.animate()
+ return True