Improved zoom model

This commit is contained in:
Marco Pesenti Gritti 2006-08-29 14:39:34 +02:00
parent a29230c183
commit f597375aff
4 changed files with 60 additions and 62 deletions

View File

@ -8,15 +8,18 @@ import Theme
class FriendIcon(IconItem): class FriendIcon(IconItem):
def __init__(self, friend): def __init__(self, friend):
IconItem.__init__(self, icon_name='stock-buddy', IconItem.__init__(self, icon_name='stock-buddy',
color=friend.get_color(), size=48, color=friend.get_color(), size=96,
x=random.random() * 1100, x=random.random() * 2400,
y=random.random() * 800) y=random.random() * 1800)
self._friend = friend self._friend = friend
def get_friend(self): def get_friend(self):
return self._friend return self._friend
class FriendsGroup(goocanvas.Group): class FriendsGroup(goocanvas.Group):
WIDTH = 1200.0 * 1.9
HEIGHT = 900.0 * 1.9
def __init__(self, data_model): def __init__(self, data_model):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
self._friend_to_child = {} self._friend_to_child = {}
@ -24,13 +27,9 @@ class FriendsGroup(goocanvas.Group):
self._theme = Theme.get_instance() self._theme = Theme.get_instance()
self._theme.connect("theme-changed", self.__theme_changed_cb) self._theme.connect("theme-changed", self.__theme_changed_cb)
color = self._theme.get_home_mesh_color()
self._mesh_rect = goocanvas.Rect(width=1200, height=900,
line_width=0, fill_color=color)
self.add_child(self._mesh_rect)
color = self._theme.get_home_friends_color() color = self._theme.get_home_friends_color()
self._friends_rect = goocanvas.Rect(x=50, y=50, width=1100, height=800, self._friends_rect = goocanvas.Rect(width=FriendsGroup.WIDTH,
height=FriendsGroup.HEIGHT,
line_width=0, fill_color=color, line_width=0, fill_color=color,
radius_x=30, radius_y=30) radius_x=30, radius_y=30)
self.add_child(self._friends_rect) self.add_child(self._friends_rect)
@ -44,8 +43,6 @@ class FriendsGroup(goocanvas.Group):
def __theme_changed_cb(self, theme): def __theme_changed_cb(self, theme):
color = self._theme.get_home_friends_color() color = self._theme.get_home_friends_color()
self._friends_rect.set_property("fill-color", color) self._friends_rect.set_property("fill-color", color)
color = self._theme.get_home_mesh_color()
self._mesh_rect.set_property("fill-color", color)
def add_friend(self, friend): def add_friend(self, friend):
icon = FriendIcon(friend) icon = FriendIcon(friend)

View File

@ -45,32 +45,23 @@ class TasksItem(DonutItem):
class Background(goocanvas.Group): class Background(goocanvas.Group):
def __init__(self): def __init__(self):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
self._theme = Theme.get_instance()
self._theme.connect("theme-changed", self.__theme_changed_cb)
color = self._theme.get_home_friends_color()
self._friends_rect = goocanvas.Rect(width=1200, height=900,
line_width=0, fill_color=color)
self.add_child(self._friends_rect)
color = self._theme.get_home_activities_color()
self._home_rect = goocanvas.Rect(x=50, y=50, width=1100, height=800,
line_width=0, fill_color=color,
radius_x=30, radius_y=30)
self.add_child(self._home_rect)
def __theme_changed_cb(self, theme):
color = self._theme.get_home_activities_color()
self._home_rect.set_property("fill-color", color)
color = self._theme.get_home_friends_color()
self._friends_rect.set_property("fill-color", color)
class HomeGroup(goocanvas.Group): class HomeGroup(goocanvas.Group):
WIDTH = 1200.0
HEIGHT = 900.0
def __init__(self, shell): def __init__(self, shell):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
background = Background() self._theme = Theme.get_instance()
self.add_child(background) self._theme.connect("theme-changed", self.__theme_changed_cb)
color = self._theme.get_home_activities_color()
self._home_rect = goocanvas.Rect(width=HomeGroup.WIDTH,
height=HomeGroup.HEIGHT,
line_width=0, fill_color=color,
radius_x=30, radius_y=30)
self.add_child(self._home_rect)
tasks = TasksItem(shell) tasks = TasksItem(shell)
tasks.translate(600, 450) tasks.translate(600, 450)
@ -83,6 +74,17 @@ class HomeGroup(goocanvas.Group):
450 - (me.get_property('height') / 2)) 450 - (me.get_property('height') / 2))
self.add_child(me) self.add_child(me)
def get_width(self):
return 1200.0 * 1.8
def get_height(self):
return 900.0 * 1.8
def __theme_changed_cb(self, theme):
color = self._theme.get_home_activities_color()
self._home_rect.set_property("fill-color", color)
# def __item_view_created_cb(self, view, item_view, item): # def __item_view_created_cb(self, view, item_view, item):
# if isinstance(item, PieceItem) or \ # if isinstance(item, PieceItem) or \
# isinstance(item, PieceIcon): # isinstance(item, PieceIcon):

