Add:Core:Added support for arrows showing the direction of lines
[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 "attr.h"
24 #include "layout.h"
25
26 struct layout * layout_new(struct attr *parent, struct attr **attrs)
27 {
28         struct layout *l;
29         struct color def_color = {0xffff, 0xefef, 0xb7b7, 0xffff};
30         struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr;
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 ((font_attr=attr_search(attrs, NULL, attr_font))) {
37                 l->font = g_strdup(font_attr->u.str);
38         }
39         if ((color_attr=attr_search(attrs, NULL, attr_color)))
40                 l->color = *color_attr->u.color;
41         else
42                 l->color = def_color;
43         if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
44                 l->order_delta=order_delta_attr->u.num;
45         return l;
46 }
47
48
49 struct layer * layer_new(const char *name, int details)
50 {
51         struct layer *l;
52
53         l = g_new0(struct layer, 1);
54         l->name = g_strdup(name);
55         l->details = details;
56         return l;
57 }
58
59 void layout_add_layer(struct layout *layout, struct layer *layer)
60 {
61         layout->layers = g_list_append(layout->layers, layer);
62 }
63
64 struct itemtype * itemtype_new(int order_min, int order_max)
65 {
66         struct itemtype *itm;
67
68         itm = g_new0(struct itemtype, 1);
69         itm->order_min=order_min;
70         itm->order_max=order_max;
71         return itm;
72 }
73
74 void itemtype_add_type(struct itemtype *this, enum item_type type)
75 {
76         this->type = g_list_append(this->type, GINT_TO_POINTER(type));
77 }
78
79
80 void layer_add_itemtype(struct layer *layer, struct itemtype * itemtype)
81 {
82         layer->itemtypes = g_list_append(layer->itemtypes, itemtype);
83
84 }
85
86 void itemtype_add_element(struct itemtype *itemtype, struct element *element)
87 {
88         itemtype->elements = g_list_append(itemtype->elements, element);
89 }
90
91 struct element *
92 polygon_new(struct color *color)
93 {
94         struct element *e;
95         e = g_new0(struct element, 1);
96         e->type=element_polygon;
97         e->color=*color;
98
99         return e;
100 }
101
102 struct element *
103 polyline_new(struct color *color, int width, int directed,
104              int dash_offset, int *dash_table, int dash_num)
105 {
106         struct element *e;
107         int i;
108         
109         e = g_new0(struct element, 1);
110         e->type=element_polyline;
111         e->color=*color;
112         e->u.polyline.width=width;
113         e->u.polyline.directed=directed;
114         e->u.polyline.dash_offset = dash_offset;
115         e->u.polyline.dash_num=dash_num;
116         for (i=0; i<dash_num; i++)
117                 e->u.polyline.dash_table[i] = dash_table[i];
118
119         return e;
120 }
121
122 struct element *
123 circle_new(struct color *color, int radius, int width, int label_size)
124 {
125         struct element *e;
126         
127         e = g_new0(struct element, 1);
128         e->type=element_circle;
129         e->color=*color;
130         e->label_size=label_size;
131         e->u.circle.width=width;
132         e->u.circle.radius=radius;
133
134         return e;
135 }
136
137 struct element *
138 label_new(int label_size)
139 {
140         struct element *e;
141         
142         e = g_new0(struct element, 1);
143         e->type=element_label;
144         e->label_size=label_size;
145
146         return e;
147 }
148
149 struct element *
150 icon_new(const char *src)
151 {
152         struct element *e;
153
154         e = g_malloc0(sizeof(*e)+strlen(src)+1);
155         e->type=element_icon;
156         e->u.icon.src=(char *)(e+1);
157         strcpy(e->u.icon.src,src);
158
159         return e;       
160 }
161
162 struct element *
163 image_new(void)
164 {
165         struct element *e;
166
167         e = g_malloc0(sizeof(*e));
168         e->type=element_image;
169
170         return e;       
171 }
172
173 struct element *
174 arrows_new(struct attr **attrs)
175 {
176         struct element *e;
177         struct attr *color=attr_search(attrs, NULL, attr_color);
178
179         e = g_malloc0(sizeof(*e));
180         e->type=element_arrows;
181         if (color)
182                 e->color=*color->u.color;
183
184         return e;       
185 }
186