Ticket #4343: 0003-CellRendererIcon-more-improvement-in-point_in_cell_r.patch

File 0003-CellRendererIcon-more-improvement-in-point_in_cell_r.patch, 2.3 KB (added by manuq, 8 years ago)
  • src/sugar3/graphics/icon.py

    From 6f74ab94aae28ffc7a4cd1a2559f4908dfb6b7fb Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Wed, 20 Mar 2013 22:49:34 -0300
    Subject: [PATCH 3/5] CellRendererIcon: more improvement in
     point_in_cell_renderer - SL #4343
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    Cache the absolute x and the width of the cell, and use this
    information as a gross filter at the beginning of the
    point_in_cell_renderer method.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/sugar3/graphics/icon.py | 17 ++++++++++++++++-
     1 file changed, 16 insertions(+), 1 deletion(-)
    
    diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
    index 7c428b7..57c6d4e 100644
    a b class CellRendererIcon(Gtk.CellRenderer): 
    761761        self._prelit_stroke_color = None
    762762        self._active_state = False
    763763        self._palette_invoker = CellRendererInvoker()
     764        self._x = None
     765        self._width = None
    764766
    765767        Gtk.CellRenderer.__init__(self)
    766768
    class CellRendererIcon(Gtk.CellRenderer): 
    887889        if x is None and y is None:
    888890            x, y = tree_view.get_pointer()
    889891            x, y = tree_view.convert_widget_to_bin_window_coords(x, y)
     892
     893        # Horizontal filter.
     894        if self._x is not None:
     895            if x < self._x or x > self._x + self._width:
     896                return False
     897
    890898        pos = tree_view.get_path_at_pos(int(x), int(y))
    891899        if pos is None:
    892900            return False
    893901
    894         path_, column, x, y_ = pos
     902        path, column, x, y_ = pos
    895903        result = column.cell_get_position(self)
    896904
    897905        # If this cell was not found in the column:
    class CellRendererIcon(Gtk.CellRenderer): 
    899907            return False
    900908
    901909        cell_x, cell_width = result
     910
     911        # Cache the absolute x and width of this cell if not done yet.
     912        if self._x is None:
     913            column_area = tree_view.get_cell_area(path, column)
     914            self._x = column_area.x + cell_x
     915            self._width = cell_width
     916
    902917        for cell_renderer in column.get_cells():
    903918            if cell_renderer == self:
    904919                if x > cell_x and x < (cell_x + cell_width):