1999-12-02 20:44:43 +00:00
|
|
|
#include <config.h>
|
1999-11-13 17:28:11 +00:00
|
|
|
#include <gtk/gtk.h>
|
2001-03-19 19:37:59 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
2000-06-22 00:05:44 +00:00
|
|
|
#include <gdk/x11/gdkx.h>
|
2001-03-19 19:37:59 +00:00
|
|
|
#elif defined (GDK_WINDOWING_WIN32)
|
|
|
|
#include <gdk/win32/gdkwin32.h>
|
|
|
|
#endif
|
1999-11-13 17:28:11 +00:00
|
|
|
|
2000-02-02 05:47:57 +00:00
|
|
|
int close_app(GtkWidget *widget, gpointer data)
|
1999-11-13 17:28:11 +00:00
|
|
|
{
|
|
|
|
gtk_main_quit();
|
2000-02-02 05:47:57 +00:00
|
|
|
return TRUE;
|
1999-11-13 17:28:11 +00:00
|
|
|
}
|
|
|
|
|
2000-02-02 05:47:57 +00:00
|
|
|
int expose_cb(GtkWidget *drawing_area, GdkEventExpose *evt, gpointer data)
|
1999-11-13 17:28:11 +00:00
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),
|
|
|
|
"pixbuf");
|
2000-04-11 07:03:25 +00:00
|
|
|
if(gdk_pixbuf_get_has_alpha (pixbuf))
|
1999-11-13 17:28:11 +00:00
|
|
|
{
|
|
|
|
gdk_draw_rgb_32_image(drawing_area->window,
|
|
|
|
drawing_area->style->black_gc,
|
|
|
|
evt->area.x, evt->area.y,
|
|
|
|
evt->area.width,
|
|
|
|
evt->area.height,
|
|
|
|
GDK_RGB_DITHER_MAX,
|
2000-04-11 07:03:25 +00:00
|
|
|
gdk_pixbuf_get_pixels (pixbuf) +
|
|
|
|
(evt->area.y * gdk_pixbuf_get_rowstride (pixbuf)) +
|
|
|
|
(evt->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
|
|
|
|
gdk_pixbuf_get_rowstride (pixbuf));
|
1999-11-13 17:28:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_draw_rgb_image(drawing_area->window,
|
2000-02-02 05:47:57 +00:00
|
|
|
drawing_area->style->black_gc,
|
|
|
|
evt->area.x, evt->area.y,
|
|
|
|
evt->area.width,
|
|
|
|
evt->area.height,
|
|
|
|
GDK_RGB_DITHER_NORMAL,
|
2000-04-11 07:03:25 +00:00
|
|
|
gdk_pixbuf_get_pixels (pixbuf) +
|
|
|
|
(evt->area.y * gdk_pixbuf_get_rowstride (pixbuf)) +
|
|
|
|
(evt->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
|
|
|
|
gdk_pixbuf_get_rowstride (pixbuf));
|
1999-11-13 17:28:11 +00:00
|
|
|
}
|
2000-02-02 05:47:57 +00:00
|
|
|
return FALSE;
|
1999-11-13 17:28:11 +00:00
|
|
|
}
|
2000-01-13 07:24:49 +00:00
|
|
|
|
2000-02-02 05:47:57 +00:00
|
|
|
int configure_cb(GtkWidget *drawing_area, GdkEventConfigure *evt, gpointer data)
|
1999-11-13 17:28:11 +00:00
|
|
|
{
|
2000-01-13 07:24:49 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
1999-11-13 17:28:11 +00:00
|
|
|
|
|
|
|
pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),
|
|
|
|
"pixbuf");
|
|
|
|
|
|
|
|
g_print("X:%d Y:%d\n", evt->width, evt->height);
|
2000-04-11 07:03:25 +00:00
|
|
|
if(evt->width != gdk_pixbuf_get_width (pixbuf) || evt->height != gdk_pixbuf_get_height (pixbuf))
|
2000-02-02 05:47:57 +00:00
|
|
|
{
|
|
|
|
GdkWindow *root;
|
|
|
|
GdkPixbuf *new_pixbuf;
|
|
|
|
|
|
|
|
root = GDK_ROOT_PARENT();
|
|
|
|
new_pixbuf = gdk_pixbuf_get_from_drawable(NULL, root, NULL,
|
|
|
|
0, 0, 0, 0, evt->width, evt->height);
|
|
|
|
gtk_object_set_data(GTK_OBJECT(drawing_area), "pixbuf", new_pixbuf);
|
|
|
|
gdk_pixbuf_unref(pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
1999-11-13 17:28:11 +00:00
|
|
|
}
|
|
|
|
|
2000-06-21 20:47:22 +00:00
|
|
|
extern void pixbuf_init();
|
|
|
|
|
1999-11-13 17:28:11 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
GdkWindow *root;
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *drawing_area;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
2000-06-21 20:47:22 +00:00
|
|
|
pixbuf_init ();
|
|
|
|
|
1999-11-13 17:28:11 +00:00
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
gdk_rgb_set_verbose(TRUE);
|
|
|
|
gdk_rgb_init();
|
|
|
|
|
|
|
|
gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
|
|
|
|
|
2000-02-02 05:47:57 +00:00
|
|
|
root = GDK_ROOT_PARENT();
|
1999-12-09 00:43:53 +00:00
|
|
|
pixbuf = gdk_pixbuf_get_from_drawable(NULL, root, NULL,
|
|
|
|
0, 0, 0, 0, 150, 160);
|
1999-11-13 17:28:11 +00:00
|
|
|
|
|
|
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
|
|
|
|
GTK_SIGNAL_FUNC(close_app), NULL);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(window), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC(close_app), NULL);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), vbox);
|
|
|
|
|
|
|
|
drawing_area = gtk_drawing_area_new();
|
2001-02-03 01:09:41 +00:00
|
|
|
gtk_widget_set_usize(GTK_WIDGET(drawing_area),
|
|
|
|
gdk_pixbuf_get_width (pixbuf),
|
|
|
|
gdk_pixbuf_get_height (pixbuf));
|
1999-11-13 17:28:11 +00:00
|
|
|
gtk_signal_connect(GTK_OBJECT(drawing_area), "expose_event",
|
|
|
|
GTK_SIGNAL_FUNC(expose_cb), NULL);
|
|
|
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(drawing_area), "configure_event",
|
|
|
|
GTK_SIGNAL_FUNC(configure_cb), NULL);
|
|
|
|
gtk_object_set_data(GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), drawing_area, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
gtk_widget_show_all(window);
|
|
|
|
gtk_main();
|
2000-01-21 22:54:44 +00:00
|
|
|
return 0;
|
1999-11-13 17:28:11 +00:00
|
|
|
}
|