tests: Replace ClutterRectangle with ClutterActor

These tests were written (and copy-pasted) before ClutterActor
had an actual background-color property. As a preparation to
the removal of ClutterRectangle, replace all these rectangles
with plain actors and background colors.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1332
This commit is contained in:
Georges Basile Stavracas Neto 2020-06-26 17:51:48 -03:00 committed by Robert Mader
parent 2802d359e5
commit e884ba7f39
26 changed files with 97 additions and 66 deletions

View File

@ -53,21 +53,25 @@ main (int argc, char *argv[])
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
button1 = clutter_rectangle_new_with_color (CLUTTER_COLOR_Yellow);
button1 = clutter_actor_new ();
clutter_actor_set_background_color (button1, CLUTTER_COLOR_Yellow);
clutter_actor_set_size (button1, SIZE, SIZE);
button2 = clutter_rectangle_new_with_color (CLUTTER_COLOR_Green);
button2 = clutter_actor_new ();
clutter_actor_set_background_color (button2, CLUTTER_COLOR_Green);
clutter_actor_set_position (button2, 2 * SIZE, 0);
clutter_actor_set_size (button2, SIZE, SIZE);
button3 = clutter_rectangle_new_with_color (CLUTTER_COLOR_Blue);
button3 = clutter_actor_new ();
clutter_actor_set_background_color (button3, CLUTTER_COLOR_Blue);
clutter_actor_set_position (button3, 0, 2 * SIZE);
clutter_actor_set_size (button3, SIZE, SIZE);
clutter_actor_set_z_position (button3, DEPTH);
/* a nested hierarchy, to check that the relative positions are
computed properly */
button4 = clutter_rectangle_new_with_color (CLUTTER_COLOR_Magenta);
button4 = clutter_actor_new ();
clutter_actor_set_background_color (button4, CLUTTER_COLOR_Magenta);
clutter_actor_set_position (button4, SIZE / 2, SIZE / 2);
clutter_actor_set_size (button4, SIZE, SIZE);

View File

