Add license files and headers
[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 "layout.h"
23
24 struct layout * layout_new(const char *name, struct color *color)
25 {
26         struct layout *l;
27
28         l = g_new0(struct layout, 1);
29         l->name = g_strdup(name);
30         l->color = g_new0(struct color,1);
31         *(l->color) = *color;
32         return l;
33 }
34
35
36 struct layer * layer_new(const char *name, int details)
37 {
38         struct layer *l;
39
40         l = g_new0(struct layer, 1);
41         l->name = g_strdup(name);
42         l->details = details;
43         return l;
44 }
45
46 void layout_add_layer(struct layout *layout, struct layer *layer)
47 {
48         layout->layers = g_list_append(layout->layers, layer);
49 }
50
51 struct itemtype * itemtype_new(int order_min, int order_max)
52 {
53         struct itemtype *itm;
54
55         itm = g_new0(struct itemtype, 1);
56         itm->order_min=order_min;
57         itm->order_max=order_max;
58         return itm;
59 }
60
61 void itemtype_add_type(struct itemtype *this, enum item_type type)
62 {
63         this->type = g_list_append(this->type, GINT_TO_POINTER(type));
64 }
65
66
67 void layer_add_itemtype(struct layer *layer, struct itemtype * itemtype)
68 {
69         layer->itemtypes = g_list_append(layer->itemtypes, itemtype);
70
71 }
72
73 void itemtype_add_element(struct itemtype *itemtype, struct element *element)
74 {
75         itemtype->elements = g_list_append(itemtype->elements, element);
76 }
77
78 struct element *
79 polygon_new(struct color *color)
80 {
81         struct element *e;
82         e = g_new0(struct element, 1);
83         e->type=element_polygon;
84         e->color=*color;
85
86         return e;
87 }
88
89 struct element *
90 polyline_new(struct color *color, int width, int directed,
91              int *dash_table, int dash_num)
92 {
93         struct element *e;
94         int i;
95         
96         e = g_new0(struct element, 1);
97         e->type=element_polyline;
98         e->color=*color;
99         e->u.polyline.width=width;
100         e->u.polyline.directed=directed;
101         e->u.polyline.dash_num=dash_num;
102         for (i=0; i<dash_num; i++)
103                 e->u.polyline.dash_table[i] = dash_table[i];
104
105         return e;
106 }
107
108 struct element *
109 circle_new(struct color *color, int radius, int width, int label_size)
110 {
111         struct element *e;
112         
113         e = g_new0(struct element, 1);
114         e->type=element_circle;
115         e->color=*color;
116         e->label_size=label_size;
117         e->u.circle.width=width;
118         e->u.circle.radius=radius;
119
120         return e;
121 }
122
123 struct element *
124 label_new(int label_size)
125 {
126         struct element *e;
127         
128         e = g_new0(struct element, 1);
129         e->type=element_label;
130         e->label_size=label_size;
131
132         return e;
133 }
134
135 struct element *
136 icon_new(const char *src)
137 {
138         struct element *e;
139
140         e = g_malloc0(sizeof(*e)+strlen(src)+1);
141         e->type=element_icon;
142         e->u.icon.src=(char *)(e+1);
143         strcpy(e->u.icon.src,src);
144
145         return e;       
146 }
147
148 struct element *
149 image_new(void)
150 {
151         struct element *e;
152
153         e = g_malloc0(sizeof(*e));
154         e->type=element_image;
155
156         return e;       
157 }
158