Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2011-03-23 23:37:03 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2011-08-17 15:13:10 (GMT)
commit507dfecc095d8bfb6b832698b2a66c205562cd7f (patch)
tree69790b2d1483a0743a549d2f9513873ed9c25e7b
parent0082e10f8ebc201d0837dc67ba739d9079903e45 (diff)
Add alpha and scale functionality to the icon, can be used in the launcher to do the animation - v2
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org> Acked-By: Simon Schampijer <simon@laptop.org>
-rw-r--r--src/sugar/graphics/icon.py50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/sugar/graphics/icon.py b/src/sugar/graphics/icon.py
index 83a80d9..62a79f6 100644
--- a/src/sugar/graphics/icon.py
+++ b/src/sugar/graphics/icon.py
@@ -328,6 +328,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)
@@ -416,8 +418,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):
"""
@@ -520,6 +536,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):
@@ -530,6 +562,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
self._buffer = _IconBuffer()
self._palette_invoker = CanvasInvoker()
+ self._alpha = 1.0
hippo.CanvasBox.__init__(self, **kwargs)
@@ -771,8 +804,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()
@@ -793,6 +824,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_paint_needed(0, 0, -1, -1)
+
+ alpha = gobject.property(
+ type=float, setter=set_alpha)
+
def set_cache(self, value):
"""
Parameters
@@ -874,7 +913,10 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
y = (height - surface.get_height()) / 2
cr.set_source_surface(surface, x, y)
- cr.paint()
+ if self._alpha == 1.0:
+ cr.paint()
+ else:
+ cr.paint_with_alpha(self._alpha)
def do_get_content_width_request(self):
"""