mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-13 04:10:13 +00:00
51a0dc303d
2000-02-02 Federico Mena Quintero <federico@helixcode.com> * gdk-pixbuf/io-gif.c (gif_get_lzw): Removed debugging g_print. Thanks to John Sullivan <sullivan@eazel.com> for the patch. * gdk-pixbuf/testpixbuf-drawable.c (configure_cb): Get a new area of the screen when the window is resized. Thanks to David N. Welton <davidw@linuxcare.com> for pointing this out. Misc. cleanups to the rest of the file.
114 lines
3.6 KiB
C
114 lines
3.6 KiB
C
#include <config.h>
|
|
#include <gtk/gtk.h>
|
|
#include <gdk/gdkx.h>
|
|
#include "gdk-pixbuf.h"
|
|
|
|
int close_app(GtkWidget *widget, gpointer data)
|
|
{
|
|
gtk_main_quit();
|
|
return TRUE;
|
|
}
|
|
|
|
int expose_cb(GtkWidget *drawing_area, GdkEventExpose *evt, gpointer data)
|
|
{
|
|
GdkPixbuf *pixbuf;
|
|
|
|
pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),
|
|
"pixbuf");
|
|
if(pixbuf->art_pixbuf->has_alpha)
|
|
{
|
|
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,
|
|
pixbuf->art_pixbuf->pixels +
|
|
(evt->area.y * pixbuf->art_pixbuf->rowstride) +
|
|
(evt->area.x * pixbuf->art_pixbuf->n_channels),
|
|
pixbuf->art_pixbuf->rowstride);
|
|
}
|
|
else
|
|
{
|
|
gdk_draw_rgb_image(drawing_area->window,
|
|
drawing_area->style->black_gc,
|
|
evt->area.x, evt->area.y,
|
|
evt->area.width,
|
|
evt->area.height,
|
|
GDK_RGB_DITHER_NORMAL,
|
|
pixbuf->art_pixbuf->pixels +
|
|
(evt->area.y * pixbuf->art_pixbuf->rowstride) +
|
|
(evt->area.x * pixbuf->art_pixbuf->n_channels),
|
|
pixbuf->art_pixbuf->rowstride);
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
int configure_cb(GtkWidget *drawing_area, GdkEventConfigure *evt, gpointer data)
|
|
{
|
|
GdkPixbuf *pixbuf;
|
|
|
|
pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),
|
|
"pixbuf");
|
|
|
|
g_print("X:%d Y:%d\n", evt->width, evt->height);
|
|
if(evt->width != pixbuf->art_pixbuf->width || evt->height != pixbuf->art_pixbuf->height)
|
|
{
|
|
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;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
GdkWindow *root;
|
|
GtkWidget *window;
|
|
GtkWidget *vbox;
|
|
GtkWidget *drawing_area;
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gtk_init(&argc, &argv);
|
|
gdk_rgb_set_verbose(TRUE);
|
|
gdk_rgb_init();
|
|
|
|
gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
|
|
gtk_widget_set_default_visual(gdk_rgb_get_visual());
|
|
|
|
root = GDK_ROOT_PARENT();
|
|
pixbuf = gdk_pixbuf_get_from_drawable(NULL, root, NULL,
|
|
0, 0, 0, 0, 150, 160);
|
|
|
|
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();
|
|
gtk_drawing_area_size(GTK_DRAWING_AREA(drawing_area),
|
|
pixbuf->art_pixbuf->width,
|
|
pixbuf->art_pixbuf->height);
|
|
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();
|
|
return 0;
|
|
}
|