mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-25 21:38:59 +02:00
Fixed map view centering during scaling change
This commit is contained in:
parent
9e3bc87a6b
commit
7504ceb256
client/mapView
@ -69,10 +69,19 @@ void MapViewController::setViewCenter(const Point & position, int level)
|
|||||||
|
|
||||||
void MapViewController::setTileSize(const Point & tileSize)
|
void MapViewController::setTileSize(const Point & tileSize)
|
||||||
{
|
{
|
||||||
|
Point oldSize = model->getSingleTileSize();
|
||||||
model->setTileSize(tileSize);
|
model->setTileSize(tileSize);
|
||||||
|
|
||||||
|
double scaleChangeX = 1.0 * tileSize.x / oldSize.x;
|
||||||
|
double scaleChangeY = 1.0 * tileSize.y / oldSize.y;
|
||||||
|
|
||||||
|
Point newViewCenter {
|
||||||
|
static_cast<int>(std::round(model->getMapViewCenter().x * scaleChangeX)),
|
||||||
|
static_cast<int>(std::round(model->getMapViewCenter().y * scaleChangeY))
|
||||||
|
};
|
||||||
|
|
||||||
// force update of view center since changing tile size may invalidated it
|
// force update of view center since changing tile size may invalidated it
|
||||||
setViewCenter(model->getMapViewCenter(), model->getLevel());
|
setViewCenter(newViewCenter, model->getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapViewController::modifyTileSize(int stepsChange)
|
void MapViewController::modifyTileSize(int stepsChange)
|
||||||
@ -101,7 +110,8 @@ void MapViewController::modifyTileSize(int stepsChange)
|
|||||||
std::clamp(desiredZoom.y, minimal.y, maximal.y)
|
std::clamp(desiredZoom.y, minimal.y, maximal.y)
|
||||||
};
|
};
|
||||||
|
|
||||||
setTileSize(actualZoom);
|
if (actualZoom != currentZoom)
|
||||||
|
setTileSize(actualZoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapViewController::MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view)
|
MapViewController::MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view)
|
||||||
|
@ -35,12 +35,15 @@ void MapViewModel::setLevel(int newLevel)
|
|||||||
|
|
||||||
Point MapViewModel::getSingleTileSizeUpperLimit() const
|
Point MapViewModel::getSingleTileSizeUpperLimit() const
|
||||||
{
|
{
|
||||||
return Point(128, 128); // arbitrary-seleted upscaling limit
|
// arbitrary-seleted upscaling limit
|
||||||
|
// TODO: figure out reason behind graphical artifacts on scaling higher than 120px (375%)
|
||||||
|
return Point(120, 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point MapViewModel::getSingleTileSizeLowerLimit() const
|
Point MapViewModel::getSingleTileSizeLowerLimit() const
|
||||||
{
|
{
|
||||||
return Point(4, 4); // arbitrary-seleted upscaling limit
|
// arbitrary-seleted downscaling limit
|
||||||
|
return Point(4, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point MapViewModel::getSingleTileSize() const
|
Point MapViewModel::getSingleTileSize() const
|
||||||
@ -114,14 +117,14 @@ Rect MapViewModel::getCacheTileArea(const int3 & coordinates) const
|
|||||||
(getTilesVisibleDimensions().y + coordinates.y) % getTilesVisibleDimensions().y
|
(getTilesVisibleDimensions().y + coordinates.y) % getTilesVisibleDimensions().y
|
||||||
};
|
};
|
||||||
|
|
||||||
return Rect(tileIndex * tileSize, tileSize);
|
return Rect(tileIndex * getSingleTileSize(), getSingleTileSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect MapViewModel::getTargetTileArea(const int3 & coordinates) const
|
Rect MapViewModel::getTargetTileArea(const int3 & coordinates) const
|
||||||
{
|
{
|
||||||
Point topLeftOffset = getMapViewCenter() - getPixelsVisibleDimensions() / 2;
|
Point topLeftOffset = getMapViewCenter() - getPixelsVisibleDimensions() / 2;
|
||||||
Point tilePosAbsolute = Point(coordinates) * tileSize;
|
Point tilePosAbsolute = Point(coordinates) * getSingleTileSize();
|
||||||
Point tilePosRelative = tilePosAbsolute - topLeftOffset;
|
Point tilePosRelative = tilePosAbsolute - topLeftOffset;
|
||||||
|
|
||||||
return Rect(tilePosRelative, tileSize);
|
return Rect(tilePosRelative, getSingleTileSize());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user