[clutter] text: Implement Scriptable interface for font-description



commit 397fe1b5b64ac188824c50a8bb3329f19691e9e2
Author: Robert Bragg <robert linux intel com>
Date:   Tue Aug 16 17:31:42 2011 +0100

    text: Implement Scriptable interface for font-description
    
    This makes ClutterText implement the Scriptable interface so that we can
    have a custom property parser and setter for the font-description
    property. This works by simply passing the string description through
    to clutter_text_set_font_name.
    
    Reviewed-by: Emmanuele Bassi <ebassi linux intel com>

 clutter/clutter-text.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c
index 2e87239..4018990 100644
--- a/clutter/clutter-text.c
+++ b/clutter/clutter-text.c
@@ -60,6 +60,7 @@
 #include "clutter-profile.h"
 #include "clutter-units.h"
 #include "clutter-paint-volume-private.h"
+#include "clutter-scriptable.h"
 
 /* cursor width in pixels */
 #define DEFAULT_CURSOR_SIZE     2
@@ -85,7 +86,13 @@ static const ClutterColor default_selection_color = {   0,   0,   0, 255 };
 static const ClutterColor default_text_color      = {   0,   0,   0, 255 };
 static const ClutterColor default_selected_text_color = {   0,   0,   0, 255 };
 
-G_DEFINE_TYPE (ClutterText, clutter_text, CLUTTER_TYPE_ACTOR);
+static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (ClutterText,
+                         clutter_text,
+                         CLUTTER_TYPE_ACTOR,
+                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
+                                                clutter_scriptable_iface_init));
 
 struct _LayoutCache
 {
@@ -2757,6 +2764,48 @@ clutter_text_add_move_binding (ClutterBindingPool  *pool,
     }
 }
 
+static gboolean
+clutter_text_parse_custom_node (ClutterScriptable *scriptable,
+                                ClutterScript     *script,
+                                GValue            *value,
+                                const gchar       *name,
+                                JsonNode          *node)
+{
+  if (strncmp (name, "font-description", 16) == 0)
+    {
+      g_value_init (value, G_TYPE_STRING);
+      g_value_set_string (value, json_node_get_string (node));
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+clutter_text_set_custom_property (ClutterScriptable *scriptable,
+                                  ClutterScript     *script,
+                                  const gchar       *name,
+                                  const GValue      *value)
+{
+  if (strncmp (name, "font-description", 16) == 0)
+    {
+      g_assert (G_VALUE_HOLDS (value, G_TYPE_STRING));
+      if (g_value_get_string (value) != NULL)
+        clutter_text_set_font_name (CLUTTER_TEXT (scriptable),
+                                    g_value_get_string (value));
+    }
+  else
+    g_object_set_property (G_OBJECT (scriptable), name, value);
+}
+
+static void
+clutter_scriptable_iface_init (ClutterScriptableIface *iface)
+{
+  iface->parse_custom_node = clutter_text_parse_custom_node;
+  iface->set_custom_property = clutter_text_set_custom_property;
+}
+
 static void
 clutter_text_class_init (ClutterTextClass *klass)
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]