Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#3872 closed defect (fixed)

CellRendererIcon has a bad clipping rectangle

Reported by: manuq Owned by: manuq
Priority: Unspecified by Maintainer Milestone:
Component: Sugar Version: Git as of bugdate
Severity: Blocker Keywords:
Cc: erikos Distribution/OS: Unspecified
Bug Status: Assigned

Description

As a consequence is not being displayed correctly. Removing the clipping line makes the icon appear again:

diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
index f3bcb06..41e8ebb 100644
--- a/src/sugar3/graphics/icon.py
+++ b/src/sugar3/graphics/icon.py
@@ -854,8 +854,6 @@ class CellRendererIcon(Gtk.CellRenderer):
         y = cell_area.y + yoffset
 
         cr.set_source_surface(surface, math.floor(x), math.floor(y))
-        cr.rectangle(cell_area.x, cell_area.y, cell_area.width,
-                     cell_area.height)
         cr.paint()

But the question is if we should clip the paint in GTK3 as we did in GTK2, and if so, how to do it. Clipping is always better for performance.

pygtk provided a expose_area parameter to the render method that according to the documentation was a clip rectangle, and sugar was calling cr.rectangle() with it before doing the paint.

GTK3 doesn't seem to provide that clip rectangle. The documentation talks about three rectangle areas, but the API shows two and doesn't mention clipping.

Change History (6)

comment:1 Changed 12 years ago by erikos

  • Bug Status changed from Unconfirmed to Assigned
  • Severity changed from Unspecified to Blocker

I just had a look at gtk_cell_renderer_render in GTK+, and they seem to use the background area for the clipping.

diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
index f3bcb06..aa149a0 100644
--- a/src/sugar3/graphics/icon.py
+++ b/src/sugar3/graphics/icon.py
@@ -854,8 +854,9 @@ class CellRendererIcon(Gtk.CellRenderer):
         y = cell_area.y + yoffset
 
         cr.set_source_surface(surface, math.floor(x), math.floor(y))
-        cr.rectangle(cell_area.x, cell_area.y, cell_area.width,
-                     cell_area.height)
+        cr.rectangle(background_area.x, background_area.y, background_area.width,
+                     background_area.height)
+        cr.clip()
         cr.paint()

This seems to work, but we should probably look a bit more closely.

comment:2 Changed 12 years ago by manuq

Just adding the clip call makes it work:

diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
index f3bcb06..9008f3f 100644
--- a/src/sugar3/graphics/icon.py
+++ b/src/sugar3/graphics/icon.py
@@ -856,6 +856,7 @@ class CellRendererIcon(Gtk.CellRenderer):
         cr.set_source_surface(surface, math.floor(x), math.floor(y))
         cr.rectangle(cell_area.x, cell_area.y, cell_area.width,
                      cell_area.height)
+        cr.clip()
         cr.paint()

comment:3 Changed 12 years ago by manuq

Note that if we don't call clip the rectangle is not applied. To test, set a half-width rectangle like this and run the cellrenderericon.py testcase. If clip is called you can see half star, otherwise you'll see the entire star.

        cr.rectangle(cell_area.x, cell_area.y, cell_area.width / 2,
                     cell_area.height)

comment:4 Changed 12 years ago by erikos

  • Resolution set to fixed
  • Status changed from new to closed

comment:5 Changed 11 years ago by dnarvaez

  • Component changed from sugar-toolkit-gtk3 to Sugar

comment:6 Changed 11 years ago by dnarvaez

  • Milestone 0.98 deleted

Milestone 0.98 deleted

Note: See TracTickets for help on using tickets.