1 #include <Elementary.h>
5 * @defgroup Route MapRoute
7 * For displaying a route on the map widget
11 typedef struct _Widget_Data Widget_Data;
12 typedef struct Segment Segment;
21 double lon_min, lon_max;
22 double lat_min, lat_max;
24 Eina_List *segments; //list of *Segment
26 Eina_Bool must_calc_segments :1;
34 EMap_Route_Node *node_start;
35 EMap_Route_Node *node_end;
38 double start_x, start_y;
41 Eina_Bool must_calc :1;
44 static const char *widtype = NULL;
45 static void _del_hook(Evas_Object *obj);
46 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
47 static void _theme_hook(Evas_Object *obj);
48 static void _sizing_eval(Evas_Object *obj);
49 static void _clear_route(Evas_Object *obj);
51 static void _update_lon_lat_min_max(Evas_Object *obj, double lon, double lat);
55 _del_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
66 _resize_cb(void *data __UNUSED__ , Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
72 _mirrored_set(Evas_Object *obj, Eina_Bool rtl __UNUSED__)
74 Widget_Data *wd = elm_widget_data_get(obj);
79 _theme_hook(Evas_Object *obj)
81 Widget_Data *wd = elm_widget_data_get(obj);
88 _sizing_eval(Evas_Object *obj)
92 Evas_Coord x, y, w, h;
93 Evas_Coord start_x, start_y, end_x, end_y;
95 Widget_Data *wd = elm_widget_data_get(obj);
96 evas_object_geometry_get(obj, &x, &y, &w, &h);
98 EINA_LIST_FOREACH(wd->segments, l, segment)
100 if (wd->must_calc_segments || segment->must_calc)
104 segment->start_x = (emap_route_node_lon_get(segment->node_start)- wd->lon_min) / (float)(wd->lon_max - wd->lon_min);
105 segment->start_y = 1 - (emap_route_node_lat_get(segment->node_start) - wd->lat_min) / (float)(wd->lat_max - wd->lat_min);
106 segment->end_x = (emap_route_node_lon_get(segment->node_end) - wd->lon_min) / (float)(wd->lon_max - wd->lon_min);
107 segment->end_y = 1 - (emap_route_node_lat_get(segment->node_end) - wd->lat_min) / (float)(wd->lat_max - wd->lat_min);
109 segment->must_calc = EINA_FALSE;
112 start_x = x+(int)(segment->start_x*w);
113 start_y = y+(int)(segment->start_y*h);
114 end_x = x+(int)(segment->end_x*w);
115 end_y = y+(int)(segment->end_y*h);
116 evas_object_line_xy_set(segment->obj, start_x, start_y, end_x, end_y);
119 wd->must_calc_segments = EINA_FALSE;
123 _clear_route(Evas_Object *obj)
126 Widget_Data *wd = elm_widget_data_get(obj);
130 wd->lon_min = EMAP_LON_MAX;
131 wd->lon_max = EMAP_LON_MIN;
132 wd->lat_min = EMAP_LAT_MAX;
133 wd->lat_max = EMAP_LAT_MIN;
136 EINA_LIST_FREE(wd->segments, segment)
138 evas_object_del(segment->obj);
145 _update_lon_lat_min_max(Evas_Object *obj, double lon, double lat)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 if (wd->lon_min > lon)
152 wd->must_calc_segments = EINA_TRUE;
154 if (wd->lat_min > lat)
157 wd->must_calc_segments = EINA_TRUE;
160 if (wd->lon_max < lon)
163 wd->must_calc_segments = EINA_TRUE;
165 if (wd->lat_max < lat)
168 wd->must_calc_segments = EINA_TRUE;
174 * Add a new route to the parent
176 * @param parent The parent object
177 * @return The new object or NULL if it cannot be created
182 elm_route_add(Evas_Object *parent)
188 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
190 ELM_SET_WIDTYPE(widtype, "map_route");
191 elm_widget_type_set(obj, "map_route");
192 elm_widget_sub_object_add(parent, obj);
193 elm_widget_data_set(obj, wd);
194 elm_widget_del_hook_set(obj, _del_hook);
195 elm_widget_theme_hook_set(obj, _theme_hook);
196 elm_widget_can_focus_set(obj, EINA_FALSE);
198 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
200 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
204 wd->lon_min = EMAP_LON_MAX;
205 wd->lon_max = EMAP_LON_MIN;
206 wd->lat_min = EMAP_LAT_MAX;
207 wd->lat_max = EMAP_LAT_MIN;
210 _mirrored_set(obj, elm_widget_mirrored_get(obj));
217 * Set the emap object which describes the route
219 * @param obj The photo object
220 * @param emap the route
222 * @return (1 = success, 0 = error)
227 elm_route_emap_set(Evas_Object *obj, EMap_Route *emap)
229 EMap_Route_Node *node, *node_prev = NULL;
233 ELM_CHECK_WIDTYPE(obj, widtype);
234 Widget_Data *wd = elm_widget_data_get(obj);
241 EINA_LIST_FOREACH(emap_route_nodes_get(wd->emap), l, node)
245 Segment *segment = calloc(1, sizeof(Segment));
246 segment->node_start = node_prev;
247 segment->node_end = node;
249 o = evas_object_line_add(evas_object_evas_get(obj));
251 evas_object_smart_member_add(o, obj);
254 segment->must_calc = EINA_TRUE;
256 _update_lon_lat_min_max(obj, emap_route_node_lon_get(node_prev), emap_route_node_lat_get(node_prev));
257 _update_lon_lat_min_max(obj, emap_route_node_lon_get(node), emap_route_node_lat_get(node));
259 wd->segments = eina_list_append(wd->segments, segment);
269 elm_route_lon_min_get(Evas_Object *obj)
271 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
272 Widget_Data *wd = elm_widget_data_get(obj);
277 elm_route_lat_min_get(Evas_Object *obj)
279 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
280 Widget_Data *wd = elm_widget_data_get(obj);
285 elm_route_lon_max_get(Evas_Object *obj)
287 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
288 Widget_Data *wd = elm_widget_data_get(obj);
293 elm_route_lat_max_get(Evas_Object *obj)
295 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
296 Widget_Data *wd = elm_widget_data_get(obj);
300 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/