Move from scaling to sizes in CanvasIcon.

This commit is contained in:
Marco Pesenti Gritti 2007-07-31 16:46:06 +02:00
parent 72d66793a7
commit b3f7e0e632
16 changed files with 75 additions and 99 deletions

View File

@ -17,7 +17,7 @@
import hippo import hippo
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units from sugar.graphics import style
from sugar.graphics.xocolor import XoColor from sugar.graphics.xocolor import XoColor
class ColorPicker(hippo.CanvasBox, hippo.CanvasItem): class ColorPicker(hippo.CanvasBox, hippo.CanvasItem):
@ -25,7 +25,7 @@ class ColorPicker(hippo.CanvasBox, hippo.CanvasItem):
hippo.CanvasBox.__init__(self, **kwargs) hippo.CanvasBox.__init__(self, **kwargs)
self.props.orientation = hippo.ORIENTATION_HORIZONTAL self.props.orientation = hippo.ORIENTATION_HORIZONTAL
self._xo = CanvasIcon(scale=units.XLARGE_ICON_SCALE, self._xo = CanvasIcon(size=style.XLARGE_ICON_SIZE,
icon_name='theme:stock-buddy') icon_name='theme:stock-buddy')
self._set_random_colors() self._set_random_colors()
self._xo.connect('activated', self._xo_activated_cb) self._xo.connect('activated', self._xo_activated_cb)

View File

@ -23,7 +23,7 @@ import gobject
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from view.clipboardmenu import ClipboardMenu from view.clipboardmenu import ClipboardMenu
from sugar.graphics.xocolor import XoColor from sugar.graphics.xocolor import XoColor
from sugar.graphics import units from sugar.graphics import style
from sugar.clipboard import clipboardservice from sugar.clipboard import clipboardservice
from sugar import util from sugar import util
from sugar import profile from sugar import profile
@ -45,9 +45,7 @@ class ClipboardIcon(CanvasIcon):
self._activity = None self._activity = None
self._selected = False self._selected = False
self._hover = False self._hover = False
self.props.box_width = units.grid_to_pixels(1) self.props.size = style.STANDARD_ICON_SIZE
self.props.box_height = units.grid_to_pixels(1)
self.props.scale = units.STANDARD_ICON_SCALE
self.props.xo_color = XoColor(profile.get_color().to_string()) self.props.xo_color = XoColor(profile.get_color().to_string())
cb_service = clipboardservice.get_instance() cb_service = clipboardservice.get_instance()

View File

@ -18,7 +18,7 @@ import gtk
from gettext import gettext as _ from gettext import gettext as _
from sugar.graphics import canvasicon from sugar.graphics import canvasicon
from sugar.graphics import units from sugar.graphics import style
from sugar.graphics.palette import Palette from sugar.graphics.palette import Palette
_ICON_NAME = 'device-battery' _ICON_NAME = 'device-battery'
@ -29,7 +29,7 @@ _STATUS_FULLY_CHARGED = 2
class DeviceView(canvasicon.CanvasIcon): class DeviceView(canvasicon.CanvasIcon):
def __init__(self, model): def __init__(self, model):
canvasicon.CanvasIcon.__init__(self, scale=units.MEDIUM_ICON_SCALE) canvasicon.CanvasIcon.__init__(self, size=style.MEDIUM_ICON_SIZE)
self._model = model self._model = model
self._palette = BatteryPalette(_('My Battery life')) self._palette = BatteryPalette(_('My Battery life'))
self.set_palette(self._palette) self.set_palette(self._palette)

View File

@ -17,12 +17,11 @@
from sugar.graphics import canvasicon from sugar.graphics import canvasicon
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics import units
from model.devices import device from model.devices import device
class DeviceView(canvasicon.CanvasIcon): class DeviceView(canvasicon.CanvasIcon):
def __init__(self, model): def __init__(self, model):
canvasicon.CanvasIcon.__init__(self, scale=units.MEDIUM_ICON_SCALE, canvasicon.CanvasIcon.__init__(self, size=style.MEDIUM_ICON_SIZE,
icon_name='theme:device-network-mesh') icon_name='theme:device-network-mesh')
self._model = model self._model = model

