1 |
/* |
/* |
2 |
* Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
* Copyright (C) 2008-2009 Till Harbaum <till@harbaum.org>. |
3 |
* |
* |
4 |
* This file is part of GPXView. |
* This file is part of GPXView. |
5 |
* |
* |
18 |
*/ |
*/ |
19 |
|
|
20 |
#include "gpxview.h" |
#include "gpxview.h" |
21 |
|
#include "converter.h" |
22 |
#include <math.h> // for isnan |
#include <math.h> // for isnan |
23 |
|
|
24 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
25 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
26 |
#endif |
#endif |
27 |
|
|
28 |
/* equatorial radius in meters */ |
#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENSTREETMAP |
29 |
#define EQ_RADIUS (6378137.0) |
#define GPS_DEFAULT_ZOOM 13 |
|
|
|
|
#define RAD2DEG(a) (((a)*180.0)/M_PI) |
|
|
#define DEG2RAD(a) (((a)*M_PI)/180.0) |
|
|
|
|
|
typedef struct { |
|
|
appdata_t *appdata; |
|
|
GtkWidget *widget; |
|
|
GtkWidget *zoomin, *zoomout, *gps; |
|
|
gint handler_id; |
|
|
cache_t *press_on; |
|
|
#if MAEMO_VERSION_MAJOR == 5 |
|
|
GtkWidget *old_view; |
|
|
#endif |
|
|
} map_context_t; |
|
30 |
|
|
31 |
#define PROXY_KEY "/system/http_proxy/" |
#define PROXY_KEY "/system/http_proxy/" |
32 |
|
|
67 |
} |
} |
68 |
|
|
69 |
static void map_zoom(map_context_t *context, int step) { |
static void map_zoom(map_context_t *context, int step) { |
70 |
int zoom; |
gint zoom; |
71 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
72 |
g_object_get(map, "zoom", &zoom, NULL); |
g_object_get(map, "zoom", &zoom, NULL); |
73 |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
74 |
|
|
75 |
/* enable/disable zoom buttons as required */ |
/* enable/disable zoom buttons as required */ |
76 |
gtk_widget_set_sensitive(context->zoomin, zoom<17); |
gtk_widget_set_sensitive(context->zoomin, |
77 |
gtk_widget_set_sensitive(context->zoomout, zoom>1); |
zoom < osm_gps_map_source_get_max_zoom(MAP_SOURCE)); |
78 |
|
gtk_widget_set_sensitive(context->zoomout, |
79 |
|
zoom > osm_gps_map_source_get_min_zoom(MAP_SOURCE)); |
80 |
|
|
81 |
|
/* save new zoom */ |
82 |
|
context->appdata->map.zoom = zoom; |
83 |
} |
} |
84 |
|
|
85 |
static gboolean |
static gboolean |
99 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
100 |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
101 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
102 |
refpos->lat, refpos->lon, 14); |
refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); |
103 |
} else { |
} else { |
104 |
/* no coordinates given: display the entire world */ |
/* no coordinates given: display the entire world */ |
105 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
110 |
} |
} |
111 |
|
|
112 |
static GtkWidget |
static GtkWidget |
113 |
*map_add_button(const gchar *icon, GCallback cb, gpointer data, |
*map_add_button(int icon, GCallback cb, gpointer data, |
114 |
char *tooltip) { |
char *tooltip) { |
115 |
GtkWidget *button = gtk_button_new(); |
GtkWidget *button = gtk_button_new(); |
116 |
gtk_button_set_image(GTK_BUTTON(button), |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, icon)); |
|
gtk_image_new_from_stock(icon, GTK_ICON_SIZE_BUTTON)); |
|
117 |
g_signal_connect(button, "clicked", cb, data); |
g_signal_connect(button, "clicked", cb, data); |
118 |
#ifndef USE_MAEMO |
#ifndef USE_MAEMO |
119 |
gtk_widget_set_tooltip_text(button, tooltip); |
gtk_widget_set_tooltip_text(button, tooltip); |
121 |
return button; |
return button; |
122 |
} |
} |
123 |
|
|
124 |
|
static int dist2pixel(map_context_t *context, float km, float lat) { |
125 |
|
return 1000.0*km/osm_gps_map_get_scale(OSM_GPS_MAP(context->widget)); |
126 |
|
} |
127 |
|
|
128 |
static gboolean map_gps_update(gpointer data) { |
static gboolean map_gps_update(gpointer data) { |
129 |
map_context_t *context = (map_context_t*)data; |
map_context_t *context = (map_context_t*)data; |
130 |
|
|
131 |
|
/* get reference position ... */ |
132 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
133 |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
134 |
|
|
135 |
/* get reference position and go there */ |
/* ... and enable "goto" button if it's valid */ |
136 |
gtk_widget_set_sensitive(context->gps, ok); |
gtk_widget_set_sensitive(context->gps, ok); |
137 |
|
|
138 |
|
if(ok) { |
139 |
|
float heading = NAN; |
140 |
|
int radius = 0; |
141 |
|
|
142 |
|
if(context->appdata->use_gps) { |
143 |
|
heading = gps_get_heading(context->appdata); |
144 |
|
|
145 |
|
/* get error */ |
146 |
|
float eph = gps_get_eph(context->appdata); |
147 |
|
if(!isnan(eph)) |
148 |
|
radius = dist2pixel(context, eph/1000, refpos->lat); |
149 |
|
} |
150 |
|
|
151 |
|
g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL); |
152 |
|
osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget), |
153 |
|
refpos->lat, refpos->lon, heading); |
154 |
|
} else |
155 |
|
osm_gps_map_clear_gps(OSM_GPS_MAP(context->widget)); |
156 |
|
|
157 |
return TRUE; |
return TRUE; |
158 |
} |
} |
159 |
|
|
161 |
GdkEventConfigure *event, |
GdkEventConfigure *event, |
162 |
map_context_t *context) { |
map_context_t *context) { |
163 |
|
|
164 |
cb_map_gps(NULL, context); |
/* set default values if they are invalid */ |
165 |
|
if(!context->appdata->map.zoom || |
166 |
|
isnan(context->appdata->map.pos.lat) || |
167 |
|
isnan(context->appdata->map.pos.lon)) { |
168 |
|
printf("no valid map position found\n"); |
169 |
|
|
170 |
|
pos_t *refpos = get_pos(context->appdata); |
171 |
|
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
172 |
|
/* use gps position if present */ |
173 |
|
context->appdata->map.pos = *refpos; |
174 |
|
context->appdata->map.zoom = GPS_DEFAULT_ZOOM; |
175 |
|
} else { |
176 |
|
/* use world map otherwise */ |
177 |
|
context->appdata->map.pos.lat = 0.0; |
178 |
|
context->appdata->map.pos.lon = 0.0; |
179 |
|
context->appdata->map.zoom = 1; |
180 |
|
} |
181 |
|
} |
182 |
|
|
183 |
|
/* jump to initial position */ |
184 |
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
185 |
|
context->appdata->map.pos.lat, |
186 |
|
context->appdata->map.pos.lon, |
187 |
|
context->appdata->map.zoom); |
188 |
|
|
189 |
return FALSE; |
return FALSE; |
190 |
} |
} |
191 |
|
|
200 |
} |
} |
201 |
} |
} |
202 |
|
|
|
/* draw a nice popup */ |
|
|
typedef struct { |
|
|
appdata_t *appdata; |
|
|
GtkWidget *window; |
|
|
GMainLoop *loop; |
|
|
} popup_context_t; |
|
|
|
|
|
|
|
|
#ifndef USE_HILDON |
|
|
#define POPUP_WIDTH 300 |
|
|
#define POPUP_HEIGHT 100 |
|
|
#else |
|
|
#define POPUP_WIDTH 600 |
|
|
#define POPUP_HEIGHT 200 |
|
|
#endif |
|
|
|
|
|
static gboolean |
|
|
pointer_in_window(GtkWidget *widget, gint x_root, gint y_root) { |
|
|
if(GTK_WIDGET_MAPPED(gtk_widget_get_toplevel(widget))) { |
|
|
gint window_x, window_y; |
|
|
|
|
|
gdk_window_get_position(gtk_widget_get_toplevel(widget)->window, |
|
|
&window_x, &window_y); |
|
|
|
|
|
if(x_root >= window_x && x_root < window_x + widget->allocation.width && |
|
|
y_root >= window_y && y_root < window_y + widget->allocation.height) |
|
|
return TRUE; |
|
|
} |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
on_button_press_event(GtkWidget *widget, |
|
|
GdkEventButton *event, popup_context_t *context) { |
|
|
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
|
|
|
|
|
printf("overlay button press (in = %d)\n", in); |
|
|
return !in; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
on_button_release_event(GtkWidget *widget, |
|
|
GdkEventButton *event, popup_context_t *context) { |
|
|
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
|
|
|
|
|
printf("overlay button release (in = %d)\n", in); |
|
|
|
|
|
if(!in) { |
|
|
printf("destroying popup\n"); |
|
|
gtk_widget_destroy(gtk_widget_get_toplevel(widget)); |
|
|
} |
|
|
|
|
|
return !in; |
|
|
} |
|
|
|
|
|
static void |
|
|
shutdown_loop(popup_context_t *context) { |
|
|
if(g_main_loop_is_running(context->loop)) |
|
|
g_main_loop_quit(context->loop); |
|
|
} |
|
|
|
|
|
static gint |
|
|
run_delete_handler(GtkWindow *window, GdkEventAny *event, |
|
|
popup_context_t *context) { |
|
|
shutdown_loop(context); |
|
|
return TRUE; /* Do not destroy */ |
|
|
} |
|
|
|
|
|
static void |
|
|
run_destroy_handler(GtkWindow *window, popup_context_t *context) { |
|
|
/* shutdown_loop will be called by run_unmap_handler */ |
|
|
printf("popup destroyed\n"); |
|
|
} |
|
|
|
|
|
static void |
|
|
run_unmap_handler(GtkWindow *window, popup_context_t *context) { |
|
|
shutdown_loop(context); |
|
|
} |
|
|
|
|
|
/* draw shape */ |
|
|
#define ARROW_BORDER 20 |
|
|
#define CORNER_RADIUS 10 |
|
|
|
|
|
static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) { |
|
|
GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1); |
|
|
|
|
|
GdkGC *gc = gdk_gc_new(mask); |
|
|
GdkColormap *colormap; |
|
|
GdkColor black; |
|
|
GdkColor white; |
|
|
|
|
|
/* get black/white color values */ |
|
|
colormap = gdk_colormap_get_system(); |
|
|
gdk_color_black(colormap, &black); |
|
|
gdk_color_white(colormap, &white); |
|
|
|
|
|
/* erase */ |
|
|
gdk_gc_set_foreground(gc, &black); |
|
|
gdk_gc_set_background(gc, &white); |
|
|
|
|
|
/* erase background */ |
|
|
gdk_draw_rectangle(mask, gc, TRUE, 0, 0, POPUP_WIDTH, POPUP_HEIGHT); |
|
|
|
|
|
gdk_gc_set_foreground(gc, &white); |
|
|
gdk_gc_set_background(gc, &black); |
|
|
|
|
|
gdk_draw_rectangle(mask, gc, TRUE, |
|
|
0, ARROW_BORDER + CORNER_RADIUS, |
|
|
POPUP_WIDTH, |
|
|
POPUP_HEIGHT - 2*CORNER_RADIUS - 2*ARROW_BORDER); |
|
|
|
|
|
gdk_draw_rectangle(mask, gc, TRUE, |
|
|
CORNER_RADIUS, ARROW_BORDER, |
|
|
POPUP_WIDTH - 2*CORNER_RADIUS, |
|
|
POPUP_HEIGHT - 2*ARROW_BORDER); |
|
|
|
|
|
int off[][2] = { |
|
|
{ CORNER_RADIUS, ARROW_BORDER + CORNER_RADIUS }, |
|
|
{ POPUP_WIDTH - CORNER_RADIUS, |
|
|
ARROW_BORDER + CORNER_RADIUS }, |
|
|
{ POPUP_WIDTH - CORNER_RADIUS, |
|
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER }, |
|
|
{ CORNER_RADIUS, |
|
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER}}; |
|
|
|
|
|
int i; |
|
|
for(i=0;i<4;i++) { |
|
|
gdk_draw_arc(mask, gc, TRUE, |
|
|
off[i][0]-CORNER_RADIUS, off[i][1]-CORNER_RADIUS, |
|
|
2*CORNER_RADIUS, 2*CORNER_RADIUS, |
|
|
0, 360*64); |
|
|
} |
|
|
|
|
|
GdkPoint points[3] = { {POPUP_WIDTH*1/3, POPUP_HEIGHT/2}, |
|
|
{POPUP_WIDTH*2/3, POPUP_HEIGHT/2}, |
|
|
{tip_x,tip_y} }; |
|
|
gdk_draw_polygon(mask, gc, TRUE, points, 3); |
|
|
|
|
|
|
|
|
gdk_window_shape_combine_mask(window->window, mask, 0, 0); |
|
|
} |
|
|
|
|
|
void cache_popup(map_context_t *mcontext, cache_t *cache) { |
|
|
popup_context_t pcontext; |
|
|
pcontext.appdata = mcontext->appdata; |
|
|
|
|
|
pcontext.window = gtk_window_new(GTK_WINDOW_POPUP); |
|
|
gtk_widget_realize(pcontext.window); |
|
|
gtk_window_set_default_size(GTK_WINDOW(pcontext.window), |
|
|
POPUP_WIDTH, POPUP_HEIGHT); |
|
|
gtk_window_resize(GTK_WINDOW(pcontext.window), POPUP_WIDTH, POPUP_HEIGHT); |
|
|
// gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE); |
|
|
gtk_window_set_transient_for(GTK_WINDOW(pcontext.window), |
|
|
GTK_WINDOW(mcontext->appdata->window)); |
|
|
gtk_window_set_keep_above(GTK_WINDOW(pcontext.window), TRUE); |
|
|
gtk_window_set_destroy_with_parent(GTK_WINDOW(pcontext.window), TRUE); |
|
|
gtk_window_set_gravity(GTK_WINDOW(pcontext.window), GDK_GRAVITY_STATIC); |
|
|
gtk_window_set_modal(GTK_WINDOW(pcontext.window), TRUE); |
|
|
|
|
|
/* connect events */ |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "button-press-event", |
|
|
G_CALLBACK(on_button_press_event), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "button-release-event", |
|
|
G_CALLBACK(on_button_release_event), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "delete-event", |
|
|
G_CALLBACK(run_delete_handler), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "destroy", |
|
|
G_CALLBACK(run_destroy_handler), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "unmap", |
|
|
G_CALLBACK(run_unmap_handler), &pcontext); |
|
|
|
|
|
gdk_pointer_grab(pcontext.window->window, TRUE, |
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK, |
|
|
NULL, NULL, GDK_CURRENT_TIME); |
|
|
gtk_grab_add(pcontext.window); |
|
|
|
|
|
/* check whether cache is in upper or lower half of window */ |
|
|
gint x, y, sx, sy; |
|
|
osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget), |
|
|
cache->pos.lat, cache->pos.lon, |
|
|
&sx, &sy); |
|
|
|
|
|
printf("screen pos %d/%d\n", sx, sy); |
|
|
|
|
|
gdk_window_get_origin(mcontext->widget->window, &x, &y); |
|
|
printf("window = %d/%d +%d+%d %d*%d\n", x, y, |
|
|
mcontext->widget->allocation.x, |
|
|
mcontext->widget->allocation.y, |
|
|
mcontext->widget->allocation.width, |
|
|
mcontext->widget->allocation.height |
|
|
); |
|
|
|
|
|
gint ax = 0, ay = 0; |
|
|
if(sx > mcontext->widget->allocation.width/2) |
|
|
ax = POPUP_WIDTH; |
|
|
|
|
|
if(sy > mcontext->widget->allocation.height/2) |
|
|
ay = POPUP_HEIGHT; |
|
|
|
|
|
#if !defined(USE_HILDON) || (MAEMO_VERSION_MAJOR < 5) |
|
|
GdkColor color; |
|
|
gdk_color_parse("darkgray", &color); |
|
|
gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color); |
|
|
#endif |
|
|
|
|
|
gtk_window_move(GTK_WINDOW(pcontext.window), |
|
|
x + mcontext->widget->allocation.x + sx - ax, |
|
|
y + mcontext->widget->allocation.y + sy - ay); |
|
|
|
|
|
|
|
|
GtkWidget *frame = gtk_frame_new(NULL); |
|
|
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); |
|
|
gtk_container_set_border_width(GTK_CONTAINER(frame), |
|
|
ARROW_BORDER+CORNER_RADIUS); |
|
|
gtk_container_add(GTK_CONTAINER(frame), |
|
|
gtk_button_new_with_label(cache->name)); |
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(pcontext.window), frame); |
|
|
|
|
|
/* --------- give the window its shape ----------- */ |
|
|
popup_window_shape(pcontext.window, ax, ay); |
|
|
|
|
|
gtk_widget_show_all(pcontext.window); |
|
|
|
|
|
/* handle this popup until it's gone */ |
|
|
|
|
|
pcontext.loop = g_main_loop_new(NULL, FALSE); |
|
|
|
|
|
GDK_THREADS_LEAVE(); |
|
|
g_main_loop_run(pcontext.loop); |
|
|
GDK_THREADS_ENTER(); |
|
|
|
|
|
g_main_loop_unref(pcontext.loop); |
|
|
|
|
|
printf("cache popup removed\n"); |
|
|
} |
|
|
|
|
203 |
static void |
static void |
204 |
map_cachelist_nearest(cache_t *cache, pos_t *pos, |
map_cachelist_nearest(cache_t *cache, pos_t *pos, |
205 |
cache_t **result, float *distance) { |
cache_t **result, float *distance) { |
243 |
/* translate between osm-gps-map positions and gpxview ones */ |
/* translate between osm-gps-map positions and gpxview ones */ |
244 |
pos_t coord2pos(coord_t coo) { |
pos_t coord2pos(coord_t coo) { |
245 |
pos_t pos; |
pos_t pos; |
246 |
pos.lat = RAD2DEG(coo.rlat); |
pos.lat = rad2deg(coo.rlat); |
247 |
pos.lon = RAD2DEG(coo.rlon); |
pos.lon = rad2deg(coo.rlon); |
248 |
return pos; |
return pos; |
249 |
} |
} |
250 |
|
|
251 |
static int dist2pixel(map_context_t *context, float km, float lat) { |
#define CLICK_FUZZ (24) |
|
int zoom; |
|
|
g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); |
|
|
|
|
|
/* world at zoom 1 == 512 pixels */ |
|
|
float m_per_pix = |
|
|
cos(DEG2RAD(lat))*2*M_PI*EQ_RADIUS/(1<<(8+zoom)); |
|
|
|
|
|
return 1000.0*km/m_per_pix; |
|
|
} |
|
|
|
|
|
#define CLICK_FUZZ (16) |
|
252 |
|
|
253 |
static gboolean |
static gboolean |
254 |
on_map_button_press_event(GtkWidget *widget, |
on_map_button_press_event(GtkWidget *widget, |
274 |
return FALSE; |
return FALSE; |
275 |
} |
} |
276 |
|
|
277 |
|
static void |
278 |
|
cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) { |
279 |
|
/* convert the pixbuf into something cairo can handle */ |
280 |
|
|
281 |
|
// Create a new ImageSurface |
282 |
|
cairo_surface_t *image_surface = |
283 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
284 |
|
gdk_pixbuf_get_width(buf), |
285 |
|
gdk_pixbuf_get_height(buf)); |
286 |
|
|
287 |
|
// Create the new Context for the ImageSurface |
288 |
|
cairo_t *context = cairo_create(image_surface); |
289 |
|
|
290 |
|
// Draw the image on the new Context |
291 |
|
gdk_cairo_set_source_pixbuf(context, buf, 0.0, 0.0); |
292 |
|
cairo_paint(context); |
293 |
|
|
294 |
|
// now draw this onto the original context |
295 |
|
cairo_set_source_surface(cr, image_surface, x, y); |
296 |
|
|
297 |
|
cairo_paint(cr); |
298 |
|
} |
299 |
|
|
300 |
|
#define LINE_SKIP 7 |
301 |
|
|
302 |
|
static void |
303 |
|
balloon_draw_cb(cairo_t *cr, OsmGpsMapRect_t *rect, gpointer data) { |
304 |
|
cache_t *cache = (cache_t*)data; |
305 |
|
|
306 |
|
// printf("draw cb for \"%s\"\n", cache->name); |
307 |
|
|
308 |
|
#if 0 |
309 |
|
/* draw pink background to check clipping */ |
310 |
|
cairo_rectangle (cr, rect->x-20, rect->y-20, rect->w+40, rect->h+40); |
311 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 0.3); |
312 |
|
cairo_fill_preserve (cr); |
313 |
|
cairo_set_line_width (cr, 0); |
314 |
|
cairo_stroke (cr); |
315 |
|
#endif |
316 |
|
|
317 |
|
/* leave a little border top and left */ |
318 |
|
gint x = rect->x, y = rect->y; |
319 |
|
|
320 |
|
/* draw the cache type icon ... */ |
321 |
|
GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); |
322 |
|
cairo_draw_pixbuf(cr, icon, x, y); |
323 |
|
|
324 |
|
/* ... and right of it the waypoint id */ |
325 |
|
cairo_text_extents_t extents; |
326 |
|
|
327 |
|
if(cache->id) { |
328 |
|
cairo_select_font_face (cr, "Sans", |
329 |
|
CAIRO_FONT_SLANT_NORMAL, |
330 |
|
CAIRO_FONT_WEIGHT_BOLD); |
331 |
|
|
332 |
|
cairo_set_font_size (cr, 20.0); |
333 |
|
cairo_text_extents (cr, cache->id, &extents); |
334 |
|
|
335 |
|
/* display id right of icon vertically centered */ |
336 |
|
x += gdk_pixbuf_get_width(icon) + 5; |
337 |
|
y += (gdk_pixbuf_get_height(icon) + extents.height)/2; |
338 |
|
cairo_move_to (cr, x, y); |
339 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
340 |
|
cairo_show_text (cr, cache->id); |
341 |
|
cairo_stroke (cr); |
342 |
|
|
343 |
|
y += (gdk_pixbuf_get_height(icon) - extents.height)/2 + LINE_SKIP; |
344 |
|
} else |
345 |
|
y += gdk_pixbuf_get_height(icon); |
346 |
|
|
347 |
|
/* return to the left border and below icon/text */ |
348 |
|
x = rect->x; |
349 |
|
|
350 |
|
/* everything from here uses the same font */ |
351 |
|
cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, |
352 |
|
CAIRO_FONT_WEIGHT_NORMAL); |
353 |
|
cairo_set_font_size (cr, 14.0); |
354 |
|
|
355 |
|
if(cache->name) { |
356 |
|
/* draw cache name */ |
357 |
|
cairo_text_extents (cr, cache->name, &extents); |
358 |
|
y += extents.height; |
359 |
|
cairo_move_to (cr, x, y); |
360 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
361 |
|
cairo_show_text (cr, cache->name); |
362 |
|
cairo_stroke (cr); |
363 |
|
|
364 |
|
/* return to the left border and below text */ |
365 |
|
y += LINE_SKIP; |
366 |
|
x = rect->x; |
367 |
|
} |
368 |
|
|
369 |
|
if(cache->terrain) { |
370 |
|
/* draw cache rating */ |
371 |
|
const char *terrain = "Terrain:"; |
372 |
|
icon = icon_get(ICON_STARS, (int)(cache->terrain*2-2)); |
373 |
|
cairo_text_extents (cr, _(terrain), &extents); |
374 |
|
y += (gdk_pixbuf_get_height(icon) + extents.height)/2; |
375 |
|
|
376 |
|
/* draw "Terrain:" string */ |
377 |
|
cairo_move_to (cr, x, y); |
378 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
379 |
|
cairo_show_text (cr, _(terrain)); |
380 |
|
cairo_stroke (cr); |
381 |
|
x += extents.width + 2; |
382 |
|
|
383 |
|
/* draw terrain stars */ |
384 |
|
cairo_draw_pixbuf(cr, icon, x, y - |
385 |
|
(gdk_pixbuf_get_height(icon) + extents.height)/2); |
386 |
|
|
387 |
|
x += gdk_pixbuf_get_width(icon) + LINE_SKIP; |
388 |
|
y -= (gdk_pixbuf_get_height(icon) + extents.height)/2; |
389 |
|
} |
390 |
|
|
391 |
|
if(cache->difficulty) { |
392 |
|
const char *difficulty = "Difficulty:"; |
393 |
|
cairo_text_extents (cr, _(difficulty), &extents); |
394 |
|
y += (gdk_pixbuf_get_height(icon) + extents.height)/2; |
395 |
|
|
396 |
|
/* draw "Difficulty:" string */ |
397 |
|
cairo_move_to (cr, x, y); |
398 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
399 |
|
cairo_show_text (cr, _(difficulty)); |
400 |
|
cairo_stroke (cr); |
401 |
|
x += extents.width + 2; |
402 |
|
|
403 |
|
icon = icon_get(ICON_STARS, (int)(cache->difficulty*2-2)); |
404 |
|
cairo_draw_pixbuf(cr, icon, x, y - |
405 |
|
(gdk_pixbuf_get_height(icon) + extents.height)/2); |
406 |
|
} |
407 |
|
} |
408 |
|
|
409 |
static gboolean |
static gboolean |
410 |
on_map_button_release_event(GtkWidget *widget, |
on_map_button_release_event(GtkWidget *widget, |
411 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
412 |
|
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
413 |
|
|
414 |
if(context->press_on) { |
if(context->press_on) { |
415 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
coord_t coo; |
416 |
|
coo = osm_gps_map_get_co_ordinates(map, event->x, event->y); |
417 |
|
|
418 |
pos_t pos = |
pos_t pos = |
419 |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
421 |
cache_t *nearest = map_closest(context, &pos); |
cache_t *nearest = map_closest(context, &pos); |
422 |
if(nearest && nearest == context->press_on) { |
if(nearest && nearest == context->press_on) { |
423 |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
424 |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { |
425 |
cache_popup(context, nearest); |
|
426 |
|
osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon, |
427 |
|
balloon_draw_cb, nearest); |
428 |
|
} |
429 |
} |
} |
430 |
context->press_on = NULL; |
context->press_on = NULL; |
431 |
|
} else { |
432 |
|
/* save new map position */ |
433 |
|
gfloat lat, lon; |
434 |
|
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
435 |
|
context->appdata->map.pos.lat = lat; |
436 |
|
context->appdata->map.pos.lon = lon; |
437 |
} |
} |
438 |
|
|
439 |
return FALSE; |
return FALSE; |
440 |
} |
} |
441 |
|
|
|
|
|
|
#if MAEMO_VERSION_MAJOR == 5 |
|
442 |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
443 |
printf("destroy map view\n"); |
appdata_t *appdata = context->appdata; |
444 |
|
|
445 |
|
printf("destroy map window\n"); |
446 |
|
|
447 |
|
/* save map parameters */ |
448 |
|
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
449 |
|
gint zoom; |
450 |
|
g_object_get(map, "zoom", &zoom, NULL); |
451 |
|
context->appdata->map.zoom = zoom; |
452 |
|
|
453 |
|
gfloat lat, lon; |
454 |
|
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
455 |
|
context->appdata->map.pos.lat = lat; |
456 |
|
context->appdata->map.pos.lon = lon; |
457 |
|
|
458 |
|
#if MAEMO_VERSION_MAJOR == 5 |
459 |
/* restore cur_view */ |
/* restore cur_view */ |
460 |
context->appdata->cur_view = context->old_view; |
context->appdata->cur_view = context->old_view; |
461 |
|
#endif |
462 |
|
|
463 |
gtk_timeout_remove(context->handler_id); |
gtk_timeout_remove(context->handler_id); |
464 |
|
|
465 |
g_free(context); |
g_free(context); |
466 |
|
appdata->map.context = NULL; |
467 |
} |
} |
|
#endif |
|
468 |
|
|
469 |
void map(appdata_t *appdata) { |
void map(appdata_t *appdata) { |
470 |
map_context_t *context = g_new0(map_context_t, 1); |
map_context_t *context = NULL; |
471 |
|
|
472 |
|
/* if the map window already exists, just raise it */ |
473 |
|
if(appdata->map.context) { |
474 |
|
gtk_window_present(GTK_WINDOW(appdata->map.context->window)); |
475 |
|
return; |
476 |
|
} |
477 |
|
|
478 |
|
context = appdata->map.context = g_new0(map_context_t, 1); |
479 |
context->appdata = appdata; |
context->appdata = appdata; |
480 |
|
|
481 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
484 |
const char *proxy = get_proxy_uri(appdata); |
const char *proxy = get_proxy_uri(appdata); |
485 |
|
|
486 |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
487 |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
"map-source", MAP_SOURCE, |
488 |
"tile-cache", path, |
"tile-cache", path, |
489 |
proxy?"proxy-uri":NULL, proxy, |
"auto-center", FALSE, |
490 |
|
"record-trip-history", FALSE, |
491 |
|
"show-trip-history", FALSE, |
492 |
|
proxy?"proxy-uri":NULL, proxy, |
493 |
NULL); |
NULL); |
494 |
|
|
495 |
g_free(path); |
g_free(path); |
515 |
char *title = g_strdup_printf(_("Map - %s"), name); |
char *title = g_strdup_printf(_("Map - %s"), name); |
516 |
g_free(name); |
g_free(name); |
517 |
|
|
518 |
#if MAEMO_VERSION_MAJOR == 5 |
#ifdef USE_MAEMO |
519 |
GtkWidget *window = hildon_stackable_window_new(); |
#ifdef USE_STACKABLE_WINDOW |
520 |
gtk_window_set_title(GTK_WINDOW(window), title); |
context->window = hildon_stackable_window_new(); |
521 |
#else |
#else |
522 |
GtkWidget *dialog = gtk_dialog_new_with_buttons(title, |
context->window = hildon_window_new(); |
523 |
GTK_WINDOW(appdata->window), |
#endif |
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
|
|
NULL); |
|
|
|
|
|
#ifndef USE_MAEMO |
|
|
gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480); |
|
524 |
#else |
#else |
525 |
gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); |
context->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
526 |
#endif |
#endif |
527 |
|
|
528 |
|
gtk_window_set_title(GTK_WINDOW(context->window), title); |
529 |
|
|
530 |
|
#ifndef USE_MAEMO |
531 |
|
gtk_window_set_default_size(GTK_WINDOW(context->window), 640, 480); |
532 |
#endif |
#endif |
533 |
|
|
534 |
g_free(title); |
g_free(title); |
547 |
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
548 |
|
|
549 |
context->zoomin = |
context->zoomin = |
550 |
map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin), |
map_add_button(10, G_CALLBACK(cb_map_zoomin), |
551 |
context, _("Zoom in")); |
context, _("Zoom in")); |
552 |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); |
553 |
|
|
554 |
context->zoomout = |
context->zoomout = |
555 |
map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout), |
map_add_button(11, G_CALLBACK(cb_map_zoomout), |
556 |
context, _("Zoom out")); |
context, _("Zoom out")); |
557 |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); |
558 |
|
|
559 |
context->gps = |
context->gps = |
560 |
map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_gps), |
map_add_button(9, G_CALLBACK(cb_map_gps), |
561 |
context, _("Jump to GPS position")); |
context, _("Jump to GPS position")); |
562 |
gtk_widget_set_sensitive(context->gps, FALSE); |
gtk_widget_set_sensitive(context->gps, FALSE); |
563 |
|
|
564 |
/* install handler for timed updates of the gps button */ |
/* install handler for timed updates of the gps button */ |
565 |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
566 |
gtk_box_pack_start(GTK_BOX(vbox), context->gps, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context->gps, FALSE, FALSE, 0); |
571 |
/* prevent some of the main screen things */ |
/* prevent some of the main screen things */ |
572 |
context->old_view = appdata->cur_view; |
context->old_view = appdata->cur_view; |
573 |
appdata->cur_view = NULL; |
appdata->cur_view = NULL; |
574 |
|
#endif |
575 |
|
|
576 |
g_signal_connect(G_OBJECT(window), "destroy", |
g_signal_connect(G_OBJECT(context->window), "destroy", |
577 |
G_CALLBACK(on_window_destroy), context); |
G_CALLBACK(on_window_destroy), context); |
578 |
|
|
579 |
gtk_container_add(GTK_CONTAINER(window), hbox); |
gtk_container_add(GTK_CONTAINER(context->window), hbox); |
580 |
gtk_widget_show_all(GTK_WIDGET(window)); |
gtk_widget_show_all(GTK_WIDGET(context->window)); |
|
|
|
|
#else |
|
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
|
|
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); |
|
|
gtk_widget_show_all(dialog); |
|
|
gtk_dialog_run(GTK_DIALOG(dialog)); |
|
|
gtk_timeout_remove(context->handler_id); |
|
|
gtk_widget_destroy(dialog); |
|
|
g_free(context); |
|
|
#endif |
|
581 |
} |
} |