Window shape and back_pixmap



Hi all,

this message gather issues from two different threads posted in last two weeks, so I decided to post a completely new one.

The problem:
  - drawing a custom shaped window with a background pixmap.

My current (partially working) solution:

int main (int argc, char * argv[])
{
  GtkWidget * window1;
  ...
  GdkBitmap * mask;
  GdkPixmap * map;
  GdkPixbuf * pbuf;
        
  gtk_set_locale ();
  gtk_init (&argc, &argv);
        
  ... /* creating a simple window with an exit button */

  gtk_widget_show (winmain);
        
  /* questo pezzo di codice serve a creare una finestra
   * con una forma non rettangolare
   */
  pbuf = gdk_pixbuf_new_from_file
                 ("/home/carlo/Projects/shape/sfondo.png", NULL);
  gdk_pixbuf_render_pixmap_and_mask (pbuf, &map, &mask, 1);
  gdk_window_shape_combine_mask (winmain->window, mask, 0, 0);
  gdk_window_set_back_pixmap (winmain->window, map, FALSE);

  gtk_main ();
  return 0;
}

It works well for the part related to the shape, but does not show (except for some msec) the background image. It looks like if the theme engine has got control at the end of the rendering chain, overriding its own settings on the widget.

In order to see what were happening, I tried to hook the window expose event:

gboolean on_winmain_expose_event (GtkWidget *      widget,
                                  GdkEventExpose * event,
                                  gpointer         user_data)
{
  GdkBitmap * mask;
  GdkPixmap * map;
  GdkPixbuf * pbuf;

  pbuf = gdk_pixbuf_new_from_file
                 ("/home/carlo/Projects/shape/sfondo.png", NULL);
  gdk_pixbuf_render_pixmap_and_mask (pbuf, &map, &mask, 1);
  gdk_window_shape_combine_mask (winmain->window, mask, 0, 0);
  gdk_window_set_back_pixmap (winmain->window, map, FALSE);

  return TRUE;
         ^^^^
}

And now the background image is shown correctly, but the default expose-event handler is stopped and the button is no more shown (even if it is at its own place and accepting clicks).

Any hint?

PS: it works the same way both under linux and windowsxp.





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