@ -150,7 +150,8 @@ _create_button (const gchar *text)
ClutterActor *label = NULL;
button = clutter_actor_new ();
rectangle = clutter_rectangle_new_with_color (CLUTTER_COLOR_Magenta);
rectangle = clutter_actor_new ();
clutter_actor_set_background_color (rectangle, CLUTTER_COLOR_Magenta);
clutter_actor_set_size (rectangle, 375, 35);
label = clutter_text_new_full ("Sans Bold 32px",

View File

@ -121,7 +121,8 @@ make_ui (ClutterActor *stage)
clutter_actor_set_reactive (editable, TRUE);
/* rectangle: to create a entry "feeling" */
rectangle = clutter_rectangle_new_with_color (&color_rect);
rectangle = clutter_actor_new ();
clutter_actor_set_background_color (rectangle, &color_rect);
clutter_actor_set_position (rectangle, 150, editable_geom_y);
clutter_actor_set_size (rectangle, 500, 75);

View File

@ -210,7 +210,8 @@ make_ui (ClutterActor *stage)
/* test button */
button = clutter_actor_new ();
rectangle = clutter_rectangle_new_with_color (&color_rect);
rectangle = clutter_actor_new ();
clutter_actor_set_background_color (rectangle, &color_rect);
clutter_actor_set_size (rectangle, 75, 35);
label = clutter_text_new_full ("Sans Bold 32px",

View File

@ -66,7 +66,8 @@ make_ui (ClutterActor *stage)
clutter_actor_set_reactive (editable, TRUE);
/* rectangle: to create a entry "feeling" */
rectangle = clutter_rectangle_new_with_color (&color_rect);
rectangle = clutter_actor_new ();
clutter_actor_set_background_color (rectangle, &color_rect);
clutter_actor_set_position (rectangle, 150, 50);
clutter_actor_add_constraint (rectangle, clutter_bind_constraint_new (editable, CLUTTER_BIND_SIZE, 0));

View File

@ -120,7 +120,7 @@ test_destroy_class_init (TestDestroyClass *klass)
static void
test_destroy_init (TestDestroy *self)
{
self->bg = clutter_rectangle_new ();
self->bg = clutter_actor_new ();
clutter_container_add_actor (CLUTTER_CONTAINER (self), self->bg);
clutter_actor_set_name (self->bg, "Background");
@ -164,7 +164,7 @@ static void
actor_destruction (void)
{
ClutterActor *test = g_object_new (TEST_TYPE_DESTROY, NULL);
ClutterActor *child = clutter_rectangle_new ();
ClutterActor *child = clutter_actor_new ();
gboolean destroy_called = FALSE;
gboolean parent_set_called = FALSE;
gboolean property_changed = FALSE;

View File

@ -50,20 +50,21 @@ opacity_rectangle (void)
stage = clutter_test_get_stage ();
rect = clutter_rectangle_new_with_color (&rect_color);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &rect_color);
clutter_actor_set_size (rect, 128, 128);
clutter_actor_set_position (rect, 150, 90);
if (!g_test_quiet ())
g_print ("rect 100%%.get_color()/1\n");
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
clutter_actor_get_background_color (rect, &color_check);
g_assert (color_check.alpha == rect_color.alpha);
clutter_actor_add_child (stage, rect);
if (!g_test_quiet ())
g_print ("rect 100%%.get_color()/2\n");
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
clutter_actor_set_background_color (rect, &color_check);
g_assert (color_check.alpha == rect_color.alpha);
if (!g_test_quiet ())
@ -115,19 +116,20 @@ opacity_paint (void)
clutter_container_add (CLUTTER_CONTAINER (group1), group2, NULL);
clutter_actor_set_position (group2, 10, 60);
rect = clutter_rectangle_new_with_color (&rect_color);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &rect_color);
clutter_actor_set_size (rect, 128, 128);
if (!g_test_quiet ())
g_print ("rect 100%% + group 100%% + group 50%%.get_color()/1\n");
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
clutter_actor_get_background_color (rect, &color_check);
g_assert (color_check.alpha == rect_color.alpha);
clutter_container_add (CLUTTER_CONTAINER (group2), rect, NULL);
if (!g_test_quiet ())
g_print ("rect 100%% + group 100%% + group 50%%.get_color()/2\n");
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
clutter_actor_get_background_color (rect, &color_check);
g_assert (color_check.alpha == rect_color.alpha);
if (!g_test_quiet ())

View File

@ -57,7 +57,8 @@ on_timeout (gpointer data)
static const ClutterColor red = { 0xff, 0x00, 0x00, 0xff };
/* Create an actor that covers the whole stage but that
isn't visible so it shouldn't affect the picking */
over_actor = clutter_rectangle_new_with_color (&red);
over_actor = clutter_actor_new ();
clutter_actor_set_background_color (over_actor, &red);
clutter_actor_set_size (over_actor, STAGE_WIDTH, STAGE_HEIGHT);
clutter_actor_add_child (state->stage, over_actor);
clutter_actor_hide (over_actor);
@ -186,8 +187,9 @@ actor_pick (void)
ClutterColor color = { x * 255 / (ACTORS_X - 1),
y * 255 / (ACTORS_Y - 1),
128, 255 };
ClutterActor *rect = clutter_rectangle_new_with_color (&color);
ClutterActor *rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &color);
clutter_actor_set_position (rect,
x * state.actor_width,
y * state.actor_height);

View File

@ -203,8 +203,8 @@ make_actor (GType shader_type)
ClutterActor *rect;
const ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
rect = clutter_rectangle_new ();
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &white);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &white);
clutter_actor_set_size (rect, 50, 50);
clutter_actor_add_effect (rect, g_object_new (shader_type, NULL));

View File

