Add:Core:Made detail level for layouts configurable
[navit-package] / navit / layout.c
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
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 #include <glib.h>
21 #include <string.h>
22 #include "item.h"
23 #include "layout.h"
24
25 struct layout * layout_new(struct attr *parent, struct attr **attrs)
26 {
27         struct layout *l;
28         struct color def_color = {0xffff, 0xefef, 0xb7b7, 0xffff};
29         struct attr *name_attr,*color_attr,*order_delta_attr;
30
31
32         if (! (name_attr=attr_search(attrs, NULL, attr_name)))
33                 return NULL;
34         l = g_new0(struct layout, 1);
35         l->name = g_strdup(name_attr->u.str);
36         if ((color_attr=attr_search(attrs, NULL, attr_color)))
37                 l->color = *color_attr->u.color;
38         else
39                 l->color = def_color;
40         if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
41                 l->order_delta=order_delta_attr->u.num;
42         return l;
43 }
44
45
46 struct layer * layer_new(const char *name, int details)
47 {
48         struct layer *l;
49
50         l = g_new0(struct layer, 1);
51         l->name = g_strdup(name);
52         l->details = details;
53         return l;
54 }
55
56 void layout_add_layer(struct layout *layout, struct layer *layer)
57 {
58         layout->layers = g_list_append(layout->layers, layer);
59 }
60
61 struct itemtype * itemtype_new(int order_min, int order_max)
62 {
63         struct itemtype *itm;
64
65         itm = g_new0(struct itemtype, 1);
66         itm->order_min=order_min;
67         itm->order_max=order_max;
68         return itm;
69 }
70
71 void itemtype_add_type(struct itemtype *this, enum item_type type)
72 {
73         this->type = g_list_append(this->type, GINT_TO_POINTER(type));
74 }
75
76
77 void layer_add_itemtype(struct layer *layer, struct itemtype * itemtype)
78 {
79         layer->itemtypes = g_list_append(layer->itemtypes, itemtype);
80
81 }
82
83 void itemtype_add_element(struct itemtype *itemtype, struct element *element)
84 {
85         itemtype->elements = g_list_append(itemtype->elements, element);
86 }
87
88 struct element *
89 polygon_new(struct color *color)
90 {
91         struct element *e;
92         e = g_new0(struct element, 1);
93         e->type=element_polygon;
94         e->color=*color;
95
96         return e;
97 }
98
99 struct element *
100 polyline_new(struct color *color, int width, int directed,
101              int *dash_table, int dash_num)
102 {
103         struct element *e;
104         int i;
105         
106         e = g_new0(struct element, 1);
107         e->type=element_polyline;
108         e->color=*color;
109         e->u.polyline.width=width;
110         e->u.polyline.directed=directed;
111         e->u.polyline.dash_num=dash_num;
112         for (i=0; i<dash_num; i++)
113                 e->u.polyline.dash_table[i] = dash_table[i];
114
115         return e;
116 }
117
118 struct element *
119 circle_new(struct color *color, int radius, int width, int label_size)
120 {
121         struct element *e;
122         
123         e = g_new0(struct element, 1);
124         e->type=element_circle;
125         e->color=*color;
126         e->label_size=label_size;
127         e->u.circle.width=width;
128         e->u.circle.radius=radius;
129
130         return e;
131 }
132
133 struct element *
134 label_new(int label_size)
135 {
136         struct element *e;
137         
138         e = g_new0(struct element, 1);
139         e->type=element_label;
140         e->label_size=label_size;
141
142         return e;
143 }
144
145 struct element *
146 icon_new(const char *src)
147 {
148         struct element *e;
149
150         e = g_malloc0(sizeof(*e)+strlen(src)+1);
151         e->type=element_icon;
152         e->u.icon.src=(char *)(e+1);
153         strcpy(e->u.icon.src,src);
154
155         return e;       
156 }
157
158 struct element *
159 image_new(void)
160 {
161         struct element *e;
162
163         e = g_malloc0(sizeof(*e));
164         e->type=element_image;
165
166         return e;       
167 }
168