Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/graphics/snowflakebox.py
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-10-06 09:11:38 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-10-06 09:11:38 (GMT)
commitb33a1c141f8e47b7d57a033baa9f0a44ea8d8834 (patch)
tree2bdb87dc43fdecf9c90dad58f359b733fb339b03 /sugar/graphics/snowflakebox.py
parentf216f7bc0a20b446bc9723e7a1e50486931ebbac (diff)
Move the layouts to be box and subclass them.
Diffstat (limited to 'sugar/graphics/snowflakebox.py')
-rw-r--r--sugar/graphics/snowflakebox.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/sugar/graphics/snowflakebox.py b/sugar/graphics/snowflakebox.py
new file mode 100644
index 0000000..4ee22c5
--- /dev/null
+++ b/sugar/graphics/snowflakebox.py
@@ -0,0 +1,67 @@
+import math
+
+import cairo
+import hippo
+
+_BASE_RADIUS = 65
+_CHILDREN_FACTOR = 1
+_FLAKE_DISTANCE = 6
+
+class SnowflakeBox(hippo.CanvasBox, hippo.CanvasItem):
+ __gtype_name__ = 'SugarSnowflakeBox'
+ def __init__(self, **kwargs):
+ CanvasBox.__init__(self, **kwargs)
+
+ self._root = None
+ self._r = 0
+
+ def set_root(self, icon):
+ self._root = icon
+
+ def _layout_root(self):
+ [width, height] = self._root.get_allocation()
+
+ x = self._cx - (width / 2)
+ y = self._cy - (height / 2)
+
+ self.move(self._root, int(x), int(y))
+
+ def _layout_child(self, child, index):
+ r = self._r
+ if (len(box.get_children()) > 10):
+ r += _FLAKE_DISTANCE * (index % 3)
+
+ angle = 2 * math.pi / len(box.get_children()) * index
+
+ [width, height] = child.get_allocation()
+ x = self._cx + math.cos(angle) * r - (width / 2)
+ y = self._cy + math.sin(angle) * r - (height / 2)
+
+ self.move(child, int(x), int(y))
+
+ def do_get_width_request(self):
+ max_child_size = 0
+ for child in box.get_children():
+ [width, height] = child.get_allocation()
+ max_child_size = max (max_child_size, width)
+ max_child_size = max (max_child_size, height)
+
+ return self._r * 2 + max_child_size + _FLAKE_DISTANCE * 2
+
+ def do_get_height_request(self, width):
+ return width
+
+ def do_allocate(self, width, height):
+ self._r = _BASE_RADIUS + _CHILDREN_FACTOR * len(box.get_children())
+
+ hippo.CanvasBox.do_allocate(self, width, height)
+
+ self._cx = self.get_width_request() / 2
+ self._cy = self.get_height_request() / 2
+
+ self._layout_root(box)
+
+ index = 0
+ for child in box.get_children():
+ self._layout_child(child, index)
+ index += 1