@ -142,7 +142,7 @@ script_child (void)
"test-rect-1", &actor,
NULL);
g_assert (TEST_IS_GROUP (container));
g_assert (CLUTTER_IS_RECTANGLE (actor));
g_assert (CLUTTER_IS_ACTOR (actor));
focus_ret = FALSE;
clutter_container_child_get (CLUTTER_CONTAINER (container),
@ -152,7 +152,7 @@ script_child (void)
g_assert (focus_ret);
actor = clutter_script_get_object (script, "test-rect-2");
g_assert (CLUTTER_IS_RECTANGLE (actor));
g_assert (CLUTTER_IS_ACTOR (actor));
focus_ret = FALSE;
clutter_container_child_get (CLUTTER_CONTAINER (container),
@ -183,13 +183,13 @@ script_single (void)
g_assert_no_error (error);
actor = clutter_script_get_object (script, "test");
g_assert (CLUTTER_IS_RECTANGLE (actor));
g_assert (CLUTTER_IS_ACTOR (actor));
rect = CLUTTER_ACTOR (actor);
g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 50.0);
g_assert_cmpfloat (clutter_actor_get_y (rect), ==, 100.0);
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color);
clutter_actor_get_background_color (rect, &color);
g_assert_cmpint (color.red, ==, 255);
g_assert_cmpint (color.green, ==, 0xcc);
g_assert_cmpint (color.alpha, ==, 0xff);

View File

@ -3,19 +3,19 @@
"id" : "test-group",
"children" : [
{
"type" : "ClutterRectangle",
"type" : "ClutterActor",
"id" : "test-rect-1",
"width" : 100.0,
"height" : 100.0,
"color" : [ 255, 0, 0, 255 ],
"background-color" : [ 255, 0, 0, 255 ],
"child::focus" : true
},
{
"type" : "ClutterRectangle",
"type" : "ClutterActor",
"id" : "test-rect-2",
"width" : 100.0,
"height" : 100.0,
"color" : [ 0, 255, 0, 255 ]
"background-color" : [ 0, 255, 0, 255 ]
}
]
}

View File

@ -4,14 +4,14 @@
"columns" : [
[ "text-column", "gchararray" ],
[ "int-column", "gint" ],
[ "actor-column", "ClutterRectangle" ]
[ "actor-column", "ClutterActor" ]
],
"rows" : [
[ "text-row-1", 1, null ],
[ "text-row-2", 2, { "type" : "ClutterRectangle", "color" : "blue" } ],
[ "text-row-2", 2, { "type" : "ClutterActor", "background-color" : "blue" } ],
{
"int-column" : 3,
"actor-column" : { "type" : "ClutterRectangle", "name" : "actor-row-3" }
"actor-column" : { "type" : "ClutterActor", "name" : "actor-row-3" }
}
]
}

View File

@ -17,7 +17,7 @@
"children" : [
{
"id" : "child-1",
"type" : "ClutterRectangle",
"type" : "ClutterActor",
"width" : "3 em",
"height" : "3 em"
}

View File

@ -5,7 +5,7 @@
"children" : [
{
"id" : "child-1",
"type" : "ClutterRectangle",
"type" : "ClutterActor",
"width" : "3 em",
"height" : "3 em"
}

View File

@ -1,10 +1,10 @@
{
"type" : "ClutterRectangle",
"type" : "ClutterActor",
"id" : "test",
"width" : 50.0,
"height" : 100.0,
"x" : 100.0,
"y" : 100.0,
"color" : "#ffccdd",
"background-color" : "#ffccdd",
"name" : "Test Rectangle"
}

View File

@ -38,14 +38,14 @@ create_source (void)
for (y = 0; y < SOURCE_DIVISIONS_Y; y++)
for (x = 0; x < SOURCE_DIVISIONS_X; x++)
{
ClutterActor *rect = clutter_rectangle_new ();
ClutterActor *rect = clutter_actor_new ();
clutter_actor_set_background_color (rect,
corner_colors +
(y * SOURCE_DIVISIONS_X + x));
clutter_actor_set_size (rect, DIVISION_WIDTH, DIVISION_HEIGHT);
clutter_actor_set_position (rect,
DIVISION_WIDTH * x,
DIVISION_HEIGHT * y);
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect),
corner_colors +
(y * SOURCE_DIVISIONS_X + x));
clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL);
}

View File

