Re: Why does Gtk::Image::set() not work with a Cairo::Surface?



The description of Cairo::ImageSurface, http://cairographics.org/documentation/cairomm/reference/classCairo_1_1ImageSurface.html#_details, says "if you modify anything and later want to continue to draw to the surface with cairo, you must let cairo know via Cairo::Surface::mark_dirty()."

I added
  surface->mark_dirty();
before
  m_face_image.set(surface);
and suddenly it works.

Kjell

Den 2015-08-01 09:50, Adam Nielsen skrev:
Interesting, thanks for checking.  Here is a patch for examplewindow.cc
that demonstrates the problem.  Must be something to do with the way the
surface is created?

Thanks again,
Adam.


diff -Nru gtk.orig/examplewindow.cc gtk/examplewindow.cc
--- gtk.orig/examplewindow.cc   2015-08-01 17:34:59.000000000 +1000
+++ gtk/examplewindow.cc        2015-08-01 17:44:54.682482453 +1000
@@ -14,6 +14,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#include <cairomm/cairomm.h>
 #include "examplewindow.h"
 
 ExampleWindow::ExampleWindow()
@@ -31,7 +32,19 @@
   settings->property_gtk_application_prefer_dark_theme().set_value(true);
 
   // Face
-  m_face_image.set_from_icon_name("face-cool", Gtk::ICON_SIZE_DIALOG);
+  auto surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 16, 16);
+
+  // Draw something onto the Cairo surface so you can see whether it worked
+  auto content = surface->get_data();
+  for (int i = 0; i < 16*16*4; i+=4) {
+    content[i+0] = content[i+1] = content[i+2] = ((i/4)%16)<<4;
+    content[i+3] = 255;
+  }
+  // Set the Cairo surface - this doesn't work
+  m_face_image.set(surface);
+  // Convert the Cairo surface to a GDK pixbuf and set that, this does work
+  //auto gdkimg = Gdk::Pixbuf::create(surface, 0, 0, 16, 16);
+  //m_face_image.set(gdkimg);
 
   // Center widget layout
   m_prev_button.set_image_from_icon_name("go-previous-symbolic",
   Gtk::ICON_SIZE_BUTTON, true);




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]