View File

@ -17,7 +17,7 @@
from sugar.graphics import canvasicon from sugar.graphics import canvasicon
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics import units from sugar.graphics import style
from model.devices.network import wireless from model.devices.network import wireless
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from model.devices import device from model.devices import device
@ -26,7 +26,7 @@ _ICON_NAME = 'device-network-wireless'
class DeviceView(CanvasIcon): class DeviceView(CanvasIcon):
def __init__(self, model): def __init__(self, model):
CanvasIcon.__init__(self, scale=units.MEDIUM_ICON_SCALE) CanvasIcon.__init__(self, size=style.MEDIUM_ICON_SIZE)
self._model = model self._model = model
model.connect('notify::name', self._name_changed_cb) model.connect('notify::name', self._name_changed_cb)

View File

@ -18,7 +18,7 @@ import hippo
import gobject import gobject
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units from sugar.graphics import style
from sugar.presence import presenceservice from sugar.presence import presenceservice
from model import bundleregistry from model import bundleregistry
@ -32,10 +32,10 @@ class FriendView(hippo.CanvasBox):
self._buddy = buddy self._buddy = buddy
self._buddy_icon = BuddyIcon(shell, buddy) self._buddy_icon = BuddyIcon(shell, buddy)
self._buddy_icon.props.scale = units.LARGE_ICON_SCALE self._buddy_icon.props.scale = style.LARGE_ICON_SIZE
self.append(self._buddy_icon) self.append(self._buddy_icon)
self._activity_icon = CanvasIcon(scale=units.LARGE_ICON_SCALE) self._activity_icon = CanvasIcon(size=style.LARGE_ICON_SIZE)
self._activity_icon_visible = False self._activity_icon_visible = False
if self._buddy.is_present(): if self._buddy.is_present():

View File

@ -21,7 +21,7 @@ import gobject
from sugar import profile from sugar import profile
from sugar.graphics.spreadlayout import SpreadLayout from sugar.graphics.spreadlayout import SpreadLayout
from sugar.graphics import units from sugar.graphics import style
from model.BuddyModel import BuddyModel from model.BuddyModel import BuddyModel
from view.BuddyIcon import BuddyIcon from view.BuddyIcon import BuddyIcon
@ -40,7 +40,7 @@ class FriendsBox(hippo.CanvasBox):
buddy_model = BuddyModel(key=profile.get_pubkey()) buddy_model = BuddyModel(key=profile.get_pubkey())
self._owner_icon = BuddyIcon(shell, buddy_model) self._owner_icon = BuddyIcon(shell, buddy_model)
self._owner_icon.props.scale = units.LARGE_ICON_SCALE self._owner_icon.props.size = style.LARGE_ICON_SIZE
self._layout.add_center(self._owner_icon) self._layout.add_center(self._owner_icon)
friends = self._shell.get_model().get_friends() friends = self._shell.get_model().get_friends()

View File

@ -24,7 +24,6 @@ import gtk
import hippo import hippo
import dbus import dbus
from sugar.graphics import units
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics.xocolor import XoColor from sugar.graphics.xocolor import XoColor
from sugar.graphics.palette import Palette, CanvasInvoker from sugar.graphics.palette import Palette, CanvasInvoker
@ -46,7 +45,7 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
box_height=style.zoom(450)) box_height=style.zoom(450))
self.append(self._donut) self.append(self._donut)
self._my_icon = HomeMyIcon(shell, units.XLARGE_ICON_SCALE) self._my_icon = HomeMyIcon(shell, style.XLARGE_ICON_SIZE)
self.append(self._my_icon, hippo.PACK_FIXED) self.append(self._my_icon, hippo.PACK_FIXED)
shell_model = shell.get_model() shell_model = shell.get_model()