@ -412,11 +412,13 @@ test_events_main (int argc, char *argv[])
g_signal_connect (stage, "deactivate",
G_CALLBACK (stage_state_cb), (char *) "deactivate");
focus_box = clutter_rectangle_new_with_color (CLUTTER_COLOR_Black);
focus_box = clutter_actor_new ();
clutter_actor_set_background_color (focus_box, CLUTTER_COLOR_Black);
clutter_actor_set_name (focus_box, "Focus Box");
clutter_container_add (CLUTTER_CONTAINER(stage), focus_box, NULL);
actor = clutter_rectangle_new_with_color (CLUTTER_COLOR_Red);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, CLUTTER_COLOR_Red);
clutter_actor_set_name (actor, "Red Box");
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 100, 100);
@ -431,7 +433,8 @@ test_events_main (int argc, char *argv[])
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), actor);
actor = clutter_rectangle_new_with_color (CLUTTER_COLOR_Green);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, CLUTTER_COLOR_Green);
clutter_actor_set_name (actor, "Green Box");
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 250, 100);
@ -443,7 +446,8 @@ test_events_main (int argc, char *argv[])
g_signal_connect (actor, "captured-event", G_CALLBACK (capture_cb), NULL);
/* non reactive */
actor = clutter_rectangle_new_with_color (CLUTTER_COLOR_Black);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, CLUTTER_COLOR_Black);
clutter_actor_set_name (actor, "Black Box");
clutter_actor_set_size (actor, 400, 50);
clutter_actor_set_position (actor, 100, 250);
@ -455,7 +459,8 @@ test_events_main (int argc, char *argv[])
focus_box);
/* non reactive group, with reactive child */
actor = clutter_rectangle_new_with_color (CLUTTER_COLOR_Yellow);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, CLUTTER_COLOR_Yellow);
clutter_actor_set_name (actor, "Yellow Box");
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_reactive (actor, TRUE);
@ -469,7 +474,8 @@ test_events_main (int argc, char *argv[])
clutter_actor_set_position (group, 100, 350);
/* border actor */
actor = clutter_rectangle_new_with_color (CLUTTER_COLOR_Magenta);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, CLUTTER_COLOR_Magenta);
clutter_actor_set_name (actor, "Border Box");
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor,

View File

@ -235,7 +235,8 @@ test_grab_main (int argc, char *argv[])
g_signal_connect (stage, "deactivate",
G_CALLBACK (stage_state_cb), (char *) "deactivate");
actor = clutter_rectangle_new_with_color (&rcol);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, &rcol);
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 100, 100);
clutter_actor_set_reactive (actor, TRUE);
@ -246,7 +247,8 @@ test_grab_main (int argc, char *argv[])
g_signal_connect (actor, "button-release-event",
G_CALLBACK (red_release_cb), NULL);
actor = clutter_rectangle_new_with_color (&ycol);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, &ycol);
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 100, 300);
clutter_actor_set_reactive (actor, TRUE);
@ -255,7 +257,8 @@ test_grab_main (int argc, char *argv[])
g_signal_connect (actor, "button-press-event",
G_CALLBACK (toggle_grab_pointer_cb), NULL);
actor = clutter_rectangle_new_with_color (&bcol);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, &bcol);
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 300, 100);
clutter_actor_set_reactive (actor, TRUE);
@ -267,7 +270,8 @@ test_grab_main (int argc, char *argv[])
g_signal_connect (actor, "button-release-event",
G_CALLBACK (blue_release_cb), NULL);
actor = clutter_rectangle_new_with_color (&gcol);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, &gcol);
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 300, 300);
clutter_actor_set_reactive (actor, TRUE);
@ -278,7 +282,8 @@ test_grab_main (int argc, char *argv[])
G_CALLBACK (green_press_cb), NULL);
actor = clutter_rectangle_new_with_color (&ccol);
actor = clutter_actor_new ();
clutter_actor_set_background_color (actor, &ccol);
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 500, 100);
clutter_actor_set_reactive (actor, TRUE);

View File

@ -116,8 +116,8 @@ test_path_constraint_main (int argc,
path = clutter_path_new ();
clutter_path_set_description (path, PATH_DESCRIPTION);
rect = clutter_rectangle_new ();
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_color);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &rect_color);
clutter_actor_set_size (rect, 128, 128);
clutter_actor_set_reactive (rect, TRUE);
clutter_actor_add_constraint_with_name (rect, "path", clutter_path_constraint_new (path, 0.0));

View File

