Diff of /trunk/src/map.c

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

revision 23 by achadwick, Thu Dec 18 17:53:38 2008 UTC revision 78 by harbaum, Sun Feb 15 12:07:04 2009 UTC
# Line 56  static void map_statusbar(map_t *map, ma Line 56  static void map_statusbar(map_t *map, ma
56      str = g_strdup_printf("%s #%ld", item_str, id);      str = g_strdup_printf("%s #%ld", item_str, id);
57    
58      /* add some tags ... */      /* add some tags ... */
59        /*
60         *  XXX Should we just try to present only the name or the ref (or the
61         *  alt_name, old_name, whatever) here?  Hurling a load of tags in the
62         *  user's face in some unpredictable, uninformative order isn't very
63         *  friendly.
64         *
65         *  Actually, a tag_short_desc() function would be useful in dialogs
66         *  nd user messages too.
67         */
68      while(tag) {      while(tag) {
69        if(!collision && info_tag_key_collision(tags, tag))        if(!collision && info_tag_key_collision(tags, tag))
70          collision = TRUE;          collision = TRUE;
# Line 370  static canvas_item_t *map_node_new(map_t Line 379  static canvas_item_t *map_node_new(map_t
379    map_item->node = node;    map_item->node = node;
380    
381    if(!node->icon_buf || !map->style->icon.enable ||    if(!node->icon_buf || !map->style->icon.enable ||
382       map->appdata->settings->no_icons)       map->appdata->settings->no_icons)
383      map_item->item = canvas_circle_new(map, CANVAS_GROUP_NODES,      map_item->item = canvas_circle_new(map, CANVAS_GROUP_NODES,
384         node->lpos.x, node->lpos.y, radius, width, fill, border);         node->lpos.x, node->lpos.y, radius, width, fill, border);
385    else    else
# Line 448  static canvas_item_t *map_way_new(map_t Line 457  static canvas_item_t *map_way_new(map_t
457    
458    if (group != CANVAS_GROUP_WAYS_OL)    if (group != CANVAS_GROUP_WAYS_OL)
459      if (way->draw.dashed)      if (way->draw.dashed)
460        canvas_item_set_dashed(map_item->item);        canvas_item_set_dashed(map_item->item, width, way->draw.dash_length);
461    
462    /* attach map_item to ways map_item_chain */    /* attach map_item to ways map_item_chain */
463    map_item_chain_t **chain = &way->map_item_chain;    map_item_chain_t **chain = &way->map_item_chain;
# Line 830  map_item_t *map_real_item_at(map_t *map, Line 839  map_item_t *map_real_item_at(map_t *map,
839    return map_item;    return map_item;
840  }  }
841    
   
   
 #ifdef USE_GOOCANVAS  
   
