1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include "libgimpbase/gimpbase.h"
26
#include "libgimpcolor/gimpcolor.h"
28
#include "gui-types.h"
32
#include "gimp-intl.h"
45
gint upper_x, upper_y;
47
gint lower_x, lower_y;
50
static GimpSplash *splash = NULL;
53
static void splash_map (void);
54
static gboolean splash_area_expose (GtkWidget *widget,
55
GdkEventExpose *event,
57
static GdkPixbuf * splash_pick_from_dir (const gchar *dirname);
58
static void splash_rectangle_union (GdkRectangle *dest,
59
PangoRectangle *pango_rect,
62
static gboolean splash_average_bottom (GtkWidget *widget,
67
/* public functions */
81
g_return_if_fail (splash == NULL);
83
filename = gimp_personal_rc_file ("gimp-splash.png");
84
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
89
filename = gimp_personal_rc_file ("splashes");
90
pixbuf = splash_pick_from_dir (filename);
96
filename = g_build_filename (gimp_data_directory (),
97
"images", "gimp-splash.png", NULL);
98
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
104
filename = g_build_filename (gimp_data_directory (), "splashes", NULL);
105
pixbuf = splash_pick_from_dir (filename);
112
splash = g_new0 (GimpSplash, 1);
115
g_object_new (GTK_TYPE_WINDOW,
116
"type", GTK_WINDOW_TOPLEVEL,
117
"type_hint", GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
118
"title", _("GIMP Startup"),
119
"role", "gimp-startup",
120
"window_position", GTK_WIN_POS_CENTER,
124
g_signal_connect_swapped (splash->window, "delete_event",
126
GINT_TO_POINTER (0));
128
/* we don't want the splash screen to send the startup notification */
129
gtk_window_set_auto_startup_notification (FALSE);
130
g_signal_connect (splash->window, "map",
131
G_CALLBACK (splash_map),
134
screen = gtk_widget_get_screen (splash->window);
136
splash->width = MIN (gdk_pixbuf_get_width (pixbuf),
137
gdk_screen_get_width (screen));
138
splash->height = MIN (gdk_pixbuf_get_height (pixbuf),
139
gdk_screen_get_height (screen));
141
frame = gtk_frame_new (NULL);
142
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
143
gtk_container_add (GTK_CONTAINER (splash->window), frame);
144
gtk_widget_show (frame);
146
vbox = gtk_vbox_new (FALSE, 0);
147
gtk_container_add (GTK_CONTAINER (frame), vbox);
148
gtk_widget_show (vbox);
150
/* prepare the drawing area */
151
splash->area = gtk_drawing_area_new ();
152
gtk_box_pack_start_defaults (GTK_BOX (vbox), splash->area);
153
gtk_widget_show (splash->area);
155
gtk_widget_set_size_request (splash->area, splash->width, splash->height);
157
gtk_widget_realize (splash->area);
159
splash_average_bottom (splash->area, pixbuf, &values.foreground);
160
splash->gc = gdk_gc_new_with_values (splash->area->window, &values,
163
splash->pixmap = gdk_pixmap_new (splash->area->window,
164
splash->width, splash->height, -1);
165
gdk_draw_pixbuf (splash->pixmap, splash->gc,
166
pixbuf, 0, 0, 0, 0, splash->width, splash->height,
167
GDK_RGB_DITHER_NORMAL, 0, 0);
168
g_object_unref (pixbuf);
170
g_signal_connect (splash->area, "expose_event",
171
G_CALLBACK (splash_area_expose),
174
/* create the pango layouts */
175
splash->upper = gtk_widget_create_pango_layout (splash->area, "");
176
splash->lower = gtk_widget_create_pango_layout (splash->area, "");
178
attrs = pango_attr_list_new ();
179
attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
180
attr->start_index = 0;
181
attr->end_index = -1;
182
pango_attr_list_insert (attrs, attr);
184
pango_layout_set_attributes (splash->upper, attrs);
185
pango_attr_list_unref (attrs);
187
/* add a progress bar */
188
splash->progress = gtk_progress_bar_new ();
189
gtk_box_pack_end (GTK_BOX (vbox), splash->progress, FALSE, FALSE, 0);
190
gtk_widget_show (splash->progress);
192
gtk_widget_show (splash->window);
194
while (gtk_events_pending ())
195
gtk_main_iteration ();
199
splash_destroy (void)
204
gtk_widget_destroy (splash->window);
206
g_object_unref (splash->gc);
207
g_object_unref (splash->pixmap);
208
g_object_unref (splash->upper);
209
g_object_unref (splash->lower);
216
splash_update (const gchar *text1,
220
GdkRectangle expose = { 0, 0, 0, 0 };
222
PangoRectangle logical;
229
width = splash->area->allocation.width;
230
height = splash->area->allocation.height;
234
pango_layout_get_pixel_extents (splash->upper, &ink, NULL);
235
splash_rectangle_union (&expose, &ink, splash->upper_x, splash->upper_y);
237
pango_layout_set_text (splash->upper, text1, -1);
238
pango_layout_get_pixel_extents (splash->upper, &ink, &logical);
240
splash->upper_x = (width - logical.width) / 2;
241
splash->upper_y = height - 2 * (logical.height + 6);
243
splash_rectangle_union (&expose, &ink, splash->upper_x, splash->upper_y);
248
pango_layout_get_pixel_extents (splash->lower, &ink, NULL);
249
splash_rectangle_union (&expose, &ink, splash->lower_x, splash->lower_y);
251
pango_layout_set_text (splash->lower, text2, -1);
252
pango_layout_get_pixel_extents (splash->lower, &ink, &logical);
254
splash->lower_x = (width - logical.width) / 2;
255
splash->lower_y = height - (logical.height + 6);
257
splash_rectangle_union (&expose, &ink, splash->lower_x, splash->lower_y);
260
if (expose.width > 0 && expose.height > 0)
261
gtk_widget_queue_draw_area (splash->area,
263
expose.width, expose.height);
265
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (splash->progress),
266
CLAMP (percentage, 0.0, 1.0));
268
while (gtk_events_pending ())
269
gtk_main_iteration ();
273
/* private functions */
276
splash_area_expose (GtkWidget *widget,
277
GdkEventExpose *event,
280
gdk_gc_set_clip_rectangle (splash->gc, &event->area);
282
gdk_draw_drawable (widget->window, splash->gc,
283
splash->pixmap, 0, 0,
284
(widget->allocation.width - splash->width) / 2,
285
(widget->allocation.height - splash->height) / 2,
289
gdk_draw_layout (widget->window, splash->gc,
290
splash->upper_x, splash->upper_y, splash->upper);
292
gdk_draw_layout (widget->window, splash->gc,
293
splash->lower_x, splash->lower_y, splash->lower);
301
/* Reenable startup notification after the splash has been shown
302
* so that the next window that is mapped sends the notification.
304
gtk_window_set_auto_startup_notification (TRUE);
308
splash_pick_from_dir (const gchar *dirname)
310
GdkPixbuf *pixbuf = NULL;
311
GDir *dir = g_dir_open (dirname, 0, NULL);
316
GList *splashes = NULL;
318
while ((entry = g_dir_read_name (dir)))
319
splashes = g_list_prepend (splashes, g_strdup (entry));
325
gint32 i = g_random_int_range (0, g_list_length (splashes));
326
gchar *filename = g_build_filename (dirname,
327
g_list_nth_data (splashes, i),
330
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
333
g_list_foreach (splashes, (GFunc) g_free, NULL);
334
g_list_free (splashes);
342
splash_rectangle_union (GdkRectangle *dest,
343
PangoRectangle *pango_rect,
349
rect.x = pango_rect->x + offset_x;
350
rect.y = pango_rect->y + offset_y;
351
rect.width = pango_rect->width;
352
rect.height = pango_rect->height;
354
if (dest->width > 0 && dest->height > 0)
355
gdk_rectangle_union (dest, &rect, dest);
360
/* This function chooses a gray value for the text color, based on
361
* the average intensity of the lower 60 rows of the splash image.
364
splash_average_bottom (GtkWidget *widget,
368
const guchar *pixels;
375
guint sum[3] = { 0, 0, 0 };
377
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
378
g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8, FALSE);
380
width = gdk_pixbuf_get_width (pixbuf);
381
height = gdk_pixbuf_get_height (pixbuf);
382
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
383
channels = gdk_pixbuf_get_n_channels (pixbuf);
384
pixels = gdk_pixbuf_get_pixels (pixbuf);
386
y = MAX (0, height - 60);
387
count = width * (height - y);
389
pixels += y * rowstride;
391
for (; y < height; y++)
393
const guchar *src = pixels;
395
for (x = 0; x < width; x++)
407
intensity = GIMP_RGB_INTENSITY (sum[0] / count,
411
intensity = CLAMP0255 (intensity > 127 ? intensity - 223 : intensity + 223);
413
color->red = color->green = color->blue = (intensity << 8 | intensity);
415
return gdk_colormap_alloc_color (gtk_widget_get_colormap (widget),