summaryrefslogtreecommitdiff
path: root/src/bin/elementary
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-12-14 18:03:21 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-12-14 20:32:29 +0900
commitd29f01e5ee53dac79f2685996a9958ef88e38b98 (patch)
treedbef5ad50a29803176a9fe762d290b72fe77e1e0 /src/bin/elementary
parent7bf8e87185d882e9d85b23d9a13d08fbe725c040 (diff)
tests: Add an example test case for shadows
This is fun.
Diffstat (limited to 'src/bin/elementary')
-rw-r--r--src/bin/elementary/test.c4
-rw-r--r--src/bin/elementary/test_part_shadow.c194
2 files changed, 197 insertions, 1 deletions
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index 8a592ab7d2..114cd7927a 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -314,6 +314,7 @@ void test_win_modal(void *data, Evas_Object *obj, void *event_info);
314void test_box_disable(void *data, Evas_Object *obj, void *event_info); 314void test_box_disable(void *data, Evas_Object *obj, void *event_info);
315void test_layout_disable(void *data, Evas_Object *obj, void *event_info); 315void test_layout_disable(void *data, Evas_Object *obj, void *event_info);
316void test_part_background(void *data, Evas_Object *obj, void *event_info); 316void test_part_background(void *data, Evas_Object *obj, void *event_info);
317void test_part_shadow(void *data, Evas_Object *obj, void *event_info);
317 318
318void test_colorclass(void *data, Evas_Object *obj, void *event_info); 319void test_colorclass(void *data, Evas_Object *obj, void *event_info);
319 320
@@ -1148,7 +1149,7 @@ add_tests:
1148 ADD_TEST(NULL, "Evas", "Gfx Filters", test_gfx_filters); 1149 ADD_TEST(NULL, "Evas", "Gfx Filters", test_gfx_filters);
1149 ADD_TEST(NULL, "Evas", "Snapshot", test_evas_snapshot); 1150 ADD_TEST(NULL, "Evas", "Snapshot", test_evas_snapshot);
1150 ADD_TEST(NULL, "Evas", "Map", test_evas_map); 1151 ADD_TEST(NULL, "Evas", "Map", test_evas_map);
1151 ADD_TEST_EO(NULL, "Evas", "Gfx Map", test_efl_gfx_map); 1152 ADD_TEST_EO(NULL, "Evas", "Efl.Gfx.Map", test_efl_gfx_map);
1152 1153
1153 //------------------------------// 1154 //------------------------------//
1154 ADD_TEST(NULL, "Widgets Disable/Enable", "Box", test_box_disable); 1155 ADD_TEST(NULL, "Widgets Disable/Enable", "Box", test_box_disable);
@@ -1156,6 +1157,7 @@ add_tests:
1156 1157
1157 //------------------------------// 1158 //------------------------------//
1158 ADD_TEST_EO(NULL, "Widgets Part", "Part Background", test_part_background); 1159 ADD_TEST_EO(NULL, "Widgets Part", "Part Background", test_part_background);
1160 ADD_TEST_EO(NULL, "Widgets Part", "Part Shadow", test_part_shadow);
1159#undef ADD_TEST 1161#undef ADD_TEST
1160 1162
1161 if (autorun) 1163 if (autorun)
diff --git a/src/bin/elementary/test_part_shadow.c b/src/bin/elementary/test_part_shadow.c
new file mode 100644
index 0000000000..a1eee81a4d
--- /dev/null
+++ b/src/bin/elementary/test_part_shadow.c
@@ -0,0 +1,194 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#define ELM_WIDGET_PROTECTED
6#include <Elementary.h>
7
8typedef struct Test_Data
9{
10 Evas_Object *pb1;
11 Evas_Object *pb2;
12 Evas_Object *pb3;
13 Evas_Object *pb4;
14 Evas_Object *pb5;
15 Evas_Object *ico;
16 Evas_Object *btn_start;
17 Evas_Object *btn_stop;
18 int loop;
19} Test_Data;
20
21static void
22animate(void *data, const Efl_Event *ev EINA_UNUSED)
23{
24 Test_Data *td = data;
25 int loop = td->loop++;
26 double radius;
27
28 loop = (loop % 120) < 60 ? (loop % 60) : (60 - (loop % 60));
29 radius = 3.0 + (loop * 32.0 / 60.0);
30 radius *= elm_config_scale_get() / elm_app_base_scale_get();
31 efl_gfx_blur_radius_set(efl_part(td->ico, "shadow"), radius, radius);
32}
33
34static void
35pulse_start(void *data, const Efl_Event *ev EINA_UNUSED)
36{
37 Test_Data *td = data;
38
39 efl_ui_progressbar_pulse_set(td->pb1, EINA_TRUE);
40 efl_ui_progressbar_pulse_set(td->pb2, EINA_TRUE);
41 efl_ui_progressbar_pulse_set(td->pb3, EINA_TRUE);
42 efl_ui_progressbar_pulse_set(td->pb4, EINA_TRUE);
43 efl_ui_progressbar_pulse_set(td->pb5, EINA_TRUE);
44
45 efl_ui_widget_disabled_set(td->btn_start, EINA_TRUE);
46 efl_ui_widget_disabled_set(td->btn_stop, EINA_FALSE);
47
48 efl_event_callback_add(td->ico, EFL_EVENT_ANIMATOR_TICK, animate, td);
49}
50
51static void
52pulse_stop(void *data, const Efl_Event *ev EINA_UNUSED)
53{
54 Test_Data *td = data;
55
56 efl_ui_progressbar_pulse_set(td->pb1, EINA_FALSE);
57 efl_ui_progressbar_pulse_set(td->pb2, EINA_FALSE);
58 efl_ui_progressbar_pulse_set(td->pb3, EINA_FALSE);
59 efl_ui_progressbar_pulse_set(td->pb4, EINA_FALSE);
60 efl_ui_progressbar_pulse_set(td->pb5, EINA_FALSE);
61
62 efl_ui_widget_disabled_set(td->btn_start, EINA_FALSE);
63 efl_ui_widget_disabled_set(td->btn_stop, EINA_TRUE);
64
65 efl_event_callback_del(td->ico, EFL_EVENT_ANIMATOR_TICK, animate, td);
66}
67
68static void
69_delete_cb(void *data, const Efl_Event *ev)
70{
71 Test_Data *td = data;
72
73 pulse_stop(td, NULL);
74 efl_del(ev->object);
75 free(td);
76}
77
78void
79test_part_shadow(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
80{
81 Evas_Object *win, *pb, *bx, *hbx, *bt, *bt_bx, *ic, *shadow;
82 char buf[PATH_MAX];
83 Test_Data *td;
84 char loops[32];
85
86 td = calloc(1, sizeof(*td));
87
88 win = efl_add(EFL_UI_WIN_CLASS, NULL,
89 efl_ui_win_name_set(efl_added, "shadow"),
90 efl_text_set(efl_added, "Shadow effects"));
91 efl_event_callback_add(win, EFL_UI_WIN_EVENT_DELETE_REQUEST, _delete_cb, td);
92
93 bx = efl_add(EFL_UI_BOX_CLASS, win);
94 efl_content_set(win, bx);
95
96 pb = efl_add(EFL_UI_PROGRESSBAR_CLASS, win);
97 efl_gfx_size_hint_weight_set(pb, EFL_GFX_SIZE_HINT_EXPAND, 0);
98 efl_ui_progressbar_pulse_mode_set(pb, EINA_TRUE);
99 efl_pack(bx, pb);
100 td->pb1 = pb;
101
102 // A black drop-down shadow
103 shadow = efl_ref(efl_part(pb, "shadow"));
104 efl_gfx_color_set(shadow, 0, 0, 0, 255);
105 efl_gfx_blur_grow_set(shadow, ELM_SCALE_SIZE(1));
106 efl_gfx_blur_radius_set(shadow, ELM_SCALE_SIZE(8), ELM_SCALE_SIZE(8));
107 efl_gfx_blur_offset_set(shadow, ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5));
108 efl_unref(shadow);
109
110 ic = efl_add(EFL_UI_IMAGE_CLASS, win);
111 snprintf(buf, sizeof(buf), "%s/images/logo.png", elm_app_data_dir_get());
112 efl_file_set(ic, buf, NULL);
113 efl_pack(bx, ic);
114 td->ico = ic;
115
116 // A red glow
117 shadow = efl_ref(efl_part(ic, "shadow"));
118 efl_gfx_color_set(shadow, 255, 0, 0, 255);
119 efl_gfx_blur_grow_set(shadow, ELM_SCALE_SIZE(3));
120 efl_gfx_blur_radius_set(shadow, ELM_SCALE_SIZE(5), ELM_SCALE_SIZE(5));
121 efl_unref(shadow);
122
123 pb = efl_add(EFL_UI_PROGRESSBAR_CLASS, win);
124 efl_ui_progressbar_pulse_mode_set(pb, EINA_TRUE);
125 efl_gfx_size_hint_weight_set(pb, EFL_GFX_SIZE_HINT_EXPAND, 0);
126 efl_pack(bx, pb);
127 td->pb4 = pb;
128
129 // A custom 3D shadow effect
130 static const char *filter_code =
131 "for i = 1,loops,1 do\n"
132 " local offset = i - loops - 1\n"
133 " local alpha = i * 128/loops\n"
134 " blend { ox = offset, oy = offset, color = color(255, 255, 255, alpha) }\n"
135 "end"
136 ;
137
138 sprintf(loops, "%f", (double) ELM_SCALE_SIZE(12));
139 shadow = efl_ref(efl_part(pb, "shadow"));
140 efl_gfx_filter_data_set(shadow, "loops", loops, EINA_TRUE);
141 efl_gfx_filter_program_set(shadow, filter_code, "custom");
142 efl_unref(shadow);
143
144 hbx = efl_add(EFL_UI_BOX_CLASS, win);
145 efl_ui_direction_set(hbx, EFL_UI_DIR_HORIZONTAL);
146 efl_gfx_size_hint_weight_set(hbx, EFL_GFX_SIZE_HINT_EXPAND, 0);
147 efl_pack(bx, hbx);
148
149 // FIXME: Needs wheel progressbar class
150 pb = efl_add(EFL_UI_PROGRESSBAR_CLASS, win,
151 efl_ui_widget_style_set(efl_added, "wheel"));
152 efl_ui_progressbar_pulse_mode_set(pb, EINA_TRUE);
153 efl_pack(hbx, pb);
154 td->pb2 = pb;
155
156 // A cyan glow
157 shadow = efl_ref(efl_part(pb, "shadow"));
158 efl_gfx_color_set(shadow, 0, 255, 255, 255);
159 efl_gfx_blur_grow_set(shadow, ELM_SCALE_SIZE(5));
160 efl_gfx_blur_radius_set(shadow, ELM_SCALE_SIZE(8), ELM_SCALE_SIZE(8));
161 efl_unref(shadow);
162
163 pb = efl_add(EFL_UI_PROGRESSBAR_CLASS, win,
164 efl_ui_widget_style_set(efl_added, "wheel"));
165 efl_ui_progressbar_pulse_mode_set(pb, EINA_TRUE);
166 efl_pack(hbx, pb);
167 td->pb3 = pb;
168
169 // A black drop-down shadow
170 shadow = efl_ref(efl_part(pb, "shadow"));
171 efl_gfx_color_set(shadow, 0, 0, 0, 255);
172 efl_gfx_blur_grow_set(shadow, ELM_SCALE_SIZE(1));
173 efl_gfx_blur_radius_set(shadow, ELM_SCALE_SIZE(8), ELM_SCALE_SIZE(8));
174 efl_gfx_blur_offset_set(shadow, ELM_SCALE_SIZE(6), ELM_SCALE_SIZE(6));
175 efl_unref(shadow);
176
177 bt_bx = efl_add(EFL_UI_BOX_CLASS, win);
178 efl_ui_direction_set(bt_bx, EFL_UI_DIR_HORIZONTAL);
179 efl_gfx_size_hint_weight_set(bt_bx, EFL_GFX_SIZE_HINT_EXPAND, 0);
180 efl_pack(bx, bt_bx);
181
182 bt = efl_add(EFL_UI_BUTTON_CLASS, win, efl_text_set(efl_added, "Start"));
183 efl_event_callback_add(bt, EFL_UI_EVENT_CLICKED, pulse_start, td);
184 efl_pack(bt_bx, bt);
185 td->btn_start = bt;
186
187 bt = efl_add(EFL_UI_BUTTON_CLASS, win, efl_text_set(efl_added, "Stop"));
188 efl_event_callback_add(bt, EFL_UI_EVENT_CLICKED, pulse_stop, td);
189 efl_ui_widget_disabled_set(bt, EINA_TRUE);
190 efl_pack(bt_bx, bt);
191 td->btn_stop = bt;
192
193 efl_gfx_size_set(win, EINA_SIZE2D(240, 320));
194}