From 3a6427cdc64d1fc3854f77a6120ab7ee19edb89b Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 7 May 2014 09:00:21 -0300 Subject: [PATCH 1/3] CellRendererIcon: improve calculation in do_render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a more efficient method to check if the pointer is inside the cell, because we have the cell_area in the do_render method. Signed-off-by: Manuel Quiñones Signed-off-by: Gonzalo Odiard --- src/sugar3/graphics/icon.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index c9a11026..3d7e281a 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -983,7 +983,14 @@ class CellRendererIcon(Gtk.CellRenderer): context.save() context.add_class("sugar-icon-cell") - pointer_inside = self._point_in_cell_renderer(widget) + def is_pointer_inside(): + # widget is the treeview + x, y = widget.get_pointer() + x, y = widget.convert_widget_to_bin_window_coords(x, y) + return ((cell_area.x <= x <= cell_area.x + cell_area.width) + and (cell_area.y <= y <= cell_area.y + cell_area.height)) + + pointer_inside = is_pointer_inside() # The context will have prelight state if the mouse pointer is # in the entire row, but we want that state if the pointer is From f08757d75fbc09e0f4d16ff42611aac9d7804c77 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 7 May 2014 09:04:09 -0300 Subject: [PATCH 2/3] CellRendererIcon: remove unused frame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The white frame is not visible over the white background. Signed-off-by: Manuel Quiñones --- src/sugar3/graphics/icon.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 3d7e281a..a708f8bb 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -1006,9 +1006,6 @@ class CellRendererIcon(Gtk.CellRenderer): context, cr, background_area.x, background_area.y, background_area.width, background_area.height) - Gtk.render_frame(context, cr, background_area.x, background_area.y, - background_area.width, background_area.height) - if self._xo_color is not None: stroke_color = self._xo_color.get_stroke_color() fill_color = self._xo_color.get_fill_color() From d9e6fa68135d81776c039a9f9063d26a5b6509b4 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 7 May 2014 09:07:36 -0300 Subject: [PATCH 3/3] CellRendererIcon: cache offsets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of calculating them on each render. The cache is removed when the size is changed. Signed-off-by: Manuel Quiñones --- src/sugar3/graphics/icon.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index a708f8bb..fc798ee7 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -837,6 +837,7 @@ class CellRendererIcon(Gtk.CellRenderer): self._prelit_stroke_color = None self._active_state = False self._palette_invoker = CellRendererInvoker() + self._cached_offsets = None Gtk.CellRenderer.__init__(self) @@ -924,6 +925,8 @@ class CellRendererIcon(Gtk.CellRenderer): self._buffer.width = value self._buffer.height = value + self._cached_offsets = None + size = GObject.property(type=object, setter=set_size) def do_get_size(self, widget, cell_area, x_offset=None, y_offset=None, @@ -942,9 +945,17 @@ class CellRendererIcon(Gtk.CellRenderer): xoffset = max(xoffset * (cell_area.width - width), 0) yoffset = max(self.props.yalign * (cell_area.height - height), 0) + self._cached_offsets = xoffset, yoffset return xoffset, yoffset, width, height + def _get_offsets(self, widget, cell_area): + if self._cached_offsets is not None: + return self._cached_offsets + + xoffset, yoffset, width_, height_ = self.do_get_size(widget, cell_area) + return xoffset, yoffset + def do_activate(self, event, widget, path, background_area, cell_area, flags): pass @@ -1033,7 +1044,7 @@ class CellRendererIcon(Gtk.CellRenderer): if surface is None: return - xoffset, yoffset, width_, height_ = self.do_get_size(widget, cell_area) + xoffset, yoffset = self._get_offsets(widget, cell_area) x = cell_area.x + xoffset y = cell_area.y + yoffset