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);
50 static void _update_lon_lat_min_max(Evas_Object *obj, double lon, double lat);
53 _del_hook(Evas_Object *obj)
56 Widget_Data *wd = elm_widget_data_get(obj);
65 _resize_cb(void *data __UNUSED__ , Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
71 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
73 Widget_Data *wd = elm_widget_data_get(obj);
78 _theme_hook(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
87 _sizing_eval(Evas_Object *obj)
91 Evas_Coord x, y, w, h;
92 Evas_Coord start_x, start_y, end_x, end_y;
94 Widget_Data *wd = elm_widget_data_get(obj);
95 evas_object_geometry_get(obj, &x, &y, &w, &h);
97 EINA_LIST_FOREACH(wd->segments, l, segment)
99 if(wd->must_calc_segments || segment->must_calc)
103 segment->start_x = (emap_route_node_lon_get(segment->node_start)- wd->lon_min) / (float)(wd->lon_max - wd->lon_min);
104 segment->start_y = 1 - (emap_route_node_lat_get(segment->node_start) - wd->lat_min) / (float)(wd->lat_max - wd->lat_min);
105 segment->end_x = (emap_route_node_lon_get(segment->node_end) - wd->lon_min) / (float)(wd->lon_max - wd->lon_min);
106 segment->end_y = 1 - (emap_route_node_lat_get(segment->node_end) - wd->lat_min) / (float)(wd->lat_max - wd->lat_min);
108 segment->must_calc = EINA_FALSE;
111 start_x = x+(int)(segment->start_x*w);
112 start_y = y+(int)(segment->start_y*h);
113 end_x = x+(int)(segment->end_x*w);
114 end_y = y+(int)(segment->end_y*h);
115 evas_object_line_xy_set(segment->obj, start_x, start_y, end_x, end_y);
118 wd->must_calc_segments = EINA_FALSE;
122 _clear_route(Evas_Object *obj)
125 Widget_Data *wd = elm_widget_data_get(obj);
129 wd->lon_min = EMAP_LON_MAX;
130 wd->lon_max = EMAP_LON_MIN;
131 wd->lat_min = EMAP_LAT_MAX;
132 wd->lat_max = EMAP_LAT_MIN;
135 EINA_LIST_FREE(wd->segments, segment)
137 evas_object_del(segment->obj);
143 _update_lon_lat_min_max(Evas_Object *obj, double lon, double lat)
145 Widget_Data *wd = elm_widget_data_get(obj);
147 if(wd->lon_min > lon)
150 wd->must_calc_segments = EINA_TRUE;
152 if(wd->lat_min > lat)
155 wd->must_calc_segments = EINA_TRUE;
158 if(wd->lon_max < lon)
161 wd->must_calc_segments = EINA_TRUE;
163 if(wd->lat_max < lat)
166 wd->must_calc_segments = EINA_TRUE;
171 * Add a new route to the parent
173 * @param parent The parent object
174 * @return The new object or NULL if it cannot be created
179 elm_route_add(Evas_Object *parent)
186 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
188 ELM_SET_WIDTYPE(widtype, "map_route");
189 elm_widget_type_set(obj, "map_route");
190 elm_widget_sub_object_add(parent, obj);
191 elm_widget_data_set(obj, wd);
192 elm_widget_del_hook_set(obj, _del_hook);
193 elm_widget_theme_hook_set(obj, _theme_hook);
194 elm_widget_can_focus_set(obj, EINA_FALSE);
196 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
198 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
202 wd->lon_min = EMAP_LON_MAX;
203 wd->lon_max = EMAP_LON_MIN;
204 wd->lat_min = EMAP_LAT_MAX;
205 wd->lat_max = EMAP_LAT_MIN;
208 _mirrored_set(obj, elm_widget_mirrored_get(obj));
215 * Set the emap object which describes the route
217 * @param obj The photo object
218 * @param emap the route
220 * @return (1 = success, 0 = error)
225 elm_route_emap_set(Evas_Object *obj, EMap_Route *emap)
227 EMap_Route_Node *node, *node_prev = NULL;
231 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
232 Widget_Data *wd = elm_widget_data_get(obj);
234 if (!wd) return EINA_FALSE;
239 EINA_LIST_FOREACH(emap_route_nodes_get(wd->emap), l, node)
243 Segment *segment = calloc(1, sizeof(Segment));
244 segment->node_start = node_prev;
245 segment->node_end = node;
247 o = evas_object_line_add(evas_object_evas_get(obj));
249 evas_object_smart_member_add(o, obj);
252 segment->must_calc = EINA_TRUE;
254 _update_lon_lat_min_max(obj, emap_route_node_lon_get(node_prev), emap_route_node_lat_get(node_prev));
255 _update_lon_lat_min_max(obj, emap_route_node_lon_get(node), emap_route_node_lat_get(node));
257 wd->segments = eina_list_append(wd->segments, segment);
267 elm_route_lon_min_get(Evas_Object *obj)
269 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
270 Widget_Data *wd = elm_widget_data_get(obj);
275 elm_route_lat_min_get(Evas_Object *obj)
277 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
278 Widget_Data *wd = elm_widget_data_get(obj);
283 elm_route_lon_max_get(Evas_Object *obj)
285 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
286 Widget_Data *wd = elm_widget_data_get(obj);
291 elm_route_lat_max_get(Evas_Object *obj)
293 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
294 Widget_Data *wd = elm_widget_data_get(obj);
298 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/