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-basic.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-basic.c | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/edje-basic.c b/libraries/edje/src/examples/edje-basic.c new file mode 100644 index 0000000..2a7a862 --- /dev/null +++ b/libraries/edje/src/examples/edje-basic.c | |||
@@ -0,0 +1,226 @@ | |||
1 | /** | ||
2 | * Simple Edje example illustrating the very basic functions of the | ||
3 | * library | ||
4 | * | ||
5 | * You'll need at least one Evas engine built for it (excluding the | ||
6 | * buffer one). See stdout/stderr for output. | ||
7 | * | ||
8 | * @verbatim | ||
9 | * gcc -o edje-basic edje-basic.c `pkg-config --libs --cflags evas ecore ecore-evas edje` | ||
10 | * @endverbatim | ||
11 | */ | ||
12 | |||
13 | #ifdef HAVE_CONFIG_H | ||
14 | #include "config.h" | ||
15 | #else | ||
16 | #define PACKAGE_EXAMPLES_DIR "." | ||
17 | #define __UNUSED__ | ||
18 | #endif | ||
19 | |||
20 | #include <Ecore.h> | ||
21 | #include <Ecore_Evas.h> | ||
22 | #include <Edje.h> | ||
23 | #include <stdio.h> | ||
24 | |||
25 | #define WIDTH (300) | ||
26 | #define HEIGHT (300) | ||
27 | |||
28 | static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png"; | ||
29 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/basic.edj"; | ||
30 | |||
31 | static Ecore_Evas *ee; | ||
32 | static Evas_Object *edje_obj; | ||
33 | |||
34 | static const char commands[] = \ | ||
35 | "commands are:\n" | ||
36 | "\ts - change Edje's global scaling factor\n" | ||
37 | "\tr - change center rectangle's scaling factor\n" | ||
38 | "\th - print help\n"; | ||
39 | |||
40 | static void | ||
41 | _on_keydown(void *data __UNUSED__, | ||
42 | Evas *evas __UNUSED__, | ||
43 | Evas_Object *o __UNUSED__, | ||
44 | void *einfo) | ||
45 | { | ||
46 | Evas_Event_Key_Down *ev = einfo; | ||
47 | |||
48 | if (strcmp(ev->keyname, "h") == 0) /* print help */ | ||
49 | { | ||
50 | fprintf(stdout, commands); | ||
51 | return; | ||
52 | } | ||
53 | |||
54 | if (strcmp(ev->keyname, "s") == 0) /* global scaling factor */ | ||
55 | { | ||
56 | double scale = edje_scale_get(); | ||
57 | |||
58 | printf("got scale %f\n", scale); | ||
59 | |||
60 | if (scale != 1.0) scale = 1.0; | ||
61 | else scale = 2.0; | ||
62 | |||
63 | edje_scale_set(scale); | ||
64 | |||
65 | fprintf(stdout, "Setting global scaling factor to %f.\n", scale); | ||
66 | |||
67 | return; | ||
68 | } | ||
69 | |||
70 | if (strcmp(ev->keyname, "r") == 0) /* individual scaling factor */ | ||
71 | { | ||
72 | double scale = edje_object_scale_get(edje_obj); | ||
73 | |||
74 | printf("got scale %f\n", scale); | ||
75 | |||
76 | if (!scale) scale = 1.0; | ||
77 | else if (scale == 1.0) scale = 2.0; | ||
78 | else scale = 0.0; | ||
79 | |||
80 | edje_object_scale_set(edje_obj, scale); | ||
81 | |||
82 | fprintf(stdout, "Setting center rectangle's scaling factor to %f.\n", | ||
83 | scale); | ||
84 | |||
85 | return; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | static void | ||
90 | _on_delete(Ecore_Evas *ee __UNUSED__) | ||
91 | { | ||
92 | ecore_main_loop_quit(); | ||
93 | } | ||
94 | |||
95 | int | ||
96 | main(void) | ||
97 | { | ||
98 | Evas_Object *border, *bg; | ||
99 | int x, y, w, h; | ||
100 | Evas *evas; | ||
101 | |||
102 | if (!ecore_evas_init()) | ||
103 | return EXIT_FAILURE; | ||
104 | |||
105 | if (!edje_init()) | ||
106 | return EXIT_FAILURE; | ||
107 | |||
108 | /* this will give you a window with an Evas canvas under the first | ||
109 | * engine available */ | ||
110 | ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
111 | if (!ee) | ||
112 | goto error; | ||
113 | |||
114 | ecore_evas_callback_delete_request_set(ee, _on_delete); | ||
115 | ecore_evas_title_set(ee, "Edje Basics Example"); | ||
116 | ecore_evas_show(ee); | ||
117 | |||
118 | evas = ecore_evas_get(ee); | ||
119 | |||
120 | bg = evas_object_rectangle_add(evas); | ||
121 | evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */ | ||
122 | evas_object_move(bg, 0, 0); /* at canvas' origin */ | ||
123 | evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */ | ||
124 | evas_object_show(bg); | ||
125 | ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); | ||
126 | |||
127 | evas_object_focus_set(bg, EINA_TRUE); | ||
128 | evas_object_event_callback_add( | ||
129 | bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL); | ||
130 | |||
131 | edje_obj = edje_object_add(evas); | ||
132 | |||
133 | /* exercising Edje loading error, on purpose */ | ||
134 | if (!edje_object_file_set(edje_obj, edje_file_path, "unexistant_group")) | ||
135 | { | ||
136 | int err = edje_object_load_error_get(edje_obj); | ||
137 | const char *errmsg = edje_load_error_str(err); | ||
138 | fprintf(stderr, "Could not load 'unexistant_group' from basic.edj:" | ||
139 | " %s\n", errmsg); | ||
140 | } | ||
141 | |||
142 | if (!edje_object_file_set(edje_obj, edje_file_path, "example_group")) | ||
143 | { | ||
144 | int err = edje_object_load_error_get(edje_obj); | ||
145 | const char *errmsg = edje_load_error_str(err); | ||
146 | fprintf(stderr, "Could not load 'example_group' from basic.edj: %s\n", | ||
147 | errmsg); | ||
148 | |||
149 | evas_object_del(edje_obj); | ||
150 | goto error_edj; | ||
151 | } | ||
152 | |||
153 | fprintf(stdout, "Loaded Edje object bound to group 'example_group' from" | ||
154 | " file basic.edj with success!\n"); | ||
155 | |||
156 | evas_object_move(edje_obj, 20, 20); | ||
157 | evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40); | ||
158 | evas_object_show(edje_obj); | ||
159 | |||
160 | /* this is a border around the Edje object above, here just to | ||
161 | * emphasize its geometry */ | ||
162 | border = evas_object_image_filled_add(evas); | ||
163 | evas_object_image_file_set(border, border_img_path, NULL); | ||
164 | evas_object_image_border_set(border, 2, 2, 2, 2); | ||
165 | evas_object_image_border_center_fill_set(border, EVAS_BORDER_FILL_NONE); | ||
166 | |||
167 | evas_object_resize(border, WIDTH - 40 + 4, HEIGHT - 40 + 4); | ||
168 | evas_object_move(border, 20 - 2, 20 - 2); | ||
169 | evas_object_show(border); | ||
170 | |||
171 | fprintf(stdout, "'example_data' data field in group 'example_group' has " | ||
172 | "the value: %s\n", edje_object_data_get(edje_obj, | ||
173 | "example_data")); | ||
174 | |||
175 | fprintf(stdout, "Testing if 'part_one' part exists: %s\n", | ||
176 | edje_object_part_exists(edje_obj, "part_one") ? "yes!" : "no"); | ||
177 | |||
178 | edje_object_part_geometry_get(edje_obj, "part_one", &x, &y, &w, &h); | ||
179 | fprintf(stdout, "The geometry of that part inside the Edje object's area " | ||
180 | "is: x = %d, y = %d, w = %d, h = %d\n", x, y, w, h); | ||
181 | |||
182 | evas_object_color_get(edje_object_part_object_get(edje_obj, "part_one"), | ||
183 | &x, &y, &w, &h); | ||
184 | fprintf(stdout, "That part's color components are: r = %d, g = %d, b = %d," | ||
185 | " a = %d\n", x, y, w, h); | ||
186 | |||
187 | edje_object_size_max_get(edje_obj, &w, &h); | ||
188 | fprintf(stdout, "The Edje object's max. size is: %d, %d\n", w, h); | ||
189 | |||
190 | edje_object_size_min_get(edje_obj, &w, &h); | ||
191 | fprintf(stdout, "The Edje object's min. size is: %d, %d\n", w, h); | ||
192 | |||
193 | edje_object_size_min_calc(edje_obj, &w, &h); | ||
194 | fprintf(stdout, "The Edje object's min. size reported by min. size" | ||
195 | " calculation is: w = %d, h = %d\n", w, h); | ||
196 | |||
197 | edje_object_size_min_restricted_calc(edje_obj, &w, &h, 500, 500); | ||
198 | fprintf(stdout, "The Edje object's min. size reported by *restricted* " | ||
199 | "min. size calculation is: w = %d, h = %d\n", w, h); | ||
200 | |||
201 | edje_object_parts_extends_calc(edje_obj, &x, &y, &w, &h); | ||
202 | fprintf(stdout, "The Edje object's \"extended\" geometry is: x = %d, " | ||
203 | "y = %d, w = %d, h = %d\n", x, y, w, h); | ||
204 | |||
205 | fprintf(stdout, commands); | ||
206 | ecore_main_loop_begin(); | ||
207 | |||
208 | ecore_evas_free(ee); | ||
209 | ecore_evas_shutdown(); | ||
210 | edje_shutdown(); | ||
211 | return 0; | ||
212 | |||
213 | error: | ||
214 | fprintf(stderr, "You got to have at least one evas engine built" | ||
215 | " and linked up to ecore-evas for this example to run" | ||
216 | " properly.\n"); | ||
217 | ecore_evas_shutdown(); | ||
218 | return -1; | ||
219 | |||
220 | error_edj: | ||
221 | fprintf(stderr, "Failed to load basic.edj!\n"); | ||
222 | |||
223 | ecore_evas_shutdown(); | ||
224 | return -2; | ||
225 | } | ||
226 | |||