~foxtrotgps-team/foxtrotgps/trunk

« back to all changes in this revision

Viewing changes to src/wp.c

  • Committer: Joshua Judson Rosen
  • Date: 2009-09-26 02:35:15 UTC
  • Revision ID: rozzin@geekspace.com-20090926023515-yxl5sg1a45gupuc8
Imported from tangogps-0.9.7 tarball.

Show diffs side-by-side

added added

removed removed

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