Fix scrolling code even more. (Fixes some really minor scrolling bugs.)

This outside_area() function confused some people, me included.

Also, the implementation was 1/4 hex off.
This commit is contained in:
Martin Renold 2008-02-09 20:51:46 +00:00
parent f6de6205fc
commit f3f98c7525
2 changed files with 8 additions and 22 deletions

View file

@ -158,7 +158,7 @@ const SDL_Rect& display::map_area() const
bool display::outside_area(const SDL_Rect& area, const int x, const int y) const
{
const int x_thresh = hex_width();
const int x_thresh = hex_size();
const int y_thresh = hex_size();
return (x < area.x || x > area.x + area.w - x_thresh ||
y < area.y || y > area.y + area.h - y_thresh);
@ -1437,15 +1437,8 @@ void display::scroll_to_tile(const gamemap::location& loc, SCROLL_TYPE scroll_ty
const int screenxpos = get_location_x(loc);
const int screenypos = get_location_y(loc);
if (scroll_type == ONSCREEN) {
// The tile must be fully visible
SDL_Rect r = map_area();
r.w -= hex_width();
r.h -= zoom_;
if (!outside_area(r,screenxpos,screenypos)) {
return;
}
if (scroll_type == ONSCREEN && !outside_area(map_area(),screenxpos,screenypos)) {
return;
}
const SDL_Rect area = map_area();
@ -1560,18 +1553,11 @@ void display::scroll_to_tiles(const gamemap::location& loc1, const gamemap::loca
if(!check_fogged || ( !fogged(loc1) && !fogged(loc2))) {
// Scroll to middle point of rectangle
if (scroll_type == ONSCREEN) {
// The tile must be fully visible
SDL_Rect r = map_area();
r.w -= hex_width(); // sure? shouldn't this be zoom_?
r.h -= zoom_;
if (!outside_area(r,get_location_x(loc1),get_location_y(loc1)) &&
!outside_area(r,get_location_x(loc2),get_location_x(loc2)) ) {
return;
}
scroll_to_tile(gamemap::location((loc1.x+loc2.x)/2,(loc1.y+loc2.y)/2),SCROLL,check_fogged);
// note: on-screen check was already done unconditionally
// We also have to scroll if the middle point already is on-screen.
scroll_type = SCROLL;
}
scroll_to_tile(gamemap::location((loc1.x+loc2.x)/2,(loc1.y+loc2.y)/2),scroll_type,check_fogged);
scroll_to_tile(gamemap::location((loc1.x+loc2.x)/2,(loc1.y+loc2.y)/2),scroll_type,false);
} else if(!fogged(loc1)) {
scroll_to_tile(loc1,scroll_type,check_fogged);
} else if(!fogged(loc2)) {

View file

@ -96,7 +96,7 @@ public:
const SDL_Rect& map_outside_area() const
{ return theme_.main_map_location(screen_area()); }
//! Check if pixel x,y is outside specified area.
//! Check if the bbox of the hex at x,y has pixels outside the area rectangle.
bool outside_area(const SDL_Rect& area, const int x,const int y) const;
//! Function which returns the width of a hex in pixels,