1 |
zoff99 |
2 |
/**
|
2 |
zoff99 |
31 |
* ZANavi, Zoff Android Navigation system.
|
3 |
|
|
* Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
|
4 |
|
|
*
|
5 |
|
|
* This program is free software; you can redistribute it and/or
|
6 |
|
|
* modify it under the terms of the GNU General Public License
|
7 |
|
|
* version 2 as published by the Free Software Foundation.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the
|
16 |
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
|
|
* Boston, MA 02110-1301, USA.
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
zoff99 |
2 |
* Navit, a modular navigation system.
|
22 |
|
|
* Copyright (C) 2005-2009 Navit Team
|
23 |
|
|
*
|
24 |
|
|
* This program is free software; you can redistribute it and/or
|
25 |
|
|
* modify it under the terms of the GNU General Public License
|
26 |
|
|
* version 2 as published by the Free Software Foundation.
|
27 |
|
|
*
|
28 |
|
|
* This program is distributed in the hope that it will be useful,
|
29 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
|
|
* GNU General Public License for more details.
|
32 |
|
|
*
|
33 |
|
|
* You should have received a copy of the GNU General Public License
|
34 |
|
|
* along with this program; if not, write to the
|
35 |
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
36 |
|
|
* Boston, MA 02110-1301, USA.
|
37 |
|
|
*/
|
38 |
|
|
|
39 |
|
|
#include <glib.h>
|
40 |
|
|
#include <string.h>
|
41 |
|
|
#include "item.h"
|
42 |
|
|
#include "attr.h"
|
43 |
|
|
#include "layout.h"
|
44 |
|
|
#include "coord.h"
|
45 |
|
|
#include "debug.h"
|
46 |
|
|
|
47 |
|
|
struct layout * layout_new(struct attr *parent, struct attr **attrs)
|
48 |
|
|
{
|
49 |
|
|
struct layout *l;
|
50 |
zoff99 |
31 |
struct color def_color = { COLOR_BACKGROUND_ };
|
51 |
zoff99 |
27 |
struct attr *name_attr, *color_attr, *order_delta_attr, *font_attr, *day_attr, *night_attr, *active_attr;
|
52 |
zoff99 |
2 |
|
53 |
zoff99 |
27 |
if (!(name_attr = attr_search(attrs, NULL, attr_name)))
|
54 |
|
|
{
|
55 |
zoff99 |
2 |
return NULL;
|
56 |
zoff99 |
51 |
}
|
57 |
|
|
|
58 |
|
|
l = g_new0(struct layout, 1);
|
59 |
zoff99 |
2 |
l->name = g_strdup(name_attr->u.str);
|
60 |
zoff99 |
51 |
|
61 |
zoff99 |
27 |
if ((font_attr = attr_search(attrs, NULL, attr_font)))
|
62 |
|
|
{
|
63 |
zoff99 |
2 |
l->font = g_strdup(font_attr->u.str);
|
64 |
|
|
}
|
65 |
zoff99 |
51 |
|
66 |
zoff99 |
27 |
if ((day_attr = attr_search(attrs, NULL, attr_daylayout)))
|
67 |
|
|
{
|
68 |
zoff99 |
2 |
l->dayname = g_strdup(day_attr->u.str);
|
69 |
|
|
}
|
70 |
zoff99 |
51 |
|
71 |
zoff99 |
27 |
if ((night_attr = attr_search(attrs, NULL, attr_nightlayout)))
|
72 |
|
|
{
|
73 |
zoff99 |
2 |
l->nightname = g_strdup(night_attr->u.str);
|
74 |
|
|
}
|
75 |
zoff99 |
51 |
|
76 |
zoff99 |
27 |
if ((color_attr = attr_search(attrs, NULL, attr_color)))
|
77 |
|
|
{
|
78 |
zoff99 |
2 |
l->color = *color_attr->u.color;
|
79 |
zoff99 |
27 |
}
|
80 |
zoff99 |
2 |
else
|
81 |
zoff99 |
27 |
{
|
82 |
zoff99 |
2 |
l->color = def_color;
|
83 |
zoff99 |
27 |
}
|
84 |
zoff99 |
51 |
|
85 |
zoff99 |
27 |
if ((order_delta_attr = attr_search(attrs, NULL, attr_order_delta)))
|
86 |
|
|
{
|
87 |
|
|
l->order_delta = order_delta_attr->u.num;
|
88 |
|
|
}
|
89 |
zoff99 |
51 |
|
90 |
zoff99 |
27 |
if ((active_attr = attr_search(attrs, NULL, attr_active)))
|
91 |
|
|
{
|
92 |
zoff99 |
2 |
l->active = active_attr->u.num;
|
93 |
zoff99 |
27 |
}
|
94 |
zoff99 |
51 |
|
95 |
zoff99 |
2 |
return l;
|
96 |
|
|
}
|
97 |
|
|
|
98 |
zoff99 |
27 |
struct attr_iter
|
99 |
|
|
{
|
100 |
|
|
GList *last;
|
101 |
zoff99 |
2 |
};
|
102 |
|
|
|
103 |
|
|
struct attr_iter *
|
104 |
|
|
layout_attr_iter_new(void)
|
105 |
|
|
{
|
106 |
zoff99 |
27 |
return g_new0(struct attr_iter, 1);
|
107 |
zoff99 |
2 |
}
|
108 |
|
|
|
109 |
zoff99 |
27 |
void layout_attr_iter_destroy(struct attr_iter *iter)
|
110 |
zoff99 |
2 |
{
|
111 |
|
|
g_free(iter);
|
112 |
|
|
}
|
113 |
|
|
|
114 |
zoff99 |
27 |
int layout_get_attr(struct layout *layout, enum attr_type type, struct attr *attr, struct attr_iter *iter)
|
115 |
zoff99 |
2 |
{
|
116 |
zoff99 |
27 |
GList *cursor, *layer;
|
117 |
|
|
attr->type = type;
|
118 |
|
|
switch (type)
|
119 |
|
|
{
|
120 |
|
|
case attr_cursor:
|
121 |
|
|
cursor = layout->cursors;
|
122 |
|
|
while (cursor)
|
123 |
|
|
{
|
124 |
|
|
if (!iter || iter->last == g_list_previous(cursor))
|
125 |
|
|
{
|
126 |
|
|
attr->u.cursor = cursor->data;
|
127 |
|
|
if (iter)
|
128 |
|
|
iter->last = cursor;
|
129 |
|
|
return 1;
|
130 |
|
|
}
|
131 |
|
|
cursor = g_list_next(cursor);
|
132 |
zoff99 |
2 |
}
|
133 |
zoff99 |
27 |
break;
|
134 |
|
|
case attr_layer:
|
135 |
|
|
layer = layout->layers;
|
136 |
|
|
while (layer)
|
137 |
|
|
{
|
138 |
|
|
if (!iter || iter->last == g_list_previous(layer))
|
139 |
|
|
{
|
140 |
|
|
attr->u.layer = layer->data;
|
141 |
|
|
if (iter)
|
142 |
|
|
iter->last = layer;
|
143 |
|
|
return 1;
|
144 |
|
|
}
|
145 |
|
|
layer = g_list_next(layer);
|
146 |
zoff99 |
2 |
}
|
147 |
zoff99 |
27 |
break;
|
148 |
|
|
case attr_active:
|
149 |
|
|
attr->u.num = layout->active;
|
150 |
|
|
break;
|
151 |
|
|
default:
|
152 |
|
|
break;
|
153 |
zoff99 |
2 |
}
|
154 |
|
|
return 0;
|
155 |
|
|
}
|
156 |
|
|
|
157 |
zoff99 |
27 |
int layout_add_attr(struct layout *layout, struct attr *attr)
|
158 |
zoff99 |
2 |
{
|
159 |
zoff99 |
27 |
switch (attr->type)
|
160 |
|
|
{
|
161 |
|
|
case attr_cursor:
|
162 |
|
|
layout->cursors = g_list_append(layout->cursors, attr->u.cursor);
|
163 |
|
|
return 1;
|
164 |
|
|
case attr_layer:
|
165 |
|
|
layout->layers = g_list_append(layout->layers, attr->u.layer);
|
166 |
|
|
return 1;
|
167 |
|
|
default:
|
168 |
|
|
return 0;
|
169 |
zoff99 |
2 |
}
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
/**
|
173 |
|
|
* Searchs the layout for a cursor with the given name.
|
174 |
|
|
*
|
175 |
|
|
* @param layout The layout
|
176 |
|
|
* @param name The name
|
177 |
|
|
* @returns A pointer to cursor with the given name or the name default or NULL.
|
178 |
|
|
* @author Ralph Sennhauser (10/2009)
|
179 |
zoff99 |
27 |
*/
|
180 |
zoff99 |
2 |
struct cursor *
|
181 |
|
|
layout_get_cursor(struct layout *this_, char *name)
|
182 |
|
|
{
|
183 |
|
|
GList *c;
|
184 |
zoff99 |
27 |
struct cursor *d = NULL;
|
185 |
zoff99 |
2 |
|
186 |
zoff99 |
27 |
c = g_list_first(this_->cursors);
|
187 |
|
|
while (c)
|
188 |
|
|
{
|
189 |
|
|
if (!strcmp(((struct cursor *) c->data)->name, name))
|
190 |
zoff99 |
2 |
return c->data;
|
191 |
zoff99 |
27 |
if (!strcmp(((struct cursor *) c->data)->name, "default"))
|
192 |
|
|
d = c->data;
|
193 |
|
|
c = g_list_next(c);
|
194 |
zoff99 |
2 |
}
|
195 |
|
|
return d;
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
struct cursor *
|
199 |
|
|
cursor_new(struct attr *parent, struct attr **attrs)
|
200 |
|
|
{
|
201 |
|
|
struct attr *w, *h, *name, *interval, *sequence_range;
|
202 |
|
|
struct cursor *this;
|
203 |
|
|
|
204 |
zoff99 |
27 |
w = attr_search(attrs, NULL, attr_w);
|
205 |
|
|
h = attr_search(attrs, NULL, attr_h);
|
206 |
|
|
if (!w || !h)
|
207 |
zoff99 |
2 |
return NULL;
|
208 |
|
|
|
209 |
|
|
this=g_new0(struct cursor,1);
|
210 |
zoff99 |
27 |
this->w = w->u.num;
|
211 |
|
|
this->h = h->u.num;
|
212 |
|
|
name = attr_search(attrs, NULL, attr_name);
|
213 |
zoff99 |
2 |
if (name)
|
214 |
zoff99 |
27 |
this->name = g_strdup(name->u.str);
|
215 |
zoff99 |
2 |
else
|
216 |
zoff99 |
27 |
this->name = g_strdup("default");
|
217 |
|
|
interval = attr_search(attrs, NULL, attr_interval);
|
218 |
zoff99 |
2 |
if (interval)
|
219 |
zoff99 |
27 |
this->interval = interval->u.num;
|
220 |
|
|
sequence_range = attr_search(attrs, NULL, attr_sequence_range);
|
221 |
|
|
if (sequence_range)
|
222 |
|
|
{
|
223 |
zoff99 |
2 |
struct range *r=g_new0(struct range,1);
|
224 |
zoff99 |
27 |
r->min = sequence_range->u.range.min;
|
225 |
|
|
r->max = sequence_range->u.range.max;
|
226 |
|
|
this->sequence_range = r;
|
227 |
zoff99 |
2 |
}
|
228 |
zoff99 |
27 |
else
|
229 |
|
|
{
|
230 |
|
|
this->sequence_range = NULL;
|
231 |
zoff99 |
2 |
}
|
232 |
zoff99 |
31 |
//dbg(2, "ret=%p\n", this);
|
233 |
zoff99 |
2 |
return this;
|
234 |
|
|
}
|
235 |
|
|
|
236 |
zoff99 |
27 |
void cursor_destroy(struct cursor *this_)
|
237 |
zoff99 |
2 |
{
|
238 |
|
|
if (this_->sequence_range)
|
239 |
|
|
g_free(this_->sequence_range);
|
240 |
zoff99 |
27 |
if (this_->name)
|
241 |
|
|
{
|
242 |
zoff99 |
2 |
g_free(this_->name);
|
243 |
|
|
}
|
244 |
|
|
g_free(this_);
|
245 |
|
|
}
|
246 |
|
|
|
247 |
zoff99 |
27 |
int cursor_add_attr(struct cursor *this_, struct attr *attr)
|
248 |
zoff99 |
2 |
{
|
249 |
zoff99 |
27 |
switch (attr->type)
|
250 |
|
|
{
|
251 |
|
|
case attr_itemgra:
|
252 |
|
|
this_->attrs = attr_generic_add_attr(this_->attrs, attr);
|
253 |
|
|
return 1;
|
254 |
|
|
default:
|
255 |
|
|
break;
|
256 |
zoff99 |
2 |
}
|
257 |
|
|
return 0;
|
258 |
|
|
}
|
259 |
|
|
|
260 |
zoff99 |
27 |
static int layer_set_attr_do(struct layer *l, struct attr *attr, int init)
|
261 |
zoff99 |
2 |
{
|
262 |
zoff99 |
27 |
switch (attr->type)
|
263 |
|
|
{
|
264 |
|
|
case attr_active:
|
265 |
|
|
l->active = attr->u.num;
|
266 |
|
|
return 1;
|
267 |
|
|
case attr_details:
|
268 |
|
|
l->details = attr->u.num;
|
269 |
|
|
return 1;
|
270 |
|
|
case attr_name:
|
271 |
|
|
g_free(l->name);
|
272 |
|
|
l->name = g_strdup(attr->u.str);
|
273 |
|
|
return 1;
|
274 |
|
|
default:
|
275 |
|
|
return 0;
|
276 |
zoff99 |
2 |
}
|
277 |
|
|
}
|
278 |
|
|
|
279 |
|
|
struct layer * layer_new(struct attr *parent, struct attr **attrs)
|
280 |
|
|
{
|
281 |
|
|
struct layer *l;
|
282 |
|
|
|
283 |
|
|
l = g_new0(struct layer, 1);
|
284 |
zoff99 |
27 |
l->active = 1;
|
285 |
zoff99 |
41 |
|
286 |
zoff99 |
27 |
for (; *attrs; attrs++)
|
287 |
|
|
{
|
288 |
zoff99 |
2 |
layer_set_attr_do(l, *attrs, 1);
|
289 |
|
|
}
|
290 |
zoff99 |
41 |
|
291 |
zoff99 |
2 |
return l;
|
292 |
|
|
}
|
293 |
|
|
|
294 |
zoff99 |
27 |
int layer_get_attr(struct layer *layer, enum attr_type type, struct attr *attr, struct attr_iter *iter)
|
295 |
zoff99 |
2 |
{
|
296 |
zoff99 |
27 |
attr->type = type;
|
297 |
|
|
switch (type)
|
298 |
|
|
{
|
299 |
|
|
case attr_active:
|
300 |
|
|
attr->u.num = layer->active;
|
301 |
zoff99 |
2 |
return 1;
|
302 |
zoff99 |
27 |
case attr_details:
|
303 |
|
|
attr->u.num = layer->details;
|
304 |
|
|
return 1;
|
305 |
|
|
case attr_name:
|
306 |
|
|
if (layer->name)
|
307 |
|
|
{
|
308 |
|
|
attr->u.str = layer->name;
|
309 |
|
|
return 1;
|
310 |
|
|
}
|
311 |
|
|
break;
|
312 |
|
|
default:
|
313 |
|
|
return 0;
|
314 |
zoff99 |
2 |
}
|
315 |
|
|
return 0;
|
316 |
|
|
}
|
317 |
|
|
|
318 |
zoff99 |
27 |
int layer_add_attr(struct layer *layer, struct attr *attr)
|
319 |
zoff99 |
2 |
{
|
320 |
zoff99 |
27 |
switch (attr->type)
|
321 |
|
|
{
|
322 |
|
|
case attr_itemgra:
|
323 |
|
|
layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra);
|
324 |
|
|
return 1;
|
325 |
|
|
default:
|
326 |
|
|
return 0;
|
327 |
zoff99 |
2 |
}
|
328 |
|
|
}
|
329 |
|
|
|
330 |
zoff99 |
27 |
int layer_set_attr(struct layer *layer, struct attr *attr)
|
331 |
zoff99 |
2 |
{
|
332 |
|
|
return layer_set_attr_do(layer, attr, 0);
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
|
336 |
|
|
{
|
337 |
zoff99 |
30 |
|
338 |
|
|
//dbg(0,"EEnter\n");
|
339 |
|
|
|
340 |
zoff99 |
2 |
struct itemgra *itm;
|
341 |
|
|
struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range;
|
342 |
|
|
enum item_type *type;
|
343 |
|
|
struct range defrange;
|
344 |
zoff99 |
27 |
|
345 |
zoff99 |
2 |
itm = g_new0(struct itemgra, 1);
|
346 |
zoff99 |
27 |
order = attr_search(attrs, NULL, attr_order);
|
347 |
|
|
item_types = attr_search(attrs, NULL, attr_item_types);
|
348 |
|
|
speed_range = attr_search(attrs, NULL, attr_speed_range);
|
349 |
|
|
angle_range = attr_search(attrs, NULL, attr_angle_range);
|
350 |
|
|
sequence_range = attr_search(attrs, NULL, attr_sequence_range);
|
351 |
|
|
defrange.min = 0;
|
352 |
|
|
defrange.max = 32767;
|
353 |
zoff99 |
41 |
|
354 |
zoff99 |
27 |
if (order)
|
355 |
|
|
itm->order = order->u.range;
|
356 |
|
|
else
|
357 |
|
|
itm->order = defrange;
|
358 |
|
|
if (speed_range)
|
359 |
|
|
itm->speed_range = speed_range->u.range;
|
360 |
|
|
else
|
361 |
|
|
itm->speed_range = defrange;
|
362 |
|
|
if (angle_range)
|
363 |
|
|
itm->angle_range = angle_range->u.range;
|
364 |
|
|
else
|
365 |
|
|
itm->angle_range = defrange;
|
366 |
|
|
if (sequence_range)
|
367 |
|
|
itm->sequence_range = sequence_range->u.range;
|
368 |
|
|
else
|
369 |
|
|
itm->sequence_range = defrange;
|
370 |
zoff99 |
41 |
|
371 |
zoff99 |
27 |
if (item_types)
|
372 |
|
|
{
|
373 |
|
|
type = item_types->u.item_types;
|
374 |
zoff99 |
41 |
|
375 |
zoff99 |
27 |
while (type && *type != type_none)
|
376 |
|
|
{
|
377 |
|
|
itm->type = g_list_append(itm->type, GINT_TO_POINTER(*type));
|
378 |
zoff99 |
2 |
type++;
|
379 |
|
|
}
|
380 |
|
|
}
|
381 |
zoff99 |
30 |
|
382 |
|
|
//dbg(0,"return\n");
|
383 |
|
|
|
384 |
zoff99 |
2 |
return itm;
|
385 |
|
|
}
|
386 |
zoff99 |
41 |
|
387 |
zoff99 |
27 |
int itemgra_add_attr(struct itemgra *itemgra, struct attr *attr)
|
388 |
zoff99 |
2 |
{
|
389 |
zoff99 |
27 |
switch (attr->type)
|
390 |
|
|
{
|
391 |
|
|
case attr_polygon:
|
392 |
|
|
case attr_polyline:
|
393 |
|
|
case attr_circle:
|
394 |
|
|
case attr_text:
|
395 |
|
|
case attr_icon:
|
396 |
|
|
case attr_image:
|
397 |
zoff99 |
34 |
case attr_maptile:
|
398 |
zoff99 |
27 |
case attr_arrows:
|
399 |
|
|
itemgra->elements = g_list_append(itemgra->elements, attr->u.element);
|
400 |
|
|
return 1;
|
401 |
zoff99 |
41 |
|
402 |
zoff99 |
27 |
default:
|
403 |
|
|
dbg(0, "unknown: %s\n", attr_to_name(attr->type));
|
404 |
|
|
return 0;
|
405 |
zoff99 |
2 |
}
|
406 |
|
|
}
|
407 |
|
|
|
408 |
zoff99 |
27 |
static void element_set_color(struct element *e, struct attr **attrs)
|
409 |
zoff99 |
2 |
{
|
410 |
|
|
struct attr *color;
|
411 |
zoff99 |
27 |
color = attr_search(attrs, NULL, attr_color);
|
412 |
zoff99 |
2 |
if (color)
|
413 |
zoff99 |
51 |
{
|
414 |
zoff99 |
27 |
e->color = *color->u.color;
|
415 |
zoff99 |
51 |
}
|
416 |
zoff99 |
2 |
}
|
417 |
|
|
|
418 |
zoff99 |
51 |
static void element_set_nightcol_color(struct color *c, struct color *c2, struct attr **attrs)
|
419 |
|
|
{
|
420 |
|
|
struct attr *color;
|
421 |
|
|
color = attr_search(attrs, NULL, attr_nightcol);
|
422 |
|
|
if (color)
|
423 |
|
|
{
|
424 |
|
|
*c = *color->u.color;
|
425 |
|
|
dbg(0, "nightcol set %d %d %d\n", c->r, c->g, c->b);
|
426 |
|
|
}
|
427 |
|
|
else
|
428 |
|
|
{
|
429 |
|
|
if (c2)
|
430 |
|
|
{
|
431 |
|
|
*c = *c2;
|
432 |
|
|
}
|
433 |
|
|
}
|
434 |
|
|
}
|
435 |
|
|
|
436 |
zoff99 |
27 |
static void element_set_background_color(struct color *c, struct attr **attrs)
|
437 |
zoff99 |
2 |
{
|
438 |
|
|
struct attr *color;
|
439 |
zoff99 |
27 |
color = attr_search(attrs, NULL, attr_background_color);
|
440 |
zoff99 |
2 |
if (color)
|
441 |
zoff99 |
51 |
{
|
442 |
zoff99 |
27 |
*c = *color->u.color;
|
443 |
zoff99 |
51 |
}
|
444 |
zoff99 |
2 |
}
|
445 |
|
|
|
446 |
zoff99 |
27 |
static void element_set_text_size(struct element *e, struct attr **attrs)
|
447 |
zoff99 |
2 |
{
|
448 |
|
|
struct attr *text_size;
|
449 |
zoff99 |
27 |
text_size = attr_search(attrs, NULL, attr_text_size);
|
450 |
zoff99 |
51 |
|
451 |
zoff99 |
2 |
if (text_size)
|
452 |
zoff99 |
51 |
{
|
453 |
zoff99 |
27 |
e->text_size = text_size->u.num;
|
454 |
zoff99 |
51 |
}
|
455 |
zoff99 |
2 |
}
|
456 |
|
|
|
457 |
zoff99 |
27 |
static void element_set_polyline_width(struct element *e, struct attr **attrs)
|
458 |
zoff99 |
2 |
{
|
459 |
|
|
struct attr *width;
|
460 |
zoff99 |
27 |
width = attr_search(attrs, NULL, attr_width);
|
461 |
zoff99 |
2 |
if (width)
|
462 |
zoff99 |
27 |
e->u.polyline.width = width->u.num;
|
463 |
zoff99 |
2 |
}
|
464 |
|
|
|
465 |
zoff99 |
27 |
static void element_set_polyline_directed(struct element *e, struct attr **attrs)
|
466 |
zoff99 |
2 |
{
|
467 |
|
|
struct attr *directed;
|
468 |
zoff99 |
27 |
directed = attr_search(attrs, NULL, attr_directed);
|
469 |
zoff99 |
2 |
if (directed)
|
470 |
zoff99 |
27 |
e->u.polyline.directed = directed->u.num;
|
471 |
zoff99 |
2 |
}
|
472 |
|
|
|
473 |
zoff99 |
27 |
static void element_set_polyline_dash(struct element *e, struct attr **attrs)
|
474 |
zoff99 |
2 |
{
|
475 |
|
|
struct attr *dash;
|
476 |
|
|
int i;
|
477 |
|
|
|
478 |
zoff99 |
27 |
dash = attr_search(attrs, NULL, attr_dash);
|
479 |
|
|
if (dash)
|
480 |
|
|
{
|
481 |
|
|
/*
|
482 |
zoff99 |
31 |
for (i = 0; i < 4; i++)
|
483 |
|
|
{
|
484 |
|
|
if (!dash->u.dash[i])
|
485 |
|
|
{
|
486 |
|
|
break;
|
487 |
|
|
}
|
488 |
|
|
dbg(0,"1 i=%d d=%d\n", i, dash->u.dash[i]);
|
489 |
|
|
//e->u.polyline.dash_table[i] = atoi(dash->u.dash[i]);
|
490 |
|
|
e->u.polyline.dash_table[i] = dash->u.dash[i];
|
491 |
|
|
}
|
492 |
|
|
*/
|
493 |
|
|
i = 0;
|
494 |
zoff99 |
27 |
if (!dash->u.dash[i])
|
495 |
|
|
{
|
496 |
|
|
}
|
497 |
|
|
else
|
498 |
|
|
{
|
499 |
|
|
e->u.polyline.dash_table[i] = dash->u.dash[i];
|
500 |
|
|
//dbg(0,"1 i=%d d=%d\n", i, dash->u.dash[i]);
|
501 |
|
|
e->u.polyline.dash_num = (i + 1);
|
502 |
|
|
}
|
503 |
zoff99 |
2 |
}
|
504 |
|
|
}
|
505 |
|
|
|
506 |
zoff99 |
27 |
static void element_set_polyline_offset(struct element *e, struct attr **attrs)
|
507 |
zoff99 |
2 |
{
|
508 |
|
|
struct attr *offset;
|
509 |
zoff99 |
27 |
offset = attr_search(attrs, NULL, attr_offset);
|
510 |
zoff99 |
2 |
if (offset)
|
511 |
zoff99 |
27 |
{
|
512 |
|
|
e->u.polyline.offset = offset->u.num;
|
513 |
|
|
}
|
514 |
zoff99 |
2 |
}
|
515 |
|
|
|
516 |
zoff99 |
27 |
static void element_set_circle_width(struct element *e, struct attr **attrs)
|
517 |
zoff99 |
2 |
{
|
518 |
|
|
struct attr *width;
|
519 |
zoff99 |
27 |
width = attr_search(attrs, NULL, attr_width);
|
520 |
zoff99 |
2 |
if (width)
|
521 |
zoff99 |
27 |
e->u.circle.width = width->u.num;
|
522 |
zoff99 |
2 |
}
|
523 |
|
|
|
524 |
zoff99 |
27 |
static void element_set_circle_radius(struct element *e, struct attr **attrs)
|
525 |
zoff99 |
2 |
{
|
526 |
|
|
struct attr *radius;
|
527 |
zoff99 |
27 |
radius = attr_search(attrs, NULL, attr_radius);
|
528 |
zoff99 |
2 |
if (radius)
|
529 |
zoff99 |
27 |
e->u.circle.radius = radius->u.num;
|
530 |
zoff99 |
2 |
}
|
531 |
|
|
|
532 |
|
|
struct polygon *
|
533 |
|
|
polygon_new(struct attr *parent, struct attr **attrs)
|
534 |
|
|
{
|
535 |
|
|
struct element *e;
|
536 |
|
|
e = g_new0(struct element, 1);
|
537 |
zoff99 |
27 |
e->type = element_polygon;
|
538 |
zoff99 |
2 |
element_set_color(e, attrs);
|
539 |
|
|
|
540 |
zoff99 |
27 |
return (struct polygon *) e;
|
541 |
zoff99 |
2 |
}
|
542 |
|
|
|
543 |
|
|
struct polyline *
|
544 |
|
|
polyline_new(struct attr *parent, struct attr **attrs)
|
545 |
|
|
{
|
546 |
|
|
struct element *e;
|
547 |
zoff99 |
27 |
|
548 |
zoff99 |
2 |
e = g_new0(struct element, 1);
|
549 |
zoff99 |
27 |
e->type = element_polyline;
|
550 |
zoff99 |
2 |
element_set_color(e, attrs);
|
551 |
zoff99 |
51 |
element_set_nightcol_color(&e->u.polyline.nightcol, &e->color, attrs);
|
552 |
zoff99 |
2 |
element_set_polyline_width(e, attrs);
|
553 |
|
|
element_set_polyline_directed(e, attrs);
|
554 |
|
|
element_set_polyline_dash(e, attrs);
|
555 |
|
|
element_set_polyline_offset(e, attrs);
|
556 |
zoff99 |
27 |
return (struct polyline *) e;
|
557 |
zoff99 |
2 |
}
|
558 |
|
|
|
559 |
|
|
struct circle *
|
560 |
|
|
circle_new(struct attr *parent, struct attr **attrs)
|
561 |
|
|
{
|
562 |
|
|
struct element *e;
|
563 |
zoff99 |
31 |
struct color color_black = { COLOR_BLACK_ };
|
564 |
|
|
struct color color_white = { COLOR_WHITE_ };
|
565 |
zoff99 |
2 |
|
566 |
|
|
e = g_new0(struct element, 1);
|
567 |
zoff99 |
27 |
e->type = element_circle;
|
568 |
zoff99 |
2 |
e->color = color_black;
|
569 |
|
|
e->u.circle.background_color = color_white;
|
570 |
|
|
element_set_color(e, attrs);
|
571 |
|
|
element_set_background_color(&e->u.circle.background_color, attrs);
|
572 |
|
|
element_set_text_size(e, attrs);
|
573 |
|
|
element_set_circle_width(e, attrs);
|
574 |
|
|
element_set_circle_radius(e, attrs);
|
575 |
|
|
|
576 |
zoff99 |
27 |
return (struct circle *) e;
|
577 |
zoff99 |
2 |
}
|
578 |
|
|
|
579 |
|
|
struct text *
|
580 |
|
|
text_new(struct attr *parent, struct attr **attrs)
|
581 |
|
|
{
|
582 |
|
|
struct element *e;
|
583 |
zoff99 |
31 |
struct color color_black = { COLOR_BLACK_ };
|
584 |
|
|
struct color color_white = { COLOR_WHITE_ };
|
585 |
zoff99 |
27 |
|
586 |
zoff99 |
2 |
e = g_new0(struct element, 1);
|
587 |
zoff99 |
27 |
e->type = element_text;
|
588 |
zoff99 |
2 |
element_set_text_size(e, attrs);
|
589 |
|
|
e->color = color_black;
|
590 |
|
|
e->u.text.background_color = color_white;
|
591 |
|
|
element_set_color(e, attrs);
|
592 |
|
|
element_set_background_color(&e->u.text.background_color, attrs);
|
593 |
|
|
|
594 |
zoff99 |
27 |
return (struct text *) e;
|
595 |
zoff99 |
2 |
}
|
596 |
|
|
|
597 |
|
|
struct icon *
|
598 |
|
|
icon_new(struct attr *parent, struct attr **attrs)
|
599 |
|
|
{
|
600 |
|
|
struct element *e;
|
601 |
zoff99 |
27 |
struct attr *src, *w, *h, *rotation;
|
602 |
|
|
src = attr_search(attrs, NULL, attr_src);
|
603 |
|
|
if (!src)
|
604 |
zoff99 |
2 |
return NULL;
|
605 |
|
|
|
606 |
zoff99 |
27 |
e = g_malloc0(sizeof(*e) + strlen(src->u.str) + 1);
|
607 |
|
|
e->type = element_icon;
|
608 |
|
|
e->u.icon.src = (char *) (e + 1);
|
609 |
|
|
if ((w = attr_search(attrs, NULL, attr_w)))
|
610 |
|
|
e->u.icon.width = w->u.num;
|
611 |
zoff99 |
2 |
else
|
612 |
zoff99 |
27 |
e->u.icon.width = -1;
|
613 |
|
|
if ((h = attr_search(attrs, NULL, attr_h)))
|
614 |
|
|
e->u.icon.height = h->u.num;
|
615 |
zoff99 |
2 |
else
|
616 |
zoff99 |
27 |
e->u.icon.height = -1;
|
617 |
|
|
if ((rotation = attr_search(attrs, NULL, attr_rotation)))
|
618 |
|
|
e->u.icon.rotation = rotation->u.num;
|
619 |
|
|
strcpy(e->u.icon.src, src->u.str);
|
620 |
zoff99 |
2 |
|
621 |
zoff99 |
27 |
return (struct icon *) e;
|
622 |
zoff99 |
2 |
}
|
623 |
|
|
|
624 |
|
|
struct image *
|
625 |
|
|
image_new(struct attr *parent, struct attr **attrs)
|
626 |
|
|
{
|
627 |
|
|
struct element *e;
|
628 |
|
|
|
629 |
|
|
e = g_malloc0(sizeof(*e));
|
630 |
zoff99 |
27 |
e->type = element_image;
|
631 |
zoff99 |
2 |
|
632 |
zoff99 |
27 |
return (struct image *) e;
|
633 |
zoff99 |
2 |
}
|
634 |
|
|
|
635 |
zoff99 |
34 |
struct maptile *
|
636 |
|
|
maptile_new(struct attr *parent, struct attr **attrs)
|
637 |
|
|
{
|
638 |
|
|
struct element *e;
|
639 |
|
|
|
640 |
|
|
e = g_malloc0(sizeof(*e));
|
641 |
|
|
e->type = element_maptile;
|
642 |
|
|
|
643 |
|
|
return (struct maptile *) e;
|
644 |
|
|
}
|
645 |
|
|
|
646 |
zoff99 |
2 |
struct arrows *
|
647 |
|
|
arrows_new(struct attr *parent, struct attr **attrs)
|
648 |
|
|
{
|
649 |
|
|
struct element *e;
|
650 |
|
|
e = g_malloc0(sizeof(*e));
|
651 |
zoff99 |
27 |
e->type = element_arrows;
|
652 |
zoff99 |
2 |
element_set_color(e, attrs);
|
653 |
zoff99 |
27 |
return (struct arrows *) e;
|
654 |
zoff99 |
2 |
}
|
655 |
|
|
|
656 |
zoff99 |
27 |
int element_add_attr(struct element *e, struct attr *attr)
|
657 |
zoff99 |
2 |
{
|
658 |
zoff99 |
27 |
switch (attr->type)
|
659 |
|
|
{
|
660 |
|
|
case attr_coord:
|
661 |
|
|
e->coord = g_realloc(e->coord, (e->coord_count + 1) * sizeof(struct coord));
|
662 |
|
|
e->coord[e->coord_count++] = *attr->u.coord;
|
663 |
|
|
return 1;
|
664 |
|
|
default:
|
665 |
|
|
return 0;
|
666 |
zoff99 |
2 |
}
|
667 |
|
|
}
|