Re: Draw on top of a window

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

 



Hi,

Thanks.
Actually I tried return TRUE before, but it causes bottom_image to never be drawn.
What I want is top_image on top of bottom_image.

Richard


On 03/12/2010 10:55 AM, Lucas Hermann Negri wrote:
On Thu, Mar 11, 2010 at 11:41 PM, Richard Kung <richardkung@xxxxxxxxxx> wrote:
  
Hi,

I want to use cairo to draw on top of a window but don't know how to achieve
it.
Below is my code.
bottom_image is always on top of top_image.
Any suggestion for beginners is welcome.

Richard

#include <cairo.h>
#include <gtk/gtk.h>

cairo_surface_t *top_image;
GtkWidget *bottom_image;

static gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event,
gpointer data)
{
  cairo_t *cr;
  cr = gdk_cairo_create(widget->window);
  cairo_set_source_surface(cr, top_image, 0, 0);
  cairo_paint(cr);
  cairo_destroy(cr);

  return FALSE;
}

int main(int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init(&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  top_image = cairo_image_surface_create_from_png("top.png");
  bottom_image  = gtk_image_new_from_file("bottom.png");
  gtk_container_add(GTK_CONTAINER(window), bottom_image);

  g_signal_connect(window, "expose-event", G_CALLBACK (on_expose_event),
NULL);
  g_signal_connect(window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  gtk_widget_set_app_paintable(window, TRUE);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
  gtk_widget_show_all(window);
  gtk_main();

  cairo_surface_destroy(top_image);
  return 0;
}


_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list


    
Your callback should return TRUE, to indicate that the event shouldn't
be propagated further.

  

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux