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

Contents of /navit/navit/osd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 40 - (show annotations) (download)
Wed Mar 4 14:00:54 2015 UTC (9 years ago) by zoff99
File MIME type: text/plain
File size: 12834 byte(s)
new market version, lots of fixes
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 #ifdef PLUGSSS
73 //dbg(0, "oo 001\n");
74 new = plugin_get_osd_type(type->u.str);
75 //dbg(0, "oo 002\n");
76 if (!new)
77 {
78 return NULL;
79 }
80 #endif
81
82 o=g_new0(struct osd, 1);
83
84 dbg(0, "osd_new:type=%s\n", type->u.str);
85
86 #ifdef PLUGSSS
87 o->priv = new(parent->u.navit, &o->meth, attrs);
88 #else
89 if (strncmp("compass", type->u.str, 7) == 0)
90 {
91 o->priv = osd_compass_new(parent->u.navit, &o->meth, attrs);
92 }
93 else if (strncmp("navigation_next_turn", type->u.str, 20) == 0)
94 {
95 o->priv = osd_nav_next_turn_new(parent->u.navit, &o->meth, attrs);
96 }
97 else if (strncmp("button", type->u.str, 6) == 0)
98 {
99 o->priv = osd_button_new(parent->u.navit, &o->meth, attrs);
100 }
101 else if (strncmp("toggle_announcer", type->u.str, 16) == 0)
102 {
103 o->priv = osd_nav_toggle_announcer_new(parent->u.navit, &o->meth, attrs);
104 }
105 else if (strncmp("speed_warner", type->u.str, 12) == 0)
106 {
107 o->priv = osd_speed_warner_new(parent->u.navit, &o->meth, attrs);
108 }
109 else if (strncmp("speed_cam", type->u.str, 9) == 0)
110 {
111 o->priv = osd_speed_cam_new(parent->u.navit, &o->meth, attrs);
112 }
113 else if (strncmp("text", type->u.str, 4) == 0)
114 {
115 o->priv = osd_text_new(parent->u.navit, &o->meth, attrs);
116 }
117 else if (strncmp("gps_status", type->u.str, 10) == 0)
118 {
119 o->priv = osd_gps_status_new(parent->u.navit, &o->meth, attrs);
120 }
121 else if (strncmp("volume", type->u.str, 6) == 0)
122 {
123 o->priv = osd_volume_new(parent->u.navit, &o->meth, attrs);
124 }
125 else if (strncmp("scale", type->u.str, 5) == 0)
126 {
127 o->priv = osd_scale_new(parent->u.navit, &o->meth, attrs);
128 }
129 else if (strncmp("image", type->u.str, 5) == 0)
130 {
131 o->priv = osd_image_new(parent->u.navit, &o->meth, attrs);
132 }
133 else if (strncmp("stopwatch", type->u.str, 9) == 0)
134 {
135 o->priv = osd_stopwatch_new(parent->u.navit, &o->meth, attrs);
136 }
137 else if (strncmp("odometer", type->u.str, 8) == 0)
138 {
139 o->priv = osd_odometer_new(parent->u.navit, &o->meth, attrs);
140 }
141 else if (strncmp("auxmap", type->u.str, 6) == 0)
142 {
143 o->priv = osd_auxmap_new(parent->u.navit, &o->meth, attrs);
144 }
145 else if (strncmp("cmd_interface", type->u.str, 13) == 0)
146 {
147 o->priv = osd_cmd_interface_new(parent->u.navit, &o->meth, attrs);
148 }
149 #endif
150
151 dbg(0, "osd_new:ready\n");
152
153 attr = attr_search(attrs, NULL, attr_name);
154 if (attr && attr->u.str)
155 {
156 if (NULL == osd_hash)
157 {
158 //dbg(0, "oo 005\n");
159 osd_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free_func, NULL);
160 }
161 //dbg(0, "oo 006\n");
162 g_hash_table_insert(osd_hash, g_strdup(attr->u.str), o);
163 }
164 //dbg(0, "oo 007\n");
165
166 return o;
167 }
168
169 struct osd*
170 osd_get_osd_by_name(char *name)
171 {
172 return g_hash_table_lookup(osd_hash, name);
173 }
174
175 int osd_set_attr(struct osd *osd, struct attr* attr)
176 {
177 if (osd && osd->meth.set_attr)
178 {
179 osd->meth.set_attr(osd->priv, attr);
180 }
181 return 0;
182 }
183
184 void osd_wrap_point(struct point *p, struct navit *nav)
185 {
186 if (p->x < 0)
187 p->x += navit_get_width(nav);
188 if (p->y < 0)
189 p->y += navit_get_height(nav);
190
191 }
192
193 static void osd_evaluate_command(struct osd_item *this, struct navit *nav)
194 {
195 struct attr navit;
196 navit.type = attr_navit;
197 navit.u.navit = nav;
198 //dbg(0, "calling command '%s'\n", this->command);
199 command_evaluate(&navit, this->command);
200 }
201
202 void osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p)
203 {
204 /*
205 struct point bp = this->p;
206 if (!this->command || !this->command[0])
207 return;
208 osd_wrap_point(&bp, nav);
209 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)
210 return;
211 if (button != 1)
212 return;
213 if (!!pressed == !!this->pressed)
214 return;
215 if (navit_ignore_button(nav))
216 return;
217 this->pressed = pressed;
218 if (pressed && this->command)
219 osd_evaluate_command(this, nav);
220 */
221 }
222
223 void osd_std_resize(struct osd_item *item)
224 {
225 // graphics_overlay_resize(item->gr, &item->p, item->w, item->h, 65535, 1);
226 }
227
228 static void osd_std_calculate_sizes(struct osd_item *item, struct osd_priv *priv, int w, int h)
229 {
230 /*
231 struct attr vehicle_attr;
232
233 if (item->rel_w) {
234 item->w = (item->rel_w * w) / 100;
235 }
236
237 if (item->rel_h) {
238 item->h = (item->rel_h * h) / 100;
239 }
240
241 if (item->rel_x) {
242 item->p.x = (item->rel_x * w) / 100;
243 }
244
245 if (item->rel_y) {
246 item->p.y = (item->rel_y * h) / 100;
247 }
248
249 osd_std_resize(item);
250 if (item->meth.draw) {
251 if (navit_get_attr(item->navit, attr_vehicle, &vehicle_attr, NULL)) {
252 item->meth.draw(priv, item->navit, vehicle_attr.u.vehicle);
253 }
254 }
255 */
256 }
257
258 static void osd_std_keypress(struct osd_item *item, struct navit *nav, char *key)
259 {
260 #if 0
261 int i;
262 dbg(0,"key=%s\n",key);
263 for (i = 0; i < strlen(key); i++)
264 {
265 dbg(0,"key:0x%02x\n",key[i]);
266 }
267 for (i = 0; i < strlen(item->accesskey); i++)
268 {
269 dbg(0,"accesskey:0x%02x\n",item->accesskey[i]);
270 }
271 #endif
272 if (item->accesskey && key && !strcmp(key, item->accesskey))
273 osd_evaluate_command(item, nav);
274 }
275
276 static void osd_std_reconfigure(struct osd_item *item, struct command_saved *cs)
277 {
278 /*
279 if (!command_saved_error(cs)) {
280 graphics_overlay_disable(item->gr, !command_saved_get_int(cs));
281 } else {
282 dbg(0, "Error in saved command: %i\n", command_saved_error(cs));
283 }
284 */
285 }
286
287 void osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags)
288 {
289 struct attr *attr;
290
291 item->flags = flags;
292 item->osd_configuration = -1;
293 item->color_white.r = 0xffff;
294 item->color_white.g = 0xffff;
295 item->color_white.b = 0xffff;
296 item->color_white.a = 0xffff;
297 item->text_color.r = 0xffff;
298 item->text_color.g = 0xffff;
299 item->text_color.b = 0xffff;
300 item->text_color.a = 0xffff;
301 if (flags & 1)
302 {
303 item->color_bg.r = 0x0808;
304 item->color_bg.g = 0x0808;
305 item->color_bg.b = 0xf8f8;
306 item->color_bg.a = 0x0000;
307 }
308 else
309 {
310 item->color_bg.r = 0x0;
311 item->color_bg.g = 0x0;
312 item->color_bg.b = 0x0;
313 item->color_bg.a = 0x5fff;
314 }
315
316 attr = attr_search(attrs, NULL, attr_osd_configuration);
317 if (attr)
318 item->osd_configuration = attr->u.num;
319
320 attr = attr_search(attrs, NULL, attr_enable_expression);
321 if (attr)
322 {
323 item->enable_cs = command_saved_new(attr->u.str, item->navit, NULL);
324 }
325
326 attr = attr_search(attrs, NULL, attr_w);
327 if (attr)
328 {
329 if (attr->u.num > ATTR_REL_MAXABS)
330 {
331 item->rel_w = attr->u.num - ATTR_REL_RELSHIFT;
332 }
333 else
334 {
335 item->rel_w = 0;
336 item->w = attr->u.num;
337 }
338 }
339
340 attr = attr_search(attrs, NULL, attr_h);
341 if (attr)
342 {
343 if (attr->u.num > ATTR_REL_MAXABS)
344 {
345 item->rel_h = attr->u.num - ATTR_REL_RELSHIFT;
346 }
347 else
348 {
349 item->rel_h = 0;
350 item->h = attr->u.num;
351 }
352 }
353
354 attr = attr_search(attrs, NULL, attr_x);
355 if (attr)
356 {
357 if (attr->u.num > ATTR_REL_MAXABS)
358 {
359 item->rel_x = attr->u.num - ATTR_REL_RELSHIFT;
360 }
361 else
362 {
363 item->rel_x = 0;
364 item->p.x = attr->u.num;
365 }
366 }
367
368 attr = attr_search(attrs, NULL, attr_y);
369 if (attr)
370 {
371 if (attr->u.num > ATTR_REL_MAXABS)
372 {
373 item->rel_y = attr->u.num - ATTR_REL_RELSHIFT;
374 }
375 else
376 {
377 item->rel_y = 0;
378 item->p.y = attr->u.num;
379 }
380 }
381
382 attr = attr_search(attrs, NULL, attr_font_size);
383 if (attr)
384 item->font_size = attr->u.num;
385
386 attr = attr_search(attrs, NULL, attr_background_color);
387 if (attr)
388 item->color_bg = *attr->u.color;
389 attr = attr_search(attrs, NULL, attr_command);
390 if (attr)
391 item->command = g_strdup(attr->u.str);
392 attr = attr_search(attrs, NULL, attr_text_color);
393 if (attr)
394 item->text_color = *attr->u.color;
395 attr = attr_search(attrs, NULL, attr_flags);
396 if (attr)
397 item->attr_flags = attr->u.num;
398 attr = attr_search(attrs, NULL, attr_accesskey);
399 if (attr)
400 item->accesskey = g_strdup(attr->u.str);
401 attr = attr_search(attrs, NULL, attr_font);
402 if (attr)
403 item->font_name = g_strdup(attr->u.str);
404
405 }
406 void osd_std_config(struct osd_item *item, struct navit *navit)
407 {
408 struct attr attr;
409 //dbg(1, "enter\n");
410 if (item->enable_cs)
411 {
412 item->reconfig_cb = callback_new_1(callback_cast(osd_std_reconfigure), item);
413 command_saved_set_cb(item->enable_cs, item->reconfig_cb);
414
415 if (!command_saved_error(item->enable_cs))
416 {
417 item->configured = !!command_saved_get_int(item->enable_cs);
418 }
419 else
420 {
421 //dbg(0, "Error in saved command: %i.\n", command_saved_error(item->enable_cs));
422 }
423 }
424 else
425 {
426 if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL))
427 attr.u.num = -1;
428 item->configured = !!(attr.u.num & item->osd_configuration);
429 }
430
431 //if (item->gr && !(item->flags & 16))
432 // graphics_overlay_disable(item->gr, !item->configured);
433 }
434
435 void osd_set_std_config(struct navit *nav, struct osd_item *item)
436 {
437 item->cb = callback_new_attr_2(callback_cast(osd_std_config), attr_osd_configuration, item, nav);
438 callback_add_names(item->cb, "osd_set_std_config", "osd_std_config");
439 navit_add_callback(nav, item->cb);
440 osd_std_config(item, nav);
441 }
442
443 void osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *priv)
444 {
445 // struct graphics *navit_gr;
446
447 // navit_gr = navit_get_graphics(nav);
448 item->gr = NULL;
449 // DISABLE OVERLAYS // graphics_overlay_new(navit_gr, &item->p, item->w, item->h, 65535, 1);
450
451 // item->graphic_bg = graphics_gc_new(item->gr);
452 // graphics_gc_set_foreground(item->graphic_bg, &item->color_bg);
453 // graphics_background_gc(item->gr, item->graphic_bg);
454
455 // item->graphic_fg_white = graphics_gc_new(item->gr);
456 // graphics_gc_set_foreground(item->graphic_fg_white, &item->color_white);
457
458 // if (item->flags & 2) {
459 // item->font = graphics_named_font_new(item->gr, item->font_name, item->font_size, 1);
460 // item->graphic_fg_text = graphics_gc_new(item->gr);
461 // graphics_gc_set_foreground(item->graphic_fg_text, &item->text_color);
462 // }
463
464 osd_set_std_config(nav, item);
465
466 item->resize_cb = callback_new_attr_2(callback_cast(osd_std_calculate_sizes), attr_resize, item, priv);
467 callback_add_names(item->resize_cb, "osd_set_std_graphic", "osd_std_calculate_sizes");
468
469 // graphics_add_callback(navit_gr, item->resize_cb);
470 //dbg(0, "accesskey %s\n", item->accesskey);
471 // if (item->accesskey) {
472 // item->keypress_cb=callback_new_attr_2(callback_cast(osd_std_keypress), attr_keypress, item, nav);
473 // graphics_add_callback(navit_gr, item->keypress_cb);
474 // }
475
476 }
477
478 void osd_std_draw(struct osd_item *item)
479 {
480 /*
481
482 struct point p[2];
483 int flags=item->attr_flags;
484
485 graphics_draw_mode(item->gr, draw_mode_begin);
486 p[0].x=0;
487 p[0].y=0;
488 graphics_draw_rectangle(item->gr, item->graphic_bg, p, item->w, item->h);
489 p[1].x=item->w-1;
490 p[1].y=0;
491 if (flags & 1)
492 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
493 p[0].x=item->w-1;
494 p[0].y=item->h-1;
495 if (flags & 2)
496 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
497 p[1].x=0;
498 p[1].y=item->h-1;
499 if (flags & 4)
500 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
501 p[0].x=0;
502 p[0].y=0;
503 if (flags & 8)
504 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
505
506 */
507 }
508

   
Visit the ZANavi Wiki