Better applying of transformations

This commit is contained in:
Marco Pesenti Gritti 2006-07-24 11:53:02 +02:00
parent 78660bfcf6
commit 5cec8f9734
4 changed files with 41 additions and 14 deletions

View File

@ -1,17 +1,47 @@
class Actor:
import gobject
from sugar.scene.Transformation import Transformation
class Actor(gobject.GObject):
__gsignals__ = {
'changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
}
def __init__(self):
gobject.GObject.__init__(self)
self._parent = None
self._x = 0
self._y = 0
self._width = -1
self._height = -1
self._transf = Transformation()
def set_position(self, x, y):
self._x = x
self._y = y
def _get_parents(self):
parents = []
parent = self._parent
while parent:
parents.insert(0, parent)
parent = parent._parent
return parents
def _get_abs_position(self, x, y):
transf = None
parents = self._get_parents()
for actor in parents:
if transf:
transf = transf.compose(actor._transf)
else:
transf = actor._transf
return transf.get_position(x, y)
def set_size(self, width, height):
self._width = width
self._height = height
def render(self, window, transf):
def render(self, drawable):
pass

View File

@ -1,17 +1,18 @@
from sugar.scene.Actor import Actor
from sugar.scene.Transformation import Transformation
class Group(Actor):
def __init__(self):
Actor.__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):
actor._parent = self
self._actors.append(actor)
self.do_layout()
@ -33,7 +34,6 @@ class Group(Actor):
if self._layout:
self._layout.layout_group(self)
def render(self, drawable, transf):
transf = transf.compose(self._transf)
def render(self, drawable):
for actor in self._actors:
actor.render(drawable, transf)
actor.render(drawable)

View File

@ -8,7 +8,7 @@ class PixbufActor(Actor):
self._pixbuf = pixbuf
def render(self, drawable, transf):
(x, y) = transf.get_position(self._x, self._y)
def render(self, drawable):
(x, y) = self._get_abs_position(self._x, self._y)
gc = gtk.gdk.GC(drawable)
drawable.draw_pixbuf(gc, self._pixbuf, 0, 0, x, y)

View File

@ -1,5 +1,4 @@
from sugar.scene.Group import Group
from sugar.scene.Transformation import Transformation
class Stage(Group):
def __init__(self):
@ -9,7 +8,5 @@ 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)
def render(self, drawable):
Group.render(self, drawable)