View File

@ -18,7 +18,7 @@ import gtk
import hippo import hippo
import cairo import cairo
from sugar.graphics import units from sugar.graphics import style
from view.home.MeshBox import MeshBox from view.home.MeshBox import MeshBox
from view.home.HomeBox import HomeBox from view.home.HomeBox import HomeBox
@ -113,13 +113,13 @@ class HomeWindow(gtk.Window):
self._canvas.set_root(self._transition_box) self._canvas.set_root(self._transition_box)
if level == ShellModel.ZOOM_HOME: if level == ShellModel.ZOOM_HOME:
scale = units.XLARGE_ICON_SCALE size = style.XLARGE_ICON_SIZE
elif level == ShellModel.ZOOM_FRIENDS: elif level == ShellModel.ZOOM_FRIENDS:
scale = units.LARGE_ICON_SCALE size = style.LARGE_ICON_SIZE
elif level == ShellModel.ZOOM_MESH: elif level == ShellModel.ZOOM_MESH:
scale = units.STANDARD_ICON_SCALE size = style.STANDARD_ICON_SIZE
self._transition_box.set_scale(scale) self._transition_box.set_size(size)
def _transition_completed_cb(self, transition_box): def _transition_completed_cb(self, transition_box):
if self._level == ShellModel.ZOOM_HOME: if self._level == ShellModel.ZOOM_HOME:

View File

@ -25,7 +25,7 @@ from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics import xocolor from sugar.graphics import xocolor
from sugar.graphics import canvasicon from sugar.graphics import canvasicon
from sugar.graphics import units from sugar.graphics import style
from sugar import profile from sugar import profile
from model import accesspointmodel from model import accesspointmodel
@ -120,7 +120,7 @@ _MESH_ICON_NAME = 'theme:device-network-mesh'
class MeshDeviceView(PulsingIcon): class MeshDeviceView(PulsingIcon):
def __init__(self, nm_device): def __init__(self, nm_device):
PulsingIcon.__init__(self, scale=units.MEDIUM_ICON_SCALE, PulsingIcon.__init__(self, size=style.MEDIUM_ICON_SIZE,
icon_name=_MESH_ICON_NAME) icon_name=_MESH_ICON_NAME)
self._nm_device = nm_device self._nm_device = nm_device
self.set_tooltip(_("Mesh Network")) self.set_tooltip(_("Mesh Network"))

View File

@ -18,7 +18,7 @@ from sugar.graphics.canvasicon import CanvasIcon
from sugar import profile from sugar import profile
class MyIcon(CanvasIcon): class MyIcon(CanvasIcon):
def __init__(self, scale): def __init__(self, size):
CanvasIcon.__init__(self, scale=scale, CanvasIcon.__init__(self, size=size,
icon_name='theme:stock-buddy', icon_name='theme:stock-buddy',
xo_color=profile.get_color()) xo_color=profile.get_color())

View File

@ -20,7 +20,7 @@ import gobject
import colorsys import colorsys
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units from sugar.graphics import style
from sugar.graphics import xocolor from sugar.graphics import xocolor
from sugar import profile from sugar import profile
@ -56,7 +56,7 @@ class ActivityIcon(CanvasIcon):
color = self._icon_colors[self._level] color = self._icon_colors[self._level]
CanvasIcon.__init__(self, icon_name=icon_name, xo_color=color, CanvasIcon.__init__(self, icon_name=icon_name, xo_color=color,
scale=units.MEDIUM_ICON_SCALE, cache=True) size=style.MEDIUM_ICON_SIZE, cache=True)
self._activity = activity self._activity = activity
self._pulse_id = 0 self._pulse_id = 0

View File