@ -22,8 +22,8 @@ static const gchar *test_unmerge =
" },"
" {"
" \"id\" : \"blue-button\","
" \"type\" : \"ClutterRectangle\","
" \"color\" : \"#0000ffff\","
" \"type\" : \"ClutterActor\","
" \"background-color\" : \"#0000ffff\","
" \"x\" : 350,"
" \"y\" : 50,"
" \"width\" : 100,"

View File

@ -11,8 +11,8 @@
"children" : [
{
"id" : "red-button",
"type" : "ClutterRectangle",
"color" : "#ff0000ff",
"type" : "ClutterActor",
"background-color" : "#ff0000ff",
"x" : 50, "y" : 50, "width" : 100, "height" : 100,
"reactive" : true,
"rotation" : [
@ -21,8 +21,8 @@
},
{
"id" : "green-button",
"type" : "ClutterRectangle",
"color" : "#00ff00ff",
"type" : "ClutterActor",
"background-color" : "#00ff00ff",
"border-width" : 5,
"border-color" : "#00cc00ff",
"position" : [ 200.0, 50.0 ],

View File

@ -49,7 +49,8 @@ test_shader_effects_main (int argc, char *argv[])
"opacity", 128,
NULL);
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_DarkOrange);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, CLUTTER_COLOR_DarkOrange);
clutter_actor_add_effect_with_name (rect, "blur", clutter_blur_effect_new ());
clutter_actor_set_position (rect, 415, 215);
clutter_actor_set_size (rect, 150, 150);

View File

@ -123,7 +123,8 @@ test_swipe_action_main (int argc, char *argv[])
clutter_actor_set_size (stage, 640, 480);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_Red);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Red);
clutter_actor_set_name (rect, "Vertical swipes");
clutter_actor_set_size (rect, 150, 150);
clutter_actor_set_position (rect, 10, 100);
@ -131,7 +132,8 @@ test_swipe_action_main (int argc, char *argv[])
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
attach_action (rect, VERTICAL);
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_Blue);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Blue);
clutter_actor_set_name (rect, "Horizontal swipes");
clutter_actor_set_size (rect, 150, 150);
clutter_actor_set_position (rect, 170, 100);
@ -139,7 +141,8 @@ test_swipe_action_main (int argc, char *argv[])
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
attach_action (rect, HORIZONTAL);
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_Green);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Green);
clutter_actor_set_name (rect, "All swipes");
clutter_actor_set_size (rect, 150, 150);
clutter_actor_set_position (rect, 330, 100);

View File

@ -112,7 +112,7 @@ rect_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer data)
return FALSE;
color = static_colors[g_random_int_range (0, NUM_COLORS)];
clutter_rectangle_set_color (CLUTTER_RECTANGLE (actor), &color);
clutter_actor_set_background_color (actor, &color);
return TRUE;
}
@ -152,7 +152,9 @@ test_touch_events_main (int argc, char *argv[])
{
gfloat size = STAGE_HEIGHT / NUM_ACTORS;
ClutterColor color = static_colors[i % NUM_COLORS];
ClutterActor *rectangle = clutter_rectangle_new_with_color (&color);
ClutterActor *rectangle = clutter_actor_new ();
clutter_actor_set_background_color (rectangle, &color);
/* Test that event delivery to actors work */
g_signal_connect (rectangle, "event", G_CALLBACK (rect_event_cb), NULL);

View File

@ -112,7 +112,8 @@ main (int argc, char **argv)
fmod ((i + (n_actors/3.0)), n_actors)))) /
(gdouble)(n_actors/4.0) - 1.0)) * 255.0;
rect = clutter_rectangle_new_with_color (&color);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &color);
clutter_actor_set_size (rect, 100, 100);
clutter_actor_set_anchor_point_from_gravity (rect,
CLUTTER_GRAVITY_CENTER);

View File

@ -107,7 +107,8 @@ main (int argc, char **argv)
fmod ((i + (n_actors/3.0)), n_actors)))) /
(gdouble)(n_actors/4.0) - 1.0)) * 255.0;
rect = clutter_rectangle_new_with_color (&color);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &color);
clutter_actor_set_size (rect, 100, 100);
clutter_actor_set_anchor_point_from_gravity (rect,
CLUTTER_GRAVITY_CENTER);