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

Contents of /navit/navit/compass.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 3891 byte(s)
import files
1 /**
2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
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 #include <math.h>
21 #include <stdio.h>
22 #include <glib.h>
23 #include "point.h"
24 #include "coord.h"
25 #include "graphics.h"
26 #include "transform.h"
27 #include "item.h"
28 #include "route.h"
29 #include "vehicle.h"
30 #include "navit.h"
31 #include "compass.h"
32
33 #if 0
34 struct compass {
35 struct graphics *gr;
36 struct graphics_gc *bg;
37 struct graphics_gc *white;
38 struct graphics_gc *green;
39 struct graphics_font *font;
40 };
41
42 static void
43 transform_rotate(struct point *center, int angle, struct point *p, int count)
44 {
45 int i,x,y;
46 double dx,dy;
47 for (i = 0 ; i < count ; i++)
48 {
49 dx=sin(M_PI*angle/180.0);
50 dy=cos(M_PI*angle/180.0);
51 x=dy*p->x-dx*p->y;
52 y=dx*p->x+dy*p->y;
53
54 p->x=center->x+x;
55 p->y=center->y+y;
56 p++;
57 }
58 }
59
60 static void
61 handle(struct graphics *gr, struct graphics_gc *gc, struct point *p, int r, int dir)
62 {
63 struct point ph[3];
64 int l=r*0.4;
65
66 ph[0].x=0;
67 ph[0].y=r;
68 ph[1].x=0;
69 ph[1].y=-r;
70 transform_rotate(p, dir, ph, 2);
71 gr->draw_lines(gr, gc, ph, 2);
72 ph[0].x=-l;
73 ph[0].y=-r+l;
74 ph[1].x=0;
75 ph[1].y=-r;
76 ph[2].x=l;
77 ph[2].y=-r+l;
78 transform_rotate(p, dir, ph, 3);
79 gr->draw_lines(gr, gc, ph, 3);
80 }
81
82 void
83 compass_draw(struct compass *comp, struct container *co)
84 {
85 struct point p;
86 struct coord *pos, *dest;
87 double *vehicle_dir,dir,distance;
88 int dx,dy;
89 char buffer[16];
90
91 if (! co->vehicle)
92 return;
93
94 vehicle_dir=vehicle_dir_get(co->vehicle);
95 comp->gr->draw_mode(comp->gr, draw_mode_begin);
96 p.x=0;
97 p.y=0;
98 comp->gr->draw_rectangle(comp->gr, comp->bg, &p, 60, 80);
99 p.x=30;
100 p.y=30;
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);
104 else
105 handle(comp->gr, comp->white, &p, 20, -*vehicle_dir);
106 #if 0 /* FIXME */
107 dest=route_get_destination(co->route);
108 if (dest) {
109 pos=vehicle_pos_get(co->vehicle);
110 dx=dest->x-pos->x;
111 dy=dest->y-pos->y;
112 dir=atan2(dx,dy)*180.0/M_PI;
113 #if 0
114 printf("dx %d dy %d dir=%f vehicle_dir=%f\n", dx, dy, dir, *vehicle_dir);
115 #endif
116 if (! co->flags->orient_north)
117 dir-=*vehicle_dir;
118 handle(comp->gr, comp->green, &p, 20, dir);
119 p.x=8;
120 p.y=72;
121 distance=transform_distance(projection_mg, pos, dest)/1000.0;
122 if (distance >= 100)
123 sprintf(buffer,"%.0f km", distance);
124 else if (distance >= 10)
125 sprintf(buffer,"%.1f km", distance);
126 else
127 sprintf(buffer,"%.2f km", distance);
128
129 comp->gr->draw_text(comp->gr, comp->green, NULL, comp->font, buffer, &p, 0x10000, 0);
130 }
131 #endif
132 comp->gr->draw_mode(comp->gr, draw_mode_end);
133 }
134
135 struct compass *
136 compass_new(struct container *co)
137 {
138 struct compass *this=g_new0(struct compass, 1);
139 struct point p;
140 p.x=10;
141 p.y=10;
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);
151
152 this->font=this->gr->font_new(this->gr, 200);
153 compass_draw(this, co);
154 return this;
155 }
156 #endif

   
Visit the ZANavi Wiki