842  /* Limitations on the amount by which we can scroll. Keeps part of the  /* Limitations on the amount by which we can scroll. Keeps part of the
843   * map visible at all times */   * map visible at all times */
844  static void map_limit_scroll(map_t *map, gint *sx, gint *sy) {  static void map_limit_scroll(map_t *map, gint *sx, gint *sy) {
# Line 904  static gboolean map_limit_zoom(map_t *ma Line 909  static gboolean map_limit_zoom(map_t *ma
909  }  }
910    
911    
 #if 0  
 /* Scroll the map a little towards the centre from where it is right now.  
  * This is used as a cute recentring trick when the map is at its outer  
  * scroll limit. */  
 static void map_scroll_towards_centre(map_t *map, gdouble amt) {  
     gint sx, sy, sx_orig, sy_orig;  
     canvas_get_scroll_offsets(map->canvas, &sx, &sy);  
     gdouble zoom = goo_canvas_get_scale(GOO_CANVAS(map->canvas));  
     sx_orig=sx;  
     sy_orig=sy;  
   
     // Work in canvas units  
     gdouble sx_cu = sx / zoom;  
     gdouble sy_cu = sy / zoom;  
   
     // Map bounds  
     gdouble bmin_x_cu, bmin_y_cu, bmax_x_cu, bmax_y_cu;  
     bmin_x_cu = map->appdata->osm->bounds->min.x;  
     bmin_y_cu = map->appdata->osm->bounds->min.y;  
     bmax_x_cu = map->appdata->osm->bounds->max.x;  
     bmax_y_cu = map->appdata->osm->bounds->max.y;  
   
     // Canvas viewport dimensions  
     GtkAllocation *a = &GTK_WIDGET(map->canvas)->allocation;  
     gdouble ah_cu = a->height / zoom;  
     gdouble aw_cu = a->width / zoom;  
   
     // Scroll offsets that would recentre the map  
     gdouble centre_sx_cu, centre_sy_cu;  
     centre_sx_cu = - (aw_cu/2);  
     centre_sy_cu = - (ah_cu/2);  
   
     // Move towards centre by a given fraction of the whole map  
     if (sx_cu > centre_sx_cu) {  
         sx_cu -= ((bmax_x_cu - bmin_x_cu) * amt);  
         if (sx_cu < centre_sx_cu) {  
             printf("force-centre-x\n");  
             sx_cu = centre_sx_cu;  
         }  
     }  
     if (sx_cu < centre_sx_cu) {  
         sx_cu += ((bmax_x_cu - bmin_x_cu) * amt);  
         if (sx_cu > centre_sx_cu) {  
             printf("force-centre-x\n");  
             sx_cu = centre_sx_cu;  
         }  
     }  
   
     if (sy_cu > centre_sy_cu) {  
         sy_cu -= ((bmax_y_cu - bmin_y_cu) * amt);  
         if (sy_cu < centre_sy_cu) {  
             printf("force-centre-y\n");  
             sy_cu = centre_sy_cu;  
         }  
     }  
     if (sy_cu < centre_sy_cu) {  
         sy_cu += ((bmax_y_cu - bmin_y_cu) * amt);  
         if (sy_cu > centre_sy_cu) {  
             printf("force-centre-y\n");  
             sy_cu = centre_sy_cu;  
         }  
     }  
   
     // Back to pixels for setting the scroll  
     sx = (gint)(sx_cu * zoom);  
     sy = (gint)(sy_cu * zoom);  
     canvas_scroll_to(map->canvas, sx, sy);  
     map->state->scroll_offset.x = sx;  
     map->state->scroll_offset.y = sy;  
 }  
 #endif // #if 0  
   
912  /*  /*
913   * Scroll the map to a point if that point is currently offscreen.   * Scroll the map to a point if that point is currently offscreen.
914   */   */
# Line 1031  void map_scroll_to_if_offscreen(map_t *m Line 964  void map_scroll_to_if_offscreen(map_t *m
964    
965    if (horiz_recentre_needed || vert_recentre_needed) {    if (horiz_recentre_needed || vert_recentre_needed) {
966      gint new_sx, new_sy;      gint new_sx, new_sy;
967  #if 0  
     // Only recentre the drifting axis.  
     new_sx = horiz_recentre_needed ? zoom*(lpos->x - (aw/2)) : sx;  
     new_sy = vert_recentre_needed  ? zoom*(lpos->y - (ah/2)) : sy;  
     // Not sure about this. I don't think it really buys us anything.  
 #else  
968      // Just centre both at once      // Just centre both at once
969      new_sx = zoom * (lpos->x - (aw/2));      new_sx = zoom * (lpos->x - (aw/2));
970      new_sy = zoom * (lpos->y - (ah/2));      new_sy = zoom * (lpos->y - (ah/2));
971  #endif  
972      map_limit_scroll(map, &new_sx, &new_sy);      map_limit_scroll(map, &new_sx, &new_sy);
973      canvas_scroll_to(map->canvas, new_sx, new_sy);      canvas_scroll_to(map->canvas, new_sx, new_sy);
974    }    }
975  }  }
976    
 #endif // #ifdef USE_GOOCANVAS  
   
