2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2009 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.
29 struct layout * layout_new(struct attr *parent, struct attr **attrs)
32 struct color def_color = {0xffff, 0xefef, 0xb7b7, 0xffff};
33 struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr;
35 if (! (name_attr=attr_search(attrs, NULL, attr_name)))
37 l = g_new0(struct layout, 1);
38 l->name = g_strdup(name_attr->u.str);
39 if ((font_attr=attr_search(attrs, NULL, attr_font))) {
40 l->font = g_strdup(font_attr->u.str);
42 if ((color_attr=attr_search(attrs, NULL, attr_color)))
43 l->color = *color_attr->u.color;
46 if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
47 l->order_delta=order_delta_attr->u.num;
52 layout_add_attr(struct layout *layout, struct attr *attr)
56 layout->cursors = g_list_append(layout->cursors, attr->u.cursor);
59 layout->layers = g_list_append(layout->layers, attr->u.layer);
67 * Searchs the layout for a cursor with the given name.
69 * @param layout The layout
70 * @param name The name
71 * @returns A pointer to cursor with the given name or the name default or NULL.
72 * @author Ralph Sennhauser (10/2009)
75 layout_get_cursor(struct layout *this_, char *name)
78 struct cursor *d=NULL;
80 c=g_list_first(this_->cursors);
82 if (! strcmp(((struct cursor *)c->data)->name, name))
84 if (! strcmp(((struct cursor *)c->data)->name, "default"))
94 cursor_new(struct attr *parent, struct attr **attrs)
96 struct attr *w, *h, *name, *interval, *sequence_range;
98 w=attr_search(attrs, NULL, attr_w);
99 h=attr_search(attrs, NULL, attr_h);
103 struct cursor *this=g_new0(struct cursor,1);
106 name=attr_search(attrs, NULL, attr_name);
108 this->name=g_strdup(name->u.str);
110 this->name=g_strdup("default");
111 interval=attr_search(attrs, NULL, attr_interval);
113 this->interval=interval->u.num;
114 sequence_range=attr_search(attrs, NULL, attr_sequence_range);
115 if (sequence_range) {
116 struct range *r=g_new0(struct range,1);
117 r->min=sequence_range->u.range.min;
118 r->max=sequence_range->u.range.max;
119 this->sequence_range=r;
122 this->sequence_range=NULL;
124 dbg(2,"ret=%p\n", this);
129 cursor_destroy(struct cursor *this_)
131 if (this_->sequence_range)
132 g_free(this_->sequence_range);
140 cursor_add_attr(struct cursor *this_, struct attr *attr)
142 switch (attr->type) {
144 this_->attrs=attr_generic_add_attr(this_->attrs, attr);
154 struct layer * layer_new(struct attr *parent, struct attr **attrs)
158 struct attr *name, *details;
159 l = g_new0(struct layer, 1);
160 name=attr_search(attrs, NULL, attr_name);
162 l->name = g_strdup(name->u.str);
163 details=attr_search(attrs, NULL, attr_details);
165 l->details = details->u.num;
170 layer_add_attr(struct layer *layer, struct attr *attr)
172 switch (attr->type) {
174 layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra);
182 struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
185 struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range;
186 enum item_type *type;
187 struct range defrange;
189 itm = g_new0(struct itemgra, 1);
190 order=attr_search(attrs, NULL, attr_order);
191 item_types=attr_search(attrs, NULL, attr_item_types);
192 speed_range=attr_search(attrs, NULL, attr_speed_range);
193 angle_range=attr_search(attrs, NULL, attr_angle_range);
194 sequence_range=attr_search(attrs, NULL, attr_sequence_range);
198 itm->order=order->u.range;
202 itm->speed_range=speed_range->u.range;
204 itm->speed_range=defrange;
206 itm->angle_range=angle_range->u.range;
208 itm->angle_range=defrange;
210 itm->sequence_range=sequence_range->u.range;
212 itm->sequence_range=defrange;
214 type=item_types->u.item_types;
215 while (type && *type != type_none) {
216 itm->type=g_list_append(itm->type, GINT_TO_POINTER(*type));
223 itemgra_add_attr(struct itemgra *itemgra, struct attr *attr)
225 switch (attr->type) {
233 itemgra->elements = g_list_append(itemgra->elements, attr->u.element);
236 dbg(0,"unknown: %s\n", attr_to_name(attr->type));
242 element_set_color(struct element *e, struct attr **attrs)
245 color=attr_search(attrs, NULL, attr_color);
247 e->color=*color->u.color;
251 element_set_text_size(struct element *e, struct attr **attrs)
253 struct attr *text_size;
254 text_size=attr_search(attrs, NULL, attr_text_size);
256 e->text_size=text_size->u.num;
260 element_set_polyline_width(struct element *e, struct attr **attrs)
263 width=attr_search(attrs, NULL, attr_width);
265 e->u.polyline.width=width->u.num;
269 element_set_polyline_directed(struct element *e, struct attr **attrs)
271 struct attr *directed;
272 directed=attr_search(attrs, NULL, attr_directed);
274 e->u.polyline.directed=directed->u.num;
278 element_set_polyline_dash(struct element *e, struct attr **attrs)
283 dash=attr_search(attrs, NULL, attr_dash);
285 for (i=0; i<4; i++) {
286 if (!dash->u.dash[i])
288 e->u.polyline.dash_table[i] = dash->u.dash[i];
290 e->u.polyline.dash_num=i;
295 element_set_polyline_offset(struct element *e, struct attr **attrs)
298 offset=attr_search(attrs, NULL, attr_offset);
300 e->u.polyline.offset=offset->u.num;
304 element_set_circle_width(struct element *e, struct attr **attrs)
307 width=attr_search(attrs, NULL, attr_width);
309 e->u.circle.width=width->u.num;
313 element_set_circle_radius(struct element *e, struct attr **attrs)
316 radius=attr_search(attrs, NULL, attr_radius);
318 e->u.circle.radius=radius->u.num;
322 polygon_new(struct attr *parent, struct attr **attrs)
325 e = g_new0(struct element, 1);
326 e->type=element_polygon;
327 element_set_color(e, attrs);
329 return (struct polygon *)e;
333 polyline_new(struct attr *parent, struct attr **attrs)
337 e = g_new0(struct element, 1);
338 e->type=element_polyline;
339 element_set_color(e, attrs);
340 element_set_polyline_width(e, attrs);
341 element_set_polyline_directed(e, attrs);
342 element_set_polyline_dash(e, attrs);
343 element_set_polyline_offset(e, attrs);
344 return (struct polyline *)e;
348 circle_new(struct attr *parent, struct attr **attrs)
352 e = g_new0(struct element, 1);
353 e->type=element_circle;
354 element_set_color(e, attrs);
355 element_set_text_size(e, attrs);
356 element_set_circle_width(e, attrs);
357 element_set_circle_radius(e, attrs);
359 return (struct circle *)e;
363 text_new(struct attr *parent, struct attr **attrs)
367 e = g_new0(struct element, 1);
368 e->type=element_text;
369 element_set_text_size(e, attrs);
371 return (struct text *)e;
375 icon_new(struct attr *parent, struct attr **attrs)
378 struct attr *src,*w,*h,*rotation;
379 src=attr_search(attrs, NULL, attr_src);
383 e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1);
384 e->type=element_icon;
385 e->u.icon.src=(char *)(e+1);
386 if ((w=attr_search(attrs, NULL, attr_w)))
387 e->u.icon.width=w->u.num;
390 if ((h=attr_search(attrs, NULL, attr_h)))
391 e->u.icon.height=h->u.num;
394 if ((rotation=attr_search(attrs, NULL, attr_rotation)))
395 e->u.icon.rotation=rotation->u.num;
396 strcpy(e->u.icon.src,src->u.str);
398 return (struct icon *)e;
402 image_new(struct attr *parent, struct attr **attrs)
406 e = g_malloc0(sizeof(*e));
407 e->type=element_image;
409 return (struct image *)e;
413 arrows_new(struct attr *parent, struct attr **attrs)
416 e = g_malloc0(sizeof(*e));
417 e->type=element_arrows;
418 element_set_color(e, attrs);
419 return (struct arrows *)e;
423 element_add_attr(struct element *e, struct attr *attr)
425 switch (attr->type) {
427 e->coord=g_realloc(e->coord,(e->coord_count+1)*sizeof(struct coord));
428 e->coord[e->coord_count++]=*attr->u.coord;