2006-07-24 11:53:02 +02:00
|
|
|
import gobject
|
|
|
|
|
|
|
|
from sugar.scene.Transformation import Transformation
|
|
|
|
|
|
|
|
class Actor(gobject.GObject):
|
|
|
|
__gsignals__ = {
|
|
|
|
'changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
|
|
|
|
}
|
|
|
|
|
2006-07-22 11:54:27 +02:00
|
|
|
def __init__(self):
|
2006-07-24 11:53:02 +02:00
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
|
|
|
|
self._parent = None
|
2006-07-22 11:54:27 +02:00
|
|
|
self._x = 0
|
|
|
|
self._y = 0
|
|
|
|
self._width = -1
|
|
|
|
self._height = -1
|
2006-07-24 11:53:02 +02:00
|
|
|
self._transf = Transformation()
|
2006-07-22 11:54:27 +02:00
|
|
|
|
|
|
|
def set_position(self, x, y):
|
|
|
|
self._x = x
|
|
|
|
self._y = y
|
2006-07-24 12:15:52 +02:00
|
|
|
self.notify_changed()
|
2006-07-22 11:54:27 +02:00
|
|
|
|
2006-07-24 11:53:02 +02:00
|
|
|
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)
|
|
|
|
|
2006-07-24 12:15:52 +02:00
|
|
|
def notify_changed(self):
|
|
|
|
if self._parent:
|
|
|
|
self._parent.notify_changed()
|
|
|
|
else:
|
|
|
|
self.emit('changed')
|
|
|
|
|
2006-07-22 11:54:27 +02:00
|
|
|
def set_size(self, width, height):
|
|
|
|
self._width = width
|
|
|
|
self._height = height
|
2006-07-24 12:15:52 +02:00
|
|
|
self.notify_changed()
|
2006-07-22 11:54:27 +02:00
|
|
|
|
2006-07-24 11:53:02 +02:00
|
|
|
def render(self, drawable):
|
2006-07-22 11:54:27 +02:00
|
|
|
pass
|