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)
51 pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
53 if (pixbuf->art_pixbuf->has_alpha){
54 gdk_draw_rgb_32_image (drawing_area->window,
55 drawing_area->style->black_gc,
56 event->area.x, event->area.y,
60 pixbuf->art_pixbuf->pixels
61 + (event->area.y * pixbuf->art_pixbuf->rowstride)
62 + (event->area.x * pixbuf->art_pixbuf->n_channels),
63 pixbuf->art_pixbuf->rowstride);
65 gdk_draw_rgb_image (drawing_area->window,
66 drawing_area->style->white_gc,
67 event->area.x, event->area.y,
70 GDK_RGB_DITHER_NORMAL,
71 pixbuf->art_pixbuf->pixels
72 + (event->area.y * pixbuf->art_pixbuf->rowstride)
73 + (event->area.x * pixbuf->art_pixbuf->n_channels),
74 pixbuf->art_pixbuf->rowstride);
78 config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
80 GdkPixBuf *pixbuf, *spb;
82 pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
84 g_print("X:%d Y:%d\n", event->width, event->height);
86 if (((event->width) != (pixbuf->art_pixbuf->width)) ||
87 ((event->height) != (pixbuf->art_pixbuf->height)))
88 gdk_pixbuf_scale(pixbuf, event->width, event->height);
93 new_testrgb_window (GdkPixBuf *pixbuf)
98 GtkWidget *drawing_area;
101 w = pixbuf->art_pixbuf->width;
102 h = pixbuf->art_pixbuf->height;
104 window = gtk_widget_new (gtk_window_get_type (),
105 "GtkObject::user_data", NULL,
106 "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
107 "GtkWindow::title", "testrgb",
108 "GtkWindow::allow_shrink", TRUE,
110 gtk_signal_connect (GTK_OBJECT (window), "destroy",
111 (GtkSignalFunc) quit_func, NULL);
113 vbox = gtk_vbox_new (FALSE, 0);
115 drawing_area = gtk_drawing_area_new ();
117 gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), w, h);
118 gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
120 gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
121 GTK_SIGNAL_FUNC(expose_func), NULL);
122 gtk_signal_connect (GTK_OBJECT(drawing_area), "configure_event",
123 GTK_SIGNAL_FUNC (config_func), NULL);
125 gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
127 gtk_widget_show (drawing_area);
129 button = gtk_button_new_with_label ("Quit");
130 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
131 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
132 (GtkSignalFunc) gtk_widget_destroy,
133 GTK_OBJECT (window));
135 gtk_widget_show (button);
137 gtk_container_add (GTK_CONTAINER (window), vbox);
138 gtk_widget_show (vbox);
140 gtk_widget_show (window);
144 main (int argc, char **argv)
147 int found_valid = FALSE;
151 gtk_init (&argc, &argv);
153 gdk_rgb_set_verbose (TRUE);
157 gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
158 gtk_widget_set_default_visual (gdk_rgb_get_visual ());
161 for (i = 1; i < argc; i++)
163 pixbuf = gdk_pixbuf_load_image (argv[i]);
167 new_testrgb_window (pixbuf);