diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/edje/src/examples/edje-color-class.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r-- | libraries/edje/src/examples/edje-color-class.c | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/edje-color-class.c b/libraries/edje/src/examples/edje-color-class.c new file mode 100644 index 0000000..9ac8653 --- /dev/null +++ b/libraries/edje/src/examples/edje-color-class.c | |||
@@ -0,0 +1,257 @@ | |||
1 | /** | ||
2 | * Simple Edje example illustrating color class functions. | ||
3 | * | ||
4 | * You'll need at least one Evas engine built for it (excluding the | ||
5 | * buffer one). See stdout/stderr for output. | ||
6 | * | ||
7 | * @verbatim | ||
8 | * edje_cc color-class.edc && gcc -o edje-table edje-color-class.c `pkg-config --libs --cflags evas ecore ecore-evas edje` | ||
9 | * @endverbatim | ||
10 | */ | ||
11 | |||
12 | #ifdef HAVE_CONFIG_H | ||
13 | #include "config.h" | ||
14 | #else | ||
15 | #define PACKAGE_EXAMPLES_DIR "." | ||
16 | #define __UNUSED__ | ||
17 | #endif | ||
18 | |||
19 | #include <Ecore.h> | ||
20 | #include <Ecore_Evas.h> | ||
21 | #include <Edje.h> | ||
22 | |||
23 | #define WIDTH (400) | ||
24 | #define HEIGHT (400) | ||
25 | |||
26 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/color-class.edj"; | ||
27 | |||
28 | typedef int color[4]; /* rgba */ | ||
29 | |||
30 | static Ecore_Evas *ee, *ee2; | ||
31 | static Evas *evas, *evas2; | ||
32 | static Evas_Object *bg, *edje_obj, *bg2, *edje_obj2; | ||
33 | static const char *selected_class; | ||
34 | |||
35 | static color colors_init_data[] = | ||
36 | {{255, 0, 0, 255}, /* red */ | ||
37 | {0, 255, 0, 255}, /* green */ | ||
38 | {0, 0, 255, 255}, /* blue */ | ||
39 | {0, 0, 0, 255}, /* black */ | ||
40 | {255, 255, 255, 255}, /* white */ | ||
41 | {128, 128, 128, 255}, /* gray */ | ||
42 | {255, 255, 0, 255}, /* yellow */ | ||
43 | {255, 0, 255, 255} /* pink */ | ||
44 | }; | ||
45 | |||
46 | static char *color_names[] = | ||
47 | {"red", "green", "blue", "black", "white", | ||
48 | "gray", "yellow", "pink"}; | ||
49 | |||
50 | static Eina_Bool | ||
51 | _get_color_from_name(const char *n, color *c) | ||
52 | { | ||
53 | int i; | ||
54 | for (i = 0; i < 8; i++) | ||
55 | if (!strcmp(n, color_names[i])) | ||
56 | { | ||
57 | (*c)[0] = (colors_init_data[i])[0]; | ||
58 | (*c)[1] = (colors_init_data[i])[1]; | ||
59 | (*c)[2] = (colors_init_data[i])[2]; | ||
60 | (*c)[3] = (colors_init_data[i])[3]; | ||
61 | return EINA_TRUE; | ||
62 | } | ||
63 | |||
64 | return EINA_FALSE; | ||
65 | } | ||
66 | |||
67 | static void | ||
68 | _color_classes_print(void) | ||
69 | { | ||
70 | Eina_List *classes; | ||
71 | char *class_name; | ||
72 | |||
73 | fprintf(stdout, "Getting the color classes\n\n"); | ||
74 | classes = edje_color_class_list(); | ||
75 | EINA_LIST_FREE(classes, class_name) | ||
76 | { | ||
77 | int r1, r2, r3, g1, g2, g3, b1, b2, b3, | ||
78 | a1, a2, a3; | ||
79 | |||
80 | fprintf(stdout, "\ncolor class: %s\n", class_name); | ||
81 | if (!edje_color_class_get(class_name, &r1, &g1, &b1, &a1, | ||
82 | &r2, &g2, &b2, &a2, &r3, &g3, &b3, &a3)) | ||
83 | fprintf(stderr, "Cannot get the color class\n"); | ||
84 | else | ||
85 | { | ||
86 | |||
87 | fprintf(stdout,"Object color r: %d g: %d b: %d a: %d\n", | ||
88 | r1, g1, b1, a1); | ||
89 | fprintf(stdout,"Text outline color r: %d g: %d b: %d a: %d\n", | ||
90 | r2, g2, b2, a2); | ||
91 | fprintf(stdout,"Text shadow color r: %d g: %d b: %d a: %d\n", | ||
92 | r3, g3, b3, a3); | ||
93 | } | ||
94 | free(class_name); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | static void | ||
99 | _on_destroy(Ecore_Evas *ee) | ||
100 | { | ||
101 | ecore_main_loop_quit(); | ||
102 | } | ||
103 | |||
104 | static void | ||
105 | _on_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) | ||
106 | { | ||
107 | Evas_Event_Mouse_Down *ev = event_info; | ||
108 | |||
109 | if (ev->button == 1) | ||
110 | if (obj == edje_obj) | ||
111 | edje_color_class_del(selected_class); | ||
112 | else | ||
113 | edje_object_color_class_del(edje_obj2, selected_class); | ||
114 | } | ||
115 | |||
116 | /* here just to keep our example's window size | ||
117 | * in synchrony. */ | ||
118 | static void | ||
119 | _canvas_resize_cb(Ecore_Evas *_ee) | ||
120 | { | ||
121 | int w, h; | ||
122 | |||
123 | ecore_evas_geometry_get(_ee, NULL, NULL, &w, &h); | ||
124 | |||
125 | if (_ee == ee) | ||
126 | { | ||
127 | evas_object_resize(bg, w, h); | ||
128 | evas_object_resize(edje_obj, w, h); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | evas_object_resize(bg2, w, h); | ||
133 | evas_object_resize(edje_obj2, w, h); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | static void | ||
138 | _color_class_callback_delete(void *data, Evas *evas, Evas_Object *obj, | ||
139 | const char *emission, void *source) | ||
140 | { | ||
141 | if (!strcmp(data, "process")) | ||
142 | fprintf(stdout, "Color class: %s deleted on process level\n", emission); | ||
143 | else | ||
144 | fprintf(stdout, "Color class: %s deleted on object level\n", emission); | ||
145 | } | ||
146 | |||
147 | static void | ||
148 | _create_windows(void) | ||
149 | { | ||
150 | /* this will give you a window with an Evas canvas under the first | ||
151 | * engine available */ | ||
152 | ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
153 | ee2 = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
154 | |||
155 | ecore_evas_callback_destroy_set(ee, _on_destroy); | ||
156 | ecore_evas_callback_resize_set(ee, _canvas_resize_cb); | ||
157 | ecore_evas_title_set(ee, "Edje Color Class Example"); | ||
158 | ecore_evas_show(ee); | ||
159 | |||
160 | ecore_evas_callback_destroy_set(ee2, _on_destroy); | ||
161 | ecore_evas_callback_resize_set(ee2, _canvas_resize_cb); | ||
162 | ecore_evas_title_set(ee2, "Edje Object Color Class Example"); | ||
163 | ecore_evas_show(ee2); | ||
164 | |||
165 | evas = ecore_evas_get(ee); | ||
166 | evas2 = ecore_evas_get(ee2); | ||
167 | |||
168 | bg = evas_object_rectangle_add(evas); | ||
169 | evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */ | ||
170 | evas_object_move(bg, 0, 0); /* at canvas' origin */ | ||
171 | evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */ | ||
172 | evas_object_show(bg); | ||
173 | |||
174 | bg2 = evas_object_rectangle_add(evas2); | ||
175 | evas_object_color_set(bg2, 255, 255, 255, 255); /* white bg */ | ||
176 | evas_object_move(bg2, 0, 0); /* at canvas' origin */ | ||
177 | evas_object_resize(bg2, WIDTH, HEIGHT); /* covers full canvas */ | ||
178 | evas_object_show(bg2); | ||
179 | |||
180 | edje_obj = edje_object_add(evas); | ||
181 | evas_object_event_callback_add(edje_obj, EVAS_CALLBACK_MOUSE_DOWN, | ||
182 | _on_mouse_down, NULL); | ||
183 | |||
184 | edje_object_file_set(edje_obj, edje_file_path, "example_color_class"); | ||
185 | evas_object_move(edje_obj, 0, 0); /* at canvas' origin */ | ||
186 | evas_object_resize(edje_obj, WIDTH, HEIGHT); | ||
187 | edje_object_part_text_set(edje_obj, "part_four", "EDJE EXAMPLE"); | ||
188 | edje_object_signal_callback_add(edje_obj, "color_class,del", "*", | ||
189 | (Edje_Signal_Cb) _color_class_callback_delete, | ||
190 | "process"); | ||
191 | evas_object_show(edje_obj); | ||
192 | |||
193 | edje_obj2 = edje_object_add(evas2); | ||
194 | evas_object_event_callback_add(edje_obj2, EVAS_CALLBACK_MOUSE_DOWN, | ||
195 | _on_mouse_down, NULL); | ||
196 | |||
197 | edje_object_file_set(edje_obj2, edje_file_path, "example_color_class"); | ||
198 | evas_object_move(edje_obj2, 0, 0); /* at canvas' origin */ | ||
199 | evas_object_resize(edje_obj2, WIDTH, HEIGHT); | ||
200 | edje_object_part_text_set(edje_obj2, "part_four", "EDJE OBJECT EXAMPLE"); | ||
201 | edje_object_signal_callback_add(edje_obj2, "color_class,del", "*", | ||
202 | (Edje_Signal_Cb) _color_class_callback_delete, | ||
203 | "object"); | ||
204 | evas_object_show(edje_obj2); | ||
205 | } | ||
206 | |||
207 | int | ||
208 | main(int argc, char *argv[]) | ||
209 | { | ||
210 | color c1, c2, c3; | ||
211 | int i; | ||
212 | |||
213 | if (argc != 5) | ||
214 | { | ||
215 | fprintf(stderr, "You have to use: %s color_class_name color1, color2," \ | ||
216 | "color3\n", argv[0]); | ||
217 | fprintf(stderr, "Available colors:\n"); | ||
218 | for (i = 0; i < 8; i++) | ||
219 | fprintf(stderr, "%s\n", color_names[i]); | ||
220 | |||
221 | return 1; | ||
222 | } | ||
223 | |||
224 | selected_class = argv[1]; | ||
225 | if (!(_get_color_from_name(argv[2], &c1) && | ||
226 | _get_color_from_name(argv[3], &c2) && | ||
227 | _get_color_from_name(argv[4], &c3))) | ||
228 | { | ||
229 | fprintf(stderr, "Color not available!\n"); | ||
230 | return 2; | ||
231 | } | ||
232 | |||
233 | ecore_evas_init(); | ||
234 | edje_init(); | ||
235 | |||
236 | _create_windows(); | ||
237 | |||
238 | edje_color_class_set(argv[1], /* class name */ | ||
239 | c1[0], c1[1], c1[2], c1[3], /* Object color */ | ||
240 | c2[0], c2[1], c2[2], c2[3], /* Text outline */ | ||
241 | c3[0], c3[1], c3[2], c3[3]); /* Text shadow */ | ||
242 | |||
243 | /* Setting an arbitrary value just to see the difference between */ | ||
244 | /* process level and object level */ | ||
245 | edje_object_color_class_set(edje_obj2, argv[1], /* class name */ | ||
246 | 128, 180, 77, 255, /* Object color */ | ||
247 | 200, 22, 86, 255, /* Text outline */ | ||
248 | 39, 90, 187, 255); /* Text shadow */ | ||
249 | |||
250 | _color_classes_print(); | ||
251 | ecore_main_loop_begin(); | ||
252 | ecore_evas_free(ee); | ||
253 | ecore_evas_free(ee2); | ||
254 | ecore_evas_shutdown(); | ||
255 | edje_shutdown(); | ||
256 | return 0; | ||
257 | } | ||