@ -17,23 +17,23 @@
import hippo import hippo
import gobject import gobject
from sugar.graphics import units from sugar.graphics import style
from sugar.graphics import animator from sugar.graphics import animator
from sugar.graphics.spreadlayout import SpreadLayout from sugar.graphics.spreadlayout import SpreadLayout
from view.home.MyIcon import MyIcon from view.home.MyIcon import MyIcon
class _Animation(animator.Animation): class _Animation(animator.Animation):
def __init__(self, icon, start_scale, end_scale): def __init__(self, icon, start_size, end_size):
animator.Animation.__init__(self, 0.0, 1.0) animator.Animation.__init__(self, 0.0, 1.0)
self._icon = icon self._icon = icon
self.start_scale = start_scale self.start_size = start_size
self.end_scale = end_scale self.end_size = end_size
def next_frame(self, current): def next_frame(self, current):
d = (self.end_scale - self.start_scale) * current d = (self.end_size - self.start_size) * current
self._icon.props.scale = self.start_scale + d self._icon.props.size = self.start_size + d
class _Layout(gobject.GObject,hippo.CanvasLayout): class _Layout(gobject.GObject,hippo.CanvasLayout):
__gtype_name__ = 'SugarTransitionBoxLayout' __gtype_name__ = 'SugarTransitionBoxLayout'
@ -70,12 +70,12 @@ class TransitionBox(hippo.CanvasBox):
def __init__(self): def __init__(self):
hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff) hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff)
self._scale = units.XLARGE_ICON_SCALE self._size = style.XLARGE_ICON_SIZE
self._layout = _Layout() self._layout = _Layout()
self.set_layout(self._layout) self.set_layout(self._layout)
self._my_icon = MyIcon(self._scale) self._my_icon = MyIcon(self._size)
self.append(self._my_icon) self.append(self._my_icon)
self._animator = animator.Animator(0.3) self._animator = animator.Animator(0.3)
@ -84,10 +84,10 @@ class TransitionBox(hippo.CanvasBox):
def _animation_completed_cb(self, anim): def _animation_completed_cb(self, anim):
self.emit('completed') self.emit('completed')
def set_scale(self, scale): def set_size(self, size):
self._animator.remove_all() self._animator.remove_all()
self._animator.add(_Animation(self._my_icon, self._scale, scale)) self._animator.add(_Animation(self._my_icon, self._size, size))
self._animator.start() self._animator.start()
self._scale = scale self._size = size

View File

