12 #include "transform.h"
20 #include "navigation.h"
28 struct graphics_gc *bg;
29 struct graphics_gc *white;
30 struct graphics_gc *green;
31 struct graphics_font *font;
36 transform_rotate(struct point *center, int angle, struct point *p, int count)
40 for (i = 0 ; i < count ; i++)
42 dx=sin(M_PI*angle/180.0);
43 dy=cos(M_PI*angle/180.0);
54 handle(struct graphics *gr, struct graphics_gc *gc, struct point *p, int r, int dir)
63 transform_rotate(p, dir, ph, 2);
64 graphics_draw_lines(gr, gc, ph, 2);
71 transform_rotate(p, dir, ph, 3);
72 graphics_draw_lines(gr, gc, ph, 3);
76 format_distance(char *buffer, double distance)
78 if (distance >= 100000)
79 sprintf(buffer,"%.0f km", distance/1000);
80 else if (distance >= 10000)
81 sprintf(buffer,"%.1f km", distance/1000);
82 else if (distance >= 300)
83 sprintf(buffer,"%.0f m", round(distance/25)*25);
84 else if (distance >= 50)
85 sprintf(buffer,"%.0f m", round(distance/10)*10);
86 else if (distance >= 10)
87 sprintf(buffer,"%.0f m", distance);
89 sprintf(buffer,"%.1f m", distance);
93 osd_compass_draw(struct compass *this, struct navit *nav, struct vehicle *v)
96 struct attr attr_dir, destination_attr, position_attr;
102 graphics_draw_mode(this->gr, draw_mode_begin);
105 graphics_draw_rectangle(this->gr, this->bg, &p, this->w, this->h);
108 graphics_draw_circle(this->gr, this->white, &p, 50);
109 if (v && vehicle_get_attr(v, attr_position_direction, &attr_dir)) {
110 vdir=*attr_dir.u.numd;
111 handle(this->gr, this->white, &p, 20, -vdir);
113 if (navit_get_attr(nav, attr_destination, &destination_attr, NULL) && v && vehicle_get_attr(v, attr_position_coord_geo, &position_attr)) {
114 pro=destination_attr.u.pcoord->pro;
115 transform_from_geo(pro, position_attr.u.coord_geo, &c1);
116 c2.x=destination_attr.u.pcoord->x;
117 c2.y=destination_attr.u.pcoord->y;
118 dir=atan2(c2.x-c1.x,c2.y-c1.y)*180.0/M_PI;
120 handle(this->gr, this->green, &p, 20, dir);
121 format_distance(buffer, transform_distance(pro, &c1, &c2));
124 graphics_draw_text(this->gr, this->green, NULL, this->font, buffer, &p, 0x10000, 0);
126 graphics_draw_mode(this->gr, draw_mode_end);
130 osd_compass_init(struct compass *this, struct navit *nav)
132 struct graphics *navit_gr;
134 navit_gr=navit_get_graphics(nav);
135 this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
137 this->bg=graphics_gc_new(this->gr);
139 graphics_gc_set_foreground(this->bg, &c);
141 this->white=graphics_gc_new(this->gr);
142 c.r=65535; c.g=65535; c.b=65535;
143 graphics_gc_set_foreground(this->white, &c);
144 graphics_gc_set_linewidth(this->white, 2);
146 this->green=graphics_gc_new(this->gr);
147 c.r=0; c.g=65535; c.b=0;
148 graphics_gc_set_foreground(this->green, &c);
149 graphics_gc_set_linewidth(this->green, 2);
151 this->font=graphics_font_new(this->gr, 200, 1);
152 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_draw), attr_position_coord_geo, this));
154 osd_compass_draw(this, nav, NULL);
157 static struct osd_priv *
158 osd_compass_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
160 struct compass *this=g_new0(struct compass, 1);
166 attr=attr_search(attrs, NULL, attr_x);
168 this->p.x=attr->u.num;
169 attr=attr_search(attrs, NULL, attr_y);
171 this->p.y=attr->u.num;
172 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_init), attr_navit, this));
173 return (struct osd_priv *) this;
180 struct graphics_gc *bg;
181 struct graphics_gc *white;
182 struct graphics_font *font;
183 struct graphics_image *flag;
186 char last_distance[16];
190 osd_eta_draw(struct eta *this, struct navit *navit, struct vehicle *v)
195 int days=0,do_draw=0;
197 struct tm tm,eta_tm,eta_tm0;
199 struct navigation *nav=NULL;
200 struct map *map=NULL;
201 struct map_rect *mr=NULL;
202 struct item *item=NULL;
209 nav=navit_get_navigation(navit);
211 map=navigation_get_map(nav);
213 mr=map_rect_new(map, NULL);
215 item=map_rect_get_item(mr);
217 if (item_attr_get(item, attr_destination_length, &attr)) {
218 format_distance(distance, attr.u.num);
220 if (item_attr_get(item, attr_destination_time, &attr)) {
222 tm=*localtime(&etat);
224 eta_tm=*localtime(&etat);
225 if (tm.tm_year != eta_tm.tm_year || tm.tm_mon != eta_tm.tm_mon || tm.tm_mday != eta_tm.tm_mday) {
233 days=(mktime(&eta_tm0)-mktime(&tm)+43200)/86400;
236 sprintf(eta, "%d+%02d:%02d", days, eta_tm.tm_hour, eta_tm.tm_min);
238 sprintf(eta, " %02d:%02d", eta_tm.tm_hour, eta_tm.tm_min);
240 if (this->active != 1 || strcmp(this->last_distance, distance) || strcmp(this->last_eta, eta)) {
242 strcpy(this->last_distance, distance);
243 strcpy(this->last_eta, eta);
247 if (this->active != 0) {
253 map_rect_destroy(mr);
256 graphics_draw_mode(this->gr, draw_mode_begin);
259 graphics_draw_rectangle(this->gr, this->bg, &p, this->w, this->h);
263 graphics_draw_image(this->gr, this->white, &p, this->flag);
267 graphics_draw_text(this->gr, this->white, NULL, this->font, "ETA", &p, 0x10000, 0);
270 graphics_draw_text(this->gr, this->white, NULL, this->font, eta, &p, 0x10000, 0);
275 graphics_draw_text(this->gr, this->white, NULL, this->font, distance, &p, 0x10000, 0);
277 graphics_draw_mode(this->gr, draw_mode_end);
282 osd_eta_init(struct eta *this, struct navit *nav)
284 struct graphics *navit_gr;
286 char *flag=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/xpm/flag_wh_bk.xpm", NULL);
287 navit_gr=navit_get_graphics(nav);
288 this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
290 this->bg=graphics_gc_new(this->gr);
292 graphics_gc_set_foreground(this->bg, &c);
294 this->white=graphics_gc_new(this->gr);
295 c.r=65535; c.g=65535; c.b=65535;
296 graphics_gc_set_foreground(this->white, &c);
297 graphics_gc_set_linewidth(this->white, 2);
299 this->font=graphics_font_new(this->gr, 200, 1);
300 this->flag=graphics_image_new(this->gr, flag);
301 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_eta_draw), attr_position_coord_geo, this));
303 osd_eta_draw(this, nav, NULL);
307 static struct osd_priv *
308 osd_eta_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
310 struct eta *this=g_new0(struct eta, 1);
317 attr=attr_search(attrs, NULL, attr_x);
319 this->p.x=attr->u.num;
320 attr=attr_search(attrs, NULL, attr_y);
322 this->p.y=attr->u.num;
323 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_eta_init), attr_navit, this));
324 return (struct osd_priv *) this;
327 struct osd_navigation {
331 struct graphics_gc *bg;
332 struct graphics_gc *white;
333 struct graphics_font *font;
335 char last_distance[16];
340 osd_navigation_draw(struct osd_navigation *this, struct navit *navit, struct vehicle *v)
346 struct navigation *nav=NULL;
347 struct map *map=NULL;
348 struct map_rect *mr=NULL;
349 struct item *item=NULL;
350 struct graphics_image *gr_image;
352 char *name="unknown";
357 nav=navit_get_navigation(navit);
359 map=navigation_get_map(nav);
361 mr=map_rect_new(map, NULL);
363 item=map_rect_get_item(mr);
365 name=item_to_name(item->type);
366 dbg(1,"name=%s\n", name);
367 if (item_attr_get(item, attr_length, &attr)) {
368 format_distance(distance, attr.u.num);
370 if (this->active != 1 || strcmp(this->last_distance, distance) || this->last_name != name) {
372 strcpy(this->last_distance, distance);
373 this->last_name=name;
377 if (this->active != 0) {
383 map_rect_destroy(mr);
386 graphics_draw_mode(this->gr, draw_mode_begin);
389 graphics_draw_rectangle(this->gr, this->bg, &p, this->w, this->h);
391 image=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/xpm/", name, "_32.xpm", NULL);
392 gr_image=graphics_image_new(this->gr, image);
395 image=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/xpm/unknown.xpm", NULL);
396 gr_image=graphics_image_new(this->gr, image);
398 dbg(1,"gr_image=%p\n", gr_image);
400 p.x=(this->w-gr_image->width)/2;
401 p.y=(46-gr_image->height)/2;
402 graphics_draw_image(this->gr, this->white, &p, gr_image);
403 graphics_image_free(this->gr, gr_image);
407 graphics_draw_text(this->gr, this->white, NULL, this->font, distance, &p, 0x10000, 0);
409 graphics_draw_mode(this->gr, draw_mode_end);
414 osd_navigation_init(struct osd_navigation *this, struct navit *nav)
416 struct graphics *navit_gr;
418 navit_gr=navit_get_graphics(nav);
419 this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
421 this->bg=graphics_gc_new(this->gr);
423 graphics_gc_set_foreground(this->bg, &c);
425 this->white=graphics_gc_new(this->gr);
426 c.r=65535; c.g=65535; c.b=65535;
427 graphics_gc_set_foreground(this->white, &c);
428 graphics_gc_set_linewidth(this->white, 2);
430 this->font=graphics_font_new(this->gr, 200, 1);
431 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_navigation_draw), attr_position_coord_geo, this));
433 osd_navigation_draw(this, nav, NULL);
436 static struct osd_priv *
437 osd_navigation_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
439 struct osd_navigation *this=g_new0(struct osd_navigation, 1);
446 attr=attr_search(attrs, NULL, attr_x);
448 this->p.x=attr->u.num;
449 attr=attr_search(attrs, NULL, attr_y);
451 this->p.y=attr->u.num;
452 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_navigation_init), attr_navit, this));
453 return (struct osd_priv *) this;
456 struct osd_street_name {
460 struct graphics_gc *bg;
461 struct graphics_gc *white;
462 struct graphics_font *font;
468 osd_street_name_draw(struct osd_street_name *this, struct navit *navit, struct vehicle *v)
473 struct attr attr_name1, attr_name2;
474 char *name1=NULL,*name2=NULL;
475 struct tracking *tr=NULL;
476 struct map_rect *mr=NULL;
477 struct item *item=NULL;
482 tr=navit_get_tracking(navit);
484 item=tracking_get_current_item(tr);
485 dbg(1,"navit=%p tr=%p item=%p\n", navit, tr, item);
487 if (!item_is_equal(*item, this->item)) {
490 mr=map_rect_new(item->map,NULL);
491 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
492 if (item_attr_get(item, attr_street_name, &attr_name1))
493 name1=map_convert_string(item->map, attr_name1.u.str);
494 if (item_attr_get(item, attr_street_name_systematic, &attr_name2))
495 name2=map_convert_string(item->map, attr_name2.u.str);
496 printf("name1=%s name2=%s\n", name1, name2);
497 map_rect_destroy(mr);
499 name=g_strdup_printf("%s/%s", name2,name1);
501 name=g_strdup(name1?name1:name2);
502 map_convert_free(name1);
503 map_convert_free(name2);
507 if (this->item.map || this->active)
510 memset(&this->item, 0, sizeof(this->item));
514 dbg(1,"name=%s\n", name);
515 graphics_draw_mode(this->gr, draw_mode_begin);
518 graphics_draw_rectangle(this->gr, this->bg, &p, 32767, 32767);
522 graphics_draw_text(this->gr, this->white, NULL, this->font, name, &p, 0x10000, 0);
524 graphics_draw_mode(this->gr, draw_mode_end);
529 osd_street_name_init(struct osd_street_name *this, struct navit *nav)
531 struct graphics *navit_gr;
533 navit_gr=navit_get_graphics(nav);
535 this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
537 this->bg=graphics_gc_new(this->gr);
539 graphics_gc_set_foreground(this->bg, &c);
541 this->white=graphics_gc_new(this->gr);
542 c.r=65535; c.g=65535; c.b=65535;
543 graphics_gc_set_foreground(this->white, &c);
545 this->font=graphics_font_new(this->gr, 200, 1);
546 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_street_name_draw), attr_position_coord_geo, this));
548 osd_street_name_draw(this, nav, NULL);
551 static struct osd_priv *
552 osd_street_name_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
554 struct osd_street_name *this=g_new0(struct osd_street_name, 1);
560 attr=attr_search(attrs, NULL, attr_x);
562 this->p.x=attr->u.num;
563 attr=attr_search(attrs, NULL, attr_y);
565 this->p.y=attr->u.num;
566 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_street_name_init), attr_navit, this));
567 return (struct osd_priv *) this;
573 plugin_register_osd_type("compass", osd_compass_new);
574 plugin_register_osd_type("eta", osd_eta_new);
575 plugin_register_osd_type("navigation", osd_navigation_new);
576 plugin_register_osd_type("street_name", osd_street_name_new);