~foxtrotgps-team/foxtrotgps/trunk

« back to all changes in this revision

Viewing changes to src/map_management.c

  • Committer: Paul Wise
  • Date: 2018-03-06 03:32:21 UTC
  • Revision ID: pabs3@bonedaddy.net-20180306033221-lzyia8y0cpw95j1b
Remove trailing whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
hash_sieve_func (gpointer key, gpointer value, gpointer user_data)
52
52
{
53
53
        gboolean remove = TRUE;
54
 
        
 
54
 
55
55
        tile_hash_t *tile_hash = value;
56
 
        
 
56
 
57
57
        if(tile_hash->reused)
58
58
        {
59
59
                tile_hash->reused = FALSE;
84
84
        repo_t          *repo;
85
85
        tile_hash_t     *tile_hash;
86
86
 
87
 
        
 
87
 
88
88
        if(gc_map)
89
89
                g_object_unref(gc_map);
90
90
        if(pixmap)
98
98
 
99
99
        g_snprintf(wanted_filename, 255, "%s/%u/%u/%u.png", dir, zoom, x, y);
100
100
        tile_hash = g_hash_table_lookup(hash_table, wanted_filename);
101
 
        
 
101
 
102
102
        if(tile_hash)
103
103
        {
104
104
                pixbuf = tile_hash->pixbuf;
105
 
                
 
105
 
106
106
                tile_hash->reused = TRUE;
107
107
                hash_not_found    = FALSE;
108
108
        }
109
 
        
 
109
 
110
110
        else
111
111
        {
112
 
                
 
112
 
113
113
                for(overzoom=0; overzoom<=3; overzoom++)
114
114
                {
115
115
                        g_snprintf(filename, 255, "%s/%u/%u/%u.png", dir, zoom-overzoom, x/upscale, y/upscale);
116
 
        
 
116
 
117
117
                        pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
118
 
        
 
118
 
119
119
                        if(pixbuf)
120
120
                                break;
121
 
        
 
121
 
122
122
                        upscale *= 2;
123
123
                }
124
 
                
 
124
 
125
125
                if(pixbuf && upscale > 1)
126
126
                {
127
127
                        GdkPixbuf       *pixbuf_scaled  = NULL;
128
 
                        pixbuf_scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 256, 256); 
129
 
        
 
128
                        pixbuf_scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 256, 256);
 
129
 
130
130
                        gdk_pixbuf_scale (      pixbuf, pixbuf_scaled,
131
131
                                                0, 0,
132
132
                                                TILESIZE, TILESIZE,
141
141
                        pixbuf = pixbuf_scaled;
142
142
                }
143
143
        }
144
 
        
 
144
 
145
145
        if(!pixbuf)
146
146
        {
147
 
                
 
147
 
148
148
                GtkWidget *widget;
149
 
                        
 
149
 
150
150
                widget = lookup_widget(window1, "drawingarea1");
151
 
                        
 
151
 
152
152
                gdk_draw_rectangle (
153
153
                        pixmap,
154
154
                        widget->style->white_gc,
156
156
                        offset_x, offset_y,
157
157
                        256,
158
158
                        256);
159
 
                                                
 
159
 
160
160
                gtk_widget_queue_draw_area (
161
161
                        widget,
162
162
                        offset_x,offset_y,256,256);
163
163
        }
164
 
        
 
164
 
165
165
        else
166
166
        {
167
 
                
 
167
 
168
168
                gdk_draw_pixbuf (
169
169
                        pixmap,
170
170
                        gc_map,
174
174
                        TILESIZE,TILESIZE,
175
175
                        GDK_RGB_DITHER_NONE, 0, 0);
176
176
 
177
 
                
 
177
 
178
178
                if(hash_not_found)
179
179
                {
180
180
                        tile_hash = g_new0(tile_hash_t,1);
181
181
                        tile_hash->pixbuf = pixbuf;
182
182
                        tile_hash->reused = TRUE;
183
 
        
 
183
 
184
184
                        g_hash_table_insert(hash_table, g_strdup(wanted_filename), tile_hash);
185
185
                }
186
186
        }
187
187
 
188
 
        
 
188
 
189
189
        drawingarea11 = lookup_widget(window1, "drawingarea1");
190
 
        
 
190
 
191
191
        gtk_widget_queue_draw_area (
192
 
                drawingarea11, 
 
192
                drawingarea11,
193
193
                offset_x,offset_y,
194
194
                TILESIZE,TILESIZE);
195
195
 
197
197
        {
198
198
                repo = global_curr_repo->data;
199
199
                download_tile(repo,zoom,x/detail_scale,y/detail_scale);
200
 
        }       
 
200
        }
201
201
}
202
202
 
203
203
 
217
217
        int offset_y;
218
218
        gboolean success = FALSE;
219
219
        repo_t *repo = global_curr_repo->data;
220
 
        
221
 
        
 
220
 
 
221
 
222
222
        if (!hash_table)
223
223
        {
224
224
                hash_table = g_hash_table_new_full (g_str_hash,
226
226
                                                    hash_destroy_key_func,
227
227
                                                    hash_destroy_value_func);
228
228
        }
