8fd577800cdd30e8d07cbcfa025743ff1d46a083
[framework/uifw/elementary.git] / src / examples / map_example_01.c
1 /**
2  * Simple Elementary's <b>map widget</b> example, illustrating its
3  * creation.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g `pkg-config --cflags --libs elementary` map_example_01.c -o map_example_01
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13 #ifdef HAVE_CONFIG_H
14 # include "elementary_config.h"
15 #else
16 # define __UNUSED__
17 #endif
18
19 static void
20 _bt_zoom_in(void *data, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
21 {
22    Evas_Object *map = data;
23    int zoom;
24
25    elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_MANUAL);
26    zoom = elm_map_zoom_get(map);
27    elm_map_zoom_set(map, zoom + 1);
28 }
29
30 static void
31 _bt_zoom_out(void *data, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
32 {
33    Evas_Object *map = data;
34    int zoom;
35
36    elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_MANUAL);
37    zoom = elm_map_zoom_get(map);
38    elm_map_zoom_set(map, zoom - 1);
39 }
40
41 static void
42 _bt_zoom_fit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
43 {
44    Evas_Object *map = data;
45    elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_AUTO_FIT);
46 }
47
48 static void
49 _bt_zoom_fill(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
50 {
51    Evas_Object *map = data;
52    elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_AUTO_FILL);
53 }
54
55 static void
56 _on_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
57 {
58    elm_exit();
59 }
60
61 /* FIXME: it shouldn't be required. For unknown reason map won't call
62  * pan_calculate until shot delay time, but then it will take a screenshot
63  * when the map isn't loaded yet (actually it won't be downloaded, because
64  * after the SS it will kill the example). */
65 static Eina_Bool
66 _nasty_hack(void *data)
67 {
68    Evas_Object *o = data;
69    Evas *e = evas_object_evas_get(o);
70    evas_smart_objects_calculate(e);
71    return ECORE_CALLBACK_CANCEL;
72 }
73
74 EAPI_MAIN int
75 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
76 {
77    Evas_Object *win, *bg, *map, *box, *bt;
78
79    win = elm_win_add(NULL, "map", ELM_WIN_BASIC);
80    elm_win_title_set(win, "Map Creation Example");
81    evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
82
83    bg = elm_bg_add(win);
84    elm_win_resize_object_add(win, bg);
85    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
86    evas_object_show(bg);
87
88    map = elm_map_add(win);
89    elm_win_resize_object_add(win, map);
90    evas_object_size_hint_weight_set(map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
91    evas_object_show(map);
92
93    box = elm_box_add(win);
94    evas_object_show(box);
95
96    bt = elm_button_add(win);
97    elm_object_text_set(bt, "+");
98    elm_box_pack_end(box, bt);
99    evas_object_show(bt);
100    evas_object_smart_callback_add(bt, "clicked", _bt_zoom_in, map);
101
102    bt = elm_button_add(win);
103    elm_object_text_set(bt, "-");
104    elm_box_pack_end(box, bt);
105    evas_object_show(bt);
106    evas_object_smart_callback_add(bt, "clicked", _bt_zoom_out, map);
107
108    bt = elm_button_add(win);
109    elm_object_text_set(bt, "X");
110    elm_box_pack_end(box, bt);
111    evas_object_show(bt);
112    evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fit, map);
113
114    bt = elm_button_add(win);
115    elm_object_text_set(bt, "#");
116    elm_box_pack_end(box, bt);
117    evas_object_show(bt);
118    evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fill, map);
119
120    elm_map_geo_region_show(map, -43.2, -22.9);
121    elm_map_zoom_set(map, 12);
122
123    evas_object_resize(win, 512, 512);
124    evas_object_show(win);
125
126    ecore_timer_add(0.5, _nasty_hack, win);
127
128    elm_run();
129    return 0;
130 }
131 ELM_MAIN()