Diff of /trunk/src/map.c

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

revision 64 by harbaum, Mon Feb 9 13:23:17 2009 UTC revision 78 by harbaum, Sun Feb 15 12:07:04 2009 UTC
# Line 839  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 913  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 1040  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 1081  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 1094  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 1152  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 1167  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 1598  static gboolean map_motion_notify_event( Line 1503  static gboolean map_motion_notify_event(
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 1896  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 changes antialias settings */    /* user may have changed antialias settings */
1805    GooCanvasItem *root = goo_canvas_get_root_item(GOO_CANVAS(map->canvas));    GooCanvasItem *root = goo_canvas_get_root_item(GOO_CANVAS(map->canvas));
1806    g_object_set(G_OBJECT(root), "antialias",    g_object_set(G_OBJECT(root), "antialias",
1807                 appdata->settings->no_antialias?CAIRO_ANTIALIAS_NONE:                 appdata->settings->no_antialias?CAIRO_ANTIALIAS_NONE:

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