Imported Upstream version 1.7.1
[platform/upstream/edje.git] / src / examples / signals2.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #else
4 #define PACKAGE_EXAMPLES_DIR "."
5 #define __UNUSED__
6 #endif
7
8 #include <Ecore.h>
9 #include <Ecore_Evas.h>
10 #include <Edje.h>
11 #include <stdio.h>
12
13 #define WIDTH     (700)
14 #define HEIGHT    (700)
15
16 static void
17 _on_delete(Ecore_Evas *ee __UNUSED__)
18 {
19    ecore_main_loop_quit();
20 }
21
22 /* mouse over signals */
23 static void
24 _on_mouse_over(void *data, Evas_Object *edje_obj,
25                const char *emission __UNUSED__, const char *source __UNUSED__)
26 {
27    Evas *evas;
28    int x, y, mouseX, mouseY;
29
30    evas = (Evas *) data;
31    evas_object_geometry_get(edje_obj, &x, &y, NULL, NULL);
32
33    evas_pointer_output_xy_get(evas, &mouseX, &mouseY);
34
35    if ((rand() % 2) == 0)
36      x += ((mouseX - x) + (x / 4 + mouseY / 2));
37    else
38      x -= ((mouseX - x) + (x / 4 + mouseY / 2));
39
40    if ((rand() % 2) == 0)
41      y += ((mouseY - y) + (y / 4 + mouseX / 2));
42    else
43      y -= ((mouseY - y) + (y / 4 + mouseX / 2));
44
45    if (x > WIDTH)
46      x = WIDTH;
47    else if (x < 0) x = 0;
48
49    if (y > HEIGHT)
50      y = HEIGHT;
51    else if (y < 0) y = 0;
52
53    fprintf(stdout, "Moving object to - (%d,%d)\n", x, y);
54
55    evas_object_move(edje_obj, x, y);
56 }
57
58 int
59 main(int argc __UNUSED__, char **argv)
60 {
61    const char *edje_file = "signalsBubble.edj";
62    char edje_file_path[PATH_MAX];
63    Eina_Prefix *pfx;
64    Ecore_Evas *ee;
65    Evas *evas;
66    Evas_Object *bg;
67    Evas_Object *edje_obj;
68
69    if (!ecore_evas_init()) return EXIT_FAILURE;
70
71    if (!edje_init()) goto shutdown_ecore_evas;
72
73    pfx = eina_prefix_new(argv[0], main, "EDJE_EXAMPLES", "edje/examples",
74                          edje_file, PACKAGE_BIN_DIR, PACKAGE_LIB_DIR,
75                          PACKAGE_DATA_DIR, PACKAGE_DATA_DIR);
76
77    if (!pfx) goto shutdown_edje;
78
79    ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
80
81    if (!ee) goto eina_prefix_free;
82
83    ecore_evas_callback_delete_request_set(ee, _on_delete);
84    ecore_evas_title_set(ee, "Edje animations and signals");
85
86    evas = ecore_evas_get(ee);
87
88    bg = evas_object_rectangle_add(evas);
89    evas_object_color_set(bg, 255, 255, 255, 255); //White
90    evas_object_move(bg, 0, 0); //orign
91    evas_object_resize(bg, WIDTH, HEIGHT); //cover the window
92    evas_object_show(bg);
93
94    ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
95    evas_object_focus_set(bg, EINA_TRUE);
96
97    edje_obj = edje_object_add(evas);
98
99    snprintf(edje_file_path, sizeof(edje_file_path), "%s/examples/%s",
100             eina_prefix_data_get(pfx), edje_file);
101
102    if (!edje_object_file_set(edje_obj, edje_file_path, "image_group"))
103      {
104         int err = edje_object_load_error_get(edje_obj);
105         const char *errmsg = edje_load_error_str(err);
106         fprintf(stderr, "Could not load the edje file - reason:%s\n", errmsg);
107         goto eina_prefix_free;
108      }
109
110    edje_object_signal_callback_add(edje_obj, "mouse,move", "part_image",
111                                    _on_mouse_over, evas);
112    evas_object_resize(edje_obj, 63, 63);
113    evas_object_move(edje_obj, 50, 50);
114    evas_object_show(edje_obj);
115
116    ecore_evas_show(ee);
117
118    ecore_main_loop_begin();
119
120    eina_prefix_free(pfx);
121    ecore_evas_free(ee);
122    edje_shutdown();
123    ecore_evas_shutdown();
124
125    return EXIT_SUCCESS;
126
127    eina_prefix_free: eina_prefix_free(pfx);
128
129    shutdown_edje: edje_shutdown();
130
131    shutdown_ecore_evas: ecore_evas_shutdown();
132
133    return EXIT_FAILURE;
134 }