aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/examples/edje-basic.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-04-22 09:19:23 +1000
committerDavid Walter Seikel2012-04-22 09:19:23 +1000
commitc963d75dfdeec11f82e79e727062fbf89afa2c04 (patch)
tree895633dbf641110be46f117c29890c49b3ffc0bd /libraries/edje/src/examples/edje-basic.c
parentAdding the new extantz viewer and grid manager. (diff)
downloadSledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.zip
SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.gz
SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.bz2
SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.xz
Update EFL to latest beta.
Diffstat (limited to 'libraries/edje/src/examples/edje-basic.c')
-rw-r--r--libraries/edje/src/examples/edje-basic.c107
1 files changed, 69 insertions, 38 deletions
diff --git a/libraries/edje/src/examples/edje-basic.c b/libraries/edje/src/examples/edje-basic.c
index 2a7a862..8a85312 100644
--- a/libraries/edje/src/examples/edje-basic.c
+++ b/libraries/edje/src/examples/edje-basic.c
@@ -11,47 +11,46 @@
11 */ 11 */
12 12
13#ifdef HAVE_CONFIG_H 13#ifdef HAVE_CONFIG_H
14#include "config.h" 14# include "config.h"
15#else 15#else
16#define PACKAGE_EXAMPLES_DIR "." 16# define __UNUSED__
17#define __UNUSED__
18#endif 17#endif
19 18
19#include <stdio.h>
20
21#include <Eina.h>
20#include <Ecore.h> 22#include <Ecore.h>
21#include <Ecore_Evas.h> 23#include <Ecore_Evas.h>
22#include <Edje.h> 24#include <Edje.h>
23#include <stdio.h>
24 25
25#define WIDTH (300) 26#define WIDTH (300)
26#define HEIGHT (300) 27#define HEIGHT (300)
27 28
28static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
29static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/basic.edj";
30
31static Ecore_Evas *ee;
32static Evas_Object *edje_obj;
33
34static const char commands[] = \ 29static const char commands[] = \
35 "commands are:\n" 30 "commands are:\n"
36 "\ts - change Edje's global scaling factor\n" 31 "\ts - change Edje's global scaling factor\n"
37 "\tr - change center rectangle's scaling factor\n" 32 "\tr - change center rectangle's scaling factor\n"
33 "\tEsc - exit\n"
38 "\th - print help\n"; 34 "\th - print help\n";
39 35
40static void 36static void
41_on_keydown(void *data __UNUSED__, 37_on_keydown(void *data,
42 Evas *evas __UNUSED__, 38 Evas *evas __UNUSED__,
43 Evas_Object *o __UNUSED__, 39 Evas_Object *o __UNUSED__,
44 void *einfo) 40 void *einfo)
45{ 41{
46 Evas_Event_Key_Down *ev = einfo; 42 Evas_Event_Key_Down *ev;
43 Evas_Object *edje_obj;
44
45 ev = (Evas_Event_Key_Down *)einfo;
46 edje_obj = (Evas_Object *)data;
47 47
48 if (strcmp(ev->keyname, "h") == 0) /* print help */ 48 if (strcmp(ev->keyname, "h") == 0) /* print help */
49 { 49 {
50 fprintf(stdout, commands); 50 fprintf(stdout, commands);
51 return; 51 return;
52 } 52 }
53 53 else if (strcmp(ev->keyname, "s") == 0) /* global scaling factor */
54 if (strcmp(ev->keyname, "s") == 0) /* global scaling factor */
55 { 54 {
56 double scale = edje_scale_get(); 55 double scale = edje_scale_get();
57 56
@@ -66,8 +65,7 @@ _on_keydown(void *data __UNUSED__,
66 65
67 return; 66 return;
68 } 67 }
69 68 else if (strcmp(ev->keyname, "r") == 0) /* individual scaling factor */
70 if (strcmp(ev->keyname, "r") == 0) /* individual scaling factor */
71 { 69 {
72 double scale = edje_object_scale_get(edje_obj); 70 double scale = edje_object_scale_get(edje_obj);
73 71
@@ -84,6 +82,13 @@ _on_keydown(void *data __UNUSED__,
84 82
85 return; 83 return;
86 } 84 }
85 else if (!strcmp(ev->keyname, "Escape"))
86 ecore_main_loop_quit();
87 else
88 {
89 printf("unhandled key: %s\n", ev->keyname);
90 fprintf(stdout, commands);
91 }
87} 92}
88 93
89static void 94static void
@@ -93,27 +98,47 @@ _on_delete(Ecore_Evas *ee __UNUSED__)
93} 98}
94 99
95int 100int
96main(void) 101main(int argc __UNUSED__, char *argv[])
97{ 102{
98 Evas_Object *border, *bg; 103 char border_img_path[PATH_MAX];
99 int x, y, w, h; 104 char edje_file_path[PATH_MAX];
100 Evas *evas; 105 const char *edje_file = "basic.edj";
106 Ecore_Evas *ee;
107 Evas *evas;
108 Evas_Object *bg;
109 Evas_Object *border;
110 Evas_Object *edje_obj;
111 Eina_Prefix *pfx;
112 int x;
113 int y;
114 int w;
115 int h;
101 116
102 if (!ecore_evas_init()) 117 if (!ecore_evas_init())
103 return EXIT_FAILURE; 118 return EXIT_FAILURE;
104 119
105 if (!edje_init()) 120 if (!edje_init())
106 return EXIT_FAILURE; 121 goto shutdown_ecore_evas;
122
123 pfx = eina_prefix_new(argv[0], main,
124 "EDJE_EXAMPLES",
125 "edje/examples",
126 edje_file,
127 PACKAGE_BIN_DIR,
128 PACKAGE_LIB_DIR,
129 PACKAGE_DATA_DIR,
130 PACKAGE_DATA_DIR);
131 if (!pfx)
132 goto shutdown_edje;
107 133
108 /* this will give you a window with an Evas canvas under the first 134 /* this will give you a window with an Evas canvas under the first
109 * engine available */ 135 * engine available */
110 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); 136 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
111 if (!ee) 137 if (!ee)
112 goto error; 138 goto free_prefix;
113 139
114 ecore_evas_callback_delete_request_set(ee, _on_delete); 140 ecore_evas_callback_delete_request_set(ee, _on_delete);
115 ecore_evas_title_set(ee, "Edje Basics Example"); 141 ecore_evas_title_set(ee, "Edje Basics Example");
116 ecore_evas_show(ee);
117 142
118 evas = ecore_evas_get(ee); 143 evas = ecore_evas_get(ee);
119 144
@@ -125,11 +150,12 @@ main(void)
125 ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); 150 ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
126 151
127 evas_object_focus_set(bg, EINA_TRUE); 152 evas_object_focus_set(bg, EINA_TRUE);
128 evas_object_event_callback_add(
129 bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
130 153
131 edje_obj = edje_object_add(evas); 154 edje_obj = edje_object_add(evas);
132 155
156 snprintf(edje_file_path, sizeof(edje_file_path),
157 "%s/examples/%s", eina_prefix_data_get(pfx), edje_file);
158 printf("%s\n", edje_file_path);
133 /* exercising Edje loading error, on purpose */ 159 /* exercising Edje loading error, on purpose */
134 if (!edje_object_file_set(edje_obj, edje_file_path, "unexistant_group")) 160 if (!edje_object_file_set(edje_obj, edje_file_path, "unexistant_group"))
135 { 161 {
@@ -147,7 +173,7 @@ main(void)
147 errmsg); 173 errmsg);
148 174
149 evas_object_del(edje_obj); 175 evas_object_del(edje_obj);
150 goto error_edj; 176 goto free_prefix;
151 } 177 }
152 178
153 fprintf(stdout, "Loaded Edje object bound to group 'example_group' from" 179 fprintf(stdout, "Loaded Edje object bound to group 'example_group' from"
@@ -157,6 +183,11 @@ main(void)
157 evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40); 183 evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40);
158 evas_object_show(edje_obj); 184 evas_object_show(edje_obj);
159 185
186 evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, edje_obj);
187
188 snprintf(border_img_path, sizeof(border_img_path),
189 "%s/edje/examples/red.png", eina_prefix_data_get(pfx));
190
160 /* this is a border around the Edje object above, here just to 191 /* this is a border around the Edje object above, here just to
161 * emphasize its geometry */ 192 * emphasize its geometry */
162 border = evas_object_image_filled_add(evas); 193 border = evas_object_image_filled_add(evas);
@@ -203,24 +234,24 @@ main(void)
203 "y = %d, w = %d, h = %d\n", x, y, w, h); 234 "y = %d, w = %d, h = %d\n", x, y, w, h);
204 235
205 fprintf(stdout, commands); 236 fprintf(stdout, commands);
237
238 ecore_evas_show(ee);
239
206 ecore_main_loop_begin(); 240 ecore_main_loop_begin();
207 241
242 eina_prefix_free(pfx);
208 ecore_evas_free(ee); 243 ecore_evas_free(ee);
209 ecore_evas_shutdown(); 244 ecore_evas_shutdown();
210 edje_shutdown(); 245 edje_shutdown();
211 return 0;
212 246
213error: 247 return EXIT_SUCCESS;
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
220error_edj:
221 fprintf(stderr, "Failed to load basic.edj!\n");
222 248
249 free_prefix:
250 eina_prefix_free(pfx);
251 shutdown_edje:
252 edje_shutdown();
253 shutdown_ecore_evas:
223 ecore_evas_shutdown(); 254 ecore_evas_shutdown();
224 return -2;
225}
226 255
256 return EXIT_FAILURE;
257}