From: Emmanuele Bassi Date: Thu, 17 Apr 2008 15:41:00 +0000 (+0000) Subject: 2008-04-17 Emmanuele Bassi X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=7e3bf4204b8c90aa075a3ef8c18faf39d24300a2;p=clutter-gtk 2008-04-17 Emmanuele Bassi * clutter-gtk/gtk-clutter-util.[ch]: Add utility functions to ClutterGtk to be able to retrieve the ClutterColor equivalent of the various style color components of a GtkWidget. * clutter-gtk/Makefile.am: Add gtk-clutter-util.[ch] to the build. * doc/reference/clutter-gtk-docs.sgml: Add the new section in the documentation. * examples/gtk-clutter-events.c (create_colors): Test the newly added color retrieval API. --- diff --git a/ChangeLog b/ChangeLog index 3de6c13..1998783 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-04-17 Emmanuele Bassi + + * clutter-gtk/gtk-clutter-util.[ch]: Add utility functions to + ClutterGtk to be able to retrieve the ClutterColor equivalent + of the various style color components of a GtkWidget. + + * clutter-gtk/Makefile.am: Add gtk-clutter-util.[ch] to the build. + + * doc/reference/clutter-gtk-docs.sgml: Add the new section in + the documentation. + + * examples/gtk-clutter-events.c (create_colors): Test the newly + added color retrieval API. + 2008-04-15 Neil Roberts * configure.ac: Added a --with-flavour option to select between diff --git a/clutter-gtk/Makefile.am b/clutter-gtk/Makefile.am index 7adf979..c3a53fd 100644 --- a/clutter-gtk/Makefile.am +++ b/clutter-gtk/Makefile.am @@ -11,9 +11,9 @@ INCLUDES = \ lib_LTLIBRARIES = libclutter-gtk-0.7.la -libclutter_gtk_0_7_la_SOURCES = gtk-clutter-embed.c +libclutter_gtk_0_7_la_SOURCES = gtk-clutter-embed.c gtk-clutter-util.c libclutter_gtk_0_7_la_LIBADD = $(CLUTTER_LIBS) $(GTK_LIBS) libclutter_gtk_0_7_la_LDFLAGS = $(CLUTTER_LT_LDFLAGS) cluttergtkheadersdir = $(includedir)/clutter-0.7/clutter-gtk -cluttergtkheaders_HEADERS = gtk-clutter-embed.h +cluttergtkheaders_HEADERS = gtk-clutter-embed.h gtk-clutter-util.h diff --git a/clutter-gtk/gtk-clutter-util.c b/clutter-gtk/gtk-clutter-util.c new file mode 100644 index 0000000..5ebd74b --- /dev/null +++ b/clutter-gtk/gtk-clutter-util.c @@ -0,0 +1,146 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "gtk-clutter-util.h" + +/** + * SECTION:gtk-clutter-util + * @short_description: Utility functions for integrating Clutter in GTK+ + * + * FIXME + * + */ + +static inline void +gtk_clutter_get_component (GtkWidget *widget, + GtkRcFlags component, + GtkStateType state, + ClutterColor *color) +{ + GtkStyle *style = gtk_widget_get_style (widget); + GdkColor gtk_color = { 0, }; + + switch (component) + { + case GTK_RC_FG: + gtk_color = style->fg[state]; + break; + + case GTK_RC_BG: + gtk_color = style->bg[state]; + break; + + case GTK_RC_TEXT: + gtk_color = style->text[state]; + break; + + case GTK_RC_BASE: + gtk_color = style->base[state]; + break; + + default: + g_assert_not_reached (); + break; + } + + color->red = (guint8) ((gtk_color.red / 65535.0) * 255); + color->green = (guint8) ((gtk_color.green / 65535.0) * 255); + color->blue = (guint8) ((gtk_color.blue / 65535.0) * 255); +} + +/** + * gtk_clutter_get_fg_color: + * @widget: + * @state: + * @color: + * + * FIXME + * + * Since: 0.8 + */ +void +gtk_clutter_get_fg_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (state >= GTK_STATE_NORMAL && + state <= GTK_STATE_INSENSITIVE); + g_return_if_fail (color != NULL); + + gtk_clutter_get_component (widget, GTK_RC_FG, state, color); +} + +/** + * gtk_clutter_get_bg_color: + * @widget: + * @state: + * @color: + * + * FIXME + * + * Since: 0.8 + */ +void +gtk_clutter_get_bg_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (state >= GTK_STATE_NORMAL && + state <= GTK_STATE_INSENSITIVE); + g_return_if_fail (color != NULL); + + gtk_clutter_get_component (widget, GTK_RC_BG, state, color); +} + +/** + * gtk_clutter_get_text_color: + * @widget: + * @state: + * @color: + * + * FIXME + * + * Since: 0.8 + */ +void +gtk_clutter_get_text_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (state >= GTK_STATE_NORMAL && + state <= GTK_STATE_INSENSITIVE); + g_return_if_fail (color != NULL); + + gtk_clutter_get_component (widget, GTK_RC_TEXT, state, color); +} + +/** + * gtk_clutter_get_base_color: + * @widget: + * @state: + * @color: + * + * FIXME + * + * Since: 0.8 + */ +void +gtk_clutter_get_base_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (state >= GTK_STATE_NORMAL && + state <= GTK_STATE_INSENSITIVE); + g_return_if_fail (color != NULL); + + gtk_clutter_get_component (widget, GTK_RC_BASE, state, color); +} + diff --git a/clutter-gtk/gtk-clutter-util.h b/clutter-gtk/gtk-clutter-util.h new file mode 100644 index 0000000..e1e928a --- /dev/null +++ b/clutter-gtk/gtk-clutter-util.h @@ -0,0 +1,24 @@ +#ifndef __GTK_CLUTTER_UTIL_H__ +#define __GTK_CLUTTER_UTIL_H__ + +#include +#include + +G_BEGIN_DECLS + +void gtk_clutter_get_fg_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color); +void gtk_clutter_get_bg_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color); +void gtk_clutter_get_text_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color); +void gtk_clutter_get_base_color (GtkWidget *widget, + GtkStateType state, + ClutterColor *color); + +G_END_DECLS + +#endif /* __GTK_CLUTTER_UTIL_H__ */ diff --git a/doc/reference/clutter-gtk-docs.sgml b/doc/reference/clutter-gtk-docs.sgml index dcf667d..0edd64e 100644 --- a/doc/reference/clutter-gtk-docs.sgml +++ b/doc/reference/clutter-gtk-docs.sgml @@ -44,12 +44,18 @@ yada-yada-yada - + + Clutter-Gtk Widgets + + Miscellaneous + + + License diff --git a/examples/gtk-clutter-events.c b/examples/gtk-clutter-events.c index bb2f04e..43a9b29 100644 --- a/examples/gtk-clutter-events.c +++ b/examples/gtk-clutter-events.c @@ -2,6 +2,7 @@ #include #include +#include typedef struct { @@ -63,20 +64,8 @@ on_opacity_changed (GtkSpinButton *button, EventApp *app) static void create_colors (EventApp *app, ClutterColor *stage, ClutterColor *text) { - GtkStyle *style = gtk_widget_get_style (app->window); - GdkColor color; - - /* Set the stage color to base[NORMAL] */ - color = style->bg[GTK_STATE_NORMAL]; - stage->red = (guint8) ((color.red/65535.0) * 255); - stage->green = (guint8) ((color.green/65535.0) * 255); - stage->blue = (guint8) ((color.blue/65535.0) * 255); - - /* Now the text color */ - color = style->text[GTK_STATE_NORMAL]; - text->red =(guint8) ((color.red/65535.0) * 255); - text->green = (guint8) ((color.green/65535.0) * 255); - text->blue = (guint8) ((color.blue/65535.0) * 255); + gtk_clutter_get_bg_color (app->window, GTK_STATE_NORMAL, stage); + gtk_clutter_get_text_color (app->window, GTK_STATE_NORMAL, text); } static gboolean