2 * Simple Edje example illustrating the Edje signals and messages
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
8 * gcc -o edje-signals-messages edje-signals-messages.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
15 #define PACKAGE_EXAMPLES_DIR "."
20 #include <Ecore_Evas.h>
30 static const char commands[] = \
32 "\tt - toggle right rectangle's visibility\n"
36 static Eina_Bool right_rect_show = EINA_TRUE;
39 _on_keydown(void *data,
40 Evas *evas __UNUSED__,
41 Evas_Object *o __UNUSED__,
44 Evas_Event_Key_Down *ev;
45 Evas_Object *edje_obj;
47 ev = (Evas_Event_Key_Down *)einfo;
48 edje_obj = (Evas_Object *)data;
50 if (!strcmp(ev->keyname, "h")) /* print help */
52 fprintf(stdout, commands);
55 else if (!strcmp(ev->keyname, "t")) /* toggle right rectangle's visibility */
59 right_rect_show = !right_rect_show;
60 snprintf(buf, sizeof(buf), "part_right,%s",
61 right_rect_show ? "show" : "hide");
63 printf("emitting %s\n", buf);
65 edje_object_signal_emit(edje_obj, buf, "");
69 else if (!strcmp(ev->keyname, "Escape"))
70 ecore_main_loop_quit();
73 printf("unhandled key: %s\n", ev->keyname);
74 fprintf(stdout, commands);
79 _on_delete(Ecore_Evas *ee __UNUSED__)
81 ecore_main_loop_quit();
84 /* print signals coming from theme */
86 _sig_print(const char *emission,
89 fprintf(stdout, "Signal %s coming from part %s!\n", emission, source);
93 _on_mouse_wheel(void *data __UNUSED__,
94 Evas_Object *obj __UNUSED__,
98 _sig_print(emission, source);
101 /* mouse over signals */
103 _on_mouse_over(void *data __UNUSED__,
104 Evas_Object *edje_obj,
105 const char *emission,
110 _sig_print(emission, source);
112 Edje_Message_Int_Set *msg = malloc(sizeof(*msg) + 3 * sizeof(int));
114 for (i = 0; i < 4; i++)
115 msg->val[i] = rand() % 256;
117 edje_object_message_send(edje_obj, EDJE_MESSAGE_INT_SET, MSG_COLOR, msg);
122 /* print out received message string */
124 _message_handle(void *data __UNUSED__,
125 Evas_Object *obj __UNUSED__,
126 Edje_Message_Type type,
130 Edje_Message_String *m;
132 if (type != EDJE_MESSAGE_STRING) return;
133 if (id != MSG_TEXT) return;
137 fprintf(stdout, "String message received: %s\n", m->str);
141 main(int argc __UNUSED__, char *argv[])
143 char border_img_path[PATH_MAX];
144 char edje_file_path[PATH_MAX];
145 const char *edje_file = "signals-messages.edj";
149 Evas_Object *edje_obj;
153 if (!ecore_evas_init())
157 goto shutdown_ecore_evas;
159 pfx = eina_prefix_new(argv[0], main,
170 /* this will give you a window with an Evas canvas under the first
171 * engine available */
172 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
176 ecore_evas_callback_delete_request_set(ee, _on_delete);
177 ecore_evas_title_set(ee, "Edje Basics Example");
179 evas = ecore_evas_get(ee);
181 bg = evas_object_rectangle_add(evas);
182 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
183 evas_object_move(bg, 0, 0); /* at canvas' origin */
184 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
185 evas_object_show(bg);
186 evas_object_focus_set(bg, EINA_TRUE);
187 ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
189 edje_obj = edje_object_add(evas);
191 snprintf(edje_file_path, sizeof(edje_file_path),
192 "%s/examples/%s", eina_prefix_data_get(pfx), edje_file);
193 if (!edje_object_file_set(edje_obj, edje_file_path, "example_group"))
195 int err = edje_object_load_error_get(edje_obj);
196 const char *errmsg = edje_load_error_str(err);
197 fprintf(stderr, "Could not load 'example_group' from "
198 "signals-messages.edj: %s\n", errmsg);
200 evas_object_del(edje_obj);
204 edje_object_signal_callback_add(edje_obj, "mouse,wheel,*", "part_left",
205 _on_mouse_wheel, NULL);
207 edje_object_signal_callback_add(edje_obj, "mouse,over", "part_right",
208 _on_mouse_over, NULL);
210 edje_object_message_handler_set(edje_obj, _message_handle, NULL);
212 evas_object_move(edje_obj, 20, 20);
213 evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40);
214 evas_object_show(edje_obj);
216 evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, edje_obj);
218 snprintf(border_img_path, sizeof(border_img_path),
219 "%s/edje/examples/red.png", eina_prefix_data_get(pfx));
221 /* this is a border around the Edje object above, here just to
222 * emphasize its geometry */
223 border = evas_object_image_filled_add(evas);
224 evas_object_image_file_set(border, border_img_path, NULL);
225 evas_object_image_border_set(border, 2, 2, 2, 2);
226 evas_object_image_border_center_fill_set(border, EVAS_BORDER_FILL_NONE);
228 evas_object_resize(border, WIDTH - 40 + 4, HEIGHT - 40 + 4);
229 evas_object_move(border, 20 - 2, 20 - 2);
230 evas_object_repeat_events_set(border, EINA_TRUE);
231 evas_object_show(border);
233 fprintf(stdout, commands);
237 ecore_main_loop_begin();
239 eina_prefix_free(pfx);
241 ecore_evas_shutdown();
247 eina_prefix_free(pfx);
251 ecore_evas_shutdown();