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 = {COLOR_BACKGROUND_};
33 struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_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 ((day_attr=attr_search(attrs, NULL, attr_daylayout))) {
43 l->dayname = g_strdup(day_attr->u.str);
45 if ((night_attr=attr_search(attrs, NULL, attr_nightlayout))) {
46 l->nightname = g_strdup(night_attr->u.str);
48 if ((color_attr=attr_search(attrs, NULL, attr_color)))
49 l->color = *color_attr->u.color;
52 if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
53 l->order_delta=order_delta_attr->u.num;
54 if ((active_attr=attr_search(attrs, NULL, attr_active)))
55 l->active = active_attr->u.num;
65 layout_attr_iter_new(void)
67 return g_new0(struct attr_iter, 1);
71 layout_attr_iter_destroy(struct attr_iter *iter)
77 layout_get_attr(struct layout *layout, enum attr_type type, struct attr *attr, struct attr_iter *iter)
83 cursor=layout->cursors;
85 if (!iter || iter->last == g_list_previous(cursor)) {
86 attr->u.cursor=cursor->data;
91 cursor=g_list_next(cursor);
97 if (!iter || iter->last == g_list_previous(layer)) {
98 attr->u.layer=layer->data;
103 layer=g_list_next(layer);
107 attr->u.num=layout->active;
117 layout_add_attr(struct layout *layout, struct attr *attr)
119 switch (attr->type) {
121 layout->cursors = g_list_append(layout->cursors, attr->u.cursor);
124 layout->layers = g_list_append(layout->layers, attr->u.layer);
132 * Searchs the layout for a cursor with the given name.
134 * @param layout The layout
135 * @param name The name
136 * @returns A pointer to cursor with the given name or the name default or NULL.
137 * @author Ralph Sennhauser (10/2009)
140 layout_get_cursor(struct layout *this_, char *name)
143 struct cursor *d=NULL;
145 c=g_list_first(this_->cursors);
147 if (! strcmp(((struct cursor *)c->data)->name, name))
149 if (! strcmp(((struct cursor *)c->data)->name, "default"))
159 cursor_new(struct attr *parent, struct attr **attrs)
161 struct attr *w, *h, *name, *interval, *sequence_range;
164 w=attr_search(attrs, NULL, attr_w);
165 h=attr_search(attrs, NULL, attr_h);
169 this=g_new0(struct cursor,1);
172 name=attr_search(attrs, NULL, attr_name);
174 this->name=g_strdup(name->u.str);
176 this->name=g_strdup("default");
177 interval=attr_search(attrs, NULL, attr_interval);
179 this->interval=interval->u.num;
180 sequence_range=attr_search(attrs, NULL, attr_sequence_range);
181 if (sequence_range) {
182 struct range *r=g_new0(struct range,1);
183 r->min=sequence_range->u.range.min;
184 r->max=sequence_range->u.range.max;
185 this->sequence_range=r;
188 this->sequence_range=NULL;
190 dbg(2,"ret=%p\n", this);
195 cursor_destroy(struct cursor *this_)
197 if (this_->sequence_range)
198 g_free(this_->sequence_range);
206 cursor_add_attr(struct cursor *this_, struct attr *attr)
208 switch (attr->type) {
210 this_->attrs=attr_generic_add_attr(this_->attrs, attr);
219 layer_set_attr_do(struct layer *l, struct attr *attr, int init)
221 switch (attr->type) {
223 l->active = attr->u.num;
226 l->details = attr->u.num;
230 l->name = g_strdup(attr->u.str);
239 struct layer * layer_new(struct attr *parent, struct attr **attrs)
243 l = g_new0(struct layer, 1);
245 for (;*attrs; attrs++) {
246 layer_set_attr_do(l, *attrs, 1);
252 layer_get_attr(struct layer *layer, enum attr_type type, struct attr *attr, struct attr_iter *iter)
257 attr->u.num=layer->active;
260 attr->u.num=layer->details;
264 attr->u.str=layer->name;
275 layer_add_attr(struct layer *layer, struct attr *attr)
277 switch (attr->type) {
279 layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra);
287 layer_set_attr(struct layer *layer, struct attr *attr)
289 return layer_set_attr_do(layer, attr, 0);
292 struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
295 struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range;
296 enum item_type *type;
297 struct range defrange;
299 itm = g_new0(struct itemgra, 1);
300 order=attr_search(attrs, NULL, attr_order);
301 item_types=attr_search(attrs, NULL, attr_item_types);
302 speed_range=attr_search(attrs, NULL, attr_speed_range);
303 angle_range=attr_search(attrs, NULL, attr_angle_range);
304 sequence_range=attr_search(attrs, NULL, attr_sequence_range);
308 itm->order=order->u.range;
312 itm->speed_range=speed_range->u.range;
314 itm->speed_range=defrange;
316 itm->angle_range=angle_range->u.range;
318 itm->angle_range=defrange;
320 itm->sequence_range=sequence_range->u.range;
322 itm->sequence_range=defrange;
324 type=item_types->u.item_types;
325 while (type && *type != type_none) {
326 itm->type=g_list_append(itm->type, GINT_TO_POINTER(*type));
333 itemgra_add_attr(struct itemgra *itemgra, struct attr *attr)
335 switch (attr->type) {
343 itemgra->elements = g_list_append(itemgra->elements, attr->u.element);
346 dbg(0,"unknown: %s\n", attr_to_name(attr->type));
352 element_set_color(struct element *e, struct attr **attrs)
355 color=attr_search(attrs, NULL, attr_color);
357 e->color=*color->u.color;
362 element_set_background_color(struct color *c, struct attr **attrs)
365 color=attr_search(attrs, NULL, attr_background_color);
372 element_set_text_size(struct element *e, struct attr **attrs)
374 struct attr *text_size;
375 text_size=attr_search(attrs, NULL, attr_text_size);
377 e->text_size=text_size->u.num;
381 element_set_polyline_width(struct element *e, struct attr **attrs)
384 width=attr_search(attrs, NULL, attr_width);
386 e->u.polyline.width=width->u.num;
390 element_set_polyline_directed(struct element *e, struct attr **attrs)
392 struct attr *directed;
393 directed=attr_search(attrs, NULL, attr_directed);
395 e->u.polyline.directed=directed->u.num;
399 element_set_polyline_dash(struct element *e, struct attr **attrs)
404 dash=attr_search(attrs, NULL, attr_dash);
406 for (i=0; i<4; i++) {
407 if (!dash->u.dash[i])
409 e->u.polyline.dash_table[i] = dash->u.dash[i];
411 e->u.polyline.dash_num=i;
416 element_set_polyline_offset(struct element *e, struct attr **attrs)
419 offset=attr_search(attrs, NULL, attr_offset);
421 e->u.polyline.offset=offset->u.num;
425 element_set_circle_width(struct element *e, struct attr **attrs)
428 width=attr_search(attrs, NULL, attr_width);
430 e->u.circle.width=width->u.num;
434 element_set_circle_radius(struct element *e, struct attr **attrs)
437 radius=attr_search(attrs, NULL, attr_radius);
439 e->u.circle.radius=radius->u.num;
443 polygon_new(struct attr *parent, struct attr **attrs)
446 e = g_new0(struct element, 1);
447 e->type=element_polygon;
448 element_set_color(e, attrs);
450 return (struct polygon *)e;
454 polyline_new(struct attr *parent, struct attr **attrs)
458 e = g_new0(struct element, 1);
459 e->type=element_polyline;
460 element_set_color(e, attrs);
461 element_set_polyline_width(e, attrs);
462 element_set_polyline_directed(e, attrs);
463 element_set_polyline_dash(e, attrs);
464 element_set_polyline_offset(e, attrs);
465 return (struct polyline *)e;
469 circle_new(struct attr *parent, struct attr **attrs)
472 struct color color_black = {COLOR_BLACK_};
473 struct color color_white = {COLOR_WHITE_};
475 e = g_new0(struct element, 1);
476 e->type=element_circle;
477 e->color = color_black;
478 e->u.circle.background_color = color_white;
479 element_set_color(e, attrs);
480 element_set_background_color(&e->u.circle.background_color, attrs);
481 element_set_text_size(e, attrs);
482 element_set_circle_width(e, attrs);
483 element_set_circle_radius(e, attrs);
485 return (struct circle *)e;
489 text_new(struct attr *parent, struct attr **attrs)
492 struct color color_black = {COLOR_BLACK_};
493 struct color color_white = {COLOR_WHITE_};
495 e = g_new0(struct element, 1);
496 e->type=element_text;
497 element_set_text_size(e, attrs);
498 e->color = color_black;
499 e->u.text.background_color = color_white;
500 element_set_color(e, attrs);
501 element_set_background_color(&e->u.text.background_color, attrs);
503 return (struct text *)e;
507 icon_new(struct attr *parent, struct attr **attrs)
510 struct attr *src,*w,*h,*rotation;
511 src=attr_search(attrs, NULL, attr_src);
515 e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1);
516 e->type=element_icon;
517 e->u.icon.src=(char *)(e+1);
518 if ((w=attr_search(attrs, NULL, attr_w)))
519 e->u.icon.width=w->u.num;
522 if ((h=attr_search(attrs, NULL, attr_h)))
523 e->u.icon.height=h->u.num;
526 if ((rotation=attr_search(attrs, NULL, attr_rotation)))
527 e->u.icon.rotation=rotation->u.num;
528 strcpy(e->u.icon.src,src->u.str);
530 return (struct icon *)e;
534 image_new(struct attr *parent, struct attr **attrs)
538 e = g_malloc0(sizeof(*e));
539 e->type=element_image;
541 return (struct image *)e;
545 arrows_new(struct attr *parent, struct attr **attrs)
548 e = g_malloc0(sizeof(*e));
549 e->type=element_arrows;
550 element_set_color(e, attrs);
551 return (struct arrows *)e;
555 element_add_attr(struct element *e, struct attr *attr)
557 switch (attr->type) {
559 e->coord=g_realloc(e->coord,(e->coord_count+1)*sizeof(struct coord));
560 e->coord[e->coord_count++]=*attr->u.coord;