clutter/actor: Make unsetting color state an explicit function

It makes things easier and more straight forward to handle.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3433>
This commit is contained in:
Jonas Ådahl 2024-05-10 14:42:24 +02:00 committed by Sebastian Wick
parent 1fa5a016be
commit 8b425f4e85
3 changed files with 44 additions and 19 deletions

View File

@ -965,6 +965,9 @@ static void pop_in_paint_unmapped_branch (ClutterActor *self,
static void clutter_actor_update_devices (ClutterActor *self);
static void clutter_actor_set_color_state_internal (ClutterActor *self,
ClutterColorState *color_state);
static GQuark quark_actor_layout_info = 0;
static GQuark quark_actor_transform_info = 0;
static GQuark quark_actor_animation_info = 0;
@ -4800,7 +4803,7 @@ clutter_actor_set_property (GObject *object,
break;
case PROP_COLOR_STATE:
clutter_actor_set_color_state (actor, g_value_get_object (value));
clutter_actor_set_color_state_internal (actor, g_value_get_object (value));
break;
default:
@ -5561,6 +5564,9 @@ clutter_actor_constructor (GType gtype,
if (!self->priv->context)
self->priv->context = _clutter_context_get_default ();
if (!self->priv->color_state)
clutter_actor_unset_color_state (self);
return retval;
}
@ -17844,29 +17850,48 @@ create_default_color_state (ClutterActor *self)
return color_state;
}
static void
clutter_actor_set_color_state_internal (ClutterActor *self,
ClutterColorState *color_state)
{
ClutterActorPrivate *priv = clutter_actor_get_instance_private (self);
if (g_set_object (&priv->color_state, color_state))
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_COLOR_STATE]);
}
/**
* clutter_actor_unset_color_state:
* @self: a #ClutterActor
*
* Set @self's color state to the default.
*/
void
clutter_actor_unset_color_state (ClutterActor *self)
{
g_autoptr (ClutterColorState) default_color_state = NULL;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
default_color_state = create_default_color_state (self);
clutter_actor_set_color_state_internal (self, default_color_state);
}
/**
* clutter_actor_set_color_state:
* @self: a #ClutterActor
* @color_state: (nullable): a #ClutterColorState
* @color_state: a #ClutterColorState
*
* Set @self's color state to @color_state, or a default one if %NULL.
* Set @self's color state to @color_state.
*/
void
clutter_actor_set_color_state (ClutterActor *self,
ClutterColorState *color_state)
{
ClutterActorPrivate *priv;
g_autoptr (ClutterColorState) default_color_state = NULL;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
g_return_if_fail (CLUTTER_IS_COLOR_STATE (color_state));
priv = clutter_actor_get_instance_private (self);
if (!color_state)
color_state = default_color_state = create_default_color_state (self);
if (g_set_object (&priv->color_state, color_state))
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_COLOR_STATE]);
clutter_actor_set_color_state_internal (self, color_state);
}
/**

View File

@ -565,6 +565,9 @@ CLUTTER_EXPORT
void clutter_actor_set_color_state (ClutterActor *self,
ClutterColorState *color_state);
CLUTTER_EXPORT
void clutter_actor_unset_color_state (ClutterActor *self);
CLUTTER_EXPORT
ClutterColorState * clutter_actor_get_color_state (ClutterActor *self);

View File

@ -106,10 +106,8 @@ actor_change_color_state (void)
clutter_actor_destroy (actor);
}
/* changing an actor's color state to NULL ends up with it being changed back
* to a color state with the sRGB color space */
static void
actor_change_color_state_to_null (void)
actor_unset_color_state (void)
{
ClutterActor *actor;
ClutterColorState *color_state;
@ -118,7 +116,7 @@ actor_change_color_state_to_null (void)
actor = clutter_actor_new ();
clutter_actor_set_color_state (actor, NULL);
clutter_actor_unset_color_state (actor);
color_state = clutter_actor_get_color_state (actor);
colorspace = clutter_color_state_get_colorspace (color_state);
@ -134,6 +132,5 @@ CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/color-state-default", actor_color_state_default)
CLUTTER_TEST_UNIT ("/actor/color-state-passed", actor_color_state_passed)
CLUTTER_TEST_UNIT ("/actor/change-color-state", actor_change_color_state)
CLUTTER_TEST_UNIT ("/actor/change-color-state-to-null",
actor_change_color_state_to_null)
CLUTTER_TEST_UNIT ("/actor/unset-color-state", actor_unset_color_state)
)