I've done this simple app in Gtk, just to test things out... I come from swing so redefining a draw event function is normal for me... Anyway seems not to work:
#include <gtk-2.0/gtk/gtk.h>
#include <gtk-2.0/gdk-pixbuf/gdk-pixbuf.h>
#include <stdlib.h>
#include<string.h>
#include<stdio.h>
#include <iostream>
GdkPixbuf *imm;
void destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}
gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event,
gpointer data) {
gdk_draw_pixbuf((GdkDrawable*) widget, widget->style->white_gc, imm, 0, 0,
0, 0, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
return FALSE;
}
int main(int argc, char** argv) {
char* filename = new char[1000];
GError *error = NULL;
GtkWidget *window;
gtk_set_locale();
gtk_init(&argc, &argv);
if (argv[1] == NULL) {
std::cout << "Err.";
return -1;
}
strcpy(filename, argv[1]);
imm = gdk_pixbuf_new_from_file(filename, &error);
if (!imm) {
std::cout << "err closing";
return 0;
}
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request((GtkWidget*) window, 500, 350);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
g_signal_connect(window, "expose-event",
G_CALLBACK(on_expose_event), NULL);
gtk_container_set_border_width(GTK_CONTAINER (window), 10);
gtk_widget_show(window);
gtk_main();
return 0;
}
..in fact at runtinme says (on line gdk_draw_pixbuf(....)):
(cConvolve:5011): Gdk-CRITICAL **: gdk_draw_pixbuf: assertion `GDK_IS_DRAWABLE (drawable)' failed
is it because the pixbuf is not good??? Or is it because I can't draw to the window like this?