View File

@ -8,11 +8,11 @@ from home.FriendsGroup import FriendsGroup
import sugar import sugar
class HomeWindow(gtk.Window): class HomeWindow(gtk.Window):
CANVAS_WIDTH = 1200
CANVAS_HEIGHT = 900
def __init__(self, shell): def __init__(self, shell):
gtk.Window.__init__(self) gtk.Window.__init__(self)
self._shell = shell self._shell = shell
self._width = MeshGroup.WIDTH
self._height = MeshGroup.HEIGHT
self.realize() self.realize()
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP) self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
@ -27,40 +27,35 @@ class HomeWindow(gtk.Window):
data_model = model.get_friends() data_model = model.get_friends()
self._friends_group = FriendsGroup(data_model) self._friends_group = FriendsGroup(data_model)
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
(self._height - FriendsGroup.HEIGHT) / 2)
root.add_child(self._friends_group) root.add_child(self._friends_group)
self._home_group = HomeGroup(self._shell) self._home_group = HomeGroup(self._shell)
self._home_group.translate((self._width - HomeGroup.WIDTH) / 2,
(self._height - HomeGroup.HEIGHT) / 2)
root.add_child(self._home_group) root.add_child(self._home_group)
canvas = goocanvas.CanvasView() self._canvas = goocanvas.CanvasView()
canvas.set_bounds(0, 0, HomeWindow.CANVAS_WIDTH, self._canvas.set_size_request(gtk.gdk.screen_width(),
HomeWindow.CANVAS_HEIGHT)
canvas.set_scale(float(gtk.gdk.screen_width()) /
float(HomeWindow.CANVAS_WIDTH))
canvas.set_size_request(gtk.gdk.screen_width(),
gtk.gdk.screen_height()) gtk.gdk.screen_height())
canvas.set_model(self._model) self._canvas.set_model(self._model)
self.add(canvas) self.add(self._canvas)
canvas.show() self._canvas.show()
def _set_group_scale(self, group, d):
x = HomeWindow.CANVAS_WIDTH * (1 - d) / 2
y = HomeWindow.CANVAS_HEIGHT * (1 - d) / 2
matrix = cairo.Matrix(1, 0, 0, 1, 0, 0)
matrix.translate(x, y)
matrix.scale(d, d)
group.set_transform(matrix)
def set_zoom_level(self, level): def set_zoom_level(self, level):
if level == sugar.ZOOM_HOME: if level == sugar.ZOOM_HOME:
self._set_group_scale(self._home_group, 1.0) width = HomeGroup.WIDTH * 1.1
height = HomeGroup.HEIGHT * 1.1
elif level == sugar.ZOOM_FRIENDS: elif level == sugar.ZOOM_FRIENDS:
self._set_group_scale(self._home_group, 0.5) width = FriendsGroup.WIDTH * 1.1
self._set_group_scale(self._friends_group, 1.0) height = FriendsGroup.HEIGHT * 1.1
elif level == sugar.ZOOM_MESH: elif level == sugar.ZOOM_MESH:
self._set_group_scale(self._home_group, 0.2) width = MeshGroup.WIDTH
self._set_group_scale(self._friends_group, 0.4) height = MeshGroup.HEIGHT
self._set_group_scale(self._mesh_group, 1.0)
self._canvas.set_bounds((self._width - width) / 2,
(self._height - height) / 2,
width, height)
self._canvas.set_scale(gtk.gdk.screen_width() / width)

View File

@ -15,7 +15,7 @@ class ActivityItem(IconItem):
icon_name = info.get_icon() icon_name = info.get_icon()
IconItem.__init__(self, icon_name=icon_name, IconItem.__init__(self, icon_name=icon_name,
color=activity.get_color(), size=48) color=activity.get_color(), size=144)
self._activity = activity self._activity = activity
@ -23,13 +23,17 @@ class ActivityItem(IconItem):
return self._activity.get_service() return self._activity.get_service()
class MeshGroup(goocanvas.Group): class MeshGroup(goocanvas.Group):
WIDTH = 1200.0 * 3.5
HEIGHT = 900.0 * 3.5
def __init__(self, data_model): def __init__(self, data_model):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
self._theme = Theme.get_instance() self._theme = Theme.get_instance()
self._theme.connect("theme-changed", self.__theme_changed_cb) self._theme.connect("theme-changed", self.__theme_changed_cb)
color = self._theme.get_home_mesh_color() color = self._theme.get_home_mesh_color()
self._mesh_rect = goocanvas.Rect(width=1200, height=900, self._mesh_rect = goocanvas.Rect(width=MeshGroup.WIDTH,
height=MeshGroup.HEIGHT,
fill_color=color) fill_color=color)
self.add_child(self._mesh_rect) self.add_child(self._mesh_rect)