2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 /* Note: these #includes differ slightly from the testrgb.c file included
30 in the GdkRgb release. */
32 /* For gettimeofday */
38 #include "gdk-pixbuf.h"
41 quit_func (GtkWidget *widget, gpointer dummy)
46 expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
50 pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
52 if (pixbuf->art_pixbuf->has_alpha){
53 gdk_draw_rgb_32_image (drawing_area->window,
54 drawing_area->style->black_gc,
56 pixbuf->art_pixbuf->width,
57 pixbuf->art_pixbuf->height,
58 GDK_RGB_DITHER_NORMAL,
59 pixbuf->art_pixbuf->pixels,
60 pixbuf->art_pixbuf->rowstride);
62 gdk_draw_rgb_image (drawing_area->window,
63 drawing_area->style->white_gc,
65 pixbuf->art_pixbuf->width,
66 pixbuf->art_pixbuf->height,
67 GDK_RGB_DITHER_NORMAL,
68 pixbuf->art_pixbuf->pixels,
69 pixbuf->art_pixbuf->rowstride);
73 config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
75 GdkPixBuf *pixbuf, *spb;
77 pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
79 g_print("X:%d Y:%d\n", event->width, event->height);
81 if (((event->width) != (pixbuf->art_pixbuf->width)) ||
82 ((event->height) != (pixbuf->art_pixbuf->height))) {
83 spb = gdk_pixbuf_scale(pixbuf, event->width, event->height);
84 gdk_pixbuf_free (pixbuf);
85 gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", spb);
90 new_testrgb_window (GdkPixBuf *pixbuf)
95 GtkWidget *drawing_area;
98 w = pixbuf->art_pixbuf->width;
99 h = pixbuf->art_pixbuf->height;
101 window = gtk_widget_new (gtk_window_get_type (),
102 "GtkObject::user_data", NULL,
103 "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
104 "GtkWindow::title", "testrgb",
105 "GtkWindow::allow_shrink", TRUE,
107 gtk_signal_connect (GTK_OBJECT (window), "destroy",
108 (GtkSignalFunc) quit_func, NULL);
110 vbox = gtk_vbox_new (FALSE, 0);
112 drawing_area = gtk_drawing_area_new ();
114 gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), w, h);
115 gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
117 gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
118 GTK_SIGNAL_FUNC(expose_func), NULL);
119 gtk_signal_connect (GTK_OBJECT(drawing_area), "configure_event",
120 GTK_SIGNAL_FUNC (config_func), NULL);
122 gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
124 gtk_widget_show (drawing_area);
126 button = gtk_button_new_with_label ("Quit");
127 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
128 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
129 (GtkSignalFunc) gtk_widget_destroy,
130 GTK_OBJECT (window));
132 gtk_widget_show (button);
134 gtk_container_add (GTK_CONTAINER (window), vbox);
135 gtk_widget_show (vbox);
137 gtk_widget_show (window);
141 main (int argc, char **argv)
144 int found_valid = FALSE;
148 gtk_init (&argc, &argv);
150 gdk_rgb_set_verbose (TRUE);
154 gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
155 gtk_widget_set_default_visual (gdk_rgb_get_visual ());
158 for (i = 1; i < argc; i++) {
160 pixbuf = gdk_pixbuf_load_image (argv[i]);
163 new_testrgb_window (pixbuf);