diff options
author | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
commit | c963d75dfdeec11f82e79e727062fbf89afa2c04 (patch) | |
tree | 895633dbf641110be46f117c29890c49b3ffc0bd /libraries/edje/src/examples/edje-drag.c | |
parent | Adding the new extantz viewer and grid manager. (diff) | |
download | SledjHamr-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-drag.c')
-rw-r--r-- | libraries/edje/src/examples/edje-drag.c | 175 |
1 files changed, 114 insertions, 61 deletions
diff --git a/libraries/edje/src/examples/edje-drag.c b/libraries/edje/src/examples/edje-drag.c index 78e2e72..bb61b68 100644 --- a/libraries/edje/src/examples/edje-drag.c +++ b/libraries/edje/src/examples/edje-drag.c | |||
@@ -10,10 +10,9 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #ifdef HAVE_CONFIG_H | 12 | #ifdef HAVE_CONFIG_H |
13 | #include "config.h" | 13 | # include "config.h" |
14 | #else | 14 | #else |
15 | #define PACKAGE_EXAMPLES_DIR "." | 15 | # define __UNUSED__ |
16 | #define __UNUSED__ | ||
17 | #endif | 16 | #endif |
18 | 17 | ||
19 | #include <Ecore.h> | 18 | #include <Ecore.h> |
@@ -28,15 +27,17 @@ | |||
28 | 27 | ||
29 | #define NRECTS 20 | 28 | #define NRECTS 20 |
30 | 29 | ||
31 | static const char *PARTNAME = "example/knob"; | 30 | static const char commands[] = \ |
32 | 31 | "commands are:\n" | |
33 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/drag.edj"; | 32 | "\tDdown - set drag step to 1\n" |
33 | "\tUp - set drag step to -1\n" | ||
34 | "\tm - set drag value to 0.5\n" | ||
35 | "\tPrior - set drag page to -1\n" | ||
36 | "\tNext - set drag page to -1\n" | ||
37 | "\tEsc - exit\n" | ||
38 | "\th - print help\n"; | ||
34 | 39 | ||
35 | struct _App { | 40 | static const char *PARTNAME = "example/knob"; |
36 | Ecore_Evas *ee; | ||
37 | Evas_Object *edje; | ||
38 | Evas_Object *bg; | ||
39 | }; | ||
40 | 41 | ||
41 | static void | 42 | static void |
42 | _on_destroy(Ecore_Evas *ee __UNUSED__) | 43 | _on_destroy(Ecore_Evas *ee __UNUSED__) |
@@ -47,111 +48,163 @@ _on_destroy(Ecore_Evas *ee __UNUSED__) | |||
47 | /* here just to keep our example's window size and background image's | 48 | /* here just to keep our example's window size and background image's |
48 | * size in synchrony */ | 49 | * size in synchrony */ |
49 | static void | 50 | static void |
50 | _canvas_resize_cb(Ecore_Evas *ee) | 51 | _on_canvas_resize(Ecore_Evas *ee) |
51 | { | 52 | { |
52 | int w, h; | 53 | Evas_Object *bg; |
53 | struct _App *app = ecore_evas_data_get(ee, "app"); | 54 | Evas_Object *edje_obj; |
55 | int w; | ||
56 | int h; | ||
57 | |||
58 | bg = ecore_evas_data_get(ee, "background"); | ||
59 | edje_obj = ecore_evas_data_get(ee, "edje_obj"); | ||
54 | 60 | ||
55 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | 61 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); |
56 | evas_object_resize(app->bg, w, h); | 62 | evas_object_resize(bg, w, h); |
57 | evas_object_resize(app->edje, w, h); | 63 | evas_object_resize(edje_obj, w, h); |
58 | } | 64 | } |
59 | 65 | ||
60 | static void | 66 | static void |
61 | _bg_key_down(void *data, Evas *e, Evas_Object *o __UNUSED__, void *event_info) | 67 | _on_bg_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info) |
62 | { | 68 | { |
63 | struct _App *app = data; | 69 | Ecore_Evas *ee; |
64 | Evas_Event_Key_Down *ev = event_info; | 70 | Evas_Event_Key_Down *ev; |
65 | Evas_Object *rect; | 71 | Evas_Object *edje_obj; |
66 | Eina_Bool r; | ||
67 | 72 | ||
73 | ee = (Ecore_Evas *)data; | ||
74 | ev = (Evas_Event_Key_Down *)event_info; | ||
75 | edje_obj = ecore_evas_data_get(ee, "edje_obj"); | ||
68 | 76 | ||
69 | if (!strcmp(ev->keyname, "Down")) | 77 | if (!strcmp(ev->keyname, "h")) |
70 | { | 78 | { |
71 | edje_object_part_drag_step(app->edje, PARTNAME, 0, 1.0); | 79 | fprintf(stdout, commands); |
80 | return; | ||
81 | } | ||
82 | else if (!strcmp(ev->keyname, "Down")) | ||
83 | { | ||
84 | edje_object_part_drag_step(edje_obj, PARTNAME, 0, 1.0); | ||
72 | } | 85 | } |
73 | else if (!strcmp(ev->keyname, "Up")) | 86 | else if (!strcmp(ev->keyname, "Up")) |
74 | { | 87 | { |
75 | edje_object_part_drag_step(app->edje, PARTNAME, 0, -1.0); | 88 | edje_object_part_drag_step(edje_obj, PARTNAME, 0, -1.0); |
76 | } | 89 | } |
77 | else if (!strcmp(ev->keyname, "m")) | 90 | else if (!strcmp(ev->keyname, "m")) |
78 | { | 91 | { |
79 | edje_object_part_drag_value_set(app->edje, PARTNAME, 0.0, 0.5); | 92 | edje_object_part_drag_value_set(edje_obj, PARTNAME, 0.0, 0.5); |
80 | } | 93 | } |
81 | else if (!strcmp(ev->keyname, "Prior")) | 94 | else if (!strcmp(ev->keyname, "Prior")) |
82 | { | 95 | { |
83 | edje_object_part_drag_page(app->edje, PARTNAME, 0.0, -1.0); | 96 | edje_object_part_drag_page(edje_obj, PARTNAME, 0.0, -1.0); |
84 | } | 97 | } |
85 | else if (!strcmp(ev->keyname, "Next")) | 98 | else if (!strcmp(ev->keyname, "Next")) |
86 | { | 99 | { |
87 | edje_object_part_drag_page(app->edje, PARTNAME, 0.0, 1.0); | 100 | edje_object_part_drag_page(edje_obj, PARTNAME, 0.0, 1.0); |
88 | } | 101 | } |
89 | else if (!strcmp(ev->keyname, "Escape")) | 102 | else if (!strcmp(ev->keyname, "Escape")) |
90 | ecore_main_loop_quit(); | 103 | ecore_main_loop_quit(); |
91 | else | 104 | else |
92 | printf("unhandled key: %s\n", ev->keyname); | 105 | { |
106 | printf("unhandled key: %s\n", ev->keyname); | ||
107 | fprintf(stdout, commands); | ||
108 | } | ||
93 | } | 109 | } |
94 | 110 | ||
95 | static void | 111 | static void |
96 | _knob_moved_cb(void *data, Evas_Object *o, const char *emission, const char *source) | 112 | _on_knob_moved(void *data __UNUSED__, Evas_Object *o, const char *emission __UNUSED__, const char *source __UNUSED__) |
97 | { | 113 | { |
98 | double val; | 114 | double val; |
115 | |||
99 | edje_object_part_drag_value_get(o, PARTNAME, NULL, &val); | 116 | edje_object_part_drag_value_get(o, PARTNAME, NULL, &val); |
100 | printf("value changed to: %0.3f\n", val); | 117 | printf("value changed to: %0.3f\n", val); |
101 | } | 118 | } |
102 | 119 | ||
103 | int | 120 | int |
104 | main(void) | 121 | main(int argc __UNUSED__, char *argv[]) |
105 | { | 122 | { |
106 | Evas *evas; | 123 | char edje_file_path[PATH_MAX]; |
107 | struct _App app; | 124 | const char *edje_file = "drag.edj"; |
108 | int i; | 125 | Ecore_Evas *ee; |
109 | 126 | Evas *evas; | |
110 | ecore_evas_init(); | 127 | Evas_Object *bg; |
111 | edje_init(); | 128 | Evas_Object *edje_obj; |
129 | Eina_Prefix *pfx; | ||
130 | |||
131 | if (!ecore_evas_init()) | ||
132 | return EXIT_FAILURE; | ||
133 | |||
134 | if (!edje_init()) | ||
135 | goto shutdown_ecore_evas; | ||
136 | |||
137 | pfx = eina_prefix_new(argv[0], main, | ||
138 | "EDJE_EXAMPLES", | ||
139 | "edje/examples", | ||
140 | edje_file, | ||
141 | PACKAGE_BIN_DIR, | ||
142 | PACKAGE_LIB_DIR, | ||
143 | PACKAGE_DATA_DIR, | ||
144 | PACKAGE_DATA_DIR); | ||
145 | if (!pfx) | ||
146 | goto shutdown_edje; | ||
112 | 147 | ||
113 | /* this will give you a window with an Evas canvas under the first | 148 | /* this will give you a window with an Evas canvas under the first |
114 | * engine available */ | 149 | * engine available */ |
115 | app.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | 150 | ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); |
116 | 151 | if (!ee) | |
117 | ecore_evas_callback_destroy_set(app.ee, _on_destroy); | 152 | goto free_prefix; |
118 | ecore_evas_callback_resize_set(app.ee, _canvas_resize_cb); | ||
119 | ecore_evas_title_set(app.ee, "Edje Box Example"); | ||
120 | ecore_evas_show(app.ee); | ||
121 | 153 | ||
122 | ecore_evas_data_set(app.ee, "app", &app); | 154 | ecore_evas_callback_destroy_set(ee, _on_destroy); |
155 | ecore_evas_callback_resize_set(ee, _on_canvas_resize); | ||
156 | ecore_evas_title_set(ee, "Edje Box Example"); | ||
123 | 157 | ||
124 | evas = ecore_evas_get(app.ee); | 158 | evas = ecore_evas_get(ee); |
125 | 159 | ||
126 | app.bg = evas_object_rectangle_add(evas); | 160 | bg = evas_object_rectangle_add(evas); |
127 | evas_object_color_set(app.bg, 255, 255, 255, 255); | 161 | evas_object_color_set(bg, 255, 255, 255, 255); |
128 | evas_object_resize(app.bg, WIDTH, HEIGHT); | 162 | evas_object_resize(bg, WIDTH, HEIGHT); |
129 | evas_object_focus_set(app.bg, EINA_TRUE); | 163 | evas_object_focus_set(bg, EINA_TRUE); |
130 | evas_object_show(app.bg); | 164 | evas_object_show(bg); |
165 | ecore_evas_data_set(ee, "background", bg); | ||
131 | 166 | ||
132 | evas_object_event_callback_add(app.bg, EVAS_CALLBACK_KEY_DOWN, _bg_key_down, &app); | 167 | evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_bg_key_down, ee); |
133 | 168 | ||
134 | app.edje = edje_object_add(evas); | 169 | edje_obj = edje_object_add(evas); |
135 | 170 | ||
136 | edje_object_file_set(app.edje, edje_file_path, "example/group"); | 171 | snprintf(edje_file_path, sizeof(edje_file_path), |
137 | evas_object_move(app.edje, 0, 0); | 172 | "%s/examples/%s", eina_prefix_data_get(pfx), edje_file); |
138 | evas_object_resize(app.edje, WIDTH, HEIGHT); | 173 | edje_object_file_set(edje_obj, edje_file_path, "example/group"); |
139 | evas_object_show(app.edje); | 174 | evas_object_move(edje_obj, 0, 0); |
175 | evas_object_resize(edje_obj, WIDTH, HEIGHT); | ||
176 | evas_object_show(edje_obj); | ||
177 | ecore_evas_data_set(ee, "edje_obj", edje_obj); | ||
140 | 178 | ||
141 | edje_object_part_drag_size_set(app.edje, PARTNAME, 1.0, 0.4); | 179 | edje_object_part_drag_size_set(edje_obj, PARTNAME, 1.0, 0.4); |
142 | 180 | ||
143 | if (!edje_object_part_drag_step_set(app.edje, PARTNAME, 0.0, 0.1)) | 181 | if (!edje_object_part_drag_step_set(edje_obj, PARTNAME, 0.0, 0.1)) |
144 | printf("error when setting drag step size.\n"); | 182 | printf("error when setting drag step size.\n"); |
145 | 183 | ||
146 | if (!edje_object_part_drag_page_set(app.edje, PARTNAME, 0.0, 0.3)) | 184 | if (!edje_object_part_drag_page_set(edje_obj, PARTNAME, 0.0, 0.3)) |
147 | printf("error when setting drag page step size.\n"); | 185 | printf("error when setting drag page step size.\n"); |
148 | 186 | ||
149 | edje_object_signal_callback_add(app.edje, "drag", PARTNAME, _knob_moved_cb, &app); | 187 | edje_object_signal_callback_add(edje_obj, "drag", PARTNAME, _on_knob_moved, NULL); |
188 | |||
189 | fprintf(stdout, commands); | ||
190 | |||
191 | ecore_evas_show(ee); | ||
150 | 192 | ||
151 | ecore_main_loop_begin(); | 193 | ecore_main_loop_begin(); |
152 | 194 | ||
153 | ecore_evas_free(app.ee); | 195 | eina_prefix_free(pfx); |
196 | ecore_evas_free(ee); | ||
154 | ecore_evas_shutdown(); | 197 | ecore_evas_shutdown(); |
155 | edje_shutdown(); | 198 | edje_shutdown(); |
156 | return 0; | 199 | |
200 | return EXIT_SUCCESS; | ||
201 | |||
202 | free_prefix: | ||
203 | eina_prefix_free(pfx); | ||
204 | shutdown_edje: | ||
205 | edje_shutdown(); | ||
206 | shutdown_ecore_evas: | ||
207 | ecore_evas_shutdown(); | ||
208 | |||
209 | return EXIT_FAILURE; | ||
157 | } | 210 | } |