@ -30,8 +30,6 @@ from sugar.graphics import style
from sugar.graphics import units from sugar.graphics import units
from sugar.graphics.palette import Palette, CanvasInvoker from sugar.graphics.palette import Palette, CanvasInvoker
BADGE_SCALE_FACTOR = 0.33
class _IconCacheIcon: class _IconCacheIcon:
def __init__(self, name, fill_color, stroke_color, now): def __init__(self, name, fill_color, stroke_color, now):
self.data_size = None self.data_size = None
@ -143,8 +141,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
gobject.PARAM_READWRITE), gobject.PARAM_READWRITE),
'stroke-color' : (object, None, None, 'stroke-color' : (object, None, None,
gobject.PARAM_READWRITE), gobject.PARAM_READWRITE),
'scale' : (float, None, None, 'size' : (int, None, None, 0, 1024, 0,
0.0, 1024.0, units.STANDARD_ICON_SCALE,
gobject.PARAM_READWRITE), gobject.PARAM_READWRITE),
'cache' : (bool, None, None, False, 'cache' : (bool, None, None, False,
gobject.PARAM_READWRITE), gobject.PARAM_READWRITE),
@ -159,7 +156,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._buffers = {} self._buffers = {}
self._cur_buffer = None self._cur_buffer = None
self._scale = units.STANDARD_ICON_SCALE self._size = 0
self._fill_color = None self._fill_color = None
self._stroke_color = None self._stroke_color = None
self._icon_name = None self._icon_name = None
@ -209,10 +206,10 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
self._stroke_color = value self._stroke_color = value
self._handle = None self._handle = None
self.emit_paint_needed(0, 0, -1, -1) self.emit_paint_needed(0, 0, -1, -1)
elif pspec.name == 'scale': elif pspec.name == 'size':
if self._scale != value and not self._cache: if self._size != value and not self._cache:
self._clear_buffers() self._clear_buffers()
self._scale = value self._size = value
self.emit_request_changed() self.emit_request_changed()
elif pspec.name == 'cache': elif pspec.name == 'cache':
self._cache = value self._cache = value
@ -264,11 +261,11 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
def _get_current_buffer_key(self, name): def _get_current_buffer_key(self, name):
[fill_color, stroke_color] = self._choose_colors() [fill_color, stroke_color] = self._choose_colors()
return (name, fill_color, stroke_color, self._scale) return (name, fill_color, stroke_color, self._size)
def do_get_property(self, pspec): def do_get_property(self, pspec):
if pspec.name == 'scale': if pspec.name == 'size':
return self._scale return self._size
elif pspec.name == 'icon-name': elif pspec.name == 'icon-name':
return self._icon_name return self._icon_name
elif pspec.name == 'fill-color': elif pspec.name == 'fill-color':
@ -283,13 +280,17 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
return self._badge_name return self._badge_name
def _get_icon_size(self, handle): def _get_icon_size(self, handle):
if not handle: if handle:
dimensions = handle.get_dimension_data()
return int(dimensions[0]), int(dimensions[1])
else:
return [0, 0] return [0, 0]
dimensions = handle.get_dimension_data() def _get_size(self, handle):
if self._size == 0:
width = int(dimensions[0] * self._scale) + 1 width, height = self._get_icon_size(handle)
height = int(dimensions[1] * self._scale) + 1 else:
width = height = self._size
return [width, height] return [width, height]
@ -302,15 +303,19 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
if self._buffers.has_key(key): if self._buffers.has_key(key):
buf = self._buffers[key] buf = self._buffers[key]
else: else:
[w, h] = self._get_icon_size(handle) [icon_w, icon_h] = self._get_icon_size(handle)
scale = self._scale [target_w, target_h] = self._get_size(handle)
if scale_factor: if scale_factor:
scale = scale_factor target_w = target_w * scale_factor
target_h = target_h * scale_factor
target = cr.get_target() target = cr.get_target()
buf = target.create_similar(cairo.CONTENT_COLOR_ALPHA, w, h) buf = target.create_similar(cairo.CONTENT_COLOR_ALPHA,
target_w, target_h)
ctx = cairo.Context(buf) ctx = cairo.Context(buf)
ctx.scale(scale, scale) ctx.scale(float(target_w) / float(icon_w),
float(target_h) / float(icon_h))
handle.render_cairo(ctx) handle.render_cairo(ctx)
del ctx del ctx
@ -334,7 +339,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
if self._badge_name: if self._badge_name:
badge_handle = self._get_badge_handle() badge_handle = self._get_badge_handle()
if badge_handle: if badge_handle:
badge_buf = self._get_buffer(cr, self._badge_name, badge_handle, self._scale * 0.66) badge_buf = self._get_buffer(cr, self._badge_name, badge_handle, 0.66)
badge_x = icon_x + icon_buf.get_width() - (icon_buf.get_width() / 4) badge_x = icon_x + icon_buf.get_width() - (icon_buf.get_width() / 4)
badge_y = icon_y + icon_buf.get_height() - (icon_buf.get_height() / 4) badge_y = icon_y + icon_buf.get_height() - (icon_buf.get_height() / 4)
cr.set_source_surface(badge_buf, badge_x, badge_y) cr.set_source_surface(badge_buf, badge_x, badge_y)
@ -342,12 +347,12 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
def do_get_content_width_request(self): def do_get_content_width_request(self):
handle = self._get_icon_handle() handle = self._get_icon_handle()
[width, height] = self._get_icon_size(handle) [width, height] = self._get_size(handle)
return (width, width) return (width, width)
def do_get_content_height_request(self, for_width): def do_get_content_height_request(self, for_width):
handle = self._get_icon_handle() handle = self._get_icon_handle()
[width, height] = self._get_icon_size(handle) [width, height] = self._get_size(handle)
return (height, height) return (height, height)
def do_button_press_event(self, event): def do_button_press_event(self, event):

