| 1 |
#include <clutter/clutter.h> |
| 2 |
#include <stdlib.h> |
| 3 |
|
| 4 |
static void |
| 5 |
opacity_label (void) |
| 6 |
{ |
| 7 |
ClutterActor *stage; |
| 8 |
ClutterActor *label; |
| 9 |
ClutterColor label_color = { 255, 0, 0, 128 }; |
| 10 |
ClutterColor color_check = { 0, }; |
| 11 |
|
| 12 |
stage = clutter_test_get_stage (); |
| 13 |
|
| 14 |
label = clutter_text_new_with_text ("Sans 18px", "Label, 50% opacity"); |
| 15 |
clutter_text_set_color (CLUTTER_TEXT (label), &label_color); |
| 16 |
|
| 17 |
if (g_test_verbose ()) |
| 18 |
g_print ("label 50%%.get_color()/1\n"); |
| 19 |
clutter_text_get_color (CLUTTER_TEXT (label), &color_check); |
| 20 |
g_assert (color_check.alpha == label_color.alpha); |
| 21 |
|
| 22 |
clutter_actor_add_child (stage, label); |
| 23 |
clutter_actor_set_position (label, 10, 10); |
| 24 |
|
| 25 |
if (g_test_verbose ()) |
| 26 |
g_print ("label 50%%.get_color()/2\n"); |
| 27 |
clutter_text_get_color (CLUTTER_TEXT (label), &color_check); |
| 28 |
g_assert (color_check.alpha == label_color.alpha); |
| 29 |
|
| 30 |
if (g_test_verbose ()) |
| 31 |
g_print ("label 50%%.get_paint_opacity()/1\n"); |
| 32 |
g_assert (clutter_actor_get_paint_opacity (label) == 255); |
| 33 |
|
| 34 |
if (g_test_verbose ()) |
| 35 |
g_print ("label 50%%.get_paint_opacity()/2\n"); |
| 36 |
clutter_actor_set_opacity (label, 128); |
| 37 |
g_assert (clutter_actor_get_paint_opacity (label) == 128); |
| 38 |
} |
| 39 |
|
| 40 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 41 |
static void |
| 42 |
opacity_rectangle (void) |
| 43 |
{ |
| 44 |
ClutterActor *stage; |
| 45 |
ClutterActor *rect; |
| 46 |
ClutterColor rect_color = { 0, 0, 255, 255 }; |
| 47 |
ClutterColor color_check = { 0, }; |
| 48 |
|
| 49 |
stage = clutter_test_get_stage (); |
| 50 |
|
| 51 |
rect = clutter_rectangle_new_with_color (&rect_color); |
| 52 |
clutter_actor_set_size (rect, 128, 128); |
| 53 |
clutter_actor_set_position (rect, 150, 90); |
| 54 |
|
| 55 |
if (g_test_verbose ()) |
| 56 |
g_print ("rect 100%%.get_color()/1\n"); |
| 57 |
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check); |
| 58 |
g_assert (color_check.alpha == rect_color.alpha); |
| 59 |
|
| 60 |
clutter_actor_add_child (stage, rect); |
| 61 |
|
| 62 |
if (g_test_verbose ()) |
| 63 |
g_print ("rect 100%%.get_color()/2\n"); |
| 64 |
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check); |
| 65 |
g_assert (color_check.alpha == rect_color.alpha); |
| 66 |
|
| 67 |
if (g_test_verbose ()) |
| 68 |
g_print ("rect 100%%.get_paint_opacity()\n"); |
| 69 |
g_assert (clutter_actor_get_paint_opacity (rect) == 255); |
| 70 |
} |
| 71 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 72 |
|
| 73 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 74 |
static void |
| 75 |
opacity_paint (void) |
| 76 |
{ |
| 77 |
ClutterActor *stage, *group1, *group2; |
| 78 |
ClutterActor *label, *rect; |
| 79 |
ClutterColor label_color = { 255, 0, 0, 128 }; |
| 80 |
ClutterColor rect_color = { 0, 0, 255, 255 }; |
| 81 |
ClutterColor color_check = { 0, }; |
| 82 |
|
| 83 |
stage = clutter_test_get_stage (); |
| 84 |
|
| 85 |
group1 = clutter_group_new (); |
| 86 |
clutter_actor_set_opacity (group1, 128); |
| 87 |
clutter_container_add (CLUTTER_CONTAINER (stage), group1, NULL); |
| 88 |
clutter_actor_set_position (group1, 10, 30); |
| 89 |
clutter_actor_show (group1); |
| 90 |
|
| 91 |
label = clutter_text_new_with_text ("Sans 18px", "Label+Group, 25% opacity"); |
| 92 |
clutter_text_set_color (CLUTTER_TEXT (label), &label_color); |
| 93 |
|
| 94 |
if (g_test_verbose ()) |
| 95 |
g_print ("label 50%% + group 50%%.get_color()/1\n"); |
| 96 |
clutter_text_get_color (CLUTTER_TEXT (label), &color_check); |
| 97 |
g_assert (color_check.alpha == label_color.alpha); |
| 98 |
|
| 99 |
clutter_container_add (CLUTTER_CONTAINER (group1), label, NULL); |
| 100 |
|
| 101 |
if (g_test_verbose ()) |
| 102 |
g_print ("label 50%% + group 50%%.get_color()/2\n"); |
| 103 |
clutter_text_get_color (CLUTTER_TEXT (label), &color_check); |
| 104 |
g_assert (color_check.alpha == label_color.alpha); |
| 105 |
|
| 106 |
if (g_test_verbose ()) |
| 107 |
g_print ("label 50%% + group 50%%.get_paint_opacity() = 128\n"); |
| 108 |
g_assert (clutter_actor_get_paint_opacity (label) == 128); |
| 109 |
|
| 110 |
clutter_actor_destroy (label); |
| 111 |
|
| 112 |
group2 = clutter_group_new (); |
| 113 |
clutter_container_add (CLUTTER_CONTAINER (group1), group2, NULL); |
| 114 |
clutter_actor_set_position (group2, 10, 60); |
| 115 |
|
| 116 |
rect = clutter_rectangle_new_with_color (&rect_color); |
| 117 |
clutter_actor_set_size (rect, 128, 128); |
| 118 |
|
| 119 |
if (g_test_verbose ()) |
| 120 |
g_print ("rect 100%% + group 100%% + group 50%%.get_color()/1\n"); |
| 121 |
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check); |
| 122 |
g_assert (color_check.alpha == rect_color.alpha); |
| 123 |
|
| 124 |
clutter_container_add (CLUTTER_CONTAINER (group2), rect, NULL); |
| 125 |
|
| 126 |
if (g_test_verbose ()) |
| 127 |
g_print ("rect 100%% + group 100%% + group 50%%.get_color()/2\n"); |
| 128 |
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check); |
| 129 |
g_assert (color_check.alpha == rect_color.alpha); |
| 130 |
|
| 131 |
if (g_test_verbose ()) |
| 132 |
g_print ("rect 100%%.get_paint_opacity()\n"); |
| 133 |
g_assert (clutter_actor_get_paint_opacity (rect) == 128); |
| 134 |
} |
| 135 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 136 |
|
| 137 |
CLUTTER_TEST_SUITE ( |
| 138 |
CLUTTER_TEST_UNIT ("/actor/opacity/text", opacity_label) |
| 139 |
CLUTTER_TEST_UNIT ("/actor/opacity/rectangle", opacity_rectangle) |
| 140 |
CLUTTER_TEST_UNIT ("/actor/opacity/paint", opacity_paint) |
| 141 |
) |