977  /* Deselects the current way or node if its zoom_max  /* Deselects the current way or node if its zoom_max
978   * means that it's not going to render at the current map zoom. */   * means that it's not going to render at the current map zoom. */
979  void map_deselect_if_zoom_below_zoom_max(map_t *map) {  void map_deselect_if_zoom_below_zoom_max(map_t *map) {
# Line 1072  void map_deselect_if_zoom_below_zoom_max Line 998  void map_deselect_if_zoom_below_zoom_max
998  void map_set_zoom(map_t *map, double zoom,  void map_set_zoom(map_t *map, double zoom,
999                    gboolean update_scroll_offsets) {                    gboolean update_scroll_offsets) {
1000    gboolean at_zoom_limit = 0;    gboolean at_zoom_limit = 0;
 #ifdef USE_GOOCANVAS  
1001    at_zoom_limit = map_limit_zoom(map, &zoom);    at_zoom_limit = map_limit_zoom(map, &zoom);
1002  #endif  
1003    map->state->zoom = zoom;    map->state->zoom = zoom;
1004    canvas_set_zoom(map->canvas, map->state->zoom);    canvas_set_zoom(map->canvas, map->state->zoom);
1005    
# Line 1085  void map_set_zoom(map_t *map, double zoo Line 1010  void map_set_zoom(map_t *map, double zoo
1010        /* zooming affects the scroll offsets */        /* zooming affects the scroll offsets */
1011        gint sx, sy;        gint sx, sy;
1012        canvas_get_scroll_offsets(map->canvas, &sx, &sy);        canvas_get_scroll_offsets(map->canvas, &sx, &sy);
 #ifdef USE_GOOCANVAS  
1013        map_limit_scroll(map, &sx, &sy);        map_limit_scroll(map, &sx, &sy);
1014        canvas_scroll_to(map->canvas, sx, sy);  // keep the map visible        canvas_scroll_to(map->canvas, sx, sy);  // keep the map visible
 #endif  
1015        map->state->scroll_offset.x = sx;        map->state->scroll_offset.x = sx;
1016        map->state->scroll_offset.y = sy;        map->state->scroll_offset.y = sy;
1017      }      }
 #ifdef USE_GOOCANVAS  
     else {  
       //      map_scroll_towards_centre(map, 0.20);  
     }  
 #endif  
1018    }    }
1019  }  }
1020    
# Line 1143  static void map_do_scroll(map_t *map, gi Line 1061  static void map_do_scroll(map_t *map, gi
1061    canvas_get_scroll_offsets(map->canvas, &sx, &sy);    canvas_get_scroll_offsets(map->canvas, &sx, &sy);
1062    sx -= x-map->pen_down.at.x;    sx -= x-map->pen_down.at.x;
1063    sy -= y-map->pen_down.at.y;    sy -= y-map->pen_down.at.y;
 #ifdef USE_GOOCANVAS  
1064    map_limit_scroll(map, &sx, &sy);    map_limit_scroll(map, &sx, &sy);
 #endif  
1065    canvas_scroll_to(map->canvas, sx, sy);    canvas_scroll_to(map->canvas, sx, sy);
1066    map->state->scroll_offset.x = sx;    map->state->scroll_offset.x = sx;
1067    map->state->scroll_offset.y = sy;    map->state->scroll_offset.y = sy;
# Line 1158  static void map_do_scroll_step(map_t *ma Line 1074  static void map_do_scroll_step(map_t *ma
1074    canvas_get_scroll_offsets(map->canvas, &sx, &sy);    canvas_get_scroll_offsets(map->canvas, &sx, &sy);
1075    sx += x;    sx += x;
1076    sy += y;    sy += y;
 #ifdef USE_GOOCANVAS  
