1 
2 #include <string.h>
3 #include <glib.h>
4 #include <glib/gprintf.h>
5 #include "support.h"
6 #include "converter.h"
7 #include "callbacks.h"
8 #include "wp.h"
9 #include "globals.h"
10 
11 static GdkPixbuf	*wp_icon = NULL;
12 static GdkPixbuf	*myposition_icon = NULL;
13 static GdkGC		*gc_map = NULL;
14 
15 
16 
17 void
18 do_paint_myposition();
19 
20 
21 
22 void
set_current_wp(double lat,double lon)23 set_current_wp(double lat, double lon)
24 {
25 	global_wp_on = TRUE;
26 	global_wp.lat = lat;
27 	global_wp.lon = lon;
28 
29 
30 	repaint_all();
31 }
32 
33 
34 
35 GdkPixbuf *
load_wp_icon()36 load_wp_icon ()
37 {
38 	GdkPixbuf *wp_icon = NULL;
39 	GError *error = NULL;
40 
41 	wp_icon = gdk_pixbuf_new_from_file_at_size (
42 			PACKAGE_PIXMAPS_DIR "/foxtrotgps-wp.png", 36, 36,
43 			&error);
44 	if (error)
45 	{
46 		g_print ("%s%s(): loading pixbuf failure. %s\n", __FUNCTION__,__FILE__,
47 		         error->message);
48 		g_error_free (error);
49 	}
50 
51 	return wp_icon;
52 }
53 
54 void
paint_wp()55 paint_wp()
56 {
57 	if(global_wp_on) do_paint_wp();
58 }
59 
60 void
do_paint_wp()61 do_paint_wp()
62 {
63 	int pixel_x, pixel_y, x,y;
64 	float lat, lon;
65 	GdkColor color;
66 	GdkGC *gc;
67 
68 	gc = gdk_gc_new(pixmap);
69 	color.green = 60000;
70 	color.blue = 0;
71 	color.red = 10000;
72 	gdk_gc_set_rgb_fg_color(gc, &color);
73 
74 
75 	if(!wp_icon)
76 		wp_icon = load_wp_icon ();
77 
78 	if (pixmap && !gc_map)
79 		gc_map = gdk_gc_new(pixmap);
80 
81 	lat = global_wp.lat;
82 	lon = global_wp.lon;
83 
84 
85 
86 
87 	pixel_x = lon2pixel(global_zoom, lon);
88 	pixel_y = lat2pixel(global_zoom, lat);
89 
90 	x = pixel_x - global_x;
91 	y = pixel_y - global_y;
92 
93 
94 
95 	if(!wp_icon)
96 	{
97 		gdk_draw_arc (
98 			pixmap,
99 
100 			gc,
101 			TRUE,
102 			x-4, y-4,
103 			8,8,
104 			0,23040);
105 	}
106 	else
107 	{
108 		gdk_draw_pixbuf (
109 			pixmap,
110 			gc_map,
111 			wp_icon,
112 			0,0,
113 			x,y-36,
114 			36,36,
115 			GDK_RGB_DITHER_NONE, 0, 0);
116 
117 		gtk_widget_queue_draw_area (
118 			map_drawable,
119 			x, y-36,
120 			36,36);
121 	}
122 }
123 
124 
125 
126 
127 void
osd_wp()128 osd_wp()
129 {
130 	PangoContext		*context = NULL;
131 	PangoLayout		*layout  = NULL;
132 	PangoFontDescription	*desc    = NULL;
133 
134 	GdkColor color;
135 	GdkGC *gc;
136 
137 	gchar *buffer;
138 	static gchar distunit[3];
139 
140 
141 	static int width = 0, height = 0;
142 
143 	float distance;
144 	double unit_conv = 1;
145 
146 	if(gpsdata && mouse_dx == 0 && mouse_dy == 0)
147 	{
148 		switch (global_speed_unit)
149 		{
150 			case 0:
151 				unit_conv = 1.0;
152 				g_sprintf(distunit, "%s", "km");
153 				break;
154 			case 1 :
155 				unit_conv = 1.0 / 1.609344;
156 				g_sprintf(distunit, "%s", "m");
157 				break;
158 			case 2 :
159 				unit_conv = 1.0 / 1.852;
160 				g_sprintf(distunit, "%s", "NM");
161 				break;
162 		}
163 
164 
165 		distance = get_distance(deg2rad(gpsdata->fix.latitude),
166 					deg2rad(gpsdata->fix.longitude),
167 					global_wp.lat,global_wp.lon);
168 		buffer = g_strdup_printf("%.3f\n%.1f°",
169 					distance*unit_conv,
170 
171 					rad2deg(gpsdata->fix.bearing));
172 
173 
174 		context = gtk_widget_get_pango_context (map_drawable);
175 		layout  = pango_layout_new (context);
176 		desc    = pango_font_description_new();
177 
178 		pango_font_description_set_size (desc, 20 * PANGO_SCALE);
179 		pango_layout_set_font_description (layout, desc);
180 		pango_layout_set_text (layout, buffer, strlen(buffer));
181 
182 
183 		gc = gdk_gc_new (map_drawable->window);
184 
185 
186 		color.red = 0;
187 		color.green = 0;
188 		color.blue = 0;
189 
190 		gdk_gc_set_rgb_fg_color (gc, &color);
191 
192 
193 
194 
195 
196 
197 		gdk_draw_drawable (
198 			map_drawable->window,
199 			map_drawable->style->fg_gc[GTK_WIDGET_STATE (map_drawable)],
200 			pixmap,
201 			global_drawingarea_width - width - 10,
202 			global_drawingarea_height - height - 10,
203 			global_drawingarea_width - width - 10,
204 			global_drawingarea_height - height - 10,
205 			width+10,height+10);
206 
207 
208 
209 		pango_layout_get_pixel_size(layout, &width, &height);
210 
211 
212 
213 			gdk_draw_layout(map_drawable->window,
214 					gc,
215 					global_drawingarea_width - width - 10,
216 					global_drawingarea_height - height -10,
217 					layout);
218 
219 
220 
221 
222 		g_free(buffer);
223 		pango_font_description_free (desc);
224 		g_object_unref (layout);
225 		g_object_unref (gc);
226 	}
227 }
228 
229 
230 
231 
232 
233 void
paint_myposition()234 paint_myposition()
235 {
236 	if(global_myposition.lat) do_paint_myposition();
237 }
238 
239 void
do_paint_myposition()240 do_paint_myposition()
241 {
242 	int pixel_x, pixel_y, x,y;
243 	float lat, lon;
244 	GdkColor color;
245 	GdkGC *gc;
246 	GError	*error = NULL;
247 
248 	gc = gdk_gc_new(pixmap);
249 	color.green = 60000;
250 	color.blue = 0;
251 	color.red = 10000;
252 	gdk_gc_set_rgb_fg_color(gc, &color);
253 
254 
255 	if(!myposition_icon)
256 	{
257 		myposition_icon = gdk_pixbuf_new_from_file_at_size (
258 			PACKAGE_PIXMAPS_DIR "/" PACKAGE "-myposition.png", 36,36,
259 			&error);
260 		if (error)
261 		{
262 			g_print ("%s(): loading pixbuf failure. %s\n", __FUNCTION__,
263 			error->message);
264 			g_error_free (error);
265 
266 
267 		}
268 	}
269 	if (pixmap && !gc_map)
270 		gc_map = gdk_gc_new(pixmap);
271 
272 	lat = deg2rad(global_myposition.lat);
273 	lon = deg2rad(global_myposition.lon);
274 
275 
276 
277 
278 	pixel_x = lon2pixel(global_zoom, lon);
279 	pixel_y = lat2pixel(global_zoom, lat);
280 
281 	x = pixel_x - global_x;
282 	y = pixel_y - global_y;
283 
284 	if(!myposition_icon)
285 	{
286 		gdk_draw_arc (
287 			pixmap,
288 
289 			gc,
290 			TRUE,
291 			x-4, y-4,
292 			8,8,
293 			0,23040);
294 	}
295 	else
296 	{
297 		gdk_draw_pixbuf (
298 			pixmap,
299 			gc_map,
300 			myposition_icon,
301 			0,0,
302 			x,y-36,
303 			36,36,
304 			GDK_RGB_DITHER_NONE, 0, 0);
305 
306 		gtk_widget_queue_draw_area (
307 			map_drawable,
308 			x, y-36,
309 			36,36);
310 	}
311 }
312