2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
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.
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.
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.
28 struct layout * layout_new(struct attr *parent, struct attr **attrs)
31 struct color def_color = {0xffff, 0xefef, 0xb7b7, 0xffff};
32 struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr;
34 if (! (name_attr=attr_search(attrs, NULL, attr_name)))
36 l = g_new0(struct layout, 1);
37 l->name = g_strdup(name_attr->u.str);
38 if ((font_attr=attr_search(attrs, NULL, attr_font))) {
39 l->font = g_strdup(font_attr->u.str);
41 if ((color_attr=attr_search(attrs, NULL, attr_color)))
42 l->color = *color_attr->u.color;
45 if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
46 l->order_delta=order_delta_attr->u.num;
51 layout_add_attr(struct layout *layout, struct attr *attr)
55 layout->layers = g_list_append(layout->layers, attr->u.layer);
64 struct layer * layer_new(struct attr *parent, struct attr **attrs)
68 struct attr *name, *details;
69 l = g_new0(struct layer, 1);
70 name=attr_search(attrs, NULL, attr_name);
72 l->name = g_strdup(name->u.str);
73 details=attr_search(attrs, NULL, attr_details);
75 l->details = details->u.num;
80 layer_add_attr(struct layer *layer, struct attr *attr)
84 layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra);
92 struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
95 struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range;
97 struct range defrange;
99 itm = g_new0(struct itemgra, 1);
100 order=attr_search(attrs, NULL, attr_order);
101 item_types=attr_search(attrs, NULL, attr_item_types);
102 speed_range=attr_search(attrs, NULL, attr_speed_range);
103 angle_range=attr_search(attrs, NULL, attr_angle_range);
104 sequence_range=attr_search(attrs, NULL, attr_sequence_range);
108 itm->order=order->u.range;
112 itm->speed_range=speed_range->u.range;
114 itm->speed_range=defrange;
116 itm->angle_range=angle_range->u.range;
118 itm->angle_range=defrange;
120 itm->sequence_range=sequence_range->u.range;
122 itm->sequence_range=defrange;
124 type=item_types->u.item_types;
125 while (type && *type != type_none) {
126 itm->type=g_list_append(itm->type, GINT_TO_POINTER(*type));
133 itemgra_add_attr(struct itemgra *itemgra, struct attr *attr)
135 switch (attr->type) {
143 itemgra->elements = g_list_append(itemgra->elements, attr->u.element);
146 dbg(0,"unknown: %s\n", attr_to_name(attr->type));
152 element_set_color(struct element *e, struct attr **attrs)
155 color=attr_search(attrs, NULL, attr_color);
157 e->color=*color->u.color;
161 element_set_text_size(struct element *e, struct attr **attrs)
163 struct attr *text_size;
164 text_size=attr_search(attrs, NULL, attr_text_size);
166 e->text_size=text_size->u.num;
170 element_set_polyline_width(struct element *e, struct attr **attrs)
173 width=attr_search(attrs, NULL, attr_width);
175 e->u.polyline.width=width->u.num;
179 element_set_polyline_directed(struct element *e, struct attr **attrs)
181 struct attr *directed;
182 directed=attr_search(attrs, NULL, attr_directed);
184 e->u.polyline.directed=directed->u.num;
188 element_set_polyline_dash(struct element *e, struct attr **attrs)
193 dash=attr_search(attrs, NULL, attr_dash);
195 for (i=0; i<4; i++) {
196 if (!dash->u.dash[i])
198 e->u.polyline.dash_table[i] = dash->u.dash[i];
200 e->u.polyline.dash_num=i;
205 element_set_polyline_offset(struct element *e, struct attr **attrs)
208 offset=attr_search(attrs, NULL, attr_offset);
210 e->u.polyline.offset=offset->u.num;
214 element_set_circle_width(struct element *e, struct attr **attrs)
217 width=attr_search(attrs, NULL, attr_width);
219 e->u.circle.width=width->u.num;
223 element_set_circle_radius(struct element *e, struct attr **attrs)
226 radius=attr_search(attrs, NULL, attr_radius);
228 e->u.circle.radius=radius->u.num;
232 polygon_new(struct attr *parent, struct attr **attrs)
235 e = g_new0(struct element, 1);
236 e->type=element_polygon;
237 element_set_color(e, attrs);
239 return (struct polygon *)e;
243 polyline_new(struct attr *parent, struct attr **attrs)
247 e = g_new0(struct element, 1);
248 e->type=element_polyline;
249 element_set_color(e, attrs);
250 element_set_polyline_width(e, attrs);
251 element_set_polyline_directed(e, attrs);
252 element_set_polyline_dash(e, attrs);
253 element_set_polyline_offset(e, attrs);
254 return (struct polyline *)e;
258 circle_new(struct attr *parent, struct attr **attrs)
262 e = g_new0(struct element, 1);
263 e->type=element_circle;
264 element_set_color(e, attrs);
265 element_set_text_size(e, attrs);
266 element_set_circle_width(e, attrs);
267 element_set_circle_radius(e, attrs);
269 return (struct circle *)e;
273 text_new(struct attr *parent, struct attr **attrs)
277 e = g_new0(struct element, 1);
278 e->type=element_text;
279 element_set_text_size(e, attrs);
281 return (struct text *)e;
285 icon_new(struct attr *parent, struct attr **attrs)
288 struct attr *src,*w,*h;
289 src=attr_search(attrs, NULL, attr_src);
293 e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1);
294 e->type=element_icon;
295 e->u.icon.src=(char *)(e+1);
296 if ((w=attr_search(attrs, NULL, attr_w)))
297 e->u.icon.width=w->u.num;
300 if ((h=attr_search(attrs, NULL, attr_h)))
301 e->u.icon.height=h->u.num;
304 strcpy(e->u.icon.src,src->u.str);
306 return (struct icon *)e;
310 image_new(struct attr *parent, struct attr **attrs)
314 e = g_malloc0(sizeof(*e));
315 e->type=element_image;
317 return (struct image *)e;
321 arrows_new(struct attr *parent, struct attr **attrs)
324 e = g_malloc0(sizeof(*e));
325 e->type=element_arrows;
326 element_set_color(e, attrs);
327 return (struct arrows *)e;
331 element_add_attr(struct element *e, struct attr *attr)
333 switch (attr->type) {
335 e->coord=g_realloc(e->coord,(e->coord_count+1)*sizeof(struct coord));
336 e->coord[e->coord_count++]=*attr->u.coord;