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