Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-07-22 10:28:59 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-07-22 10:28:59 (GMT)
commitfe69904b6c3adf4874893a6ff9154265d45b9b8f (patch)
tree99e419c38fb1eda1a13bb24b57d32402a6e5ce2c /sugar
parenta02313d85aa3dd2e53c4ee98a5e407460e292456 (diff)
Add layout manager and a circle layout
Diffstat (limited to 'sugar')
-rw-r--r--sugar/scene/CircleLayout.py21
-rw-r--r--sugar/scene/Group.py12
-rw-r--r--sugar/scene/LayoutManager.py7
3 files changed, 40 insertions, 0 deletions
diff --git a/sugar/scene/CircleLayout.py b/sugar/scene/CircleLayout.py
new file mode 100644
index 0000000..eb36ee4
--- /dev/null
+++ b/sugar/scene/CircleLayout.py
@@ -0,0 +1,21 @@
+import math
+
+from sugar.scene.LayoutManager import LayoutManager
+
+class CircleLayout(LayoutManager):
+ def __init__(self, radium):
+ LayoutManager.__init__(self)
+
+ self._radium = radium
+
+ def layout_group(self, group):
+ step = 2 * math.pi / len(group.get_actors())
+ angle = 2 * math.pi
+ for actor in group.get_actors():
+ self._update_position(actor, angle)
+ angle -= step
+
+ def _update_position(self, actor, angle):
+ x = math.cos(angle) * self._radium + self._radium
+ y = math.sin(angle) * self._radium + self._radium
+ actor.set_position(int(x), int(y))
diff --git a/sugar/scene/Group.py b/sugar/scene/Group.py
index b845cd8..1485d11 100644
--- a/sugar/scene/Group.py
+++ b/sugar/scene/Group.py
@@ -3,12 +3,24 @@ from sugar.scene.Actor import Actor
class Group(Actor):
def __init__(self):
self._actors = []
+ self._layout_manager = None
def add(self, actor):
self._actors.append(actor)
+ if self._layout_manager:
+ self._layout_manager.layout_group(slef)
def remove(self, actor):
self._actors.remove(actor)
+ if self._layout_manager:
+ self._layout_manager.layout_group(self)
+
+ def get_actors(self):
+ return self._actors
+
+ def set_layout_manager(self, layout_manager):
+ self._layout_manager = layout_manager
+ self._layout_manager.layout_group(self)
def render(self, drawable):
for actor in self._actors:
diff --git a/sugar/scene/LayoutManager.py b/sugar/scene/LayoutManager.py
new file mode 100644
index 0000000..c7ada5a
--- /dev/null
+++ b/sugar/scene/LayoutManager.py
@@ -0,0 +1,7 @@
+class LayoutManager:
+ def __init__(self):
+ pass
+
+ def layout_group(self, group):
+ pass
+