Diff of /trunk/src/map.c

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

src/map.c revision 1 by harbaum, Tue Dec 9 20:06:06 2008 UTC trunk/src/map.c revision 13 by achadwick, Mon Dec 15 14:17:29 2008 UTC
# Line 442  static canvas_item_t *map_way_new(map_t Line 442  static canvas_item_t *map_way_new(map_t
442    
443    canvas_item_set_zoom_max(map_item->item, way->draw.zoom_max);    canvas_item_set_zoom_max(map_item->item, way->draw.zoom_max);
444    
445      if (group != CANVAS_GROUP_WAYS_OL)
446        if (way->draw.dashed)
447          canvas_item_set_dashed(map_item->item);
448    
449    /* attach map_item to ways map_item_chain */    /* attach map_item to ways map_item_chain */
450    map_item_chain_t **chain = &way->map_item_chain;    map_item_chain_t **chain = &way->map_item_chain;
451    while(*chain) chain = &(*chain)->next;    while(*chain) chain = &(*chain)->next;
# Line 969  static void map_scroll_towards_centre(ma Line 973  static void map_scroll_towards_centre(ma
973      map->state->scroll_offset.y = sy;      map->state->scroll_offset.y = sy;
974  }  }
975  #endif // #if 0  #endif // #if 0
976    
977    /*
978     * Scroll the map to a point if that point is currently offscreen.
979     */
980    void map_scroll_to_if_offscreen(map_t *map, lpos_t *lpos) {
981    
982      // Ignore anything outside the working area
983      if (!(map && map->appdata && map->appdata->osm)) {
984        return;
985      }
986      gint min_x, min_y, max_x, max_y;
987      min_x = map->appdata->osm->bounds->min.x;
988      min_y = map->appdata->osm->bounds->min.y;
989      max_x = map->appdata->osm->bounds->max.x;
990      max_y = map->appdata->osm->bounds->max.y;
991      if (   (lpos->x > max_x) || (lpos->x < min_x)
992          || (lpos->y > max_y) || (lpos->y < min_y)) {
993        printf("cannot scroll to (%d, %d): outside the working area\n");
994        return;
995      }
996    
997      // Viewport dimensions in canvas space
998      gdouble zoom = goo_canvas_get_scale(GOO_CANVAS(map->canvas));
999      GtkAllocation *a = &GTK_WIDGET(map->canvas)->allocation;
1000      gdouble aw = a->width / zoom;
1001      gdouble ah = a->height / zoom;
1002    
1003      // Is the point still onscreen?
1004      gboolean vert_recentre_needed = FALSE;
1005      gboolean horiz_recentre_needed = FALSE;
1006      gint sx, sy;
1007      canvas_get_scroll_offsets(map->canvas, &sx, &sy);
1008      gint viewport_left   = (sx/zoom);
1009      gint viewport_right  = (sx/zoom)+aw;
1010      gint viewport_top    = (sy/zoom);
1011      gint viewport_bottom = (sy/zoom)+ah;
1012      if (lpos->x > viewport_right) {
1013        printf("** off right edge (%d > %d)\n", lpos->x, viewport_right);
1014        horiz_recentre_needed = TRUE;
1015      }
1016      if (lpos->x < viewport_left) {
1017        printf("** off left edge (%d < %d)\n", lpos->x, viewport_left);
1018        horiz_recentre_needed = TRUE;
1019      }
1020      if (lpos->y > viewport_bottom) {
1021        printf("** off bottom edge (%d > %d)\n", lpos->y, viewport_bottom);
1022        vert_recentre_needed = TRUE;
1023      }
1024      if (lpos->y < viewport_top) {
1025        printf("** off top edge (%d < %d)\n", lpos->y, viewport_top);
1026        vert_recentre_needed = TRUE;
1027      }
1028    
1029      if (horiz_recentre_needed || vert_recentre_needed) {
1030        gint new_sx, new_sy;
1031    #if 0
1032        // Only recentre the drifting axis.
1033        new_sx = horiz_recentre_needed ? zoom*(lpos->x - (aw/2)) : sx;
1034        new_sy = vert_recentre_needed  ? zoom*(lpos->y - (ah/2)) : sy;
1035        // Not sure about this. I don't think it really buys us anything.
1036    #else
1037        // Just centre both at once
1038        new_sx = zoom * (lpos->x - (aw/2));
1039        new_sy = zoom * (lpos->y - (ah/2));
1040    #endif
1041        map_limit_scroll(map, &new_sx, &new_sy);
1042        canvas_scroll_to(map->canvas, new_sx, new_sy);
1043      }
1044    }
1045    
1046  #endif // #ifdef USE_GOOCANVAS  #endif // #ifdef USE_GOOCANVAS
1047    
1048  /* Deselects the current way or node if its zoom_max  /* Deselects the current way or node if its zoom_max
# Line 2193  void map_show_all(appdata_t *appdata) { Line 2267  void map_show_all(appdata_t *appdata) {
2267    
2268    gtk_widget_set_sensitive(appdata->menu_item_map_show_all, FALSE);    gtk_widget_set_sensitive(appdata->menu_item_map_show_all, FALSE);
2269  }  }
2270    // vim:et:ts=8:sw=2:sts=2:ai

Legend:
Removed from v.1  
changed lines
  Added in v.13