+2008-04-17 Emmanuele Bassi <ebassi@openedhand.com>
+
+ * 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 <neil@o-hand.com>
* configure.ac: Added a --with-flavour option to select between
--- /dev/null
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gtk/gtk.h>
+#include <clutter/clutter.h>
+
+#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);
+}
+
--- /dev/null
+#ifndef __GTK_CLUTTER_UTIL_H__
+#define __GTK_CLUTTER_UTIL_H__
+
+#include <gtk/gtkwidget.h>
+#include <clutter/clutter-color.h>
+
+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__ */
#include <clutter/clutter.h>
#include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter-gtk/gtk-clutter-util.h>
typedef struct {
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