diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-09-25 12:32:08 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-09-25 12:32:08 (GMT) |
commit | 0092d85d61b55c19ca6e2edffe38c7d7965ba9d7 (patch) | |
tree | b38f91f2d1d3adc6383f857c87c121a5516a53a8 /sugar | |
parent | 1070ed3ae6c64049106040f8f3fa8ee6e85b0669 (diff) |
Initial snow flake layout implementation
Diffstat (limited to 'sugar')
-rw-r--r-- | sugar/canvas/Makefile.am | 1 | ||||
-rw-r--r-- | sugar/canvas/SnowflakeLayout.py | 62 |
2 files changed, 63 insertions, 0 deletions
diff --git a/sugar/canvas/Makefile.am b/sugar/canvas/Makefile.am index fbd241e..8599177 100644 --- a/sugar/canvas/Makefile.am +++ b/sugar/canvas/Makefile.am @@ -10,4 +10,5 @@ sugar_PYTHON = \ Menu.py \ MenuIcon.py \ MenuShell.py \ + SnowflakeLayout.py \ Timeline.py diff --git a/sugar/canvas/SnowflakeLayout.py b/sugar/canvas/SnowflakeLayout.py new file mode 100644 index 0000000..aae7d07 --- /dev/null +++ b/sugar/canvas/SnowflakeLayout.py @@ -0,0 +1,62 @@ +import math + +import cairo + +class SnowflakeLayout: + _BASE_RADIUS = 65 + _CHILDREN_FACTOR = 1 + _FLAKE_DISTANCE = 6 + _BORDER = 20 + + def __init__(self): + self._root = None + self._children = [] + + def set_root(self, icon): + self._root = icon + + def add_child(self, icon): + self._children.append(icon) + self._layout() + + def remove_child(self, icon): + self._children.remove(icon) + self._layout() + + def _layout_root(self): + [width, height] = self._root.get_size_request() + + matrix = cairo.Matrix(1, 0, 0, 1, 0, 0) + matrix.translate(self._cx, self._cy) + self._root.set_transform(matrix) + + def _layout_child(self, child, index): + r = self._r + if (len(self._children) > 10): + r += SnowflakeLayout._FLAKE_DISTANCE * (index % 3) + + angle = 2 * math.pi / len(self._children) * index + + x = self._cx + math.cos(angle) * r + y = self._cy + math.sin(angle) * r + + matrix = cairo.Matrix(1, 0, 0, 1, 0, 0) + matrix.translate(x, y) + child.set_transform(matrix) + + def _layout(self): + self._r = SnowflakeLayout._BASE_RADIUS + \ + SnowflakeLayout._CHILDREN_FACTOR * len(self._children) + + c = self._r + SnowflakeLayout._BORDER + \ + SnowflakeLayout._FLAKE_DISTANCE * 2 + + self._cx = c + self._cy = c + + self._layout_root() + + index = 0 + for child in self._children: + self._layout_child(child, index) + index += 1 |