1 #include <Elementary.h>
3 #include "elm_widget_route.h"
5 EAPI const char ELM_ROUTE_SMART_NAME[] = "elm_route";
7 EVAS_SMART_SUBCLASS_NEW
8 (ELM_ROUTE_SMART_NAME, _elm_route, Elm_Route_Smart_Class,
9 Elm_Widget_Smart_Class, elm_widget_smart_class_get, NULL);
12 _clear_route(Evas_Object *obj)
16 ELM_ROUTE_DATA_GET(obj, sd);
19 sd->lon_min = EMAP_LON_MAX;
20 sd->lon_max = EMAP_LON_MIN;
21 sd->lat_min = EMAP_LAT_MAX;
22 sd->lat_max = EMAP_LAT_MIN;
25 EINA_LIST_FREE (sd->segments, segment)
27 evas_object_del(segment->obj);
33 _sizing_eval(Evas_Object *obj)
37 Evas_Coord x, y, w, h;
38 Evas_Coord start_x, start_y, end_x, end_y;
40 ELM_ROUTE_DATA_GET(obj, sd);
42 evas_object_geometry_get(obj, &x, &y, &w, &h);
44 EINA_LIST_FOREACH(sd->segments, l, segment)
46 if (sd->must_calc_segments || segment->must_calc)
50 (emap_route_node_lon_get(segment->node_start) - sd->lon_min)
51 / (float)(sd->lon_max - sd->lon_min);
53 1 - (emap_route_node_lat_get(segment->node_start)
54 - sd->lat_min) / (float)(sd->lat_max - sd->lat_min);
56 (emap_route_node_lon_get(segment->node_end) - sd->lon_min)
57 / (float)(sd->lon_max - sd->lon_min);
59 1 - (emap_route_node_lat_get(segment->node_end)
60 - sd->lat_min) / (float)(sd->lat_max - sd->lat_min);
62 segment->must_calc = EINA_FALSE;
65 start_x = x + (int)(segment->start_x * w);
66 start_y = y + (int)(segment->start_y * h);
67 end_x = x + (int)(segment->end_x * w);
68 end_y = y + (int)(segment->end_y * h);
70 evas_object_line_xy_set(segment->obj, start_x, start_y, end_x, end_y);
73 sd->must_calc_segments = EINA_FALSE;
77 _move_resize_cb(void *data __UNUSED__,
80 void *event_info __UNUSED__)
86 _elm_route_smart_theme(Evas_Object *obj)
88 if (!_elm_route_parent_sc->theme(obj)) return EINA_FALSE;
99 _update_lon_lat_min_max(Evas_Object *obj,
103 ELM_ROUTE_DATA_GET(obj, sd);
105 if (sd->lon_min > lon)
108 sd->must_calc_segments = EINA_TRUE;
110 if (sd->lat_min > lat)
113 sd->must_calc_segments = EINA_TRUE;
116 if (sd->lon_max < lon)
119 sd->must_calc_segments = EINA_TRUE;
121 if (sd->lat_max < lat)
124 sd->must_calc_segments = EINA_TRUE;
131 _elm_route_smart_add(Evas_Object *obj)
133 EVAS_SMART_DATA_ALLOC(obj, Elm_Route_Smart_Data);
135 _elm_route_parent_sc->base.add(obj);
137 elm_widget_can_focus_set(obj, EINA_FALSE);
139 evas_object_event_callback_add
140 (obj, EVAS_CALLBACK_MOVE, _move_resize_cb, obj);
141 evas_object_event_callback_add
142 (obj, EVAS_CALLBACK_RESIZE, _move_resize_cb, obj);
145 priv->lon_min = EMAP_LON_MAX;
146 priv->lon_max = EMAP_LON_MIN;
147 priv->lat_min = EMAP_LAT_MAX;
148 priv->lat_max = EMAP_LAT_MIN;
155 _elm_route_smart_del(Evas_Object *obj)
159 ELM_WIDGET_CLASS(_elm_route_parent_sc)->base.del(obj);
163 _elm_route_smart_set_user(Elm_Route_Smart_Class *sc)
165 ELM_WIDGET_CLASS(sc)->base.add = _elm_route_smart_add;
166 ELM_WIDGET_CLASS(sc)->base.del = _elm_route_smart_del;
168 ELM_WIDGET_CLASS(sc)->theme = _elm_route_smart_theme;
171 EAPI const Elm_Route_Smart_Class *
172 elm_route_smart_class_get(void)
174 static Elm_Route_Smart_Class _sc =
175 ELM_ROUTE_SMART_CLASS_INIT_NAME_VERSION(ELM_ROUTE_SMART_NAME);
176 static const Elm_Route_Smart_Class *class = NULL;
178 if (class) return class;
180 _elm_route_smart_set(&_sc);
187 * Add a new route to the parent
189 * @param parent The parent object
190 * @return The new object or NULL if it cannot be created
195 elm_route_add(Evas_Object *parent)
199 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
201 obj = elm_widget_add(_elm_route_smart_class_new(), parent);
202 if (!obj) return NULL;
204 if (!elm_widget_sub_object_add(parent, obj))
205 ERR("could not add %p as sub object of %p", obj, parent);
212 * Set the emap object which describes the route
214 * @param obj The photo object
215 * @param emap the route
220 elm_route_emap_set(Evas_Object *obj,
223 EMap_Route_Node *node, *node_prev = NULL;
227 ELM_ROUTE_CHECK(obj);
228 ELM_ROUTE_DATA_GET(obj, sd);
234 EINA_LIST_FOREACH(emap_route_nodes_get(sd->emap), l, node)
238 Segment *segment = calloc(1, sizeof(Segment));
240 segment->node_start = node_prev;
241 segment->node_end = node;
243 o = evas_object_line_add(evas_object_evas_get(obj));
245 evas_object_smart_member_add(o, obj);
247 segment->must_calc = EINA_TRUE;
249 _update_lon_lat_min_max
250 (obj, emap_route_node_lon_get(node_prev),
251 emap_route_node_lat_get(node_prev));
252 _update_lon_lat_min_max
253 (obj, emap_route_node_lon_get(node),
254 emap_route_node_lat_get(node));
256 sd->segments = eina_list_append(sd->segments, segment);
268 elm_route_longitude_min_max_get(const Evas_Object *obj,
272 ELM_ROUTE_CHECK(obj);
273 ELM_ROUTE_DATA_GET(obj, sd);
275 if (min) *min = sd->lon_min;
276 if (max) *max = sd->lon_max;
280 elm_route_latitude_min_max_get(const Evas_Object *obj,
284 ELM_ROUTE_CHECK(obj);
285 ELM_ROUTE_DATA_GET(obj, sd);
287 if (min) *min = sd->lat_min;
288 if (max) *max = sd->lat_max;