sugar-toolkit-gtk3/sugar/scene/CircleLayout.py

26 lines
646 B
Python
Raw Normal View History

2006-07-22 12:28:59 +02:00
import math
from sugar.scene.LayoutManager import LayoutManager
class CircleLayout(LayoutManager):
2006-07-22 14:32:04 +02:00
def __init__(self, radius):
2006-07-22 12:28:59 +02:00
LayoutManager.__init__(self)
2006-07-22 14:32:04 +02:00
self._radius = radius
2006-07-22 13:48:47 +02:00
self._angle = 0
def set_angle(self, angle):
self._angle = angle
2006-07-22 12:28:59 +02:00
def layout_group(self, group):
step = 2 * math.pi / len(group.get_actors())
2006-07-22 13:48:47 +02:00
angle = self._angle
2006-07-22 12:28:59 +02:00
for actor in group.get_actors():
self._update_position(actor, angle)
2006-07-22 13:48:47 +02:00
angle += step
2006-07-22 12:28:59 +02:00
def _update_position(self, actor, angle):
2006-07-22 14:32:04 +02:00
x = math.cos(angle) * self._radius + self._radius
y = math.sin(angle) * self._radius + self._radius
actor.set_position(int(x + 0.5), int(y + 0.5))