2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
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.
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.
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.
26 #include "transform.h"
36 struct graphics_gc *bg;
37 struct graphics_gc *white;
38 struct graphics_gc *green;
39 struct graphics_font *font;
43 transform_rotate(struct point *center, int angle, struct point *p, int count)
47 for (i = 0 ; i < count ; i++)
49 dx=sin(M_PI*angle/180.0);
50 dy=cos(M_PI*angle/180.0);
61 handle(struct graphics *gr, struct graphics_gc *gc, struct point *p, int r, int dir)
70 transform_rotate(p, dir, ph, 2);
71 gr->draw_lines(gr, gc, ph, 2);
78 transform_rotate(p, dir, ph, 3);
79 gr->draw_lines(gr, gc, ph, 3);
83 compass_draw(struct compass *comp, struct container *co)
86 struct coord *pos, *dest;
87 double *vehicle_dir,dir,distance;
94 vehicle_dir=vehicle_dir_get(co->vehicle);
95 comp->gr->draw_mode(comp->gr, draw_mode_begin);
98 comp->gr->draw_rectangle(comp->gr, comp->bg, &p, 60, 80);
101 comp->gr->draw_circle(comp->gr, comp->white, &p, 50);
102 if (co->flags->orient_north)
103 handle(comp->gr,comp->white, &p, 20,0);
105 handle(comp->gr, comp->white, &p, 20, -*vehicle_dir);
107 dest=route_get_destination(co->route);
109 pos=vehicle_pos_get(co->vehicle);
112 dir=atan2(dx,dy)*180.0/M_PI;
114 printf("dx %d dy %d dir=%f vehicle_dir=%f\n", dx, dy, dir, *vehicle_dir);
116 if (! co->flags->orient_north)
118 handle(comp->gr, comp->green, &p, 20, dir);
121 distance=transform_distance(projection_mg, pos, dest)/1000.0;
123 sprintf(buffer,"%.0f km", distance);
124 else if (distance >= 10)
125 sprintf(buffer,"%.1f km", distance);
127 sprintf(buffer,"%.2f km", distance);
129 comp->gr->draw_text(comp->gr, comp->green, NULL, comp->font, buffer, &p, 0x10000, 0);
132 comp->gr->draw_mode(comp->gr, draw_mode_end);
136 compass_new(struct container *co)
138 struct compass *this=g_new0(struct compass, 1);
142 this->gr=co->gra->overlay_new(co->gra, &p, 60, 80);
143 this->bg=this->gr->gc_new(this->gr);
144 this->gr->gc_set_foreground(this->bg, 0, 0, 0);
145 this->white=this->gr->gc_new(this->gr);
146 this->gr->gc_set_foreground(this->white, 0xffff, 0xffff, 0xffff);
147 this->gr->gc_set_linewidth(this->white, 2);
148 this->green=this->gr->gc_new(this->gr);
149 this->gr->gc_set_foreground(this->green, 0x0, 0xffff, 0x0);
150 this->gr->gc_set_linewidth(this->green, 2);
152 this->font=this->gr->font_new(this->gr, 200);
153 compass_draw(this, co);