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-perspective.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-perspective.c | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/edje-perspective.c b/libraries/edje/src/examples/edje-perspective.c new file mode 100644 index 0000000..5220b74 --- /dev/null +++ b/libraries/edje/src/examples/edje-perspective.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /** | ||
2 | * Simple Edje example illustrating drag 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 drag.edc && gcc -o drag-box drag-box.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 480 | ||
24 | #define HEIGHT 320 | ||
25 | |||
26 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/perspective.edj"; | ||
27 | |||
28 | struct _App { | ||
29 | Ecore_Evas *ee; | ||
30 | Evas_Object *edje; | ||
31 | Evas_Object *bg; | ||
32 | Edje_Perspective *ps; | ||
33 | Eina_Bool animating; | ||
34 | int x, y; // relative position of part in the screen | ||
35 | int focal; | ||
36 | }; | ||
37 | |||
38 | static void | ||
39 | _on_destroy(Ecore_Evas *ee __UNUSED__) | ||
40 | { | ||
41 | ecore_main_loop_quit(); | ||
42 | } | ||
43 | |||
44 | /* here just to keep our example's window size and background image's | ||
45 | * size in synchrony */ | ||
46 | static void | ||
47 | _canvas_resize_cb(Ecore_Evas *ee) | ||
48 | { | ||
49 | int w, h; | ||
50 | struct _App *app = ecore_evas_data_get(ee, "app"); | ||
51 | |||
52 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
53 | evas_object_resize(app->bg, w, h); | ||
54 | evas_object_resize(app->edje, w, h); | ||
55 | } | ||
56 | |||
57 | static void | ||
58 | _part_move(struct _App *app, int dx, int dy) | ||
59 | { | ||
60 | char emission[64]; | ||
61 | |||
62 | if (app->animating) | ||
63 | return; | ||
64 | |||
65 | app->x += dx; | ||
66 | app->y += dy; | ||
67 | if (app->x > 1) | ||
68 | app->x = 1; | ||
69 | if (app->x < 0) | ||
70 | app->x = 0; | ||
71 | if (app->y > 1) | ||
72 | app->y = 1; | ||
73 | if (app->y < 0) | ||
74 | app->y = 0; | ||
75 | |||
76 | snprintf(emission, sizeof(emission), "move,%d,%d", app->x, app->y); | ||
77 | edje_object_signal_emit(app->edje, emission, ""); | ||
78 | app->animating = EINA_TRUE; | ||
79 | } | ||
80 | |||
81 | |||
82 | static void | ||
83 | _bg_key_down(void *data, Evas *e, Evas_Object *o __UNUSED__, void *event_info) | ||
84 | { | ||
85 | struct _App *app = data; | ||
86 | Evas_Event_Key_Down *ev = event_info; | ||
87 | |||
88 | |||
89 | // just moving the part and text | ||
90 | if (!strcmp(ev->keyname, "Down")) | ||
91 | { | ||
92 | _part_move(app, 0, 1); | ||
93 | } | ||
94 | else if (!strcmp(ev->keyname, "Up")) | ||
95 | { | ||
96 | _part_move(app, 0, -1); | ||
97 | } | ||
98 | else if (!strcmp(ev->keyname, "Left")) | ||
99 | { | ||
100 | _part_move(app, -1, 0); | ||
101 | } | ||
102 | else if (!strcmp(ev->keyname, "Right")) | ||
103 | { | ||
104 | _part_move(app, 1, 0); | ||
105 | } | ||
106 | else if (!strcmp(ev->keyname, "Prior")) | ||
107 | { | ||
108 | _part_move(app, -1, -1); | ||
109 | } | ||
110 | else if (!strcmp(ev->keyname, "Next")) | ||
111 | { | ||
112 | _part_move(app, 1, 1); | ||
113 | } | ||
114 | // adjusting the perspective focal point distance | ||
115 | else if (!strcmp(ev->keyname, "KP_Add")) | ||
116 | { | ||
117 | app->focal += 5; | ||
118 | edje_perspective_set(app->ps, 240, 160, 0, app->focal); | ||
119 | edje_object_calc_force(app->edje); | ||
120 | } | ||
121 | else if (!strcmp(ev->keyname, "KP_Subtract")) | ||
122 | { | ||
123 | app->focal -= 5; | ||
124 | if (app->focal < 5) | ||
125 | app->focal = 5; | ||
126 | |||
127 | edje_perspective_set(app->ps, 240, 160, 0, app->focal); | ||
128 | edje_object_calc_force(app->edje); | ||
129 | } | ||
130 | // exiting | ||
131 | else if (!strcmp(ev->keyname, "Escape")) | ||
132 | ecore_main_loop_quit(); | ||
133 | else | ||
134 | printf("unhandled key: %s\n", ev->keyname); | ||
135 | } | ||
136 | |||
137 | static void | ||
138 | _animation_end_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) | ||
139 | { | ||
140 | struct _App *app = data; | ||
141 | |||
142 | app->animating = EINA_FALSE; | ||
143 | } | ||
144 | |||
145 | int | ||
146 | main(void) | ||
147 | { | ||
148 | Evas *evas; | ||
149 | struct _App app; | ||
150 | int i; | ||
151 | |||
152 | ecore_evas_init(); | ||
153 | edje_init(); | ||
154 | |||
155 | edje_frametime_set(((double)1) / 60); | ||
156 | |||
157 | /* this will give you a window with an Evas canvas under the first | ||
158 | * engine available */ | ||
159 | app.animating = EINA_FALSE; | ||
160 | app.x = 0; | ||
161 | app.y = 0; | ||
162 | app.focal = 50; | ||
163 | app.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
164 | |||
165 | ecore_evas_callback_destroy_set(app.ee, _on_destroy); | ||
166 | ecore_evas_callback_resize_set(app.ee, _canvas_resize_cb); | ||
167 | ecore_evas_title_set(app.ee, "Edje Box Example"); | ||
168 | ecore_evas_show(app.ee); | ||
169 | |||
170 | ecore_evas_data_set(app.ee, "app", &app); | ||
171 | |||
172 | evas = ecore_evas_get(app.ee); | ||
173 | |||
174 | app.bg = evas_object_rectangle_add(evas); | ||
175 | evas_object_color_set(app.bg, 255, 255, 255, 255); | ||
176 | evas_object_resize(app.bg, WIDTH, HEIGHT); | ||
177 | evas_object_focus_set(app.bg, EINA_TRUE); | ||
178 | evas_object_show(app.bg); | ||
179 | |||
180 | evas_object_event_callback_add(app.bg, EVAS_CALLBACK_KEY_DOWN, _bg_key_down, &app); | ||
181 | |||
182 | app.edje = edje_object_add(evas); | ||
183 | |||
184 | edje_object_file_set(app.edje, edje_file_path, "example/group"); | ||
185 | evas_object_move(app.edje, 0, 0); | ||
186 | evas_object_resize(app.edje, WIDTH, HEIGHT); | ||
187 | evas_object_show(app.edje); | ||
188 | |||
189 | edje_object_signal_callback_add(app.edje, "animation,end", "", _animation_end_cb, &app); | ||
190 | |||
191 | app.ps = edje_perspective_new(evas); | ||
192 | edje_perspective_set(app.ps, 240, 160, 0, app.focal); | ||
193 | edje_perspective_global_set(app.ps, EINA_TRUE); | ||
194 | |||
195 | ecore_main_loop_begin(); | ||
196 | |||
197 | ecore_evas_free(app.ee); | ||
198 | ecore_evas_shutdown(); | ||
199 | edje_shutdown(); | ||
200 | return 0; | ||
201 | } | ||