diff options
author | David Walter Seikel | 2012-04-22 09:20:32 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:20:32 +1000 |
commit | 3ad3455551be0d7859ecb02290376206d5e66498 (patch) | |
tree | 497917e12b4d7f458dff9765d9b53f64c4e03fc3 /libraries/elementary/src/examples/map_example_03.c | |
parent | Update EFL to latest beta. (diff) | |
download | SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.zip SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.gz SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.bz2 SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.xz |
And actually include new files, plus elementary libraries.
Diffstat (limited to 'libraries/elementary/src/examples/map_example_03.c')
-rw-r--r-- | libraries/elementary/src/examples/map_example_03.c | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/libraries/elementary/src/examples/map_example_03.c b/libraries/elementary/src/examples/map_example_03.c new file mode 100644 index 0000000..2263707 --- /dev/null +++ b/libraries/elementary/src/examples/map_example_03.c | |||
@@ -0,0 +1,208 @@ | |||
1 | /** | ||
2 | * Simple Elementary's <b>map widget</b> example, illustrating route and | ||
3 | * name usage. | ||
4 | * | ||
5 | * See stdout/stderr for output. Compile with: | ||
6 | * | ||
7 | * @verbatim | ||
8 | * gcc -g map_example_03.c -o map_example_03 `pkg-config --cflags --libs elementary` | ||
9 | * @endverbatim | ||
10 | */ | ||
11 | |||
12 | #include <Elementary.h> | ||
13 | |||
14 | typedef struct _Example_Data | ||
15 | { | ||
16 | Evas_Object *map, *entry; | ||
17 | Elm_Map_Route *route; | ||
18 | double start_lon, start_lat, dest_lon, dest_lat; | ||
19 | Elm_Map_Name *name; | ||
20 | Elm_Map_Overlay *route_ovl; | ||
21 | } Example_Data; | ||
22 | |||
23 | static Example_Data example_data; | ||
24 | |||
25 | static void | ||
26 | _route_loaded(void *data, Evas_Object *obj, void *ev) | ||
27 | { | ||
28 | Example_Data *exam_data = data; | ||
29 | |||
30 | exam_data->route_ovl = elm_map_overlay_route_add(obj, exam_data->route); | ||
31 | elm_map_overlay_color_set(exam_data->route_ovl, 0, 255, 0, 255); | ||
32 | } | ||
33 | |||
34 | static void | ||
35 | _name_loaded(void *data, Evas_Object *obj, void *ev) | ||
36 | { | ||
37 | Example_Data *exam_data = data; | ||
38 | Evas_Object *map = obj; | ||
39 | |||
40 | if (exam_data->route) | ||
41 | elm_map_route_del(exam_data->route); | ||
42 | |||
43 | elm_map_name_region_get(exam_data->name, &(exam_data->dest_lon), | ||
44 | &(exam_data->dest_lat)); | ||
45 | |||
46 | exam_data->route = elm_map_route_add(map, ELM_MAP_ROUTE_TYPE_FOOT, | ||
47 | ELM_MAP_ROUTE_METHOD_SHORTEST, | ||
48 | exam_data->start_lon, exam_data->start_lat, | ||
49 | exam_data->dest_lon, exam_data->dest_lat, | ||
50 | NULL, NULL); | ||
51 | } | ||
52 | |||
53 | static void | ||
54 | _bt_route(void *data, Evas_Object *obj, void *ev) | ||
55 | { | ||
56 | Example_Data *exam_data = data; | ||
57 | Evas_Object *map; | ||
58 | char *address; | ||
59 | |||
60 | map = exam_data->map; | ||
61 | address = (char *)elm_object_text_get(exam_data->entry); | ||
62 | |||
63 | exam_data->name = elm_map_name_add(map, address, 0, 0, NULL, NULL); | ||
64 | |||
65 | evas_object_smart_callback_add(map, "name,loaded", _name_loaded, data); | ||
66 | evas_object_smart_callback_add(map, "route,loaded", _route_loaded, data); | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | _bt_zoom_in(void *data, Evas_Object *obj, void *ev) | ||
71 | { | ||
72 | int zoom; | ||
73 | elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL); | ||
74 | zoom = elm_map_zoom_get(data); | ||
75 | elm_map_zoom_set(data, zoom + 1); | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | _bt_zoom_out(void *data, Evas_Object *obj, void *ev) | ||
80 | { | ||
81 | int zoom; | ||
82 | elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL); | ||
83 | zoom = elm_map_zoom_get(data); | ||
84 | elm_map_zoom_set(data, zoom - 1); | ||
85 | } | ||
86 | |||
87 | static void | ||
88 | _bt_zoom_fit(void *data, Evas_Object *obj, void *event_info) | ||
89 | { | ||
90 | elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FIT); | ||
91 | } | ||
92 | |||
93 | static void | ||
94 | _bt_zoom_fill(void *data, Evas_Object *obj, void *event_info) | ||
95 | { | ||
96 | elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FILL); | ||
97 | } | ||
98 | |||
99 | static void | ||
100 | _on_done(void *data, Evas_Object *obj, void *event_info) | ||
101 | { | ||
102 | elm_exit(); | ||
103 | } | ||
104 | |||
105 | /* FIXME: it shouldn't be required. For unknown reason map won't call | ||
106 | * pan_calculate until shot delay time, but then it will take a screenshot | ||
107 | * when the map isn't loaded yet (actually it won't be downloaded, because | ||
108 | * after the SS it will kill the example). */ | ||
109 | static Eina_Bool | ||
110 | _nasty_hack(void *data) | ||
111 | { | ||
112 | Evas_Object *o = data; | ||
113 | Evas *e = evas_object_evas_get(o); | ||
114 | evas_smart_objects_calculate(e); | ||
115 | return ECORE_CALLBACK_CANCEL; | ||
116 | } | ||
117 | |||
118 | EAPI_MAIN int | ||
119 | elm_main(int argc, char **argv) | ||
120 | { | ||
121 | Evas_Object *win, *bg, *map, *box, *bt, *entry; | ||
122 | |||
123 | win = elm_win_add(NULL, "map", ELM_WIN_BASIC); | ||
124 | elm_win_title_set(win, "Map Route Example"); | ||
125 | evas_object_smart_callback_add(win, "delete,request", _on_done, NULL); | ||
126 | |||
127 | bg = elm_bg_add(win); | ||
128 | elm_win_resize_object_add(win, bg); | ||
129 | evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
130 | evas_object_show(bg); | ||
131 | |||
132 | map = elm_map_add(win); | ||
133 | elm_win_resize_object_add(win, map); | ||
134 | evas_object_size_hint_weight_set(map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
135 | evas_object_show(map); | ||
136 | |||
137 | box = elm_box_add(win); | ||
138 | evas_object_show(box); | ||
139 | |||
140 | bt = elm_button_add(win); | ||
141 | elm_object_text_set(bt, "+"); | ||
142 | elm_box_pack_end(box, bt); | ||
143 | evas_object_show(bt); | ||
144 | evas_object_smart_callback_add(bt, "clicked", _bt_zoom_in, map); | ||
145 | evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0); | ||
146 | |||
147 | bt = elm_button_add(win); | ||
148 | elm_object_text_set(bt, "-"); | ||
149 | elm_box_pack_end(box, bt); | ||
150 | evas_object_show(bt); | ||
151 | evas_object_smart_callback_add(bt, "clicked", _bt_zoom_out, map); | ||
152 | evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0); | ||
153 | |||
154 | bt = elm_button_add(win); | ||
155 | elm_object_text_set(bt, "X"); | ||
156 | elm_box_pack_end(box, bt); | ||
157 | evas_object_show(bt); | ||
158 | evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fit, map); | ||
159 | evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0); | ||
160 | |||
161 | bt = elm_button_add(win); | ||
162 | elm_object_text_set(bt, "#"); | ||
163 | elm_box_pack_end(box, bt); | ||
164 | evas_object_show(bt); | ||
165 | evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fill, map); | ||
166 | evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0); | ||
167 | |||
168 | elm_box_horizontal_set(box, EINA_TRUE); | ||
169 | elm_win_resize_object_add(win, box); | ||
170 | evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
171 | evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0); | ||
172 | |||
173 | entry = elm_entry_add(win); | ||
174 | elm_entry_scrollable_set(entry, EINA_TRUE); | ||
175 | elm_entry_single_line_set(entry, EINA_TRUE); | ||
176 | elm_object_text_set(entry, "Jockey Club Brasileiro"); | ||
177 | evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
178 | evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0); | ||
179 | elm_box_pack_end(box, entry); | ||
180 | evas_object_show(entry); | ||
181 | |||
182 | bt = elm_button_add(win); | ||
183 | elm_object_text_set(bt, "Route"); | ||
184 | elm_box_pack_end(box, bt); | ||
185 | evas_object_show(bt); | ||
186 | evas_object_smart_callback_add(bt, "clicked", _bt_route, &example_data); | ||
187 | evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0); | ||
188 | |||
189 | example_data.map = map; | ||
190 | example_data.entry = entry; | ||
191 | example_data.route = NULL; | ||
192 | example_data.start_lon = -43.175; | ||
193 | example_data.start_lat = -22.97; | ||
194 | |||
195 | elm_map_zoom_set(map, 12); | ||
196 | elm_map_region_show(map, example_data.start_lon, example_data.start_lat); | ||
197 | |||
198 | evas_object_resize(win, 512, 512); | ||
199 | evas_object_show(win); | ||
200 | |||
201 | ecore_timer_add(0.5, _nasty_hack, win); | ||
202 | |||
203 | elm_run(); | ||
204 | elm_shutdown(); | ||
205 | |||
206 | return 0; | ||
207 | } | ||
208 | ELM_MAIN() | ||