Diff of /trunk/src/map-tool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 42 by harbaum, Mon Aug 3 19:18:13 2009 UTC revision 45 by harbaum, Tue Aug 4 19:27:39 2009 UTC
# Line 122  static GtkWidget Line 122  static GtkWidget
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);
# Line 199  on_button_press_event(GtkWidget *widget, Line 199  on_button_press_event(GtkWidget *widget,
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    
# Line 208  on_button_release_event(GtkWidget *widge Line 208  on_button_release_event(GtkWidget *widge
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");
# Line 250  void cache_popup(map_context_t *mcontext Line 250  void cache_popup(map_context_t *mcontext
250    gtk_widget_realize(pcontext.window);    gtk_widget_realize(pcontext.window);
251    gtk_window_set_default_size(GTK_WINDOW(pcontext.window),    gtk_window_set_default_size(GTK_WINDOW(pcontext.window),
252                                POPUP_WIDTH, POPUP_HEIGHT);                                POPUP_WIDTH, POPUP_HEIGHT);
253    gtk_window_resize(GTK_WINDOW(pcontext.window),    gtk_window_resize(GTK_WINDOW(pcontext.window), POPUP_WIDTH, POPUP_HEIGHT);
                     POPUP_WIDTH, POPUP_HEIGHT);  
254    //  gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE);    //  gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE);
255    gtk_window_set_transient_for(GTK_WINDOW(pcontext.window),    gtk_window_set_transient_for(GTK_WINDOW(pcontext.window),
256                                 GTK_WINDOW(mcontext->appdata->window));                                 GTK_WINDOW(mcontext->appdata->window));
# Line 278  void cache_popup(map_context_t *mcontext Line 277  void cache_popup(map_context_t *mcontext
277    gtk_grab_add(pcontext.window);    gtk_grab_add(pcontext.window);
278    
279    /* check whether cache is in upper or lower half of window */    /* check whether cache is in upper or lower half of window */
280    gint x, y;    gint x, y, sx, sy;
281    osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget),    osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget),
282                                     cache->pos.lat, cache->pos.lon,                                     cache->pos.lat, cache->pos.lon,
283                                     &x, &y);                                     &sx, &sy);
284    
285    printf("screen pos %d/%d\n", x, y);    printf("screen pos %d/%d\n", sx, sy);
286    
287    gdk_window_get_origin(mcontext->widget->window, &x, &y);    gdk_window_get_origin(mcontext->widget->window, &x, &y);
288    printf("window = %d/%d %d/%d\n", x, y,    printf("window = %d/%d +%d+%d %d*%d\n", x, y,
289           mcontext->widget->allocation.x,           mcontext->widget->allocation.x,
290           mcontext->widget->allocation.y);           mcontext->widget->allocation.y,
291             mcontext->widget->allocation.width,
292    //  gtk_window_move(GTK_WINDOW(pcontext.window),           mcontext->widget->allocation.height
293    //              x + button->allocation.x,           );
294    //              y + button->allocation.y - HEIGHT);  
295      gint ax = 0, ay = 0;
296      if(sx > mcontext->widget->allocation.width/2)
297        ax = POPUP_WIDTH;
298    
299      if(sy > mcontext->widget->allocation.height/2)
300        ay = POPUP_HEIGHT;
301    
302    gtk_window_move(GTK_WINDOW(pcontext.window),    gtk_window_move(GTK_WINDOW(pcontext.window),
303                    100,                    x + mcontext->widget->allocation.x + sx - ax,
304                    100);                    y + mcontext->widget->allocation.y + sy - ay);
305    
306    /* a frame with a vscale inside */    /* a frame with a vscale inside */
307    GtkWidget *frame = gtk_frame_new(NULL);    GtkWidget *frame = gtk_frame_new(NULL);
# Line 380  static int dist2pixel(map_context_t *con Line 384  static int dist2pixel(map_context_t *con
384    return 1000.0*km/m_per_pix;    return 1000.0*km/m_per_pix;
385  }  }
386    
387  #define CLICK_FUZZ (10)  #define CLICK_FUZZ (16)
388    
389  static gboolean  static gboolean
390  on_map_button_press_event(GtkWidget *widget,  on_map_button_press_event(GtkWidget *widget,
391                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
392    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
393    
394      /* got a press event without release event? eat it! */
395      if(context->press_on != NULL) {
396        printf("PRESS: already\n");
397        return TRUE;
398      }
399    
400    pos_t pos =    pos_t pos =
401      coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y));      coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y));
402    
403    cache_t *nearest = map_closest(context, &pos);    cache_t *nearest = map_closest(context, &pos);
404    if(nearest) {    if(nearest) {
405      float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);      float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);
406      if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) {      if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ)
407        context->press_on = nearest;        context->press_on = nearest;
       return TRUE;  
     }  
408    }    }
409    
   context->press_on = NULL;  
410    return FALSE;    return FALSE;
411  }  }
412    
# Line 415  on_map_button_release_event(GtkWidget *w Line 422  on_map_button_release_event(GtkWidget *w
422      cache_t *nearest = map_closest(context, &pos);      cache_t *nearest = map_closest(context, &pos);
423      if(nearest && nearest == context->press_on) {      if(nearest && nearest == context->press_on) {
424        float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);        float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);
425        if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) {        if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ)
   
426          cache_popup(context, nearest);          cache_popup(context, nearest);
   
         context->press_on = NULL;  
         return TRUE;  
       }  
427      }      }
428        context->press_on = NULL;
429    }    }
430    
   context->press_on = NULL;  
431    return FALSE;    return FALSE;
432  }  }
433    
434    
435  #if MAEMO_VERSION_MAJOR == 5  #if MAEMO_VERSION_MAJOR == 5
436  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {
437    printf("destroy map view\n");    printf("destroy map view\n");
# Line 472  void map(appdata_t *appdata) { Line 475  void map(appdata_t *appdata) {
475  #ifdef USE_MAEMO  #ifdef USE_MAEMO
476    } else {    } else {
477      map_draw_cachelist(context->widget, appdata->cur_gpx->cache);      map_draw_cachelist(context->widget, appdata->cur_gpx->cache);
478      name = g_strdup(_("appdata->cur_gpx->name"));      name = g_strdup(appdata->cur_gpx->name);
479    }    }
480  #endif  #endif
481    
# Line 490  void map(appdata_t *appdata) { Line 493  void map(appdata_t *appdata) {
493                            NULL);                            NULL);
494    
495  #ifndef USE_MAEMO  #ifndef USE_MAEMO
496    gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 350);    gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480);
497  #else  #else
498    gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480);    gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480);
499  #endif  #endif

Legend:
Removed from v.42  
changed lines
  Added in v.45