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,*day_attr,*night_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;
58 layout_add_attr(struct layout *layout, struct attr *attr)
62 layout->cursors = g_list_append(layout->cursors, attr->u.cursor);
65 layout->layers = g_list_append(layout->layers, attr->u.layer);
73 * Searchs the layout for a cursor with the given name.
75 * @param layout The layout
76 * @param name The name
77 * @returns A pointer to cursor with the given name or the name default or NULL.
78 * @author Ralph Sennhauser (10/2009)
81 layout_get_cursor(struct layout *this_, char *name)
84 struct cursor *d=NULL;
86 c=g_list_first(this_->cursors);
88 if (! strcmp(((struct cursor *)c->data)->name, name))
90 if (! strcmp(((struct cursor *)c->data)->name, "default"))
100 cursor_new(struct attr *parent, struct attr **attrs)
102 struct attr *w, *h, *name, *interval, *sequence_range;
104 w=attr_search(attrs, NULL, attr_w);
105 h=attr_search(attrs, NULL, attr_h);
109 struct cursor *this=g_new0(struct cursor,1);
112 name=attr_search(attrs, NULL, attr_name);
114 this->name=g_strdup(name->u.str);
116 this->name=g_strdup("default");
117 interval=attr_search(attrs, NULL, attr_interval);
119 this->interval=interval->u.num;
120 sequence_range=attr_search(attrs, NULL, attr_sequence_range);
121 if (sequence_range) {
122 struct range *r=g_new0(struct range,1);
123 r->min=sequence_range->u.range.min;
124 r->max=sequence_range->u.range.max;
125 this->sequence_range=r;
128 this->sequence_range=NULL;
130 dbg(2,"ret=%p\n", this);
135 cursor_destroy(struct cursor *this_)
137 if (this_->sequence_range)
138 g_free(this_->sequence_range);
146 cursor_add_attr(struct cursor *this_, struct attr *attr)
148 switch (attr->type) {
150 this_->attrs=attr_generic_add_attr(this_->attrs, attr);
160 struct layer * layer_new(struct attr *parent, struct attr **attrs)
164 struct attr *name, *details;
165 l = g_new0(struct layer, 1);
166 name=attr_search(attrs, NULL, attr_name);
168 l->name = g_strdup(name->u.str);
169 details=attr_search(attrs, NULL, attr_details);
171 l->details = details->u.num;
176 layer_add_attr(struct layer *layer, struct attr *attr)
178 switch (attr->type) {
180 layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra);
188 struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
191 struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range;
192 enum item_type *type;
193 struct range defrange;
195 itm = g_new0(struct itemgra, 1);
196 order=attr_search(attrs, NULL, attr_order);
197 item_types=attr_search(attrs, NULL, attr_item_types);
198 speed_range=attr_search(attrs, NULL, attr_speed_range);
199 angle_range=attr_search(attrs, NULL, attr_angle_range);
200 sequence_range=attr_search(attrs, NULL, attr_sequence_range);
204 itm->order=order->u.range;
208 itm->speed_range=speed_range->u.range;
210 itm->speed_range=defrange;
212 itm->angle_range=angle_range->u.range;
214 itm->angle_range=defrange;
216 itm->sequence_range=sequence_range->u.range;
218 itm->sequence_range=defrange;
220 type=item_types->u.item_types;
221 while (type && *type != type_none) {
222 itm->type=g_list_append(itm->type, GINT_TO_POINTER(*type));
229 itemgra_add_attr(struct itemgra *itemgra, struct attr *attr)
231 switch (attr->type) {
239 itemgra->elements = g_list_append(itemgra->elements, attr->u.element);
242 dbg(0,"unknown: %s\n", attr_to_name(attr->type));
248 element_set_color(struct element *e, struct attr **attrs)
251 color=attr_search(attrs, NULL, attr_color);
253 e->color=*color->u.color;
257 element_set_text_size(struct element *e, struct attr **attrs)
259 struct attr *text_size;
260 text_size=attr_search(attrs, NULL, attr_text_size);
262 e->text_size=text_size->u.num;
266 element_set_polyline_width(struct element *e, struct attr **attrs)
269 width=attr_search(attrs, NULL, attr_width);
271 e->u.polyline.width=width->u.num;
275 element_set_polyline_directed(struct element *e, struct attr **attrs)
277 struct attr *directed;
278 directed=attr_search(attrs, NULL, attr_directed);
280 e->u.polyline.directed=directed->u.num;
284 element_set_polyline_dash(struct element *e, struct attr **attrs)
289 dash=attr_search(attrs, NULL, attr_dash);
291 for (i=0; i<4; i++) {
292 if (!dash->u.dash[i])
294 e->u.polyline.dash_table[i] = dash->u.dash[i];
296 e->u.polyline.dash_num=i;
301 element_set_polyline_offset(struct element *e, struct attr **attrs)
304 offset=attr_search(attrs, NULL, attr_offset);
306 e->u.polyline.offset=offset->u.num;
310 element_set_circle_width(struct element *e, struct attr **attrs)
313 width=attr_search(attrs, NULL, attr_width);
315 e->u.circle.width=width->u.num;
319 element_set_circle_radius(struct element *e, struct attr **attrs)
322 radius=attr_search(attrs, NULL, attr_radius);
324 e->u.circle.radius=radius->u.num;
328 polygon_new(struct attr *parent, struct attr **attrs)
331 e = g_new0(struct element, 1);
332 e->type=element_polygon;
333 element_set_color(e, attrs);
335 return (struct polygon *)e;
339 polyline_new(struct attr *parent, struct attr **attrs)
343 e = g_new0(struct element, 1);
344 e->type=element_polyline;
345 element_set_color(e, attrs);
346 element_set_polyline_width(e, attrs);
347 element_set_polyline_directed(e, attrs);
348 element_set_polyline_dash(e, attrs);
349 element_set_polyline_offset(e, attrs);
350 return (struct polyline *)e;
354 circle_new(struct attr *parent, struct attr **attrs)
358 e = g_new0(struct element, 1);
359 e->type=element_circle;
360 element_set_color(e, attrs);
361 element_set_text_size(e, attrs);
362 element_set_circle_width(e, attrs);
363 element_set_circle_radius(e, attrs);
365 return (struct circle *)e;
369 text_new(struct attr *parent, struct attr **attrs)
373 e = g_new0(struct element, 1);
374 e->type=element_text;
375 element_set_text_size(e, attrs);
377 return (struct text *)e;
381 icon_new(struct attr *parent, struct attr **attrs)
384 struct attr *src,*w,*h,*rotation;
385 src=attr_search(attrs, NULL, attr_src);
389 e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1);
390 e->type=element_icon;
391 e->u.icon.src=(char *)(e+1);
392 if ((w=attr_search(attrs, NULL, attr_w)))
393 e->u.icon.width=w->u.num;
396 if ((h=attr_search(attrs, NULL, attr_h)))
397 e->u.icon.height=h->u.num;
400 if ((rotation=attr_search(attrs, NULL, attr_rotation)))
401 e->u.icon.rotation=rotation->u.num;
402 strcpy(e->u.icon.src,src->u.str);
404 return (struct icon *)e;
408 image_new(struct attr *parent, struct attr **attrs)
412 e = g_malloc0(sizeof(*e));
413 e->type=element_image;
415 return (struct image *)e;
419 arrows_new(struct attr *parent, struct attr **attrs)
422 e = g_malloc0(sizeof(*e));
423 e->type=element_arrows;
424 element_set_color(e, attrs);
425 return (struct arrows *)e;
429 element_add_attr(struct element *e, struct attr *attr)
431 switch (attr->type) {
433 e->coord=g_realloc(e->coord,(e->coord_count+1)*sizeof(struct coord));
434 e->coord[e->coord_count++]=*attr->u.coord;