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>
This commit is contained in:
Robert Bragg 2011-08-16 17:31:42 +01:00
parent 98b3834d55
commit 397fe1b5b6

View File

@ -60,6 +60,7 @@
#include "clutter-profile.h" #include "clutter-profile.h"
#include "clutter-units.h" #include "clutter-units.h"
#include "clutter-paint-volume-private.h" #include "clutter-paint-volume-private.h"
#include "clutter-scriptable.h"
/* cursor width in pixels */ /* cursor width in pixels */
#define DEFAULT_CURSOR_SIZE 2 #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_text_color = { 0, 0, 0, 255 };
static const ClutterColor default_selected_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 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 static void
clutter_text_class_init (ClutterTextClass *klass) clutter_text_class_init (ClutterTextClass *klass)
{ {