interval: Implement ClutterScriptable interface
This allows the creation of ClutterTransition objects in ClutterScript: { "id" : "scripted-transition", "type" : "ClutterPropertyTransition", "property-name" : "background-color", "interval" : { "type" : "ClutterInterval", "value-type" : "ClutterColor", "initial" : "red", "final" : "blue" } }
This commit is contained in:
parent
46c22de01e
commit
e56785501b
@ -61,6 +61,8 @@
|
||||
#include "clutter-interval.h"
|
||||
#include "clutter-private.h"
|
||||
#include "clutter-units.h"
|
||||
#include "clutter-scriptable.h"
|
||||
#include "clutter-script-private.h"
|
||||
|
||||
#include "deprecated/clutter-fixed.h"
|
||||
|
||||
@ -93,7 +95,14 @@ struct _ClutterIntervalPrivate
|
||||
GValue *values;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (ClutterInterval, clutter_interval, G_TYPE_INITIALLY_UNOWNED)
|
||||
static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (ClutterInterval,
|
||||
clutter_interval,
|
||||
G_TYPE_INITIALLY_UNOWNED,
|
||||
G_ADD_PRIVATE (ClutterInterval)
|
||||
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
|
||||
clutter_scriptable_iface_init));
|
||||
|
||||
static gboolean
|
||||
clutter_interval_real_validate (ClutterInterval *interval,
|
||||
@ -479,6 +488,45 @@ clutter_interval_get_property (GObject *gobject,
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_interval_parse_custom_node (ClutterScriptable *scriptable,
|
||||
ClutterScript *script,
|
||||
GValue *value,
|
||||
const gchar *name,
|
||||
JsonNode *node)
|
||||
{
|
||||
ClutterIntervalPrivate *priv = CLUTTER_INTERVAL (scriptable)->priv;
|
||||
|
||||
if ((strcmp (name, "initial") == 0) || (strcmp (name, "final") == 0))
|
||||
{
|
||||
g_value_init (value, priv->value_type);
|
||||
return _clutter_script_parse_node (script, value, name, node, NULL);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_interval_set_custom_property (ClutterScriptable *scriptable,
|
||||
ClutterScript *script,
|
||||
const gchar *name,
|
||||
const GValue *value)
|
||||
{
|
||||
ClutterInterval *self = CLUTTER_INTERVAL (scriptable);
|
||||
|
||||
if (strcmp (name, "initial") == 0)
|
||||
clutter_interval_set_initial_value (self, value);
|
||||
else if (strcmp (name, "final") == 0)
|
||||
clutter_interval_set_final_value (self, value);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_scriptable_iface_init (ClutterScriptableIface *iface)
|
||||
{
|
||||
iface->parse_custom_node = clutter_interval_parse_custom_node;
|
||||
iface->set_custom_property = clutter_interval_set_custom_property;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_interval_class_init (ClutterIntervalClass *klass)
|
||||
{
|
||||
|
@ -442,3 +442,38 @@ script_margin (TestConformSimpleFixture *fixture,
|
||||
g_object_unref (script);
|
||||
g_free (test_file);
|
||||
}
|
||||
|
||||
void
|
||||
script_interval (TestConformSimpleFixture *fixture,
|
||||
gpointer dummy)
|
||||
{
|
||||
ClutterScript *script = clutter_script_new ();
|
||||
ClutterInterval *interval;
|
||||
gchar *test_file;
|
||||
GError *error = NULL;
|
||||
GValue *initial, *final;
|
||||
|
||||
test_file = clutter_test_get_data_file ("test-script-interval.json");
|
||||
clutter_script_load_from_file (script, test_file, &error);
|
||||
if (g_test_verbose () && error)
|
||||
g_print ("Error: %s", error->message);
|
||||
|
||||
g_assert_no_error (error);
|
||||
|
||||
interval = CLUTTER_INTERVAL (clutter_script_get_object (script, "int-1"));
|
||||
initial = clutter_interval_peek_initial_value (interval);
|
||||
g_assert (G_VALUE_HOLDS (initial, G_TYPE_FLOAT));
|
||||
g_assert_cmpfloat (g_value_get_float (initial), ==, 23.3f);
|
||||
final = clutter_interval_peek_final_value (interval);
|
||||
g_assert (G_VALUE_HOLDS (final, G_TYPE_FLOAT));
|
||||
g_assert_cmpfloat (g_value_get_float (final), ==, 42.2f);
|
||||
|
||||
interval = CLUTTER_INTERVAL (clutter_script_get_object (script, "int-2"));
|
||||
initial = clutter_interval_peek_initial_value (interval);
|
||||
g_assert (G_VALUE_HOLDS (initial, CLUTTER_TYPE_COLOR));
|
||||
final = clutter_interval_peek_final_value (interval);
|
||||
g_assert (G_VALUE_HOLDS (final, CLUTTER_TYPE_COLOR));
|
||||
|
||||
g_object_unref (script);
|
||||
g_free (test_file);
|
||||
}
|
||||
|
@ -198,6 +198,7 @@ main (int argc, char **argv)
|
||||
TEST_CONFORM_SIMPLE ("/script", animator_multi_properties);
|
||||
TEST_CONFORM_SIMPLE ("/script", state_base);
|
||||
TEST_CONFORM_SIMPLE ("/script", script_margin);
|
||||
TEST_CONFORM_SIMPLE ("/script", script_interval);
|
||||
|
||||
TEST_CONFORM_SKIP (g_test_slow (), "/timeline", timeline_base);
|
||||
TEST_CONFORM_SIMPLE ("/timeline", timeline_markers_from_script);
|
||||
|
@ -18,6 +18,7 @@ json_files = \
|
||||
test-state-1.json \
|
||||
test-script-timeline-markers.json \
|
||||
test-script-margin.json \
|
||||
test-script-interval.json \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST += $(json_files)
|
||||
|
16
tests/data/test-script-interval.json
Normal file
16
tests/data/test-script-interval.json
Normal file
@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"id" : "int-1",
|
||||
"type" : "ClutterInterval",
|
||||
"value-type" : "gfloat",
|
||||
"initial" : 23.3,
|
||||
"final" : 42.2
|
||||
},
|
||||
{
|
||||
"id" : "int-2",
|
||||
"type" : "ClutterInterval",
|
||||
"value-type" : "ClutterColor",
|
||||
"initial" : "red",
|
||||
"final" : "blue"
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user