Skip to content

Commit

Permalink
Prevent minimap scrolling if viewport is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jun 2, 2014
1 parent a706e05 commit 2f8b997
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/display.cpp
Expand Up @@ -795,32 +795,35 @@ int display::get_location_y(const map_location& loc) const

map_location display::minimap_location_on(int x, int y)
{
//TODO: don't return location for this,
// instead directly scroll to the clicked pixel position
if(!view_locked_ || force) {

if (!point_in_rect(x, y, minimap_area())) {
return map_location();
}
//TODO: don't return location for this,
// instead directly scroll to the clicked pixel position

// we transform the coordinates from minimap to the full map image
// probably more adjustments to do (border, minimap shift...)
// but the mouse and human capacity to evaluate the rectangle center
// is not pixel precise.
int px = (x - minimap_location_.x) * get_map().w()*hex_width() / minimap_location_.w;
int py = (y - minimap_location_.y) * get_map().h()*hex_size() / minimap_location_.h;
if (!point_in_rect(x, y, minimap_area())) {
return map_location();
}

map_location loc = pixel_position_to_hex(px, py);
if (loc.x < 0)
loc.x = 0;
else if (loc.x >= get_map().w())
loc.x = get_map().w() - 1;
// we transform the coordinates from minimap to the full map image
// probably more adjustments to do (border, minimap shift...)
// but the mouse and human capacity to evaluate the rectangle center
// is not pixel precise.
int px = (x - minimap_location_.x) * get_map().w()*hex_width() / minimap_location_.w;
int py = (y - minimap_location_.y) * get_map().h()*hex_size() / minimap_location_.h;

if (loc.y < 0)
loc.y = 0;
else if (loc.y >= get_map().h())
loc.y = get_map().h() - 1;
map_location loc = pixel_position_to_hex(px, py);
if (loc.x < 0)
loc.x = 0;
else if (loc.x >= get_map().w())
loc.x = get_map().w() - 1;

return loc;
if (loc.y < 0)
loc.y = 0;
else if (loc.y >= get_map().h())
loc.y = get_map().h() - 1;

return loc;
}
}

int display::screenshot(std::string filename, bool map_screenshot)
Expand Down

0 comments on commit 2f8b997

Please sign in to comment.