From: Emmanuele Bassi Date: Mon, 21 Apr 2008 15:06:30 +0000 (+0000) Subject: 2008-04-21 Emmanuele Bassi X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=8d35a251859de3b9052665d7149430d8c4cb75c4;p=clutter-gtk 2008-04-21 Emmanuele Bassi * clutter-gtk/gtk-clutter-util.h: * clutter-gtk/gtk-clutter-util.c: (gtk_clutter_texture_new_from_pixbuf), (gtk_clutter_texture_new_from_stock), (gtk_clutter_texture_new_from_icon_name): Add utility functions to create a ClutterTexture from a Pixbuf (to replace the clutter_texture_from_pixbuf() call when it will be removed from Clutter core); from a stock id; and from an icon name. * examples/Makefile.am: Clean up. * examples/gtk-clutter-events.c: * examples/gtk-clutter-multistage.c: Use the new utility API. --- diff --git a/ChangeLog b/ChangeLog index f5b0089..7b9d11d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-04-21 Emmanuele Bassi + + * clutter-gtk/gtk-clutter-util.h: + * clutter-gtk/gtk-clutter-util.c: + (gtk_clutter_texture_new_from_pixbuf), + (gtk_clutter_texture_new_from_stock), + (gtk_clutter_texture_new_from_icon_name): Add utility functions + to create a ClutterTexture from a Pixbuf (to replace the + clutter_texture_from_pixbuf() call when it will be removed + from Clutter core); from a stock id; and from an icon name. + + * examples/Makefile.am: Clean up. + + * examples/gtk-clutter-events.c: + * examples/gtk-clutter-multistage.c: Use the new utility API. + 2008-04-17 Emmanuele Bassi * README: Update requirements diff --git a/clutter-gtk/gtk-clutter-util.c b/clutter-gtk/gtk-clutter-util.c index 5ebd74b..6cb0bd9 100644 --- a/clutter-gtk/gtk-clutter-util.c +++ b/clutter-gtk/gtk-clutter-util.c @@ -2,6 +2,7 @@ #include "config.h" #endif +#include #include #include @@ -144,3 +145,143 @@ gtk_clutter_get_base_color (GtkWidget *widget, gtk_clutter_get_component (widget, GTK_RC_BASE, state, color); } +/** + * gtk_clutter_texture_new_from_pixbuf: + * @pixbuf: a #GdkPixbuf + * + * FIXME + * + * Return value: the newly created #ClutterTexture + * + * Since: 0.8 + */ +ClutterActor * +gtk_clutter_texture_new_from_pixbuf (GdkPixbuf *pixbuf) +{ + ClutterActor *retval; + GError *error; + + g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); + + retval = clutter_texture_new (); + + error = NULL; + clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (retval), + gdk_pixbuf_get_pixels (pixbuf), + gdk_pixbuf_get_has_alpha (pixbuf), + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + gdk_pixbuf_get_rowstride (pixbuf), + 4, 0, + &error); + if (error) + { + g_warning ("Unable to set the pixbuf: %s", error->message); + g_error_free (error); + } + + return retval; +} + +/** + * gtk_clutter_texture_new_from_stock: + * @widget: a #GtkWidget + * @stock_id: FIXME + * @size: FIXME + * + * FIXME + * + * Return value: the newly created #ClutterTexture + * + * Since: 0.8 + */ +ClutterActor * +gtk_clutter_texture_new_from_stock (GtkWidget *widget, + const gchar *stock_id, + GtkIconSize size) +{ + GdkPixbuf *pixbuf; + ClutterActor *retval; + + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + g_return_val_if_fail (stock_id != NULL, NULL); + g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL); + + pixbuf = gtk_widget_render_icon (widget, stock_id, size, NULL); + if (!pixbuf) + pixbuf = gtk_widget_render_icon (widget, + GTK_STOCK_MISSING_IMAGE, size, + NULL); + + retval = gtk_clutter_texture_new_from_pixbuf (pixbuf); + g_object_unref (pixbuf); + + return retval; +} + +/** + * gtk_clutter_texture_new_from_icon_name: + * @widget: a #GtkWidget + * @icon_name: FIXME + * @size: FIXME + * + * FIXME + * + * Return value: the newly created #ClutterTexture + * + * Since: 0.8 + */ +ClutterActor * +gtk_clutter_texture_new_from_icon_name (GtkWidget *widget, + const gchar *icon_name, + GtkIconSize size) +{ + GtkSettings *settings; + GtkIconTheme *icon_theme; + gint width, height; + GdkPixbuf *pixbuf; + GError *error; + ClutterActor *retval; + + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + g_return_val_if_fail (icon_name != NULL, NULL); + g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL); + + if (gtk_widget_has_screen (widget)) + { + GdkScreen *screen; + + screen = gtk_widget_get_screen (widget); + settings = gtk_settings_get_for_screen (screen); + icon_theme = gtk_icon_theme_get_for_screen (screen); + } + else + { + settings = gtk_settings_get_default (); + icon_theme = gtk_icon_theme_get_default (); + } + + if (!gtk_icon_size_lookup_for_settings (settings, size, &width, &height)) + { + g_warning ("Invalid icon size"); + width = height = 48; + } + + error = NULL; + pixbuf = gtk_icon_theme_load_icon (icon_theme, + icon_name, + MIN (width, height), 0, + &error); + if (error) + { + g_error_free (error); + return gtk_clutter_texture_new_from_stock (widget, + GTK_STOCK_MISSING_IMAGE, + size); + } + + retval = gtk_clutter_texture_new_from_pixbuf (pixbuf); + g_object_unref (pixbuf); + + return retval; +} diff --git a/clutter-gtk/gtk-clutter-util.h b/clutter-gtk/gtk-clutter-util.h index e1e928a..0c79b07 100644 --- a/clutter-gtk/gtk-clutter-util.h +++ b/clutter-gtk/gtk-clutter-util.h @@ -19,6 +19,14 @@ void gtk_clutter_get_base_color (GtkWidget *widget, GtkStateType state, ClutterColor *color); +ClutterActor *gtk_clutter_texture_new_from_pixbuf (GdkPixbuf *pixbuf); +ClutterActor *gtk_clutter_texture_new_from_stock (GtkWidget *widget, + const gchar *stock_id, + GtkIconSize size); +ClutterActor *gtk_clutter_texture_new_from_icon_name (GtkWidget *widget, + const gchar *icon_name, + GtkIconSize size); + G_END_DECLS #endif /* __GTK_CLUTTER_UTIL_H__ */ diff --git a/examples/Makefile.am b/examples/Makefile.am index 8e4855e..87d7740 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,33 +1,34 @@ -noinst_PROGRAMS = gtk-clutter-test gtk-clutter-events gtk-clutter-multistage +NULL = + +noinst_PROGRAMS = \ + gtk-clutter-test \ + gtk-clutter-events \ + gtk-clutter-multistage INCLUDES = \ -I$(srcdir) \ - -I$(top_srcdir) \ - $(CLUTTER_CFLAGS) \ - $(GTK_CFLAGS) + -I$(top_srcdir) + +AM_CPPFLAGS = $(CLUTTER_CFLAGS) $(GTK_CFLAGS) -gtk_clutter_test_DEPENDENCIES = \ +common_deps = \ $(top_builddir)/clutter-gtk/libclutter-gtk-0.7.la -gtk_clutter_test_SOURCES = gtk-clutter-test.c -gtk_clutter_test_LDADD = \ + +common_ldadd = \ $(top_builddir)/clutter-gtk/libclutter-gtk-0.7.la \ $(CLUTTER_LIBS) \ $(GTK_LIBS) -gtk_clutter_events_DEPENDENCIES = \ - $(top_builddir)/clutter-gtk/libclutter-gtk-0.7.la +gtk_clutter_test_SOURCES = gtk-clutter-test.c +gtk_clutter_test_DEPENDENCIES = $(common_deps) +gtk_clutter_test_LDADD = $(common_ldadd) + gtk_clutter_events_SOURCES = gtk-clutter-events.c -gtk_clutter_events_LDADD = \ - $(top_builddir)/clutter-gtk/libclutter-gtk-0.7.la \ - $(CLUTTER_LIBS) \ - $(GTK_LIBS) +gtk_clutter_events_DEPENDENCIES = $(common_deps) +gtk_clutter_events_LDADD = $(common_ldadd) -gtk_clutter_multistage_DEPENDENCIES = \ - $(top_builddir)/clutter-gtk/libclutter-gtk-0.7.la gtk_clutter_multistage_SOURCES = gtk-clutter-multistage.c -gtk_clutter_multistage_LDADD = \ - $(top_builddir)/clutter-gtk/libclutter-gtk-0.7.la \ - $(CLUTTER_LIBS) \ - $(GTK_LIBS) +gtk_clutter_multistage_DEPENDENCIES = $(common_deps) +gtk_clutter_multistage_LDADD = $(common_ldadd) EXTRA_DIST = redhand.png diff --git a/examples/gtk-clutter-events.c b/examples/gtk-clutter-events.c index 43a9b29..3143bc9 100644 --- a/examples/gtk-clutter-events.c +++ b/examples/gtk-clutter-events.c @@ -148,7 +148,7 @@ main (gint argc, gchar **argv) if (pixbuf == NULL) g_error ("Unable to load pixbuf\n"); - actor = clutter_texture_new_from_pixbuf (pixbuf); + actor = gtk_clutter_texture_new_from_pixbuf (pixbuf); app->hand = actor; clutter_group_add (CLUTTER_GROUP (app->stage), actor); clutter_actor_get_size (actor, &width, &height); diff --git a/examples/gtk-clutter-multistage.c b/examples/gtk-clutter-multistage.c index 292a9fc..34abe32 100644 --- a/examples/gtk-clutter-multistage.c +++ b/examples/gtk-clutter-multistage.c @@ -1,6 +1,8 @@ #include #include + #include +#include int main (int argc, char *argv[]) @@ -18,14 +20,6 @@ main (int argc, char *argv[]) if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) g_error ("Unable to initialize GtkClutter"); - pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL); - - if (!pixbuf) - g_error("pixbuf load failed"); - - tex1 = clutter_texture_new_from_pixbuf (pixbuf); - tex2 = clutter_clone_texture_new (tex1); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); @@ -37,15 +31,29 @@ main (int argc, char *argv[]) gtk_widget_set_size_request (clutter1, 320, 240); stage1 = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter1)); clutter_stage_set_color (CLUTTER_STAGE(stage1), &col1); + tex1 = gtk_clutter_texture_new_from_stock (clutter1, + GTK_STOCK_DIALOG_INFO, + GTK_ICON_SIZE_DIALOG); + clutter_actor_set_anchor_point (tex1, + clutter_actor_get_width (tex1) / 2, + clutter_actor_get_height (tex1) / 2); + clutter_actor_set_position (tex1, 160, 120); clutter_stage_add (stage1, tex1); + clutter_actor_show (tex1); gtk_container_add (GTK_CONTAINER (vbox), clutter1); clutter2 = gtk_clutter_embed_new (); gtk_widget_set_size_request (clutter2, 320, 240); stage2 = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter2)); - clutter_stage_set_color (CLUTTER_STAGE(stage2), &col2); + tex2 = gtk_clutter_texture_new_from_icon_name (clutter1, + "user-info", + GTK_ICON_SIZE_BUTTON); + clutter_actor_set_anchor_point (tex2, + clutter_actor_get_width (tex2) / 2, + clutter_actor_get_height (tex2) / 2); + clutter_actor_set_position (tex2, 160, 120); clutter_stage_add (stage2, tex2); gtk_container_add (GTK_CONTAINER (vbox), clutter2);