Set the minimum zoom to the techical limit and not the screen size limit

thus it's possible to zoom until the map is smaller than the screen.
This commit is contained in:
Mark de Wever 2007-05-17 09:55:26 +00:00
parent 74cfdde6b8
commit a641cf0d9f
2 changed files with 7 additions and 23 deletions

View file

@ -27,6 +27,8 @@ Version 1.3.2+svn:
* better flag icons for the status bar
* taller flags that don't get hidden behind units so easily
* fixed some drawing glitches in the top row (bug #8739 and #8071)
* it's now possible to zoom in till the theoretical minimum of 4 pixels
per hex.
* sound and music:
* added a sound when a unit is slowed
* added a music track containing only silence (for stopping all music instead

View file

@ -59,24 +59,9 @@ namespace {
const int DefaultZoom = 72;
#endif
const int MinZoom = 4;
const int MaxZoom = 200;
}
static int MinZoom(const gamemap& map, const SDL_Rect& viewport)
{
if(map.x()<4 || !map.y() ) return DefaultZoom;
// These ugly formulas try to give the optimal and mathematically exact minimal zoom
const double min_zoom1 = 4.0/3.0 * ceil(static_cast<double>(viewport.w)/static_cast<double>(map.x())) ;
const double min_zoom2 = static_cast<double>(viewport.h)/static_cast<double>(map.y());
int zoom = static_cast<int>(ceil( maximum<double>(min_zoom1,min_zoom2) ));
//NOTE: keep zoom (and so tile_size) divisible by 4: stay even, prevent some precision bugs (the hexagonal engine uses many integer division by 4), don't quit the 72+4n scale and maybe help processor's optimisation (ask Torangan).
if (zoom % 4 != 0) {
zoom = zoom - zoom % 4 + 4;
}
return minimum<int>(zoom,DefaultZoom);
}
namespace {
const size_t SideBarGameStatus_x = 16;
const size_t SideBarGameStatus_y = 220;
}
@ -493,9 +478,8 @@ void display::invalidate_locations_in_rect(SDL_Rect r)
double display::zoom(int amount)
{
int new_zoom = zoom_ + amount;
const int min_zoom = MinZoom(map_, map_area());
if (new_zoom < min_zoom) {
new_zoom = min_zoom;
if (new_zoom < MinZoom) {
new_zoom = MinZoom;
}
if (new_zoom > MaxZoom) {
new_zoom = MaxZoom;
@ -698,12 +682,10 @@ void display::scroll_to_leader(unit_map& units, int side)
void display::bounds_check_position()
{
const int min_zoom = MinZoom(map_,map_area());
const int orig_zoom = zoom_;
if(zoom_ < min_zoom) {
zoom_ = min_zoom;
if(zoom_ < MinZoom) {
zoom_ = MinZoom;
}
if(zoom_ > MaxZoom) {