]> Pileus Git - ~andy/gtk/blob - demos/testpixbuf.c
reverted the expose everything changes, I'm not sure why these went in.
[~andy/gtk] / demos / testpixbuf.c
1
2 /* GTK - The GIMP Toolkit
3  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 /*
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/. 
26  */
27
28
29 /* Note: these #includes differ slightly from the testrgb.c file included
30    in the GdkRgb release. */
31
32 /* For gettimeofday */
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <string.h>
36
37 #include <gtk/gtk.h>
38 #include "gdk-pixbuf.h"
39
40 static void
41 quit_func (GtkWidget *widget, gpointer dummy)
42 {
43   gtk_main_quit ();
44 }
45
46 expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
47 {
48   GdkPixBuf *pixbuf;
49   gint x1, y1, x2, y2;
50
51   pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
52
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, 
57                            event->area.width, 
58                            event->area.height,
59                            GDK_RGB_DITHER_MAX, 
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);
64   }else{
65     gdk_draw_rgb_image (drawing_area->window,
66                         drawing_area->style->white_gc,
67                         event->area.x, event->area.y, 
68                         event->area.width, 
69                         event->area.height,
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);
75   }
76 }  
77
78 config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
79 {
80     GdkPixBuf *pixbuf, *spb;
81     
82     pixbuf = (GdkPixBuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
83
84     g_print("X:%d Y:%d\n", event->width, event->height);
85
86     if (((event->width) != (pixbuf->art_pixbuf->width)) ||
87         ((event->height) != (pixbuf->art_pixbuf->height))) 
88         gdk_pixbuf_scale(pixbuf, event->width, event->height);
89
90 }
91
92 void
93 new_testrgb_window (GdkPixBuf *pixbuf)
94 {
95   GtkWidget *window;
96   GtkWidget *vbox;
97   GtkWidget *button;
98   GtkWidget *drawing_area;
99   gint w, h;
100  
101   w = pixbuf->art_pixbuf->width;
102   h = pixbuf->art_pixbuf->height;
103
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,
109                            NULL);
110   gtk_signal_connect (GTK_OBJECT (window), "destroy",
111                       (GtkSignalFunc) quit_func, NULL);
112
113   vbox = gtk_vbox_new (FALSE, 0);
114
115   drawing_area = gtk_drawing_area_new ();
116
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);
119
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);
124
125   gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
126
127   gtk_widget_show (drawing_area);
128
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));
134
135   gtk_widget_show (button);
136
137   gtk_container_add (GTK_CONTAINER (window), vbox);
138   gtk_widget_show (vbox);
139
140   gtk_widget_show (window);
141 }
142
143 int
144 main (int argc, char **argv)
145 {
146   int i;
147   int found_valid = FALSE; 
148
149   GdkPixBuf *pixbuf;
150
151   gtk_init (&argc, &argv);
152
153   gdk_rgb_set_verbose (TRUE);
154
155   gdk_rgb_init ();
156
157   gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
158   gtk_widget_set_default_visual (gdk_rgb_get_visual ());
159
160   i = 1;
161   for (i = 1; i < argc; i++)
162     {
163       pixbuf = gdk_pixbuf_load_image (argv[i]);
164       
165       if (pixbuf)
166         {
167           new_testrgb_window (pixbuf);
168           found_valid = TRUE;
169         }
170     }
171
172   if (found_valid)
173     gtk_main ();
174
175   return 0;
176 }