gtk2/demos/testpixbuf-drawable.c
Owen Taylor 4f1ccca594 Add gdk_rgb_find_color() to get a pixel value using GdkRGB functionality
Sun Jul  2 12:45:50 2000  Owen Taylor  <otaylor@redhat.com>

	* gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel
	value using GdkRGB functionality given GdkColormap and GdkColor.
	(name not final, waiting for inspiration.)

	* gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to
	set the foreground/background of a GC using the GC's colormap
	and GdkRGB. (name not final, waiting for inspiration.)

	* gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from
	gdk_rgb_get_cmap(), put #define in gdkcompat.h.

	* gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for
	gtk_widget_get_visual(), gtk_widget_get_default_visual, etc,
	purely a function of the corresponding colormap. Make
	gtk_widget_set_visual(), etc, noop macros in gtkcompat.h.

	* gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite
	gdk_pixbuf_*create_from_xpm_* in terms of
	gdk_pixbuf_new_from_xpm_data(), move into platform independent
	code.

	* gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take
	advantage of the new draw_rgb_32_image_dithalign.

	* gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added.

	* gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap
	on each created GC.

	* gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap.

	* gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure
	which we initialize from the drawable when the GC is created,
	if the drawable has a colormap.

	* gdk/x11/gdkgc-x11.c: include string.h for memset.

	* gdk/x11/gdkinput-x11.c: include string.h for strlen, etc.

	* gtk/gtklayout.[ch]: Remove unsed configure serial member.
2000-07-02 17:03:21 +00:00

116 lines
3.6 KiB
C

#include <config.h>
#include <gtk/gtk.h>
#include <gdk/x11/gdkx.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(gdk_pixbuf_get_has_alpha (pixbuf))
{
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,
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));
}
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,
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));
}
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 != gdk_pixbuf_get_width (pixbuf) || evt->height != gdk_pixbuf_get_height (pixbuf))
{
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;
}
extern void pixbuf_init();
int main(int argc, char **argv)
{
GdkWindow *root;
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *drawing_area;
GdkPixbuf *pixbuf;
pixbuf_init ();
gtk_init(&argc, &argv);
gdk_rgb_set_verbose(TRUE);
gdk_rgb_init();
gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
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),
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf));
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;
}