1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4 * Copyright (C) 2000, 2001 Ximian, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
21 * Author: Ettore Perazzoli
26 * @short_description: Splash screen
28 * @stability: Unstable
29 * @include: libanjuta/e-splash.h
41 struct _ESplashPrivate
{
42 GdkPixbuf
*splash_image_pixbuf
;
43 GdkPixbuf
*icon_pixbuf
;
45 gint progressbar_position
;
46 gfloat progress_percentage
;
49 G_DEFINE_TYPE(ESplash
, e_splash
, GTK_TYPE_WINDOW
)
51 /* Layout constants. These need to be changed if the splash changes. */
56 #define PROGRESS_SIZE 10
58 /* GtkObject methods. */
61 impl_destroy (GtkWidget
*object
)
66 splash
= E_SPLASH (object
);
69 if (priv
->splash_image_pixbuf
!= NULL
)
70 g_object_unref (priv
->splash_image_pixbuf
);
71 if (priv
->icon_pixbuf
!= NULL
)
72 g_object_unref (priv
->icon_pixbuf
);
79 e_splash_finalize (GObject
*obj
)
81 G_OBJECT_CLASS (e_splash_parent_class
)->finalize (obj
);
85 e_splash_class_init (ESplashClass
*klass
)
87 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
88 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS (klass
);
90 widget_class
->destroy
= impl_destroy
;
92 object_class
->finalize
= e_splash_finalize
;
96 e_splash_init (ESplash
*splash
)
100 priv
= g_new0 (ESplashPrivate
, 1);
101 priv
->progressbar_position
= ICON_Y
;
106 button_press_event (GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
108 ESplash
*splash
= (ESplash
*) data
;
110 gtk_widget_hide (GTK_WIDGET (splash
));
116 on_draw_cb (GtkWidget
*widget
, cairo_t
*cr
,
119 ESplashPrivate
*priv
;
124 /* draw the background pixbuf */
126 gdk_cairo_set_source_pixbuf (cr
, priv
->splash_image_pixbuf
, 0, 0);
131 /* draw the plugin icon */
132 if (priv
->icon_pixbuf
)
135 gdk_cairo_set_source_pixbuf (cr
, priv
->icon_pixbuf
, ICON_X
, ICON_Y
);
141 /* draw the plugin text */
149 /* Aluminium 6 Tango */
150 cairo_set_source_rgba (cr
, 46/255, 52/255, 54/255, 1.0);
152 pc
= gtk_widget_get_pango_context (widget
);
153 layout
= pango_layout_new (pc
);
154 pango_layout_set_markup (layout
, priv
->title
, -1);
155 pango_layout_get_size (layout
, NULL
, &layout_height
);
157 cairo_move_to (cr
, ICON_X
+ ICON_SIZE
+ 25,
158 ICON_Y
+ ICON_SIZE
- PANGO_PIXELS (layout_height
) - 5);
160 pango_cairo_show_layout (cr
, layout
);
162 g_object_unref (layout
);
166 /* draw the progress bar */
167 inc_width
= gdk_pixbuf_get_width (priv
->splash_image_pixbuf
);
168 inc_width
-= (ICON_X
+ ICON_SIZE
+ 35);
170 /* Aluminium 6 (Tango) */
171 cairo_set_source_rgba (cr
, 46/255, 52/255, 54/255, 1.0);
172 cairo_rectangle (cr
, ICON_X
+ ICON_SIZE
+ 25, ICON_Y
+ ICON_SIZE
- 5,
173 (priv
->progress_percentage
* inc_width
), PROGRESS_SIZE
);
182 * e_splash_construct:
183 * @splash: A pointer to an ESplash widget
184 * @splash_image_pixbuf: The pixbuf for the image to appear in the splash dialog
186 * Construct @splash with @splash_image_pixbuf as the splash image.
189 e_splash_construct (ESplash
*splash
,
190 GdkPixbuf
*splash_image_pixbuf
,
191 gint progressbar_position
)
193 ESplashPrivate
*priv
;
194 int image_width
, image_height
;
196 g_return_if_fail (splash
!= NULL
);
197 g_return_if_fail (E_IS_SPLASH (splash
));
198 g_return_if_fail (splash_image_pixbuf
!= NULL
);
201 priv
->progressbar_position
= progressbar_position
;
202 priv
->splash_image_pixbuf
= g_object_ref (splash_image_pixbuf
);
204 image_width
= gdk_pixbuf_get_width (splash_image_pixbuf
);
205 image_height
= gdk_pixbuf_get_height (splash_image_pixbuf
);
207 gtk_widget_set_size_request (GTK_WIDGET (splash
), image_width
, image_height
);
209 g_signal_connect (G_OBJECT (splash
), "draw",
210 G_CALLBACK (on_draw_cb
), splash
);
211 g_signal_connect (G_OBJECT (splash
), "button-press-event",
212 G_CALLBACK (button_press_event
), splash
);
214 gtk_window_set_decorated(GTK_WINDOW(splash
), FALSE
);
215 gtk_window_set_position (GTK_WINDOW (splash
), GTK_WIN_POS_CENTER
);
216 gtk_window_set_resizable (GTK_WINDOW (splash
), FALSE
);
217 gtk_window_set_default_size (GTK_WINDOW (splash
), image_width
, image_height
);
218 gtk_window_set_title (GTK_WINDOW (splash
), PACKAGE_NAME
);
224 * @image_file: Splash image file
226 * Create a new ESplash widget.
228 * Return value: A pointer to the newly created ESplash widget.
231 e_splash_new (const char *image_file
, gint progressbar_position
)
234 GdkPixbuf
*splash_image_pixbuf
;
236 splash_image_pixbuf
= gdk_pixbuf_new_from_file (image_file
, NULL
);
237 g_return_val_if_fail (splash_image_pixbuf
!= NULL
, NULL
);
239 splash
= g_object_new (E_TYPE_SPLASH
, "type", GTK_WINDOW_TOPLEVEL
, NULL
);
240 e_splash_construct (splash
, splash_image_pixbuf
, progressbar_position
);
242 return GTK_WIDGET (splash
);
247 * @splash: A pointer to an ESplash widget
248 * @icon_pixbuf: Pixbuf for the icon to be added
250 * @desc: Description.
251 * @progress_percentage: percentage of progress.
253 * Set the current progress/icon/text.
256 e_splash_set (ESplash
*splash
, GdkPixbuf
*icon_pixbuf
,
257 const gchar
*title
, const gchar
*desc
,
258 gfloat progress_percentage
)
260 ESplashPrivate
*priv
;
262 g_return_if_fail (splash
!= NULL
);
263 g_return_if_fail (E_IS_SPLASH (splash
));
269 GdkPixbuf
*scaled_pixbuf
;
271 scaled_pixbuf
= gdk_pixbuf_new (GDK_COLORSPACE_RGB
, TRUE
,
272 8, ICON_SIZE
, ICON_SIZE
);
273 gdk_pixbuf_scale (icon_pixbuf
, scaled_pixbuf
,
275 ICON_SIZE
, ICON_SIZE
,
277 (double) ICON_SIZE
/ gdk_pixbuf_get_width (icon_pixbuf
),
278 (double) ICON_SIZE
/ gdk_pixbuf_get_height (icon_pixbuf
),
280 if (priv
->icon_pixbuf
)
281 g_object_unref (priv
->icon_pixbuf
);
282 priv
->icon_pixbuf
= scaled_pixbuf
;
287 g_free (priv
->title
);
288 priv
->title
= g_strdup (title
);
291 priv
->progress_percentage
= progress_percentage
;
293 gtk_widget_queue_draw (GTK_WIDGET (splash
));