122 |
char *tooltip) { |
char *tooltip) { |
123 |
GtkWidget *button = gtk_button_new(); |
GtkWidget *button = gtk_button_new(); |
124 |
gtk_button_set_image(GTK_BUTTON(button), |
gtk_button_set_image(GTK_BUTTON(button), |
125 |
gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU)); |
gtk_image_new_from_stock(icon, GTK_ICON_SIZE_BUTTON)); |
126 |
g_signal_connect(button, "clicked", cb, data); |
g_signal_connect(button, "clicked", cb, data); |
127 |
#ifndef USE_MAEMO |
#ifndef USE_MAEMO |
128 |
gtk_widget_set_tooltip_text(button, tooltip); |
gtk_widget_set_tooltip_text(button, tooltip); |
199 |
GdkEventButton *event, popup_context_t *context) { |
GdkEventButton *event, popup_context_t *context) { |
200 |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
201 |
|
|
202 |
printf("overlay button press(in = %d)\n", in); |
printf("overlay button press (in = %d)\n", in); |
203 |
return !in; |
return !in; |
204 |
} |
} |
205 |
|
|
208 |
GdkEventButton *event, popup_context_t *context) { |
GdkEventButton *event, popup_context_t *context) { |
209 |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
210 |
|
|
211 |
printf("overlay button release(in = %d)\n", in); |
printf("overlay button release (in = %d)\n", in); |
212 |
|
|
213 |
if(!in) { |
if(!in) { |
214 |
printf("destroying popup\n"); |
printf("destroying popup\n"); |
242 |
shutdown_loop(context); |
shutdown_loop(context); |
243 |
} |
} |
244 |
|
|
245 |
|
/* draw shape */ |
246 |
|
#define ARROW_BORDER 20 |
247 |
|
#define CORNER_RADIUS 10 |
248 |
|
|
249 |
|
static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) { |
250 |
|
GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1); |
251 |
|
|
252 |
|
GdkGC *gc = gdk_gc_new(mask); |
253 |
|
GdkColormap *colormap; |
254 |
|
GdkColor black; |
255 |
|
GdkColor white; |
256 |
|
|
257 |
|
/* get black/white color values */ |
258 |
|
colormap = gdk_colormap_get_system(); |
259 |
|
gdk_color_black(colormap, &black); |
260 |
|
gdk_color_white(colormap, &white); |
261 |
|
|
262 |
|
/* erase */ |
263 |
|
gdk_gc_set_foreground(gc, &black); |
264 |
|
gdk_gc_set_background(gc, &white); |
265 |
|
|
266 |
|
/* erase background */ |
267 |
|
gdk_draw_rectangle(mask, gc, TRUE, 0, 0, POPUP_WIDTH, POPUP_HEIGHT); |
268 |
|
|
269 |
|
gdk_gc_set_foreground(gc, &white); |
270 |
|
gdk_gc_set_background(gc, &black); |
271 |
|
|
272 |
|
gdk_draw_rectangle(mask, gc, TRUE, |
273 |
|
0, ARROW_BORDER + CORNER_RADIUS, |
274 |
|
POPUP_WIDTH, |
275 |
|
POPUP_HEIGHT - 2*CORNER_RADIUS - 2*ARROW_BORDER); |
276 |
|
|
277 |
|
gdk_draw_rectangle(mask, gc, TRUE, |
278 |
|
CORNER_RADIUS, ARROW_BORDER, |
279 |
|
POPUP_WIDTH - 2*CORNER_RADIUS, |
280 |
|
POPUP_HEIGHT - 2*ARROW_BORDER); |
281 |
|
|
282 |
|
int off[][2] = { |
283 |
|
{ CORNER_RADIUS, ARROW_BORDER + CORNER_RADIUS }, |
284 |
|
{ POPUP_WIDTH - CORNER_RADIUS, |
285 |
|
ARROW_BORDER + CORNER_RADIUS }, |
286 |
|
{ POPUP_WIDTH - CORNER_RADIUS, |
287 |
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER }, |
288 |
|
{ CORNER_RADIUS, |
289 |
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER}}; |
290 |
|
|
291 |
|
int i; |
292 |
|
for(i=0;i<4;i++) { |
293 |
|
gdk_draw_arc(mask, gc, TRUE, |
294 |
|
off[i][0]-CORNER_RADIUS, off[i][1]-CORNER_RADIUS, |
295 |
|
2*CORNER_RADIUS, 2*CORNER_RADIUS, |
296 |
|
0, 360*64); |
297 |
|
} |
298 |
|
|
299 |
|
GdkPoint points[3] = { {POPUP_WIDTH*1/3, POPUP_HEIGHT/2}, |
300 |
|
{POPUP_WIDTH*2/3, POPUP_HEIGHT/2}, |
301 |
|
{tip_x,tip_y} }; |
302 |
|
gdk_draw_polygon(mask, gc, TRUE, points, 3); |
303 |
|
|
304 |
|
|
305 |
|
gdk_window_shape_combine_mask(window->window, mask, 0, 0); |
306 |
|
} |
307 |
|
|
308 |
void cache_popup(map_context_t *mcontext, cache_t *cache) { |
void cache_popup(map_context_t *mcontext, cache_t *cache) { |
309 |
popup_context_t pcontext; |
popup_context_t pcontext; |
310 |
pcontext.appdata = mcontext->appdata; |
pcontext.appdata = mcontext->appdata; |
313 |
gtk_widget_realize(pcontext.window); |
gtk_widget_realize(pcontext.window); |
314 |
gtk_window_set_default_size(GTK_WINDOW(pcontext.window), |
gtk_window_set_default_size(GTK_WINDOW(pcontext.window), |
315 |
POPUP_WIDTH, POPUP_HEIGHT); |
POPUP_WIDTH, POPUP_HEIGHT); |
316 |
gtk_window_resize(GTK_WINDOW(pcontext.window), |
gtk_window_resize(GTK_WINDOW(pcontext.window), POPUP_WIDTH, POPUP_HEIGHT); |
|
POPUP_WIDTH, POPUP_HEIGHT); |
|
317 |
// gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE); |
// gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE); |
318 |
gtk_window_set_transient_for(GTK_WINDOW(pcontext.window), |
gtk_window_set_transient_for(GTK_WINDOW(pcontext.window), |
319 |
GTK_WINDOW(mcontext->appdata->window)); |
GTK_WINDOW(mcontext->appdata->window)); |
340 |
gtk_grab_add(pcontext.window); |
gtk_grab_add(pcontext.window); |
341 |
|
|
342 |
/* check whether cache is in upper or lower half of window */ |
/* check whether cache is in upper or lower half of window */ |
343 |
gint x, y; |
gint x, y, sx, sy; |
344 |
osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget), |
osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget), |
345 |
cache->pos.lat, cache->pos.lon, |
cache->pos.lat, cache->pos.lon, |
346 |
&x, &y); |
&sx, &sy); |
347 |
|
|
348 |
printf("screen pos %d/%d\n", x, y); |
printf("screen pos %d/%d\n", sx, sy); |
349 |
|
|
350 |
gdk_window_get_origin(mcontext->widget->window, &x, &y); |
gdk_window_get_origin(mcontext->widget->window, &x, &y); |
351 |
printf("window = %d/%d %d/%d\n", x, y, |
printf("window = %d/%d +%d+%d %d*%d\n", x, y, |
352 |
mcontext->widget->allocation.x, |
mcontext->widget->allocation.x, |
353 |
mcontext->widget->allocation.y); |
mcontext->widget->allocation.y, |
354 |
|
mcontext->widget->allocation.width, |
355 |
// gtk_window_move(GTK_WINDOW(pcontext.window), |
mcontext->widget->allocation.height |
356 |
// x + button->allocation.x, |
); |
357 |
// y + button->allocation.y - HEIGHT); |
|
358 |
|
gint ax = 0, ay = 0; |
359 |
|
if(sx > mcontext->widget->allocation.width/2) |
360 |
|
ax = POPUP_WIDTH; |
361 |
|
|
362 |
|
if(sy > mcontext->widget->allocation.height/2) |
363 |
|
ay = POPUP_HEIGHT; |
364 |
|
|
365 |
|
#if !defined(USE_HILDON) || (MAEMO_VERSION_MAJOR < 5) |
366 |
|
GdkColor color; |
367 |
|
gdk_color_parse("darkgray", &color); |
368 |
|
gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color); |
369 |
|
#endif |
370 |
|
|
371 |
gtk_window_move(GTK_WINDOW(pcontext.window), |
gtk_window_move(GTK_WINDOW(pcontext.window), |
372 |
100, |
x + mcontext->widget->allocation.x + sx - ax, |
373 |
100); |
y + mcontext->widget->allocation.y + sy - ay); |
374 |
|
|
375 |
|
|
|
/* a frame with a vscale inside */ |
|
376 |
GtkWidget *frame = gtk_frame_new(NULL); |
GtkWidget *frame = gtk_frame_new(NULL); |
377 |
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); |
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); |
378 |
|
gtk_container_set_border_width(GTK_CONTAINER(frame), |
379 |
|
ARROW_BORDER+CORNER_RADIUS); |
380 |
|
gtk_container_add(GTK_CONTAINER(frame), |
381 |
|
gtk_button_new_with_label(cache->name)); |
382 |
|
|
|
gtk_container_add(GTK_CONTAINER(frame), gtk_label_new(cache->name)); |
|
383 |
gtk_container_add(GTK_CONTAINER(pcontext.window), frame); |
gtk_container_add(GTK_CONTAINER(pcontext.window), frame); |
384 |
|
|
385 |
|
/* --------- give the window its shape ----------- */ |
386 |
|
popup_window_shape(pcontext.window, ax, ay); |
387 |
|
|
388 |
gtk_widget_show_all(pcontext.window); |
gtk_widget_show_all(pcontext.window); |
389 |
|
|
390 |
/* handle this popup until it's gone */ |
/* handle this popup until it's gone */ |
459 |
return 1000.0*km/m_per_pix; |
return 1000.0*km/m_per_pix; |
460 |
} |
} |
461 |
|
|
462 |
#define CLICK_FUZZ (10) |
#define CLICK_FUZZ (16) |
463 |
|
|
464 |
static gboolean |
static gboolean |
465 |
on_map_button_press_event(GtkWidget *widget, |
on_map_button_press_event(GtkWidget *widget, |
466 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
467 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
468 |
|
|
469 |
|
/* got a press event without release event? eat it! */ |
470 |
|
if(context->press_on != NULL) { |
471 |
|
printf("PRESS: already\n"); |
472 |
|
return TRUE; |
473 |
|
} |
474 |
|
|
475 |
pos_t pos = |
pos_t pos = |
476 |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
477 |
|
|
478 |
cache_t *nearest = map_closest(context, &pos); |
cache_t *nearest = map_closest(context, &pos); |
479 |
if(nearest) { |
if(nearest) { |
480 |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
481 |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) |
482 |
context->press_on = nearest; |
context->press_on = nearest; |
|
return TRUE; |
|
|
} |
|
483 |
} |
} |
484 |
|
|
|
context->press_on = NULL; |
|
485 |
return FALSE; |
return FALSE; |
486 |
} |
} |
487 |
|
|
497 |
cache_t *nearest = map_closest(context, &pos); |
cache_t *nearest = map_closest(context, &pos); |
498 |
if(nearest && nearest == context->press_on) { |
if(nearest && nearest == context->press_on) { |
499 |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
500 |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) |
|
|
|
501 |
cache_popup(context, nearest); |
cache_popup(context, nearest); |
|
|
|
|
context->press_on = NULL; |
|
|
return TRUE; |
|
|
} |
|
502 |
} |
} |
503 |
|
context->press_on = NULL; |
504 |
} |
} |
505 |
|
|
|
context->press_on = NULL; |
|
506 |
return FALSE; |
return FALSE; |
507 |
} |
} |
508 |
|
|
509 |
|
|
510 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
511 |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
512 |
printf("destroy map view\n"); |
printf("destroy map view\n"); |
550 |
#ifdef USE_MAEMO |
#ifdef USE_MAEMO |
551 |
} else { |
} else { |
552 |
map_draw_cachelist(context->widget, appdata->cur_gpx->cache); |
map_draw_cachelist(context->widget, appdata->cur_gpx->cache); |
553 |
name = g_strdup(_("appdata->cur_gpx->name")); |
name = g_strdup(appdata->cur_gpx->name); |
554 |
} |
} |
555 |
#endif |
#endif |
556 |
|
|
568 |
NULL); |
NULL); |
569 |
|
|
570 |
#ifndef USE_MAEMO |
#ifndef USE_MAEMO |
571 |
gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 350); |
gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480); |
572 |
#else |
#else |
573 |
gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); |
gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); |
574 |
#endif |
#endif |