summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_route.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-03-23 12:56:14 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-03-23 13:24:41 -0700
commitc2a1c49ab2042f559b28e840e54feb8494888e0e (patch)
treec6eb110b7c479499854eede9d0c3ab0a80c9a11a /src/lib/elementary/elm_route.c
parent9340855597e7e465435c69b6278650346688da14 (diff)
elementary: move all legacy files to their expected new location.
Diffstat (limited to 'src/lib/elementary/elm_route.c')
-rw-r--r--src/lib/elementary/elm_route.c264
1 files changed, 264 insertions, 0 deletions
diff --git a/src/lib/elementary/elm_route.c b/src/lib/elementary/elm_route.c
new file mode 100644
index 0000000..80d714c
--- /dev/null
+++ b/src/lib/elementary/elm_route.c
@@ -0,0 +1,264 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6
7#include "elm_priv.h"
8#include "elm_widget_route.h"
9
10#define MY_CLASS ELM_ROUTE_CLASS
11
12#define MY_CLASS_NAME "Elm_Route"
13#define MY_CLASS_NAME_LEGACY "elm_route"
14
15static void
16_clear_route(Evas_Object *obj)
17{
18 Segment *segment;
19
20 ELM_ROUTE_DATA_GET(obj, sd);
21
22#ifdef ELM_EMAP
23 sd->lon_min = EMAP_LON_MAX;
24 sd->lon_max = EMAP_LON_MIN;
25 sd->lat_min = EMAP_LAT_MAX;
26 sd->lat_max = EMAP_LAT_MIN;
27#endif
28
29 EINA_LIST_FREE(sd->segments, segment)
30 {
31 evas_object_del(segment->obj);
32 free(segment);
33 }
34}
35
36static void
37_sizing_eval(Evas_Object *obj)
38{
39 Eina_List *l;
40 Segment *segment;
41 Evas_Coord x, y, w, h;
42 Evas_Coord start_x, start_y, end_x, end_y;
43
44 ELM_ROUTE_DATA_GET(obj, sd);
45
46 evas_object_geometry_get(obj, &x, &y, &w, &h);
47
48 EINA_LIST_FOREACH(sd->segments, l, segment)
49 {
50 if (sd->must_calc_segments || segment->must_calc)
51 {
52#ifdef ELM_EMAP
53 segment->start_x =
54 (emap_route_node_lon_get(segment->node_start) - sd->lon_min)
55 / (float)(sd->lon_max - sd->lon_min);
56 segment->start_y =
57 1 - (emap_route_node_lat_get(segment->node_start)
58 - sd->lat_min) / (float)(sd->lat_max - sd->lat_min);
59 segment->end_x =
60 (emap_route_node_lon_get(segment->node_end) - sd->lon_min)
61 / (float)(sd->lon_max - sd->lon_min);
62 segment->end_y =
63 1 - (emap_route_node_lat_get(segment->node_end)
64 - sd->lat_min) / (float)(sd->lat_max - sd->lat_min);
65#endif
66 segment->must_calc = EINA_FALSE;
67 }
68
69 start_x = x + (int)(segment->start_x * w);
70 start_y = y + (int)(segment->start_y * h);
71 end_x = x + (int)(segment->end_x * w);
72 end_y = y + (int)(segment->end_y * h);
73
74 evas_object_line_xy_set(segment->obj, start_x, start_y, end_x, end_y);
75 }
76
77 sd->must_calc_segments = EINA_FALSE;
78}
79
80static void
81_move_resize_cb(void *data EINA_UNUSED,
82 Evas *e EINA_UNUSED,
83 Evas_Object *obj,
84 void *event_info EINA_UNUSED)
85{
86 _sizing_eval(obj);
87}
88
89EOLIAN static Eina_Bool
90_elm_route_elm_widget_theme_apply(Eo *obj, Elm_Route_Data *sd EINA_UNUSED)
91{
92 Eina_Bool int_ret = EINA_FALSE;
93 int_ret = elm_obj_widget_theme_apply(eo_super(obj, MY_CLASS));
94 if (!int_ret) return EINA_FALSE;
95
96 //TODO
97
98 _sizing_eval(obj);
99
100 return EINA_TRUE;
101}
102
103#ifdef ELM_EMAP
104static void
105_update_lon_lat_min_max(Evas_Object *obj,
106 double lon,
107 double lat)
108{
109 ELM_ROUTE_DATA_GET(obj, sd);
110
111 if (sd->lon_min > lon)
112 {
113 sd->lon_min = lon;
114 sd->must_calc_segments = EINA_TRUE;
115 }
116 if (sd->lat_min > lat)
117 {
118 sd->lat_min = lat;
119 sd->must_calc_segments = EINA_TRUE;
120 }
121
122 if (sd->lon_max < lon)
123 {
124 sd->lon_max = lon;
125 sd->must_calc_segments = EINA_TRUE;
126 }
127 if (sd->lat_max < lat)
128 {
129 sd->lat_max = lat;
130 sd->must_calc_segments = EINA_TRUE;
131 }
132}
133
134#endif
135
136EOLIAN static void
137_elm_route_evas_object_smart_add(Eo *obj, Elm_Route_Data *priv)
138{
139
140 evas_obj_smart_add(eo_super(obj, MY_CLASS));
141 elm_widget_sub_object_parent_add(obj);
142 elm_widget_can_focus_set(obj, EINA_FALSE);
143
144 evas_object_event_callback_add
145 (obj, EVAS_CALLBACK_MOVE, _move_resize_cb, obj);
146 evas_object_event_callback_add
147 (obj, EVAS_CALLBACK_RESIZE, _move_resize_cb, obj);
148
149#ifdef ELM_EMAP
150 priv->lon_min = EMAP_LON_MAX;
151 priv->lon_max = EMAP_LON_MIN;
152 priv->lat_min = EMAP_LAT_MAX;
153 priv->lat_max = EMAP_LAT_MIN;
154#else
155 (void)priv;
156#endif
157
158 _sizing_eval(obj);
159}
160
161EOLIAN static void
162_elm_route_evas_object_smart_del(Eo *obj, Elm_Route_Data *_pd EINA_UNUSED)
163{
164 _clear_route(obj);
165
166 evas_obj_smart_del(eo_super(obj, MY_CLASS));
167}
168
169/**
170 * Add a new route to the parent
171 *
172 * @param parent The parent object
173 * @return The new object or NULL if it cannot be created
174 *
175 * @ingroup Elm_Route
176 */
177EAPI Evas_Object *
178elm_route_add(Evas_Object *parent)
179{
180 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
181 Evas_Object *obj = eo_add(MY_CLASS, parent);
182 return obj;
183}
184
185EOLIAN static Eo *
186_elm_route_eo_base_constructor(Eo *obj, Elm_Route_Data *_pd EINA_UNUSED)
187{
188 obj = eo_constructor(eo_super(obj, MY_CLASS));
189 evas_obj_type_set(obj, MY_CLASS_NAME_LEGACY);
190
191 return obj;
192}
193
194EOLIAN static void
195_elm_route_emap_set(Eo *obj, Elm_Route_Data *sd, void *_emap)
196{
197#ifdef ELM_EMAP
198 EMap_Route *emap = _emap;
199
200 EMap_Route_Node *node, *node_prev = NULL;
201 Evas_Object *o;
202 Eina_List *l;
203
204 sd->emap = emap;
205
206 _clear_route(obj);
207
208 EINA_LIST_FOREACH(emap_route_nodes_get(sd->emap), l, node)
209 {
210 if (node_prev)
211 {
212 Segment *segment = calloc(1, sizeof(Segment));
213
214 segment->node_start = node_prev;
215 segment->node_end = node;
216
217 o = evas_object_line_add(evas_object_evas_get(obj));
218 segment->obj = o;
219 evas_object_smart_member_add(o, obj);
220
221 segment->must_calc = EINA_TRUE;
222
223 _update_lon_lat_min_max
224 (obj, emap_route_node_lon_get(node_prev),
225 emap_route_node_lat_get(node_prev));
226 _update_lon_lat_min_max
227 (obj, emap_route_node_lon_get(node),
228 emap_route_node_lat_get(node));
229
230 sd->segments = eina_list_append(sd->segments, segment);
231 }
232
233 node_prev = node;
234 }
235
236 _sizing_eval(obj);
237#else
238 (void)obj;
239 (void)sd;
240 (void)_emap;
241#endif
242}
243
244EOLIAN static void
245_elm_route_longitude_min_max_get(Eo *obj EINA_UNUSED, Elm_Route_Data *sd, double *min, double *max)
246{
247 if (min) *min = sd->lon_min;
248 if (max) *max = sd->lon_max;
249}
250
251EOLIAN static void
252_elm_route_latitude_min_max_get(Eo *obj EINA_UNUSED, Elm_Route_Data *sd, double *min, double *max)
253{
254 if (min) *min = sd->lat_min;
255 if (max) *max = sd->lat_max;
256}
257
258EOLIAN static void
259_elm_route_class_constructor(Eo_Class *klass)
260{
261 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
262}
263
264#include "elm_route.eo.c"