Better applying of transformations
This commit is contained in:
parent
78660bfcf6
commit
5cec8f9734
@ -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):
|
def __init__(self):
|
||||||
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
|
self._parent = None
|
||||||
self._x = 0
|
self._x = 0
|
||||||
self._y = 0
|
self._y = 0
|
||||||
self._width = -1
|
self._width = -1
|
||||||
self._height = -1
|
self._height = -1
|
||||||
|
self._transf = Transformation()
|
||||||
|
|
||||||
def set_position(self, x, y):
|
def set_position(self, x, y):
|
||||||
self._x = x
|
self._x = x
|
||||||
self._y = y
|
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):
|
def set_size(self, width, height):
|
||||||
self._width = width
|
self._width = width
|
||||||
self._height = height
|
self._height = height
|
||||||
|
|
||||||
def render(self, window, transf):
|
def render(self, drawable):
|
||||||
pass
|
pass
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
from sugar.scene.Actor import Actor
|
from sugar.scene.Actor import Actor
|
||||||
from sugar.scene.Transformation import Transformation
|
|
||||||
|
|
||||||
class Group(Actor):
|
class Group(Actor):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
Actor.__init__(self)
|
||||||
|
|
||||||
self._actors = []
|
self._actors = []
|
||||||
self._layout = None
|
self._layout = None
|
||||||
self._transf = Transformation()
|
|
||||||
|
|
||||||
def set_position(self, x, y):
|
def set_position(self, x, y):
|
||||||
Actor.set_position(self, x, y)
|
Actor.set_position(self, x, y)
|
||||||
self._transf.set_translation(x, y)
|
self._transf.set_translation(x, y)
|
||||||
|
|
||||||
def add(self, actor):
|
def add(self, actor):
|
||||||
|
actor._parent = self
|
||||||
self._actors.append(actor)
|
self._actors.append(actor)
|
||||||
self.do_layout()
|
self.do_layout()
|
||||||
|
|
||||||
@ -33,7 +34,6 @@ class Group(Actor):
|
|||||||
if self._layout:
|
if self._layout:
|
||||||
self._layout.layout_group(self)
|
self._layout.layout_group(self)
|
||||||
|
|
||||||
def render(self, drawable, transf):
|
def render(self, drawable):
|
||||||
transf = transf.compose(self._transf)
|
|
||||||
for actor in self._actors:
|
for actor in self._actors:
|
||||||
actor.render(drawable, transf)
|
actor.render(drawable)
|
||||||
|
@ -8,7 +8,7 @@ class PixbufActor(Actor):
|
|||||||
|
|
||||||
self._pixbuf = pixbuf
|
self._pixbuf = pixbuf
|
||||||
|
|
||||||
def render(self, drawable, transf):
|
def render(self, drawable):
|
||||||
(x, y) = transf.get_position(self._x, self._y)
|
(x, y) = self._get_abs_position(self._x, self._y)
|
||||||
gc = gtk.gdk.GC(drawable)
|
gc = gtk.gdk.GC(drawable)
|
||||||
drawable.draw_pixbuf(gc, self._pixbuf, 0, 0, x, y)
|
drawable.draw_pixbuf(gc, self._pixbuf, 0, 0, x, y)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from sugar.scene.Group import Group
|
from sugar.scene.Group import Group
|
||||||
from sugar.scene.Transformation import Transformation
|
|
||||||
|
|
||||||
class Stage(Group):
|
class Stage(Group):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -9,7 +8,5 @@ class Stage(Group):
|
|||||||
def get_fps(self):
|
def get_fps(self):
|
||||||
return self._fps
|
return self._fps
|
||||||
|
|
||||||
def render(self, drawable, transf = None):
|
def render(self, drawable):
|
||||||
if transf == None:
|
Group.render(self, drawable)
|
||||||
transf = Transformation()
|
|
||||||
Group.render(self, drawable, transf)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user