Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-07-24 09:01:25 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-07-24 09:01:25 (GMT)
commit1e3633baf791e00e4a17c09d7c29dde9762d55ed (patch)
tree20109f3d2545adfd986fae98104f31d30c5add4d
parent1c35f8d92ca82525c82ede9b543fe603798ee817 (diff)
Implement translation
-rwxr-xr-xexamples/scene/scene.py3
-rw-r--r--sugar/scene/Actor.py2
-rw-r--r--sugar/scene/Group.py11
-rw-r--r--sugar/scene/PixbufActor.py5
-rw-r--r--sugar/scene/Stage.py6
-rw-r--r--sugar/scene/Transformation.py21
6 files changed, 42 insertions, 6 deletions
diff --git a/examples/scene/scene.py b/examples/scene/scene.py
index 7a6fcdb..b54c40c 100755
--- a/examples/scene/scene.py
+++ b/examples/scene/scene.py
@@ -33,6 +33,7 @@ pixbuf = gtk.gdk.pixbuf_new_from_file('background.png')
stage.add(PixbufActor(pixbuf))
icons_group = Group()
+icons_group.set_position(100, 100)
i = 1
while i <= 5:
@@ -55,7 +56,7 @@ drawing_area.show()
window.show()
-timeline = Timeline(stage, 300)
+timeline = Timeline(stage, 200)
timeline.connect('next-frame', __next_frame_cb, icons_group)
timeline.connect('completed', __completed_cb, icons_group)
timeline.start()
diff --git a/sugar/scene/Actor.py b/sugar/scene/Actor.py
index 1ee7e2d..24074da 100644
--- a/sugar/scene/Actor.py
+++ b/sugar/scene/Actor.py
@@ -13,5 +13,5 @@ class Actor:
self._width = width
self._height = height
- def render(self, window):
+ def render(self, window, transf):
pass
diff --git a/sugar/scene/Group.py b/sugar/scene/Group.py
index 8a2a562..3cfa5e4 100644
--- a/sugar/scene/Group.py
+++ b/sugar/scene/Group.py
@@ -1,9 +1,15 @@
from sugar.scene.Actor import Actor
+from sugar.scene.Transformation import Transformation
class Group(Actor):
def __init__(self):
self._actors = []
self._layout = None
+ self._transf = Transformation()
+
+ def set_position(self, x, y):
+ Actor.set_position(self, x, y)
+ self._transf.set_translation(x, y)
def add(self, actor):
self._actors.append(actor)
@@ -27,6 +33,7 @@ class Group(Actor):
if self._layout:
self._layout.layout_group(self)
- def render(self, drawable):
+ def render(self, drawable, transf):
+ transf = transf.compose(self._transf)
for actor in self._actors:
- actor.render(drawable)
+ actor.render(drawable, transf)
diff --git a/sugar/scene/PixbufActor.py b/sugar/scene/PixbufActor.py
index 00ed587..59b3dce 100644
--- a/sugar/scene/PixbufActor.py
+++ b/sugar/scene/PixbufActor.py
@@ -8,6 +8,7 @@ class PixbufActor(Actor):
self._pixbuf = pixbuf
- def render(self, drawable):
+ def render(self, drawable, transf):
+ (x, y) = transf.get_position(self._x, self._y)
gc = gtk.gdk.GC(drawable)
- drawable.draw_pixbuf(gc, self._pixbuf, 0, 0, self._x, self._y)
+ drawable.draw_pixbuf(gc, self._pixbuf, 0, 0, x, y)
diff --git a/sugar/scene/Stage.py b/sugar/scene/Stage.py
index 1707f84..2573d02 100644
--- a/sugar/scene/Stage.py
+++ b/sugar/scene/Stage.py
@@ -1,4 +1,5 @@
from sugar.scene.Group import Group
+from sugar.scene.Transformation import Transformation
class Stage(Group):
def __init__(self):
@@ -7,3 +8,8 @@ class Stage(Group):
def get_fps(self):
return self._fps
+
+ def render(self, drawable, transf = None):
+ if transf == None:
+ transf = Transformation()
+ Group.render(self, drawable, transf)
diff --git a/sugar/scene/Transformation.py b/sugar/scene/Transformation.py
new file mode 100644
index 0000000..452c599
--- /dev/null
+++ b/sugar/scene/Transformation.py
@@ -0,0 +1,21 @@
+import copy
+
+class Transformation:
+ def __init__(self):
+ self._translation_x = 0
+ self._translation_y = 0
+
+ def set_translation(self, x, y):
+ self._translation_x = x
+ self._translation_y = y
+
+ def get_position(self, x, y):
+ translated_x = x + self._translation_x
+ translated_y = y + self._translation_y
+ return (translated_x, translated_y)
+
+ def compose(self, transf):
+ composed = copy.copy(transf)
+ composed._translation_x += transf._translation_x
+ composed._translation_y += transf._translation_y
+ return composed