state: removed special handling of state named "default"

The "default" state used for unspecified source transitions is NULL.
Small update and some other fixes to documentation.
This commit is contained in:
Øyvind Kolås 2010-06-24 02:26:46 +01:00
parent d37dee8258
commit 2a29cd2aee
2 changed files with 21 additions and 28 deletions

View File

@ -440,7 +440,7 @@ clutter_state_new_frame (ClutterTimeline *timeline,
* @target_state_name: the state to transition to * @target_state_name: the state to transition to
* @animate: whether we should animate the transition or not * @animate: whether we should animate the transition or not
* *
* Change the current state of #ClutterState to @target__name * Change the current state of #ClutterState to @target_state_name
* *
* If @animate is %FALSE, the state transition will happen immediately; * If @animate is %FALSE, the state transition will happen immediately;
* otherwise, the state transition will be animated over the duration * otherwise, the state transition will be animated over the duration
@ -466,14 +466,9 @@ clutter_state_change (ClutterState *state,
priv = state->priv; priv = state->priv;
if (target_state_name == NULL) if (target_state_name != NULL)
target_state_name = "default";
target_state_name = g_intern_string (target_state_name); target_state_name = g_intern_string (target_state_name);
if (priv->target_state_name == NULL)
priv->target_state_name = g_intern_static_string ("default");
if (target_state_name == priv->target_state_name) if (target_state_name == priv->target_state_name)
{ {
/* Avoid transitioning if the desired state is already current */ /* Avoid transitioning if the desired state is already current */
@ -626,14 +621,15 @@ get_property_from_object (GObject *gobject,
* For instance, the code below: * For instance, the code below:
* *
* |[ * |[
* clutter_state_set (state, "default", "hover", * clutter_state_set (state, NULL, "hover",
* button, "opacity", 255, CLUTTER_LINEAR, * button, "opacity", 255, CLUTTER_LINEAR,
* button, "scale-x", 1.2, CLUTTER_EASE_OUT_CUBIC, * button, "scale-x", 1.2, CLUTTER_EASE_OUT_CUBIC,
* button, "scale-y", 1.2, CLUTTER_EASE_OUT_CUBIC, * button, "scale-y", 1.2, CLUTTER_EASE_OUT_CUBIC,
* NULL); * NULL);
* ]| * ]|
* *
* will create a transition between the "default" and "hover" state; the * will create a transition from any state (a @source_state_name of NULL is
* treated as a wildcard) and a state named "hover"; the
* <emphasis>button</emphasis> object will have the #ClutterActor:opacity * <emphasis>button</emphasis> object will have the #ClutterActor:opacity
* property animated to a value of 255 using %CLUTTER_LINEAR as the animation * property animated to a value of 255 using %CLUTTER_LINEAR as the animation
* mode, and the #ClutterActor:scale-x and #ClutterActor:scale-y properties * mode, and the #ClutterActor:scale-x and #ClutterActor:scale-y properties
@ -808,16 +804,13 @@ clutter_state_get_state (ClutterState *state,
if (state_name == NULL) if (state_name == NULL)
{ {
if (force_creation)
state_name = g_intern_static_string ("default");
else
return NULL; return NULL;
} }
else else
state_name = g_intern_string (state_name); state_name = g_intern_string (state_name);
retval = g_hash_table_lookup (priv->states, state_name); retval = g_hash_table_lookup (priv->states, state_name);
if (retval == NULL) if (retval == NULL && force_creation)
{ {
retval = state_new (state, state_name); retval = state_new (state, state_name);
g_hash_table_insert (priv->states, (gpointer) state_name, retval); g_hash_table_insert (priv->states, (gpointer) state_name, retval);
@ -876,7 +869,7 @@ clutter_state_set_key (ClutterState *state,
if (pspec == NULL) if (pspec == NULL)
return state; return state;
source_state = clutter_state_get_state (state, source_state_name, FALSE); source_state = clutter_state_get_state (state, source_state_name, TRUE);
target_state = clutter_state_get_state (state, target_state_name, TRUE); target_state = clutter_state_get_state (state, target_state_name, TRUE);
property_name = g_intern_string (property_name); property_name = g_intern_string (property_name);
@ -1132,7 +1125,7 @@ clutter_state_class_init (ClutterStateClass *klass)
pspec = g_param_spec_string ("target-state", pspec = g_param_spec_string ("target-state",
"Target State", "Target State",
"Currently set state", "Currently set state",
"default", NULL,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_TARGET_STATE, pspec); g_object_class_install_property (gobject_class, PROP_TARGET_STATE, pspec);
@ -1203,8 +1196,7 @@ clutter_state_get_animator (ClutterState *state,
g_return_val_if_fail (CLUTTER_IS_STATE (state), NULL); g_return_val_if_fail (CLUTTER_IS_STATE (state), NULL);
source_state_name = g_intern_string (source_state_name); source_state_name = g_intern_string (source_state_name);
if (source_state_name == g_intern_static_string ("default") || if (source_state_name == g_intern_static_string (""))
source_state_name == g_intern_static_string (""))
source_state_name = NULL; source_state_name = NULL;
target_state_name = g_intern_string (target_state_name); target_state_name = g_intern_string (target_state_name);
@ -1533,13 +1525,11 @@ clutter_state_set_duration (ClutterState *state,
g_return_if_fail (CLUTTER_IS_STATE (state)); g_return_if_fail (CLUTTER_IS_STATE (state));
source_state_name = g_intern_string (source_state_name); source_state_name = g_intern_string (source_state_name);
if (source_state_name == g_intern_static_string ("default") || if (source_state_name == g_intern_static_string (""))
source_state_name == g_intern_static_string (""))
source_state_name = NULL; source_state_name = NULL;
target_state_name = g_intern_string (target_state_name); target_state_name = g_intern_string (target_state_name);
if (target_state_name == g_intern_static_string ("default") || if (target_state_name == g_intern_static_string (""))
target_state_name == g_intern_static_string (""))
target_state_name = NULL; target_state_name = NULL;
if (target_state_name == NULL) if (target_state_name == NULL)
@ -1591,13 +1581,11 @@ clutter_state_get_duration (ClutterState *state,
g_return_val_if_fail (CLUTTER_IS_STATE (state), 0); g_return_val_if_fail (CLUTTER_IS_STATE (state), 0);
source_state_name = g_intern_string (source_state_name); source_state_name = g_intern_string (source_state_name);
if (source_state_name == g_intern_static_string ("default") || if (source_state_name == g_intern_static_string (""))
source_state_name == g_intern_static_string (""))
source_state_name = NULL; source_state_name = NULL;
target_state_name = g_intern_string (target_state_name); target_state_name = g_intern_string (target_state_name);
if (target_state_name == g_intern_static_string ("default") || if (target_state_name == g_intern_static_string (""))
target_state_name == g_intern_static_string (""))
target_state_name = NULL; target_state_name = NULL;
if (target_state_name == NULL) if (target_state_name == NULL)
@ -1700,7 +1688,7 @@ parse_state_transition (JsonArray *array,
} }
source_name = json_object_get_string_member (object, "source"); source_name = json_object_get_string_member (object, "source");
source_state = clutter_state_get_state (clos->state, source_name, FALSE); source_state = clutter_state_get_state (clos->state, source_name, TRUE);
target_name = json_object_get_string_member (object, "target"); target_name = json_object_get_string_member (object, "target");
target_state = clutter_state_get_state (clos->state, target_name, TRUE); target_state = clutter_state_get_state (clos->state, target_name, TRUE);

View File

@ -45,6 +45,7 @@ test_state_base (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
keys = clutter_state_get_keys (CLUTTER_STATE (state), "base", "clicked", keys = clutter_state_get_keys (CLUTTER_STATE (state), "base", "clicked",
clutter_script_get_object (script, "rect"), clutter_script_get_object (script, "rect"),
"opacity"); "opacity");
g_assert (keys != NULL); g_assert (keys != NULL);
g_assert_cmpint (g_list_length (keys), ==, 1); g_assert_cmpint (g_list_length (keys), ==, 1);
@ -54,6 +55,10 @@ test_state_base (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
g_assert_cmpstr (clutter_state_key_get_property_name (state_key), ==, "opacity"); g_assert_cmpstr (clutter_state_key_get_property_name (state_key), ==, "opacity");
g_list_free (keys); g_list_free (keys);
keys = clutter_state_get_keys (CLUTTER_STATE (state), NULL, NULL, NULL, NULL);
g_assert_cmpint (g_list_length (keys), ==, 2);
g_list_free (keys);
g_object_unref (script); g_object_unref (script);
} }