1077    map_limit_scroll(map, &sx, &sy);    map_limit_scroll(map, &sx, &sy);
 #endif  
1078    canvas_scroll_to(map->canvas, sx, sy);    canvas_scroll_to(map->canvas, sx, sy);
1079    map->state->scroll_offset.x = sx;    map->state->scroll_offset.x = sx;
1080    map->state->scroll_offset.y = sy;    map->state->scroll_offset.y = sy;
# Line 1582  static gboolean map_motion_notify_event( Line 1496  static gboolean map_motion_notify_event(
1496    /* reduce update frequency on hildon to keep screen update fluid */    /* reduce update frequency on hildon to keep screen update fluid */
1497    static guint32 last_time = 0;    static guint32 last_time = 0;
1498    
1499    if(event->time - last_time < 100) return FALSE;    if(event->time - last_time < 250) return FALSE;
1500    last_time = event->time;    last_time = event->time;
1501  #endif  #endif
1502    
1503    if(!map->pen_down.is)    if(!map->pen_down.is)
1504      return FALSE;      return FALSE;
1505    
1506  #ifdef USE_GNOMECANVAS  #ifndef USE_GOOCANVAS
1507    /* handle hints, hints are handled by goocanvas directly */    /* handle hints, hints are handled by goocanvas directly */
1508    if(event->is_hint)    if(event->is_hint)
1509      gdk_window_get_pointer(event->window, &x, &y, &state);      gdk_window_get_pointer(event->window, &x, &y, &state);
# Line 1775  GtkWidget *map_new(appdata_t *appdata) { Line 1689  GtkWidget *map_new(appdata_t *appdata) {
1689                 map->style->background.color >> 8, NULL);                 map->style->background.color >> 8, NULL);
1690    
1691    GooCanvasItem *root = goo_canvas_get_root_item(GOO_CANVAS(map->canvas));    GooCanvasItem *root = goo_canvas_get_root_item(GOO_CANVAS(map->canvas));
1692      g_object_set(G_OBJECT(root), "antialias",
1693                   appdata->settings->no_antialias?CAIRO_ANTIALIAS_NONE:
1694                   CAIRO_ANTIALIAS_DEFAULT, NULL);
1695    
1696    /* create the groups */    /* create the groups */
1697    canvas_group_t group;    canvas_group_t group;
# Line 1884  void map_clear(appdata_t *appdata, gint Line 1801  void map_clear(appdata_t *appdata, gint
1801  void map_paint(appdata_t *appdata) {  void map_paint(appdata_t *appdata) {
1802    map_t *map = appdata->map;    map_t *map = appdata->map;
1803    
1804      /* user may have changed antialias settings */
1805      GooCanvasItem *root = goo_canvas_get_root_item(GOO_CANVAS(map->canvas));
1806      g_object_set(G_OBJECT(root), "antialias",
1807                   appdata->settings->no_antialias?CAIRO_ANTIALIAS_NONE:
1808                   CAIRO_ANTIALIAS_DEFAULT, NULL);
1809    
1810    josm_elemstyles_colorize_world(map->style, appdata->osm);    josm_elemstyles_colorize_world(map->style, appdata->osm);
1811    map_draw(map, appdata->osm);    map_draw(map, appdata->osm);
1812  }  }
# Line 2015  void map_delete_selected(appdata_t *appd Line 1938  void map_delete_selected(appdata_t *appd
1938    /* deleting the selected item de-selects it ... */    /* deleting the selected item de-selects it ... */
1939    map_item_deselect(appdata);    map_item_deselect(appdata);
1940    
1941      undo_remember_delete(appdata, item.type, item.ptr);
1942    
1943    switch(item.type) {    switch(item.type) {
1944    case MAP_TYPE_NODE:    case MAP_TYPE_NODE:
1945      printf("request to delete node #%ld\n", item.node->id);      printf("request to delete node #%ld\n", item.node->id);

Legend:
Removed from v.23  
changed lines
  Added in v.78