Diff of /trunk/src/map.c

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

revision 2 by achadwick, Wed Dec 10 00:00:05 2008 UTC revision 12 by achadwick, Sun Dec 14 15:38:22 2008 UTC
# Line 969  static void map_scroll_towards_centre(ma Line 969  static void map_scroll_towards_centre(ma
969      map->state->scroll_offset.y = sy;      map->state->scroll_offset.y = sy;
970  }  }
971  #endif // #if 0  #endif // #if 0
972    
973    /*
974     * Scroll the map to a point if that point is currently offscreen.
975     */
976    void map_scroll_to_if_offscreen(map_t *map, lpos_t *lpos) {
977    
978      // Ignore anything outside the working area
979      if (!(map && map->appdata && map->appdata->osm)) {
980        return;
981      }
982      gint min_x, min_y, max_x, max_y;
983      min_x = map->appdata->osm->bounds->min.x;
984      min_y = map->appdata->osm->bounds->min.y;
985      max_x = map->appdata->osm->bounds->max.x;
986      max_y = map->appdata->osm->bounds->max.y;
987      if (   (lpos->x > max_x) || (lpos->x < min_x)
988          || (lpos->y > max_y) || (lpos->y < min_y)) {
989        printf("cannot scroll to (%d, %d): outside the working area\n");
990        return;
991      }
992    
993      // Viewport dimensions in canvas space
994      gdouble zoom = goo_canvas_get_scale(GOO_CANVAS(map->canvas));
995      GtkAllocation *a = &GTK_WIDGET(map->canvas)->allocation;
996      gdouble aw = a->width / zoom;
997      gdouble ah = a->height / zoom;
998    
999      // Is the point still onscreen?
1000      gboolean vert_recentre_needed = FALSE;
1001      gboolean horiz_recentre_needed = FALSE;
1002      gint sx, sy;
1003      canvas_get_scroll_offsets(map->canvas, &sx, &sy);
1004      gint viewport_left   = (sx/zoom);
1005      gint viewport_right  = (sx/zoom)+aw;
1006      gint viewport_top    = (sy/zoom);
1007      gint viewport_bottom = (sy/zoom)+ah;
1008      if (lpos->x > viewport_right) {
1009        printf("** off right edge (%d > %d)\n", lpos->x, viewport_right);
1010        horiz_recentre_needed = TRUE;
1011      }
1012      if (lpos->x < viewport_left) {
1013        printf("** off left edge (%d < %d)\n", lpos->x, viewport_left);
1014        horiz_recentre_needed = TRUE;
1015      }
1016      if (lpos->y > viewport_bottom) {
1017        printf("** off bottom edge (%d > %d)\n", lpos->y, viewport_bottom);
1018        vert_recentre_needed = TRUE;
1019      }
1020      if (lpos->y < viewport_top) {
1021        printf("** off top edge (%d < %d)\n", lpos->y, viewport_top);
1022        vert_recentre_needed = TRUE;
1023      }
1024    
1025      if (horiz_recentre_needed || vert_recentre_needed) {
1026        gint new_sx, new_sy;
1027    #if 0
1028        // Only recentre the drifting axis.
1029        new_sx = horiz_recentre_needed ? zoom*(lpos->x - (aw/2)) : sx;
1030        new_sy = vert_recentre_needed  ? zoom*(lpos->y - (ah/2)) : sy;
1031        // Not sure about this. I don't think it really buys us anything.
1032    #else
1033        // Just centre both at once
1034        new_sx = zoom * (lpos->x - (aw/2));
1035        new_sy = zoom * (lpos->y - (ah/2));
1036    #endif
1037        map_limit_scroll(map, &new_sx, &new_sy);
1038        canvas_scroll_to(map->canvas, new_sx, new_sy);
1039      }
1040    }
1041    
1042  #endif // #ifdef USE_GOOCANVAS  #endif // #ifdef USE_GOOCANVAS
1043    
1044  /* Deselects the current way or node if its zoom_max  /* Deselects the current way or node if its zoom_max

Legend:
Removed from v.2  
changed lines
  Added in v.12