From e0cb6dbfdaf1e93543da8907d9ee7ea07d0e8862 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Fri, 04 Mar 2011 20:57:10 +0000 Subject: Add alpha and scale functionality to the icon, can be used in the launcher to do the animation Signed-off-by: Gonzalo Odiard Acked-By: Simon Schampijer --- diff --git a/src/sugar/graphics/icon.py b/src/sugar/graphics/icon.py index 870c49e..72254b6 100644 --- a/src/sugar/graphics/icon.py +++ b/src/sugar/graphics/icon.py @@ -332,6 +332,8 @@ class Icon(gtk.Image): # collected while it's still used if it's a sugar.util.TempFilePath. # See #1175 self._file = None + self._alpha = 1.0 + self._scale = 1.0 gobject.GObject.__init__(self, **kwargs) @@ -420,8 +422,22 @@ class Icon(gtk.Image): (allocation.height - requisition[1]) * yalign) cr = self.window.cairo_create() + + if self._scale != 1.0: + cr.scale(self._scale, self._scale) + + margin = self._buffer.width * (1 - self._scale) / 2 + x, y = x + margin, y + margin + + x = x / self._scale + y = y / self._scale + cr.set_source_surface(surface, x, y) - cr.paint() + + if self._alpha == 1.0: + cr.paint() + else: + cr.paint_with_alpha(self._alpha) def set_xo_color(self, value): """ @@ -524,6 +540,22 @@ class Icon(gtk.Image): badge_name = gobject.property( type=str, getter=get_badge_name, setter=set_badge_name) + def set_alpha(self, value): + if self._alpha != value: + self._alpha = value + self.queue_draw() + + alpha = gobject.property( + type=float, setter=set_alpha) + + def set_scale(self, value): + if self._scale != value: + self._scale = value + self.queue_draw() + + scale = gobject.property( + type=float, setter=set_scale) + class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): @@ -534,6 +566,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._buffer = _IconBuffer() self._palette_invoker = CanvasInvoker() + self._alpha = 1.0 hippo.CanvasBox.__init__(self, **kwargs) @@ -775,8 +808,6 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): None """ - logging.warning( - 'CanvasIcon: the scale parameter is currently unsupported') if self._buffer.scale != value: self._buffer.scale = value self.emit_request_changed() @@ -797,6 +828,14 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): scale = gobject.property( type=float, getter=get_scale, setter=set_scale) + def set_alpha(self, alpha): + if self._alpha != alpha: + self._alpha = alpha + self.emit_request_changed() + + alpha = gobject.property( + type=float, setter=set_alpha) + def set_cache(self, value): """ Parameters -- cgit v0.9.1