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
from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units
from sugar.graphics import style
from sugar.graphics.xocolor import XoColor
class ColorPicker(hippo.CanvasBox, hippo.CanvasItem):
@ -25,7 +25,7 @@ class ColorPicker(hippo.CanvasBox, hippo.CanvasItem):
hippo.CanvasBox.__init__(self, **kwargs)
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')
self._set_random_colors()
self._xo.connect('activated', self._xo_activated_cb)

View File

@ -23,7 +23,7 @@ import gobject
from sugar.graphics.canvasicon import CanvasIcon
from view.clipboardmenu import ClipboardMenu
from sugar.graphics.xocolor import XoColor
from sugar.graphics import units
from sugar.graphics import style
from sugar.clipboard import clipboardservice
from sugar import util
from sugar import profile
@ -45,9 +45,7 @@ class ClipboardIcon(CanvasIcon):
self._activity = None
self._selected = False
self._hover = False
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.props.size = style.STANDARD_ICON_SIZE
self.props.xo_color = XoColor(profile.get_color().to_string())
cb_service = clipboardservice.get_instance()

View File

@ -18,7 +18,7 @@ import gtk
from gettext import gettext as _
from sugar.graphics import canvasicon
from sugar.graphics import units
from sugar.graphics import style
from sugar.graphics.palette import Palette
_ICON_NAME = 'device-battery'
@ -29,7 +29,7 @@ _STATUS_FULLY_CHARGED = 2
class DeviceView(canvasicon.CanvasIcon):
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._palette = BatteryPalette(_('My Battery life'))
self.set_palette(self._palette)

View File

@ -17,12 +17,11 @@
from sugar.graphics import canvasicon
from sugar.graphics import style
from sugar.graphics import units
from model.devices import device
class DeviceView(canvasicon.CanvasIcon):
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')
self._model = model

View File

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

View File

@ -18,7 +18,7 @@ import hippo
import gobject
from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units
from sugar.graphics import style
from sugar.presence import presenceservice
from model import bundleregistry
@ -32,10 +32,10 @@ class FriendView(hippo.CanvasBox):
self._buddy = 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._activity_icon = CanvasIcon(scale=units.LARGE_ICON_SCALE)
self._activity_icon = CanvasIcon(size=style.LARGE_ICON_SIZE)
self._activity_icon_visible = False
if self._buddy.is_present():

View File

@ -21,7 +21,7 @@ import gobject
from sugar import profile
from sugar.graphics.spreadlayout import SpreadLayout
from sugar.graphics import units
from sugar.graphics import style
from model.BuddyModel import BuddyModel
from view.BuddyIcon import BuddyIcon
@ -40,7 +40,7 @@ class FriendsBox(hippo.CanvasBox):
buddy_model = BuddyModel(key=profile.get_pubkey())
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)
friends = self._shell.get_model().get_friends()

View File

@ -24,7 +24,6 @@ import gtk
import hippo
import dbus
from sugar.graphics import units
from sugar.graphics import style
from sugar.graphics.xocolor import XoColor
from sugar.graphics.palette import Palette, CanvasInvoker
@ -46,7 +45,7 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
box_height=style.zoom(450))
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)
shell_model = shell.get_model()

View File

@ -18,7 +18,7 @@ import gtk
import hippo
import cairo
from sugar.graphics import units
from sugar.graphics import style
from view.home.MeshBox import MeshBox
from view.home.HomeBox import HomeBox
@ -113,13 +113,13 @@ class HomeWindow(gtk.Window):
self._canvas.set_root(self._transition_box)
if level == ShellModel.ZOOM_HOME:
scale = units.XLARGE_ICON_SCALE
size = style.XLARGE_ICON_SIZE
elif level == ShellModel.ZOOM_FRIENDS:
scale = units.LARGE_ICON_SCALE
size = style.LARGE_ICON_SIZE
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):
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 xocolor
from sugar.graphics import canvasicon
from sugar.graphics import units
from sugar.graphics import style
from sugar import profile
from model import accesspointmodel
@ -120,7 +120,7 @@ _MESH_ICON_NAME = 'theme:device-network-mesh'
class MeshDeviceView(PulsingIcon):
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)
self._nm_device = nm_device
self.set_tooltip(_("Mesh Network"))

View File

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

View File

@ -20,7 +20,7 @@ import gobject
import colorsys
from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units
from sugar.graphics import style
from sugar.graphics import xocolor
from sugar import profile
@ -56,7 +56,7 @@ class ActivityIcon(CanvasIcon):
color = self._icon_colors[self._level]
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._pulse_id = 0

View File

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

View File

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

View File

@ -25,21 +25,11 @@ import gobject
import hippo
from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units
from sugar.graphics import style
STANDARD_SIZE = 0
SMALL_SIZE = 1
class IconButton(CanvasIcon, hippo.CanvasItem):
__gtype_name__ = 'SugarIconButton'
__gproperties__ = {
'size' : (int, None, None,
0, 32767, STANDARD_SIZE,
gobject.PARAM_READWRITE)
}
def __init__(self, **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.stroke_color = style.Color("#FFFFFF")
self._set_size(STANDARD_SIZE)
self.connect('activated', self._icon_clicked_cb)
def _set_size(self, size):
if size == SMALL_SIZE:
self.props.box_width = -1
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)
self.props.box_width = style.GRID_CELL_SIZE
self.props.box_height = style.GRID_CELL_SIZE
self.props.size = style.STANDARD_ICON_SIZE
def do_button_press_event(self, event):
if self._active:

View File

@ -93,6 +93,12 @@ DEFAULT_PADDING = zoom(6)
GRID_CELL_SIZE = zoom(75)
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_NORMAL = Font('Bitstream Vera Sans %d' % FONT_SIZE)
FONT_BOLD = Font('Bitstream Vera Sans bold %d' % FONT_SIZE)