Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBenjamin Berg <benjamin@sipsolutions.net>2009-02-10 16:58:02 (GMT)
committer Benjamin Berg <benjamin@sipsolutions.net>2009-02-10 16:58:02 (GMT)
commitb39ed70b11b377016527624d3779f36922b3a2c3 (patch)
tree3c880717d3d298ef049df3b505779f343c9a319a /src
parent474b2c34766614580899a21788faad6d0cad3ef1 (diff)
Added an option to set the background color of CanvasIcon. Then a RGB cache can be used.
Diffstat (limited to 'src')
-rw-r--r--src/sugar/graphics/icon.py68
1 files changed, 62 insertions, 6 deletions
diff --git a/src/sugar/graphics/icon.py b/src/sugar/graphics/icon.py
index 1608bac..f901519 100644
--- a/src/sugar/graphics/icon.py
+++ b/src/sugar/graphics/icon.py
@@ -83,6 +83,7 @@ class _IconBuffer(object):
self.icon_size = None
self.file_name = None
self.fill_color = None
+ self.background_color = None
self.stroke_color = None
self.badge_name = None
self.width = None
@@ -91,9 +92,14 @@ class _IconBuffer(object):
self.scale = 1.0
def _get_cache_key(self, sensitive):
+ if self.background_color is None:
+ color = None
+ else:
+ color = (self.background_color.red, self.background_color.green,
+ self.background_color.blue)
return (self.icon_name, self.file_name, self.fill_color,
self.stroke_color, self.badge_name, self.width, self.height,
- sensitive)
+ color, sensitive)
def _load_svg(self, file_name):
entities = {}
@@ -260,9 +266,16 @@ class _IconBuffer(object):
padding = badge_info.icon_padding
width, height = self._get_size(icon_width, icon_height, padding)
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
+ if self.background_color is None:
+ surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
+ context = cairo.Context(surface)
+ else:
+ surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
+ context = cairo.Context(surface)
+ context = gtk.gdk.CairoContext(context)
+ context.set_source_color(self.background_color)
+ context.paint()
- context = cairo.Context(surface)
context.scale(float(width) / (icon_width + padding * 2),
float(height) / (icon_height + padding * 2))
context.save()
@@ -499,6 +512,18 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
self.connect('destroy', self.__destroy_cb)
+ def _emit_paint_needed_icon_area(self):
+ surface = self._buffer.get_surface()
+ if surface:
+ width, height = self.get_allocation()
+ s_width = surface.get_width()
+ s_height = surface.get_height()
+
+ x = (width - s_width) / 2
+ y = (height - s_height) / 2
+
+ self.emit_paint_needed(x, y, s_width, s_height)
+
def __destroy_cb(self, icon):
if self._palette_invoker is not None:
self._palette_invoker.detach()
@@ -580,7 +605,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
"""
if self._buffer.xo_color != value:
self._buffer.xo_color = value
- self.emit_paint_needed(0, 0, -1, -1)
+ self._emit_paint_needed_icon_area()
xo_color = gobject.property(
type=object, getter=None, setter=set_xo_color)
@@ -598,7 +623,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
"""
if self._buffer.fill_color != value:
self._buffer.fill_color = value
- self.emit_paint_needed(0, 0, -1, -1)
+ self._emit_paint_needed_icon_area()
def get_fill_color(self):
"""
@@ -629,7 +654,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
"""
if self._buffer.stroke_color != value:
self._buffer.stroke_color = value
- self.emit_paint_needed(0, 0, -1, -1)
+ self._emit_paint_needed_icon_area()
def get_stroke_color(self):
"""
@@ -647,6 +672,37 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
stroke_color = gobject.property(
type=object, getter=get_stroke_color, setter=set_stroke_color)
+ def set_background_color(self, value):
+ """
+ Parameters
+ ----------
+ value:
+
+ Returns
+ -------
+ None
+
+ """
+ if self._buffer.background_color != value:
+ self._buffer.background_color = value
+ self.emit_paint_needed(0, 0, -1, -1)
+
+ def get_background_color(self):
+ """
+ Parameters
+ ----------
+ None
+
+ Returns
+ -------
+ fill color :
+
+ """
+ return self._buffer.background_color
+
+ background_color = gobject.property(
+ type=object, getter=get_background_color, setter=set_background_color)
+
def set_size(self, value):
"""
Parameters