229
 
        
 
229
 
230
230
        if(force_refresh)
231
231
        {
232
 
                g_hash_table_remove_all(hash_table);    
 
232
                g_hash_table_remove_all(hash_table);
233
233
        }
234
 
        
 
234
 
235
235
        widget = lookup_widget(window1,"drawingarea1");
236
 
        
237
 
 
238
 
        
239
 
        max_pixel = (int) exp2(zoom) * TILESIZE; 
 
236
 
 
237
 
 
238
 
 
239
        max_pixel = (int) exp2(zoom) * TILESIZE;
240
240
 
241
241
        if(pixel_x < 0)
242
242
                pixel_x += max_pixel;
243
 
        
 
243
 
244
244
        else if (pixel_x > max_pixel)
245
 
                pixel_x -= max_pixel;   
246
 
 
247
 
        
 
245
                pixel_x -= max_pixel;
 
246
 
 
247
 
248
248
        offset_x = - pixel_x % TILESIZE;
249
249
        offset_y = - pixel_y % TILESIZE;
250
250
        if (offset_x > 0) offset_x -= 256;
251
251
        if (offset_y > 0) offset_y -= 256;
252
 
        
 
252
 
253
253
        global_x = pixel_x;
254
254
        global_y = pixel_y;
255
255
        global_zoom = zoom;
256
 
        
257
 
        offset_xn = offset_x; 
 
256
 
 
257
        offset_xn = offset_x;
258
258
        offset_yn = offset_y;
259
259
 
260
260
        width  = map_drawable->allocation.width;
262
262
 
263
263
        tiles_nx = floor((width  - offset_x) / TILESIZE) + 1;
264
264
        tiles_ny = floor((height - offset_y) / TILESIZE) + 1;
265
 
        
 
265
 
266
266
        tile_x0 =  floor((float)pixel_x / (float)TILESIZE);
267
267
        tile_y0 =  floor((float)pixel_y / (float)TILESIZE);
268
 
        
269
 
        
 
268
 
 
269
 
270
270
 
271
271
        for (i=tile_x0; i<(tile_x0+tiles_nx); i++)
272
272
        {
273
273
                for (j=tile_y0;  j<(tile_y0+tiles_ny); j++)
274
274
                {
275
 
                        
276
 
                        
277
 
 
278
 
                        
 
275
 
 
276
 
 
277
 
 
278
 
279
279
                        if(j<0 || j>=exp2(zoom))
280
280
                        {
281
281
                                gdk_draw_rectangle (
285
285
                                        offset_xn, offset_yn,
286
286
                                        TILESIZE,
287
287
                                        TILESIZE);
288
 
                                
 
288
 
289
289
                                gtk_widget_queue_draw_area (
290
 
                                        widget, 
 
290
                                        widget,
291
291
                                        offset_xn,offset_yn,
292
292
                                        TILESIZE,TILESIZE);
293
293
                        }
294
294
                        else
295
 
                        {       
 
295
                        {
296
296
                                i_corrected = (i>=exp2(zoom)) ? i-exp2(zoom) : i;
297
 
                                
 
297
 
298
298
                                load_tile(
299
299
                                        repo->dir,
300
300
                                        zoom,
307
307
                offset_yn = offset_y;
308
308
        }
309
309
 
310
 
        
 
310
 
311
311
        g_hash_table_foreach_remove (hash_table, hash_sieve_func, NULL);
312
 
        
313
 
        
 
312
 
 
313
 
314
314
        success = g_settings_set_int(
315
 
                                global_settings, 
 
315
                                global_settings,
316
316
                                "global-x",
317
317
                                global_x);
318
318
        success = g_settings_set_int(
319
 
                                global_settings, 
 
319
                                global_settings,
320
320
                                "global-y",
321
321
                                global_y);
322
322
        success = g_settings_set_int(
323
 
                                global_settings, 
 
323
                                global_settings,
324
324
                                "global-zoom",
325
325
                                global_zoom);
326
326
}
331
331
                        int zoom)
332
332
{
333
333
        int pixel_x, pixel_y;
334
 
        
335
 
        
 
334
 
 
335
 
336
336
        pixel_x = lon2pixel(zoom, lon);
337
337
 
338
338
        pixel_y = lat2pixel(zoom, lat);
346
346
                int zoom)
347
347
{
348
348
        int pixel_x, pixel_y;
349
 
        
 
349
 
350
350
        lat = deg2rad(lat);
351
351
        lon = deg2rad(lon);
352
 
        
353
 
        
 
352
 
 
353
 
354
354
        pixel_x = lon2pixel(zoom, lon);
355
355
        pixel_y = lat2pixel(zoom, lat);
356
356
 
357
 
        
 
357
 
358
358
        osd_speed(TRUE);
359
 
        fill_tiles_pixel (      pixel_x - global_drawingarea_width/2, 
 
359
        fill_tiles_pixel (      pixel_x - global_drawingarea_width/2,
360
360
                                pixel_y - global_drawingarea_height/2,
361
361
                                zoom, FALSE);
362
362
        paint_track();