From e700ed1e2d027208f2aaed037c52ff9c4d6cc063 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 29 Aug 2007 09:34:56 +0000 Subject: Expose and size allocation fixes. --- (limited to 'sugar') diff --git a/sugar/graphics/icon.py b/sugar/graphics/icon.py index 6d7a4c6..133e256 100644 --- a/sugar/graphics/icon.py +++ b/sugar/graphics/icon.py @@ -17,6 +17,7 @@ import os import re +import math import time import logging @@ -337,18 +338,38 @@ class Icon(gtk.Image): self._buffer.width = width self._buffer.height = height - def do_expose_event(self, event): + def do_size_request(self, requisition): self._sync_image_properties() - surface = self._buffer.get_surface() - if surface is not None: - cr = self.window.cairo_create() - - x = self.allocation.x - y = self.allocation.y + if surface: + requisition[0] = surface.get_width() + requisition[1] = surface.get_height() + elif self._buffer.width and self._buffer.height: + requisition[0] = self._buffer.width + requisition[1] = self._buffer.width + else: + requisition[0] = requisition[1] = 0 - cr.set_source_surface(surface, x, y) - cr.paint() + def do_expose_event(self, event): + self._sync_image_properties() + surface = self._buffer.get_surface() + if surface is None: + return + + xpad, ypad = self.get_padding() + xalign, yalign = self.get_alignment() + requisition = self.get_child_requisition() + if self.get_direction != gtk.TEXT_DIR_LTR: + xalign = 1.0 - xalign + + x = math.floor(self.allocation.x + xpad + + (self.allocation.width - requisition[0]) * xalign) + y = math.floor(self.allocation.y + ypad + + (self.allocation.height - requisition[1]) * yalign) + + cr = self.window.cairo_create() + cr.set_source_surface(surface, x, y) + cr.paint() def do_set_property(self, pspec, value): if pspec.name == 'xo-color': -- cgit v0.9.1