View File

@ -25,21 +25,11 @@ import gobject
import hippo import hippo
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units
from sugar.graphics import style from sugar.graphics import style
STANDARD_SIZE = 0
SMALL_SIZE = 1
class IconButton(CanvasIcon, hippo.CanvasItem): class IconButton(CanvasIcon, hippo.CanvasItem):
__gtype_name__ = 'SugarIconButton' __gtype_name__ = 'SugarIconButton'
__gproperties__ = {
'size' : (int, None, None,
0, 32767, STANDARD_SIZE,
gobject.PARAM_READWRITE)
}
def __init__(self, **kwargs): def __init__(self, **kwargs):
CanvasIcon.__init__(self, cache=True, **kwargs) CanvasIcon.__init__(self, cache=True, **kwargs)
@ -47,32 +37,11 @@ class IconButton(CanvasIcon, hippo.CanvasItem):
self.props.fill_color = style.Color("#404040") self.props.fill_color = style.Color("#404040")
self.props.stroke_color = style.Color("#FFFFFF") self.props.stroke_color = style.Color("#FFFFFF")
self._set_size(STANDARD_SIZE)
self.connect('activated', self._icon_clicked_cb) self.connect('activated', self._icon_clicked_cb)
def _set_size(self, size): self.props.box_width = style.GRID_CELL_SIZE
if size == SMALL_SIZE: self.props.box_height = style.GRID_CELL_SIZE
self.props.box_width = -1 self.props.size = style.STANDARD_ICON_SIZE
self.props.box_height = -1
self.props.scale = units.SMALL_ICON_SCALE
else:
self.props.box_width = units.grid_to_pixels(1)
self.props.box_height = units.grid_to_pixels(1)
self.props.scale = units.STANDARD_ICON_SCALE
self._size = size
def do_set_property(self, pspec, value):
if pspec.name == 'size':
self._set_size(value)
else:
CanvasIcon.do_set_property(self, pspec, value)
def do_get_property(self, pspec):
if pspec.name == 'size':
return self._size
else:
return CanvasIcon.do_get_property(self, pspec)
def do_button_press_event(self, event): def do_button_press_event(self, event):
if self._active: if self._active:

View File

@ -93,6 +93,12 @@ DEFAULT_PADDING = zoom(6)
GRID_CELL_SIZE = zoom(75) GRID_CELL_SIZE = zoom(75)
LINE_WIDTH = zoom(2) LINE_WIDTH = zoom(2)
STANDARD_ICON_SIZE = zoom(55)
SMALL_ICON_SIZE = zoom(55 * 0.5)
MEDIUM_ICON_SIZE = zoom(55 * 1.5)
LARGE_ICON_SIZE = zoom(55 * 2.0)
XLARGE_ICON_SIZE = zoom(55 * 2.75)
FONT_SIZE = zoom(7 * _XO_DPI / _get_screen_dpi()) FONT_SIZE = zoom(7 * _XO_DPI / _get_screen_dpi())
FONT_NORMAL = Font('Bitstream Vera Sans %d' % FONT_SIZE) FONT_NORMAL = Font('Bitstream Vera Sans %d' % FONT_SIZE)
FONT_BOLD = Font('Bitstream Vera Sans bold %d' % FONT_SIZE) FONT_BOLD = Font('Bitstream Vera Sans bold %d' % FONT_SIZE)