/[zanavi_public1]/navit/navit/osd.c
ZANavi

Contents of /navit/navit/osd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 2 months ago) by zoff99
File MIME type: text/plain
File size: 10897 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
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 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 #include <glib.h>
40 #include "debug.h"
41 #include "plugin.h"
42 #include "item.h"
43 #include "color.h"
44 #include "point.h"
45 #include "navit.h"
46 #include "graphics.h"
47 #include "command.h"
48 #include "callback.h"
49 #include "osd.h"
50
51 struct osd
52 {
53 struct osd_methods meth;
54 struct osd_priv *priv;
55 };
56
57 static GHashTable *osd_hash = NULL;
58
59 struct osd *
60 osd_new(struct attr *parent, struct attr **attrs)
61 {
62 struct attr *attr;
63 struct osd *o;
64 struct osd_priv *(*new)(struct navit *nav, struct osd_methods *meth, struct attr **attrs);
65 struct attr *type = attr_search(attrs, NULL, attr_type);
66
67 if (!type)
68 {
69 return NULL;
70 }
71
72 //dbg(0, "oo 001\n");
73 new = plugin_get_osd_type(type->u.str);
74 //dbg(0, "oo 002\n");
75 if (!new)
76 {
77 return NULL;
78 }
79
80 o=g_new0(struct osd, 1);
81 //dbg(0, "oo 003\n");
82 o->priv = new(parent->u.navit, &o->meth, attrs);
83 //dbg(0, "oo 004\n");
84
85 attr = attr_search(attrs, NULL, attr_name);
86 if (attr && attr->u.str)
87 {
88 if (NULL == osd_hash)
89 {
90 //dbg(0, "oo 005\n");
91 osd_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free_func, NULL);
92 }
93 //dbg(0, "oo 006\n");
94 g_hash_table_insert(osd_hash, g_strdup(attr->u.str), o);
95 }
96 //dbg(0, "oo 007\n");
97
98 return o;
99 }
100
101 struct osd*
102 osd_get_osd_by_name(char *name)
103 {
104 return g_hash_table_lookup(osd_hash, name);
105 }
106
107 int osd_set_attr(struct osd *osd, struct attr* attr)
108 {
109 if (osd && osd->meth.set_attr)
110 {
111 osd->meth.set_attr(osd->priv, attr);
112 }
113 return 0;
114 }
115
116 void osd_wrap_point(struct point *p, struct navit *nav)
117 {
118 if (p->x < 0)
119 p->x += navit_get_width(nav);
120 if (p->y < 0)
121 p->y += navit_get_height(nav);
122
123 }
124
125 static void osd_evaluate_command(struct osd_item *this, struct navit *nav)
126 {
127 struct attr navit;
128 navit.type = attr_navit;
129 navit.u.navit = nav;
130 //dbg(0, "calling command '%s'\n", this->command);
131 command_evaluate(&navit, this->command);
132 }
133
134 void osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p)
135 {
136 /*
137 struct point bp = this->p;
138 if (!this->command || !this->command[0])
139 return;
140 osd_wrap_point(&bp, nav);
141 if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + this->w || p->y > bp.y + this->h || !this->configured) && !this->pressed)
142 return;
143 if (button != 1)
144 return;
145 if (!!pressed == !!this->pressed)
146 return;
147 if (navit_ignore_button(nav))
148 return;
149 this->pressed = pressed;
150 if (pressed && this->command)
151 osd_evaluate_command(this, nav);
152 */
153 }
154
155 void osd_std_resize(struct osd_item *item)
156 {
157 // graphics_overlay_resize(item->gr, &item->p, item->w, item->h, 65535, 1);
158 }
159
160 static void osd_std_calculate_sizes(struct osd_item *item, struct osd_priv *priv, int w, int h)
161 {
162 /*
163 struct attr vehicle_attr;
164
165 if (item->rel_w) {
166 item->w = (item->rel_w * w) / 100;
167 }
168
169 if (item->rel_h) {
170 item->h = (item->rel_h * h) / 100;
171 }
172
173 if (item->rel_x) {
174 item->p.x = (item->rel_x * w) / 100;
175 }
176
177 if (item->rel_y) {
178 item->p.y = (item->rel_y * h) / 100;
179 }
180
181 osd_std_resize(item);
182 if (item->meth.draw) {
183 if (navit_get_attr(item->navit, attr_vehicle, &vehicle_attr, NULL)) {
184 item->meth.draw(priv, item->navit, vehicle_attr.u.vehicle);
185 }
186 }
187 */
188 }
189
190 static void osd_std_keypress(struct osd_item *item, struct navit *nav, char *key)
191 {
192 #if 0
193 int i;
194 dbg(0,"key=%s\n",key);
195 for (i = 0; i < strlen(key); i++)
196 {
197 dbg(0,"key:0x%02x\n",key[i]);
198 }
199 for (i = 0; i < strlen(item->accesskey); i++)
200 {
201 dbg(0,"accesskey:0x%02x\n",item->accesskey[i]);
202 }
203 #endif
204 if (item->accesskey && key && !strcmp(key, item->accesskey))
205 osd_evaluate_command(item, nav);
206 }
207
208 static void osd_std_reconfigure(struct osd_item *item, struct command_saved *cs)
209 {
210 /*
211 if (!command_saved_error(cs)) {
212 graphics_overlay_disable(item->gr, !command_saved_get_int(cs));
213 } else {
214 dbg(0, "Error in saved command: %i\n", command_saved_error(cs));
215 }
216 */
217 }
218
219 void osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags)
220 {
221 struct attr *attr;
222
223 item->flags = flags;
224 item->osd_configuration = -1;
225 item->color_white.r = 0xffff;
226 item->color_white.g = 0xffff;
227 item->color_white.b = 0xffff;
228 item->color_white.a = 0xffff;
229 item->text_color.r = 0xffff;
230 item->text_color.g = 0xffff;
231 item->text_color.b = 0xffff;
232 item->text_color.a = 0xffff;
233 if (flags & 1)
234 {
235 item->color_bg.r = 0x0808;
236 item->color_bg.g = 0x0808;
237 item->color_bg.b = 0xf8f8;
238 item->color_bg.a = 0x0000;
239 }
240 else
241 {
242 item->color_bg.r = 0x0;
243 item->color_bg.g = 0x0;
244 item->color_bg.b = 0x0;
245 item->color_bg.a = 0x5fff;
246 }
247
248 attr = attr_search(attrs, NULL, attr_osd_configuration);
249 if (attr)
250 item->osd_configuration = attr->u.num;
251
252 attr = attr_search(attrs, NULL, attr_enable_expression);
253 if (attr)
254 {
255 item->enable_cs = command_saved_new(attr->u.str, item->navit, NULL);
256 }
257
258 attr = attr_search(attrs, NULL, attr_w);
259 if (attr)
260 {
261 if (attr->u.num > ATTR_REL_MAXABS)
262 {
263 item->rel_w = attr->u.num - ATTR_REL_RELSHIFT;
264 }
265 else
266 {
267 item->rel_w = 0;
268 item->w = attr->u.num;
269 }
270 }
271
272 attr = attr_search(attrs, NULL, attr_h);
273 if (attr)
274 {
275 if (attr->u.num > ATTR_REL_MAXABS)
276 {
277 item->rel_h = attr->u.num - ATTR_REL_RELSHIFT;
278 }
279 else
280 {
281 item->rel_h = 0;
282 item->h = attr->u.num;
283 }
284 }
285
286 attr = attr_search(attrs, NULL, attr_x);
287 if (attr)
288 {
289 if (attr->u.num > ATTR_REL_MAXABS)
290 {
291 item->rel_x = attr->u.num - ATTR_REL_RELSHIFT;
292 }
293 else
294 {
295 item->rel_x = 0;
296 item->p.x = attr->u.num;
297 }
298 }
299
300 attr = attr_search(attrs, NULL, attr_y);
301 if (attr)
302 {
303 if (attr->u.num > ATTR_REL_MAXABS)
304 {
305 item->rel_y = attr->u.num - ATTR_REL_RELSHIFT;
306 }
307 else
308 {
309 item->rel_y = 0;
310 item->p.y = attr->u.num;
311 }
312 }
313
314 attr = attr_search(attrs, NULL, attr_font_size);
315 if (attr)
316 item->font_size = attr->u.num;
317
318 attr = attr_search(attrs, NULL, attr_background_color);
319 if (attr)
320 item->color_bg = *attr->u.color;
321 attr = attr_search(attrs, NULL, attr_command);
322 if (attr)
323 item->command = g_strdup(attr->u.str);
324 attr = attr_search(attrs, NULL, attr_text_color);
325 if (attr)
326 item->text_color = *attr->u.color;
327 attr = attr_search(attrs, NULL, attr_flags);
328 if (attr)
329 item->attr_flags = attr->u.num;
330 attr = attr_search(attrs, NULL, attr_accesskey);
331 if (attr)
332 item->accesskey = g_strdup(attr->u.str);
333 attr = attr_search(attrs, NULL, attr_font);
334 if (attr)
335 item->font_name = g_strdup(attr->u.str);
336
337 }
338 void osd_std_config(struct osd_item *item, struct navit *navit)
339 {
340 struct attr attr;
341 //dbg(1, "enter\n");
342 if (item->enable_cs)
343 {
344 item->reconfig_cb = callback_new_1(callback_cast(osd_std_reconfigure), item);
345 command_saved_set_cb(item->enable_cs, item->reconfig_cb);
346
347 if (!command_saved_error(item->enable_cs))
348 {
349 item->configured = !!command_saved_get_int(item->enable_cs);
350 }
351 else
352 {
353 //dbg(0, "Error in saved command: %i.\n", command_saved_error(item->enable_cs));
354 }
355 }
356 else
357 {
358 if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL))
359 attr.u.num = -1;
360 item->configured = !!(attr.u.num & item->osd_configuration);
361 }
362
363 //if (item->gr && !(item->flags & 16))
364 // graphics_overlay_disable(item->gr, !item->configured);
365 }
366
367 void osd_set_std_config(struct navit *nav, struct osd_item *item)
368 {
369 item->cb = callback_new_attr_2(callback_cast(osd_std_config), attr_osd_configuration, item, nav);
370 callback_add_names(item->cb, "osd_set_std_config", "osd_std_config");
371 navit_add_callback(nav, item->cb);
372 osd_std_config(item, nav);
373 }
374
375 void osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *priv)
376 {
377 // struct graphics *navit_gr;
378
379 // navit_gr = navit_get_graphics(nav);
380 item->gr = NULL;
381 // DISABLE OVERLAYS // graphics_overlay_new(navit_gr, &item->p, item->w, item->h, 65535, 1);
382
383 // item->graphic_bg = graphics_gc_new(item->gr);
384 // graphics_gc_set_foreground(item->graphic_bg, &item->color_bg);
385 // graphics_background_gc(item->gr, item->graphic_bg);
386
387 // item->graphic_fg_white = graphics_gc_new(item->gr);
388 // graphics_gc_set_foreground(item->graphic_fg_white, &item->color_white);
389
390 // if (item->flags & 2) {
391 // item->font = graphics_named_font_new(item->gr, item->font_name, item->font_size, 1);
392 // item->graphic_fg_text = graphics_gc_new(item->gr);
393 // graphics_gc_set_foreground(item->graphic_fg_text, &item->text_color);
394 // }
395
396 osd_set_std_config(nav, item);
397
398 item->resize_cb = callback_new_attr_2(callback_cast(osd_std_calculate_sizes), attr_resize, item, priv);
399 callback_add_names(item->resize_cb, "osd_set_std_graphic", "osd_std_calculate_sizes");
400
401 // graphics_add_callback(navit_gr, item->resize_cb);
402 //dbg(0, "accesskey %s\n", item->accesskey);
403 // if (item->accesskey) {
404 // item->keypress_cb=callback_new_attr_2(callback_cast(osd_std_keypress), attr_keypress, item, nav);
405 // graphics_add_callback(navit_gr, item->keypress_cb);
406 // }
407
408 }
409
410 void osd_std_draw(struct osd_item *item)
411 {
412 /*
413
414 struct point p[2];
415 int flags=item->attr_flags;
416
417 graphics_draw_mode(item->gr, draw_mode_begin);
418 p[0].x=0;
419 p[0].y=0;
420 graphics_draw_rectangle(item->gr, item->graphic_bg, p, item->w, item->h);
421 p[1].x=item->w-1;
422 p[1].y=0;
423 if (flags & 1)
424 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
425 p[0].x=item->w-1;
426 p[0].y=item->h-1;
427 if (flags & 2)
428 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
429 p[1].x=0;
430 p[1].y=item->h-1;
431 if (flags & 4)
432 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
433 p[0].x=0;
434 p[0].y=0;
435 if (flags & 8)
436 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
437
438 */
439 }
440

   
Visit the ZANavi Wiki