View adjusts aspect ratio during resize
This commit is contained in:
parent
a0636a3637
commit
04d16e4ac4
2 changed files with 21 additions and 5 deletions
|
@ -57,7 +57,15 @@ void TrackingView::setSize(sf::Vector2f newSize)
|
|||
return;
|
||||
}
|
||||
|
||||
if (options.softResizeSpeed != 0) {
|
||||
bool didAspectRationChange = false;
|
||||
auto prevRatio = size.x / size.y;
|
||||
auto newRatio = newSize.x / newSize.y;
|
||||
if (abs(prevRatio - newRatio) > 0.001)
|
||||
{
|
||||
didAspectRationChange = true;
|
||||
}
|
||||
|
||||
if (options.softResizeSpeed != 0 && !didAspectRationChange) {
|
||||
// Smooth out transition to new size
|
||||
newSize = size + (newSize - size) * options.softResizeSpeed * FRAME_TIME.asSeconds();
|
||||
}
|
||||
|
@ -71,6 +79,12 @@ sf::Vector2f TrackingView::getSize() const
|
|||
return view->getSize();
|
||||
}
|
||||
|
||||
sf::Vector2f TrackingView::getWindowSize() const
|
||||
{
|
||||
auto size = Game::getInstance()->window->getSize();
|
||||
return {static_cast<float>(size.x), static_cast<float>(size.y)};
|
||||
}
|
||||
|
||||
sf::Vector2f TrackingView::getCenter() const
|
||||
{
|
||||
return view->getCenter();
|
||||
|
@ -189,8 +203,8 @@ void TrackingView::adjustSizeToTrackables()
|
|||
newViewSize = restrainToBounds(newViewSize);
|
||||
|
||||
// Extend view to match aspect ratio
|
||||
auto currentViewSize = getSize();
|
||||
auto aspectRatio = currentViewSize.x / currentViewSize.y;
|
||||
auto windowSize = getWindowSize();
|
||||
auto aspectRatio = windowSize.x / windowSize.y;
|
||||
if (newViewSize.x / newViewSize.y > aspectRatio)
|
||||
{
|
||||
// Extend x-axis
|
||||
|
@ -251,8 +265,8 @@ float TrackingView::getRadius(float threshold) const
|
|||
return threshold;
|
||||
}
|
||||
|
||||
auto viewSize = getSize();
|
||||
float smallestSide = std::min(viewSize.x, viewSize.y);
|
||||
auto windowSize = getWindowSize();
|
||||
float smallestSide = std::min(windowSize.x, windowSize.y);
|
||||
|
||||
// Only half of the side, since we are calculating radius
|
||||
return smallestSide / 2.f * threshold;
|
||||
|
|
|
@ -55,6 +55,8 @@ private:
|
|||
sf::Vector2f restrainToBounds(sf::Vector2f viewSize) const;
|
||||
|
||||
float getRadius(float threshold) const;
|
||||
|
||||
sf::Vector2f getWindowSize() const;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue