… | |
… | |
23 | #include "attr.h" |
23 | #include "attr.h" |
24 | #include "layout.h" |
24 | #include "layout.h" |
25 | #include "coord.h" |
25 | #include "coord.h" |
26 | #include "debug.h" |
26 | #include "debug.h" |
27 | |
27 | |
28 | |
|
|
29 | struct layout * layout_new(struct attr *parent, struct attr **attrs) |
28 | struct layout * layout_new(struct attr *parent, struct attr **attrs) |
30 | { |
29 | { |
31 | struct layout *l; |
30 | struct layout *l; |
32 | struct color def_color = {COLOR_BACKGROUND_}; |
31 | struct color def_color = |
|
|
32 | { COLOR_BACKGROUND_ }; |
33 | struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_attr; |
33 | struct attr *name_attr, *color_attr, *order_delta_attr, *font_attr, *day_attr, *night_attr, *active_attr; |
34 | |
34 | |
35 | if (! (name_attr=attr_search(attrs, NULL, attr_name))) |
35 | if (!(name_attr = attr_search(attrs, NULL, attr_name))) |
|
|
36 | { |
36 | return NULL; |
37 | return NULL; |
|
|
38 | } |
37 | l = g_new0(struct layout, 1); |
39 | l = g_new0(struct layout, 1); |
38 | l->name = g_strdup(name_attr->u.str); |
40 | l->name = g_strdup(name_attr->u.str); |
39 | if ((font_attr=attr_search(attrs, NULL, attr_font))) { |
41 | if ((font_attr = attr_search(attrs, NULL, attr_font))) |
|
|
42 | { |
40 | l->font = g_strdup(font_attr->u.str); |
43 | l->font = g_strdup(font_attr->u.str); |
41 | } |
44 | } |
42 | if ((day_attr=attr_search(attrs, NULL, attr_daylayout))) { |
45 | if ((day_attr = attr_search(attrs, NULL, attr_daylayout))) |
|
|
46 | { |
43 | l->dayname = g_strdup(day_attr->u.str); |
47 | l->dayname = g_strdup(day_attr->u.str); |
44 | } |
48 | } |
45 | if ((night_attr=attr_search(attrs, NULL, attr_nightlayout))) { |
49 | if ((night_attr = attr_search(attrs, NULL, attr_nightlayout))) |
|
|
50 | { |
46 | l->nightname = g_strdup(night_attr->u.str); |
51 | l->nightname = g_strdup(night_attr->u.str); |
47 | } |
52 | } |
48 | if ((color_attr=attr_search(attrs, NULL, attr_color))) |
53 | if ((color_attr = attr_search(attrs, NULL, attr_color))) |
|
|
54 | { |
49 | l->color = *color_attr->u.color; |
55 | l->color = *color_attr->u.color; |
|
|
56 | } |
50 | else |
57 | else |
|
|
58 | { |
51 | l->color = def_color; |
59 | l->color = def_color; |
|
|
60 | } |
52 | if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta))) |
61 | if ((order_delta_attr = attr_search(attrs, NULL, attr_order_delta))) |
|
|
62 | { |
53 | l->order_delta=order_delta_attr->u.num; |
63 | l->order_delta = order_delta_attr->u.num; |
|
|
64 | } |
54 | if ((active_attr=attr_search(attrs, NULL, attr_active))) |
65 | if ((active_attr = attr_search(attrs, NULL, attr_active))) |
|
|
66 | { |
55 | l->active = active_attr->u.num; |
67 | l->active = active_attr->u.num; |
|
|
68 | } |
56 | return l; |
69 | return l; |
57 | } |
70 | } |
58 | |
71 | |
59 | struct attr_iter { |
72 | struct attr_iter |
60 | GList *last; |
73 | { |
|
|
74 | GList *last; |
61 | }; |
75 | }; |
62 | |
|
|
63 | |
76 | |
64 | struct attr_iter * |
77 | struct attr_iter * |
65 | layout_attr_iter_new(void) |
78 | layout_attr_iter_new(void) |
66 | { |
79 | { |
67 | return g_new0(struct attr_iter, 1); |
80 | return g_new0(struct attr_iter, 1); |
68 | } |
81 | } |
69 | |
82 | |
70 | void |
|
|
71 | layout_attr_iter_destroy(struct attr_iter *iter) |
83 | void layout_attr_iter_destroy(struct attr_iter *iter) |
72 | { |
84 | { |
73 | g_free(iter); |
85 | g_free(iter); |
74 | } |
86 | } |
75 | |
87 | |
76 | int |
|
|
77 | layout_get_attr(struct layout *layout, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
88 | int layout_get_attr(struct layout *layout, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
78 | { |
89 | { |
79 | GList *cursor,*layer; |
90 | GList *cursor, *layer; |
80 | attr->type=type; |
91 | attr->type = type; |
81 | switch (type) { |
92 | switch (type) |
|
|
93 | { |
82 | case attr_cursor: |
94 | case attr_cursor: |
83 | cursor=layout->cursors; |
95 | cursor = layout->cursors; |
84 | while (cursor) { |
96 | while (cursor) |
|
|
97 | { |
85 | if (!iter || iter->last == g_list_previous(cursor)) { |
98 | if (!iter || iter->last == g_list_previous(cursor)) |
|
|
99 | { |
86 | attr->u.cursor=cursor->data; |
100 | attr->u.cursor = cursor->data; |
87 | if (iter) |
101 | if (iter) |
88 | iter->last=cursor; |
102 | iter->last = cursor; |
89 | return 1; |
103 | return 1; |
|
|
104 | } |
|
|
105 | cursor = g_list_next(cursor); |
90 | } |
106 | } |
91 | cursor=g_list_next(cursor); |
|
|
92 | } |
|
|
93 | break; |
107 | break; |
94 | case attr_layer: |
108 | case attr_layer: |
95 | layer=layout->layers; |
109 | layer = layout->layers; |
96 | while (layer) { |
110 | while (layer) |
|
|
111 | { |
97 | if (!iter || iter->last == g_list_previous(layer)) { |
112 | if (!iter || iter->last == g_list_previous(layer)) |
|
|
113 | { |
98 | attr->u.layer=layer->data; |
114 | attr->u.layer = layer->data; |
99 | if (iter) |
115 | if (iter) |
100 | iter->last=layer; |
116 | iter->last = layer; |
101 | return 1; |
117 | return 1; |
|
|
118 | } |
|
|
119 | layer = g_list_next(layer); |
102 | } |
120 | } |
103 | layer=g_list_next(layer); |
|
|
104 | } |
|
|
105 | break; |
121 | break; |
106 | case attr_active: |
122 | case attr_active: |
107 | attr->u.num=layout->active; |
123 | attr->u.num = layout->active; |
108 | break; |
124 | break; |
109 | default: |
125 | default: |
110 | break; |
126 | break; |
111 | } |
127 | } |
112 | return 0; |
128 | return 0; |
113 | } |
129 | } |
114 | |
130 | |
115 | |
|
|
116 | int |
|
|
117 | layout_add_attr(struct layout *layout, struct attr *attr) |
131 | int layout_add_attr(struct layout *layout, struct attr *attr) |
118 | { |
132 | { |
119 | switch (attr->type) { |
133 | switch (attr->type) |
|
|
134 | { |
120 | case attr_cursor: |
135 | case attr_cursor: |
121 | layout->cursors = g_list_append(layout->cursors, attr->u.cursor); |
136 | layout->cursors = g_list_append(layout->cursors, attr->u.cursor); |
122 | return 1; |
137 | return 1; |
123 | case attr_layer: |
138 | case attr_layer: |
124 | layout->layers = g_list_append(layout->layers, attr->u.layer); |
139 | layout->layers = g_list_append(layout->layers, attr->u.layer); |
125 | return 1; |
140 | return 1; |
126 | default: |
141 | default: |
127 | return 0; |
142 | return 0; |
128 | } |
143 | } |
129 | } |
144 | } |
130 | |
145 | |
131 | /** |
146 | /** |
132 | * Searchs the layout for a cursor with the given name. |
147 | * Searchs the layout for a cursor with the given name. |
133 | * |
148 | * |
134 | * @param layout The layout |
149 | * @param layout The layout |
135 | * @param name The name |
150 | * @param name The name |
136 | * @returns A pointer to cursor with the given name or the name default or NULL. |
151 | * @returns A pointer to cursor with the given name or the name default or NULL. |
137 | * @author Ralph Sennhauser (10/2009) |
152 | * @author Ralph Sennhauser (10/2009) |
138 | */ |
153 | */ |
139 | struct cursor * |
154 | struct cursor * |
140 | layout_get_cursor(struct layout *this_, char *name) |
155 | layout_get_cursor(struct layout *this_, char *name) |
141 | { |
156 | { |
142 | GList *c; |
157 | GList *c; |
143 | struct cursor *d=NULL; |
158 | struct cursor *d = NULL; |
144 | |
159 | |
145 | c=g_list_first(this_->cursors); |
160 | c = g_list_first(this_->cursors); |
146 | while (c) { |
161 | while (c) |
|
|
162 | { |
147 | if (! strcmp(((struct cursor *)c->data)->name, name)) |
163 | if (!strcmp(((struct cursor *) c->data)->name, name)) |
148 | return c->data; |
164 | return c->data; |
149 | if (! strcmp(((struct cursor *)c->data)->name, "default")) |
165 | if (!strcmp(((struct cursor *) c->data)->name, "default")) |
150 | d=c->data; |
166 | d = c->data; |
151 | c=g_list_next(c); |
167 | c = g_list_next(c); |
152 | } |
168 | } |
153 | return d; |
169 | return d; |
154 | } |
170 | } |
155 | |
|
|
156 | |
|
|
157 | |
171 | |
158 | struct cursor * |
172 | struct cursor * |
159 | cursor_new(struct attr *parent, struct attr **attrs) |
173 | cursor_new(struct attr *parent, struct attr **attrs) |
160 | { |
174 | { |
161 | struct attr *w, *h, *name, *interval, *sequence_range; |
175 | struct attr *w, *h, *name, *interval, *sequence_range; |
162 | struct cursor *this; |
176 | struct cursor *this; |
163 | |
177 | |
164 | w=attr_search(attrs, NULL, attr_w); |
178 | w = attr_search(attrs, NULL, attr_w); |
165 | h=attr_search(attrs, NULL, attr_h); |
179 | h = attr_search(attrs, NULL, attr_h); |
166 | if (! w || ! h) |
180 | if (!w || !h) |
167 | return NULL; |
181 | return NULL; |
168 | |
182 | |
169 | this=g_new0(struct cursor,1); |
183 | this=g_new0(struct cursor,1); |
170 | this->w=w->u.num; |
184 | this->w = w->u.num; |
171 | this->h=h->u.num; |
185 | this->h = h->u.num; |
172 | name=attr_search(attrs, NULL, attr_name); |
186 | name = attr_search(attrs, NULL, attr_name); |
173 | if (name) |
187 | if (name) |
174 | this->name=g_strdup(name->u.str); |
188 | this->name = g_strdup(name->u.str); |
175 | else |
189 | else |
176 | this->name=g_strdup("default"); |
190 | this->name = g_strdup("default"); |
177 | interval=attr_search(attrs, NULL, attr_interval); |
191 | interval = attr_search(attrs, NULL, attr_interval); |
178 | if (interval) |
192 | if (interval) |
179 | this->interval=interval->u.num; |
193 | this->interval = interval->u.num; |
180 | sequence_range=attr_search(attrs, NULL, attr_sequence_range); |
194 | sequence_range = attr_search(attrs, NULL, attr_sequence_range); |
181 | if (sequence_range) { |
195 | if (sequence_range) |
|
|
196 | { |
182 | struct range *r=g_new0(struct range,1); |
197 | struct range *r=g_new0(struct range,1); |
183 | r->min=sequence_range->u.range.min; |
198 | r->min = sequence_range->u.range.min; |
184 | r->max=sequence_range->u.range.max; |
199 | r->max = sequence_range->u.range.max; |
185 | this->sequence_range=r; |
200 | this->sequence_range = r; |
186 | } |
201 | } |
187 | else { |
202 | else |
|
|
203 | { |
188 | this->sequence_range=NULL; |
204 | this->sequence_range = NULL; |
189 | } |
205 | } |
190 | dbg(2,"ret=%p\n", this); |
206 | dbg(2, "ret=%p\n", this); |
191 | return this; |
207 | return this; |
192 | } |
208 | } |
193 | |
209 | |
194 | void |
|
|
195 | cursor_destroy(struct cursor *this_) |
210 | void cursor_destroy(struct cursor *this_) |
196 | { |
211 | { |
197 | if (this_->sequence_range) |
212 | if (this_->sequence_range) |
198 | g_free(this_->sequence_range); |
213 | g_free(this_->sequence_range); |
199 | if (this_->name) { |
214 | if (this_->name) |
|
|
215 | { |
200 | g_free(this_->name); |
216 | g_free(this_->name); |
201 | } |
217 | } |
202 | g_free(this_); |
218 | g_free(this_); |
203 | } |
219 | } |
204 | |
220 | |
205 | int |
|
|
206 | cursor_add_attr(struct cursor *this_, struct attr *attr) |
221 | int cursor_add_attr(struct cursor *this_, struct attr *attr) |
207 | { |
222 | { |
208 | switch (attr->type) { |
223 | switch (attr->type) |
|
|
224 | { |
209 | case attr_itemgra: |
225 | case attr_itemgra: |
210 | this_->attrs=attr_generic_add_attr(this_->attrs, attr); |
226 | this_->attrs = attr_generic_add_attr(this_->attrs, attr); |
211 | return 1; |
227 | return 1; |
212 | default: |
228 | default: |
213 | break; |
229 | break; |
214 | } |
230 | } |
215 | return 0; |
231 | return 0; |
216 | } |
232 | } |
217 | |
233 | |
218 | static int |
|
|
219 | layer_set_attr_do(struct layer *l, struct attr *attr, int init) |
234 | static int layer_set_attr_do(struct layer *l, struct attr *attr, int init) |
220 | { |
235 | { |
221 | switch (attr->type) { |
236 | switch (attr->type) |
|
|
237 | { |
222 | case attr_active: |
238 | case attr_active: |
223 | l->active = attr->u.num; |
239 | l->active = attr->u.num; |
224 | return 1; |
240 | return 1; |
225 | case attr_details: |
241 | case attr_details: |
226 | l->details = attr->u.num; |
242 | l->details = attr->u.num; |
227 | return 1; |
243 | return 1; |
228 | case attr_name: |
244 | case attr_name: |
229 | g_free(l->name); |
245 | g_free(l->name); |
230 | l->name = g_strdup(attr->u.str); |
246 | l->name = g_strdup(attr->u.str); |
231 | return 1; |
247 | return 1; |
232 | default: |
248 | default: |
233 | return 0; |
249 | return 0; |
234 | } |
250 | } |
235 | } |
251 | } |
236 | |
|
|
237 | |
|
|
238 | |
252 | |
239 | struct layer * layer_new(struct attr *parent, struct attr **attrs) |
253 | struct layer * layer_new(struct attr *parent, struct attr **attrs) |
240 | { |
254 | { |
241 | struct layer *l; |
255 | struct layer *l; |
242 | |
256 | |
243 | l = g_new0(struct layer, 1); |
257 | l = g_new0(struct layer, 1); |
244 | l->active=1; |
258 | l->active = 1; |
245 | for (;*attrs; attrs++) { |
259 | for (; *attrs; attrs++) |
|
|
260 | { |
246 | layer_set_attr_do(l, *attrs, 1); |
261 | layer_set_attr_do(l, *attrs, 1); |
247 | } |
262 | } |
248 | return l; |
263 | return l; |
249 | } |
264 | } |
250 | |
265 | |
251 | int |
|
|
252 | layer_get_attr(struct layer *layer, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
266 | int layer_get_attr(struct layer *layer, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
253 | { |
267 | { |
254 | attr->type=type; |
268 | attr->type = type; |
255 | switch(type) { |
269 | switch (type) |
|
|
270 | { |
256 | case attr_active: |
271 | case attr_active: |
257 | attr->u.num=layer->active; |
272 | attr->u.num = layer->active; |
258 | return 1; |
273 | return 1; |
259 | case attr_details: |
274 | case attr_details: |
260 | attr->u.num=layer->details; |
275 | attr->u.num = layer->details; |
261 | return 1; |
276 | return 1; |
262 | case attr_name: |
277 | case attr_name: |
263 | if (layer->name) { |
278 | if (layer->name) |
|
|
279 | { |
264 | attr->u.str=layer->name; |
280 | attr->u.str = layer->name; |
265 | return 1; |
281 | return 1; |
266 | } |
282 | } |
267 | break; |
283 | break; |
268 | default: |
284 | default: |
269 | return 0; |
285 | return 0; |
270 | } |
286 | } |
271 | return 0; |
287 | return 0; |
272 | } |
288 | } |
273 | |
289 | |
274 | int |
|
|
275 | layer_add_attr(struct layer *layer, struct attr *attr) |
290 | int layer_add_attr(struct layer *layer, struct attr *attr) |
276 | { |
291 | { |
277 | switch (attr->type) { |
292 | switch (attr->type) |
|
|
293 | { |
278 | case attr_itemgra: |
294 | case attr_itemgra: |
279 | layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra); |
295 | layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra); |
280 | return 1; |
296 | return 1; |
281 | default: |
297 | default: |
282 | return 0; |
298 | return 0; |
283 | } |
299 | } |
284 | } |
300 | } |
285 | |
301 | |
286 | int |
|
|
287 | layer_set_attr(struct layer *layer, struct attr *attr) |
302 | int layer_set_attr(struct layer *layer, struct attr *attr) |
288 | { |
303 | { |
289 | return layer_set_attr_do(layer, attr, 0); |
304 | return layer_set_attr_do(layer, attr, 0); |
290 | } |
305 | } |
291 | |
306 | |
292 | struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs) |
307 | struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs) |
293 | { |
308 | { |
294 | struct itemgra *itm; |
309 | struct itemgra *itm; |
295 | struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range; |
310 | struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range; |
296 | enum item_type *type; |
311 | enum item_type *type; |
297 | struct range defrange; |
312 | struct range defrange; |
298 | |
313 | |
299 | itm = g_new0(struct itemgra, 1); |
314 | itm = g_new0(struct itemgra, 1); |
300 | order=attr_search(attrs, NULL, attr_order); |
315 | order = attr_search(attrs, NULL, attr_order); |
301 | item_types=attr_search(attrs, NULL, attr_item_types); |
316 | item_types = attr_search(attrs, NULL, attr_item_types); |
302 | speed_range=attr_search(attrs, NULL, attr_speed_range); |
317 | speed_range = attr_search(attrs, NULL, attr_speed_range); |
303 | angle_range=attr_search(attrs, NULL, attr_angle_range); |
318 | angle_range = attr_search(attrs, NULL, attr_angle_range); |
304 | sequence_range=attr_search(attrs, NULL, attr_sequence_range); |
319 | sequence_range = attr_search(attrs, NULL, attr_sequence_range); |
305 | defrange.min=0; |
320 | defrange.min = 0; |
306 | defrange.max=32767; |
321 | defrange.max = 32767; |
307 | if (order) |
322 | if (order) |
308 | itm->order=order->u.range; |
323 | itm->order = order->u.range; |
309 | else |
324 | else |
310 | itm->order=defrange; |
325 | itm->order = defrange; |
311 | if (speed_range) |
326 | if (speed_range) |
312 | itm->speed_range=speed_range->u.range; |
327 | itm->speed_range = speed_range->u.range; |
313 | else |
328 | else |
314 | itm->speed_range=defrange; |
329 | itm->speed_range = defrange; |
315 | if (angle_range) |
330 | if (angle_range) |
316 | itm->angle_range=angle_range->u.range; |
331 | itm->angle_range = angle_range->u.range; |
317 | else |
332 | else |
318 | itm->angle_range=defrange; |
333 | itm->angle_range = defrange; |
319 | if (sequence_range) |
334 | if (sequence_range) |
320 | itm->sequence_range=sequence_range->u.range; |
335 | itm->sequence_range = sequence_range->u.range; |
321 | else |
336 | else |
322 | itm->sequence_range=defrange; |
337 | itm->sequence_range = defrange; |
323 | if (item_types) { |
338 | if (item_types) |
|
|
339 | { |
324 | type=item_types->u.item_types; |
340 | type = item_types->u.item_types; |
325 | while (type && *type != type_none) { |
341 | while (type && *type != type_none) |
|
|
342 | { |
326 | itm->type=g_list_append(itm->type, GINT_TO_POINTER(*type)); |
343 | itm->type = g_list_append(itm->type, GINT_TO_POINTER(*type)); |
327 | type++; |
344 | type++; |
328 | } |
345 | } |
329 | } |
346 | } |
330 | return itm; |
347 | return itm; |
331 | } |
348 | } |
332 | int |
|
|
333 | itemgra_add_attr(struct itemgra *itemgra, struct attr *attr) |
349 | int itemgra_add_attr(struct itemgra *itemgra, struct attr *attr) |
334 | { |
350 | { |
335 | switch (attr->type) { |
351 | switch (attr->type) |
|
|
352 | { |
336 | case attr_polygon: |
353 | case attr_polygon: |
337 | case attr_polyline: |
354 | case attr_polyline: |
338 | case attr_circle: |
355 | case attr_circle: |
339 | case attr_text: |
356 | case attr_text: |
340 | case attr_icon: |
357 | case attr_icon: |
341 | case attr_image: |
358 | case attr_image: |
342 | case attr_arrows: |
359 | case attr_arrows: |
343 | itemgra->elements = g_list_append(itemgra->elements, attr->u.element); |
360 | itemgra->elements = g_list_append(itemgra->elements, attr->u.element); |
344 | return 1; |
361 | return 1; |
345 | default: |
362 | default: |
346 | dbg(0,"unknown: %s\n", attr_to_name(attr->type)); |
363 | dbg(0, "unknown: %s\n", attr_to_name(attr->type)); |
347 | return 0; |
364 | return 0; |
348 | } |
365 | } |
349 | } |
366 | } |
350 | |
367 | |
351 | static void |
|
|
352 | element_set_color(struct element *e, struct attr **attrs) |
368 | static void element_set_color(struct element *e, struct attr **attrs) |
353 | { |
369 | { |
354 | struct attr *color; |
370 | struct attr *color; |
355 | color=attr_search(attrs, NULL, attr_color); |
371 | color = attr_search(attrs, NULL, attr_color); |
356 | if (color) |
372 | if (color) |
357 | e->color=*color->u.color; |
373 | e->color = *color->u.color; |
358 | } |
374 | } |
359 | |
375 | |
360 | |
|
|
361 | static void |
|
|
362 | element_set_background_color(struct color *c, struct attr **attrs) |
376 | static void element_set_background_color(struct color *c, struct attr **attrs) |
363 | { |
377 | { |
364 | struct attr *color; |
378 | struct attr *color; |
365 | color=attr_search(attrs, NULL, attr_background_color); |
379 | color = attr_search(attrs, NULL, attr_background_color); |
366 | if (color) |
380 | if (color) |
367 | *c=*color->u.color; |
381 | *c = *color->u.color; |
368 | } |
382 | } |
369 | |
383 | |
370 | |
|
|
371 | static void |
|
|
372 | element_set_text_size(struct element *e, struct attr **attrs) |
384 | static void element_set_text_size(struct element *e, struct attr **attrs) |
373 | { |
385 | { |
374 | struct attr *text_size; |
386 | struct attr *text_size; |
375 | text_size=attr_search(attrs, NULL, attr_text_size); |
387 | text_size = attr_search(attrs, NULL, attr_text_size); |
376 | if (text_size) |
388 | if (text_size) |
377 | e->text_size=text_size->u.num; |
389 | e->text_size = text_size->u.num; |
378 | } |
390 | } |
379 | |
391 | |
380 | static void |
|
|
381 | element_set_polyline_width(struct element *e, struct attr **attrs) |
392 | static void element_set_polyline_width(struct element *e, struct attr **attrs) |
382 | { |
393 | { |
383 | struct attr *width; |
394 | struct attr *width; |
384 | width=attr_search(attrs, NULL, attr_width); |
395 | width = attr_search(attrs, NULL, attr_width); |
385 | if (width) |
396 | if (width) |
386 | e->u.polyline.width=width->u.num; |
397 | e->u.polyline.width = width->u.num; |
387 | } |
398 | } |
388 | |
399 | |
389 | static void |
|
|
390 | element_set_polyline_directed(struct element *e, struct attr **attrs) |
400 | static void element_set_polyline_directed(struct element *e, struct attr **attrs) |
391 | { |
401 | { |
392 | struct attr *directed; |
402 | struct attr *directed; |
393 | directed=attr_search(attrs, NULL, attr_directed); |
403 | directed = attr_search(attrs, NULL, attr_directed); |
394 | if (directed) |
404 | if (directed) |
395 | e->u.polyline.directed=directed->u.num; |
405 | e->u.polyline.directed = directed->u.num; |
396 | } |
406 | } |
397 | |
407 | |
398 | static void |
|
|
399 | element_set_polyline_dash(struct element *e, struct attr **attrs) |
408 | static void element_set_polyline_dash(struct element *e, struct attr **attrs) |
400 | { |
409 | { |
401 | struct attr *dash; |
410 | struct attr *dash; |
402 | int i; |
411 | int i; |
403 | |
412 | |
404 | dash=attr_search(attrs, NULL, attr_dash); |
413 | dash = attr_search(attrs, NULL, attr_dash); |
405 | if (dash) { |
414 | if (dash) |
|
|
415 | { |
|
|
416 | /* |
406 | for (i=0; i<4; i++) { |
417 | for (i = 0; i < 4; i++) |
|
|
418 | { |
407 | if (!dash->u.dash[i]) |
419 | if (!dash->u.dash[i]) |
|
|
420 | { |
408 | break; |
421 | break; |
|
|
422 | } |
|
|
423 | dbg(0,"1 i=%d d=%d\n", i, dash->u.dash[i]); |
|
|
424 | //e->u.polyline.dash_table[i] = atoi(dash->u.dash[i]); |
409 | e->u.polyline.dash_table[i] = dash->u.dash[i]; |
425 | e->u.polyline.dash_table[i] = dash->u.dash[i]; |
410 | } |
426 | } |
|
|
427 | */ |
|
|
428 | i=0; |
|
|
429 | if (!dash->u.dash[i]) |
|
|
430 | { |
|
|
431 | } |
|
|
432 | else |
|
|
433 | { |
|
|
434 | e->u.polyline.dash_table[i] = dash->u.dash[i]; |
|
|
435 | //dbg(0,"1 i=%d d=%d\n", i, dash->u.dash[i]); |
411 | e->u.polyline.dash_num=i; |
436 | e->u.polyline.dash_num = (i + 1); |
412 | } |
437 | } |
|
|
438 | } |
413 | } |
439 | } |
414 | |
440 | |
415 | static void |
|
|
416 | element_set_polyline_offset(struct element *e, struct attr **attrs) |
441 | static void element_set_polyline_offset(struct element *e, struct attr **attrs) |
417 | { |
442 | { |
418 | struct attr *offset; |
443 | struct attr *offset; |
419 | offset=attr_search(attrs, NULL, attr_offset); |
444 | offset = attr_search(attrs, NULL, attr_offset); |
420 | if (offset) |
445 | if (offset) |
|
|
446 | { |
421 | e->u.polyline.offset=offset->u.num; |
447 | e->u.polyline.offset = offset->u.num; |
|
|
448 | } |
422 | } |
449 | } |
423 | |
450 | |
424 | static void |
|
|
425 | element_set_circle_width(struct element *e, struct attr **attrs) |
451 | static void element_set_circle_width(struct element *e, struct attr **attrs) |
426 | { |
452 | { |
427 | struct attr *width; |
453 | struct attr *width; |
428 | width=attr_search(attrs, NULL, attr_width); |
454 | width = attr_search(attrs, NULL, attr_width); |
429 | if (width) |
455 | if (width) |
430 | e->u.circle.width=width->u.num; |
456 | e->u.circle.width = width->u.num; |
431 | } |
457 | } |
432 | |
458 | |
433 | static void |
|
|
434 | element_set_circle_radius(struct element *e, struct attr **attrs) |
459 | static void element_set_circle_radius(struct element *e, struct attr **attrs) |
435 | { |
460 | { |
436 | struct attr *radius; |
461 | struct attr *radius; |
437 | radius=attr_search(attrs, NULL, attr_radius); |
462 | radius = attr_search(attrs, NULL, attr_radius); |
438 | if (radius) |
463 | if (radius) |
439 | e->u.circle.radius=radius->u.num; |
464 | e->u.circle.radius = radius->u.num; |
440 | } |
465 | } |
441 | |
466 | |
442 | struct polygon * |
467 | struct polygon * |
443 | polygon_new(struct attr *parent, struct attr **attrs) |
468 | polygon_new(struct attr *parent, struct attr **attrs) |
444 | { |
469 | { |
445 | struct element *e; |
470 | struct element *e; |
446 | e = g_new0(struct element, 1); |
471 | e = g_new0(struct element, 1); |
447 | e->type=element_polygon; |
472 | e->type = element_polygon; |
448 | element_set_color(e, attrs); |
473 | element_set_color(e, attrs); |
449 | |
474 | |
450 | return (struct polygon *)e; |
475 | return (struct polygon *) e; |
451 | } |
476 | } |
452 | |
477 | |
453 | struct polyline * |
478 | struct polyline * |
454 | polyline_new(struct attr *parent, struct attr **attrs) |
479 | polyline_new(struct attr *parent, struct attr **attrs) |
455 | { |
480 | { |
456 | struct element *e; |
481 | struct element *e; |
457 | |
482 | |
458 | e = g_new0(struct element, 1); |
483 | e = g_new0(struct element, 1); |
459 | e->type=element_polyline; |
484 | e->type = element_polyline; |
460 | element_set_color(e, attrs); |
485 | element_set_color(e, attrs); |
461 | element_set_polyline_width(e, attrs); |
486 | element_set_polyline_width(e, attrs); |
462 | element_set_polyline_directed(e, attrs); |
487 | element_set_polyline_directed(e, attrs); |
463 | element_set_polyline_dash(e, attrs); |
488 | element_set_polyline_dash(e, attrs); |
464 | element_set_polyline_offset(e, attrs); |
489 | element_set_polyline_offset(e, attrs); |
465 | return (struct polyline *)e; |
490 | return (struct polyline *) e; |
466 | } |
491 | } |
467 | |
492 | |
468 | struct circle * |
493 | struct circle * |
469 | circle_new(struct attr *parent, struct attr **attrs) |
494 | circle_new(struct attr *parent, struct attr **attrs) |
470 | { |
495 | { |
471 | struct element *e; |
496 | struct element *e; |
472 | struct color color_black = {COLOR_BLACK_}; |
497 | struct color color_black = |
|
|
498 | { COLOR_BLACK_ }; |
473 | struct color color_white = {COLOR_WHITE_}; |
499 | struct color color_white = |
|
|
500 | { COLOR_WHITE_ }; |
474 | |
501 | |
475 | e = g_new0(struct element, 1); |
502 | e = g_new0(struct element, 1); |
476 | e->type=element_circle; |
503 | e->type = element_circle; |
477 | e->color = color_black; |
504 | e->color = color_black; |
478 | e->u.circle.background_color = color_white; |
505 | e->u.circle.background_color = color_white; |
479 | element_set_color(e, attrs); |
506 | element_set_color(e, attrs); |
480 | element_set_background_color(&e->u.circle.background_color, attrs); |
507 | element_set_background_color(&e->u.circle.background_color, attrs); |
481 | element_set_text_size(e, attrs); |
508 | element_set_text_size(e, attrs); |
482 | element_set_circle_width(e, attrs); |
509 | element_set_circle_width(e, attrs); |
483 | element_set_circle_radius(e, attrs); |
510 | element_set_circle_radius(e, attrs); |
484 | |
511 | |
485 | return (struct circle *)e; |
512 | return (struct circle *) e; |
486 | } |
513 | } |
487 | |
514 | |
488 | struct text * |
515 | struct text * |
489 | text_new(struct attr *parent, struct attr **attrs) |
516 | text_new(struct attr *parent, struct attr **attrs) |
490 | { |
517 | { |
491 | struct element *e; |
518 | struct element *e; |
492 | struct color color_black = {COLOR_BLACK_}; |
519 | struct color color_black = |
|
|
520 | { COLOR_BLACK_ }; |
493 | struct color color_white = {COLOR_WHITE_}; |
521 | struct color color_white = |
494 | |
522 | { COLOR_WHITE_ }; |
|
|
523 | |
495 | e = g_new0(struct element, 1); |
524 | e = g_new0(struct element, 1); |
496 | e->type=element_text; |
525 | e->type = element_text; |
497 | element_set_text_size(e, attrs); |
526 | element_set_text_size(e, attrs); |
498 | e->color = color_black; |
527 | e->color = color_black; |
499 | e->u.text.background_color = color_white; |
528 | e->u.text.background_color = color_white; |
500 | element_set_color(e, attrs); |
529 | element_set_color(e, attrs); |
501 | element_set_background_color(&e->u.text.background_color, attrs); |
530 | element_set_background_color(&e->u.text.background_color, attrs); |
502 | |
531 | |
503 | return (struct text *)e; |
532 | return (struct text *) e; |
504 | } |
533 | } |
505 | |
534 | |
506 | struct icon * |
535 | struct icon * |
507 | icon_new(struct attr *parent, struct attr **attrs) |
536 | icon_new(struct attr *parent, struct attr **attrs) |
508 | { |
537 | { |
509 | struct element *e; |
538 | struct element *e; |
510 | struct attr *src,*w,*h,*rotation; |
539 | struct attr *src, *w, *h, *rotation; |
511 | src=attr_search(attrs, NULL, attr_src); |
540 | src = attr_search(attrs, NULL, attr_src); |
512 | if (! src) |
541 | if (!src) |
513 | return NULL; |
542 | return NULL; |
514 | |
543 | |
515 | e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1); |
544 | e = g_malloc0(sizeof(*e) + strlen(src->u.str) + 1); |
516 | e->type=element_icon; |
545 | e->type = element_icon; |
517 | e->u.icon.src=(char *)(e+1); |
546 | e->u.icon.src = (char *) (e + 1); |
518 | if ((w=attr_search(attrs, NULL, attr_w))) |
547 | if ((w = attr_search(attrs, NULL, attr_w))) |
519 | e->u.icon.width=w->u.num; |
548 | e->u.icon.width = w->u.num; |
520 | else |
549 | else |
521 | e->u.icon.width=-1; |
550 | e->u.icon.width = -1; |
522 | if ((h=attr_search(attrs, NULL, attr_h))) |
551 | if ((h = attr_search(attrs, NULL, attr_h))) |
523 | e->u.icon.height=h->u.num; |
552 | e->u.icon.height = h->u.num; |
524 | else |
553 | else |
525 | e->u.icon.height=-1; |
554 | e->u.icon.height = -1; |
526 | if ((rotation=attr_search(attrs, NULL, attr_rotation))) |
555 | if ((rotation = attr_search(attrs, NULL, attr_rotation))) |
527 | e->u.icon.rotation=rotation->u.num; |
556 | e->u.icon.rotation = rotation->u.num; |
528 | strcpy(e->u.icon.src,src->u.str); |
557 | strcpy(e->u.icon.src, src->u.str); |
529 | |
558 | |
530 | return (struct icon *)e; |
559 | return (struct icon *) e; |
531 | } |
560 | } |
532 | |
561 | |
533 | struct image * |
562 | struct image * |
534 | image_new(struct attr *parent, struct attr **attrs) |
563 | image_new(struct attr *parent, struct attr **attrs) |
535 | { |
564 | { |
536 | struct element *e; |
565 | struct element *e; |
537 | |
566 | |
538 | e = g_malloc0(sizeof(*e)); |
567 | e = g_malloc0(sizeof(*e)); |
539 | e->type=element_image; |
568 | e->type = element_image; |
540 | |
569 | |
541 | return (struct image *)e; |
570 | return (struct image *) e; |
542 | } |
571 | } |
543 | |
572 | |
544 | struct arrows * |
573 | struct arrows * |
545 | arrows_new(struct attr *parent, struct attr **attrs) |
574 | arrows_new(struct attr *parent, struct attr **attrs) |
546 | { |
575 | { |
547 | struct element *e; |
576 | struct element *e; |
548 | e = g_malloc0(sizeof(*e)); |
577 | e = g_malloc0(sizeof(*e)); |
549 | e->type=element_arrows; |
578 | e->type = element_arrows; |
550 | element_set_color(e, attrs); |
579 | element_set_color(e, attrs); |
551 | return (struct arrows *)e; |
580 | return (struct arrows *) e; |
552 | } |
581 | } |
553 | |
582 | |
554 | int |
|
|
555 | element_add_attr(struct element *e, struct attr *attr) |
583 | int element_add_attr(struct element *e, struct attr *attr) |
556 | { |
584 | { |
557 | switch (attr->type) { |
585 | switch (attr->type) |
|
|
586 | { |
558 | case attr_coord: |
587 | case attr_coord: |
559 | e->coord=g_realloc(e->coord,(e->coord_count+1)*sizeof(struct coord)); |
588 | e->coord = g_realloc(e->coord, (e->coord_count + 1) * sizeof(struct coord)); |
560 | e->coord[e->coord_count++]=*attr->u.coord; |
589 | e->coord[e->coord_count++] = *attr->u.coord; |
561 | return 1; |
590 | return 1; |
562 | default: |
591 | default: |
563 | return 0; |
592 | return 0; |
564 | } |
593 | } |
565 | } |
594 | } |