gcompris r3453 - branches/gcomprixogoo/src/anim-activity
- From: bcoudoin svn gnome org
- To: svn-commits-list gnome org
- Subject: gcompris r3453 - branches/gcomprixogoo/src/anim-activity
- Date: Sun, 25 May 2008 22:58:00 +0000 (UTC)
Author: bcoudoin
Date: Sun May 25 22:58:00 2008
New Revision: 3453
URL: http://svn.gnome.org/viewvc/gcompris?rev=3453&view=rev
Log:
anim in progress. can now move the filled rectangle and play the animation.
still a lot to do to complete it.
Modified:
branches/gcomprixogoo/src/anim-activity/AnimItem.py
branches/gcomprixogoo/src/anim-activity/Timeline.py
branches/gcomprixogoo/src/anim-activity/anim.py
Modified: branches/gcomprixogoo/src/anim-activity/AnimItem.py
==============================================================================
--- branches/gcomprixogoo/src/anim-activity/AnimItem.py (original)
+++ branches/gcomprixogoo/src/anim-activity/AnimItem.py Sun May 25 22:58:00 2008
@@ -45,6 +45,11 @@
self.old_x = 0
self.old_y = 0
+ # The timeline store the state of this item in time.
+ # The key is the time (number) and the value is a tuple
+ # (properties, transformation).
+ self.timeline = {}
+
# Given x,y return a new x,y snapped to the grid
def snap_to_grid(self, x, y):
@@ -158,6 +163,7 @@
if (event.type == gtk.gdk.BUTTON_RELEASE
or event.type == gtk.gdk.BUTTON_PRESS):
self.refpoint = None
+ self.save_at_time(self.anim.timeline.get_time())
elif (event.type == gtk.gdk.MOTION_NOTIFY
and event.state & gtk.gdk.BUTTON1_MASK):
@@ -175,10 +181,14 @@
self.refpoint,
(x, y) )
+ # We need to have a translation matrix set
+ self.item.translate(0, 0)
+
def move_item_event(self, item, target, event):
if event.type == gtk.gdk.BUTTON_RELEASE:
self.old_x = 0
self.old_y = 0
+ self.save_at_time(self.anim.timeline.get_time())
elif event.type == gtk.gdk.BUTTON_PRESS:
self.old_x = event.x
self.old_y = event.y
@@ -202,6 +212,48 @@
if self.anchor:
self.anchor.update()
+
+ # Save the current place of the object for the given time
+ def save_at_time(self, time):
+ self.timeline[time] = self.get()
+
+ def display_at_time(self, time):
+ # If we have a value at that time, use it.
+ if self.timeline.has_key(time):
+ self.set(self.timeline[time][0], self.timeline[time][1])
+ return
+
+ # We have to find the latest closest time for this object
+ lastval = []
+ for k, v in self.timeline.iteritems():
+ lastval = v
+ break
+ for k, v in self.timeline.iteritems():
+ if(k > time):
+ self.set(lastval[0],
+ lastval[1])
+ break
+ lastkey = k
+ lastval = v
+
+
+ # Return the (properties, transformation) of this
+ # object.
+ def get(self):
+ result = {}
+ for prop in self.get_properties():
+ result[prop] = self.item.get_property(prop)
+ return(result, self.item.get_transform())
+
+ # Apply the given properties and transformation to this
+ # object.
+ def set(self, prop, transform):
+ self.item.set_properties(**prop)
+ self.item.set_transform(transform)
+ if self.anchor:
+ self.anchor.update()
+
+
#
# Add the anchors and callbacks on an item
#
@@ -329,6 +381,7 @@
self.refpoint = None
self.fixed_x = 0
self.fixed_y = 0
+ self.animitem.save_at_time(self.animitem.anim.timeline.get_time())
elif (event.type == gtk.gdk.MOTION_NOTIFY
and event.state & gtk.gdk.BUTTON1_MASK):
@@ -448,3 +501,11 @@
y = self.item.get_property("y") + self.item.get_property("height")
return(x, y)
+ # Return the list of properties that have to be saved for
+ # this object
+ def get_properties(self):
+ return('x', 'y',
+ 'width', 'height',
+ 'fill_color_rgba',
+ 'stroke_color_rgba')
+
Modified: branches/gcomprixogoo/src/anim-activity/Timeline.py
==============================================================================
--- branches/gcomprixogoo/src/anim-activity/Timeline.py (original)
+++ branches/gcomprixogoo/src/anim-activity/Timeline.py Sun May 25 22:58:00 2008
@@ -27,13 +27,15 @@
class Timeline:
- def __init__(self, rootitem, drawing_area):
- self.rootitem = goocanvas.Group(parent = rootitem)
- self.drawing_area = drawing_area
+ def __init__(self, anim):
+ self.anim = anim
+ self.rootitem = goocanvas.Group(parent = anim.rootitem)
+ self.drawing_area = anim.drawing_area
self.running = False
- self.previous_selection = None
self.selected = None
+ self.timelinelist = []
+ self.current_time = 0
def hide(self):
self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
@@ -41,10 +43,6 @@
def show(self):
self.rootitem.props.visibility = goocanvas.ITEM_VISIBLE
- def getTime(self):
- if self.selected:
- self.selected.get_data("time")
-
# Display the timeline selector
def draw(self):
@@ -72,25 +70,59 @@
fill_color_rgba = self.default_color,
stroke_color_rgba = 0x101080FFL,
line_width=1.0)
- item.set_data("time", i)
+ item.set_data("time", t)
if not self.selected:
self.selected = item
+ self.timelinelist.append(item)
item.connect("button_press_event",
- self.timeline_item_event,
- t)
+ self.timeline_item_event)
i += w + 1
t += 1
- #
- def timeline_item_event(self, item, target, event, time):
- if self.previous_selection:
- self.previous_selection.set_properties(fill_color_rgba = self.default_color)
+ # Select the first item in the timeline
+ self.current_time = 0
+ self.select_it(self.selected)
+
+ # Return the current selected time
+ def get_time(self):
+ return self.current_time
+
+ def set_time(self, time):
+ self.select_it(item, self.timelinelist[time])
+
+ def next(self):
+ self.current_time += 1
+ if self.current_time >= len(self.timelinelist):
+ self.current_time = 0
+ self.select_it(self.timelinelist[self.current_time])
+
+
+ def previous(self):
+ self.current_time -= 1
+ if self.current_time < 0:
+ self.current_time = len(self.timelinelist) - 1
+ self.select_it(self.timelinelist[self.current_time])
+
+
+ def select_it(self, item):
+ # Disable previous selection
+ if self.selected:
+ self.selected.set_properties(fill_color_rgba = self.default_color)
item.set_properties(fill_color_rgba = self.selected_color)
- self.previous_selection = item
self.selected = item
+ self.current_time = item.get_data("time")
+
+ # Let anim knows there is a new time set
+ self.anim.refresh(self.get_time())
+
+ #
+ def timeline_item_event(self, item, target, event):
+
+ self.select_it(item)
+
Modified: branches/gcomprixogoo/src/anim-activity/anim.py
==============================================================================
--- branches/gcomprixogoo/src/anim-activity/anim.py (original)
+++ branches/gcomprixogoo/src/anim-activity/anim.py Sun May 25 22:58:00 2008
@@ -101,15 +101,6 @@
# Initialisation. Should not change in draw.
self.running = False
- # In draw objects are created without drag&drop
- # Default size for rect, circle, line
- self.draw_defaults_size = { 'RECT' : {'width' : 60 , 'height' : 40 },
- 'FILL_RECT' : {'width' : 60 , 'height' : 40 },
- 'CIRCLE' : {'width' : 60 , 'height' : 40 },
- 'FILL_CIRCLE' : {'width' : 60 , 'height' : 40 },
- 'LINE' : {'width' : 60 , 'height' : 40 }
- }
-
# global parameter to access object structures from global fonctions
global fles
fles=self
@@ -176,7 +167,6 @@
# Part of UI
# The root items
- self.root_coloritem = []
self.root_toolitem = []
# Anim2 variables
@@ -185,13 +175,8 @@
# - frames where it's modified
# - all modifications for each frame
#
- # list of items in current frame
- self.framelist = []
# list of items in the full animation
self.animlist = []
- # rank of the current frame being processed
- self.current_frame = 0
- self.frames_total = self.current_frame
# list of z values in last shot
self.list_z_last_shot = []
# list of actual z values
@@ -223,7 +208,7 @@
self.draw_tools()
self.draw_animtools()
- self.timeline = Timeline(self.rootitem, self.drawing_area)
+ self.timeline = Timeline(self)
self.timeline.draw()
self.color = Color(self.rootitem, self.drawing_area)
@@ -270,6 +255,10 @@
gcompris.file_selector_load( self.gcomprisBoard,
self.selector_section, self.file_type,
general_restore)
+ elif (keyval == gtk.keysyms.Left):
+ self.timeline.previous()
+ elif (keyval == gtk.keysyms.Right):
+ self.timeline.next()
# Printing
# Bruno we need a print button !
@@ -436,7 +425,7 @@
return False
elif (self.tools[tool][0] == "MOVIE"):
- if self.frames_total == 0:
+ if len(self.animlist) == 0:
print 'Mmm... Need to make shots before run anim !!'
return False
@@ -581,7 +570,7 @@
x = 16,
y = 110,
)
- run.connect("button_press_event", self.stop_event,True)
+ run.connect("button_press_event", self.stop_event, True)
def stop_event(self, item, target, event, up):
@@ -590,9 +579,10 @@
self.playing_stop()
def playing_stop(self):
- self.running=False
+ self.running = False
gobject.source_remove(self.timeout)
- #self.run_anim2()
+ self.root_toolitem.props.visibility = goocanvas.ITEM_VISIBLE
+ self.root_playingitem.props.visibility = goocanvas.ITEM_INVISIBLE
def speed_event(self, item, target, event, up):
@@ -610,8 +600,9 @@
self.anim_speed=self.anim_speed-1
gobject.source_remove(self.timeout)
- self.timeout=gobject.timeout_add(1000/self.anim_speed, self.run_anim2)
- self.speed_item.set_properties(text=self.anim_speed)
+ self.timeout = gobject.timeout_add(1000/self.anim_speed,
+ self.refresh_loop)
+ self.speed_item.set_properties(text = self.anim_speed)
# Draw the grid
#
@@ -708,6 +699,9 @@
target,
event)
+ # We keep all object in a unique list
+ self.animlist.append(self.created_object)
+
#
# MOTION EVENT
# ------------
@@ -728,25 +722,39 @@
#
# MOUSE DRAG STOP
# ---------------
- elif (event.type == gtk.gdk.BUTTON_RELEASE
- and self.created_object):
+ elif (event.type == gtk.gdk.BUTTON_RELEASE):
if self.created_object:
self.created_object.create_item_event(item,
target,
event)
self.created_object = False
return True
+ else:
+ self.selected.move_item_event(item,
+ target,
+ event)
return False
+ def refresh(self, time):
+ # We keep all object in a unique list
+ # Here we order them to refresh them for the given time
+ for item in self.animlist:
+ item.display_at_time(time)
+
+ def refresh_loop(self):
+ self.timeline.next()
+ return True
+
def playing_start(self):
if not self.running:
self.running = True
- self.root_coloritem.props.visibility = goocanvas.ITEM_INVISIBLE
self.root_toolitem.props.visibility = goocanvas.ITEM_INVISIBLE
self.root_playingitem.props.visibility = goocanvas.ITEM_VISIBLE
- #self.Anim2Run()
+ self.timeout = gobject.timeout_add(1000/self.anim_speed,
+ self.refresh_loop)
+
def playing_event(self, item, target, event, state):
if event.type == gtk.gdk.BUTTON_PRESS:
@@ -780,9 +788,9 @@
self.item_frame_counter = \
goocanvas.Text(
parent = self.rootitem,
- text = self.current_frame + 1,
+ text = 1,
x = x_left + minibutton_width + 14,
- y = y_top + 15,
+ y = y_top,
font = gcompris.skin.get_font("gcompris/board/medium"),
fill_color = "white")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]