2008-04-17 Emmanuele Bassi <ebassi@openedhand.com>
authorEmmanuele Bassi <ebassi@openedhand.com>
Thu, 17 Apr 2008 15:41:00 +0000 (15:41 +0000)
committerEmmanuele Bassi <ebassi@openedhand.com>
Thu, 17 Apr 2008 15:41:00 +0000 (15:41 +0000)
* 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.

ChangeLog
clutter-gtk/Makefile.am
clutter-gtk/gtk-clutter-util.c [new file with mode: 0644]
clutter-gtk/gtk-clutter-util.h [new file with mode: 0644]
doc/reference/clutter-gtk-docs.sgml
examples/gtk-clutter-events.c

index 3de6c13..1998783 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+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
index 7adf979..c3a53fd 100644 (file)
@@ -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 (file)
index 0000000..5ebd74b
--- /dev/null
@@ -0,0 +1,146 @@
+#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);
+}
+
diff --git a/clutter-gtk/gtk-clutter-util.h b/clutter-gtk/gtk-clutter-util.h
new file mode 100644 (file)
index 0000000..e1e928a
--- /dev/null
@@ -0,0 +1,24 @@
+#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__ */
index dcf667d..0edd64e 100644 (file)
     yada-yada-yada
     </para>
     
-  </chapter>    
+  </chapter>
+
   <chapter>
     <title>Clutter-Gtk Widgets</title>
     <xi:include href="xml/gtk-clutter-embed.xml"/>
   </chapter>
 
+  <chapter>
+    <title>Miscellaneous</title>
+    <xi:include href="xml/gtk-clutter-util.xml"/>
+  </chapter>
+
   <appendix id="license">
     <title>License</title>
 
index bb2f04e..43a9b29 100644 (file)
@@ -2,6 +2,7 @@
 #include <clutter/clutter.h>
 
 #include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter-gtk/gtk-clutter-util.h>
 
 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