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;
|
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
|
// Smooth out transition to new size
|
||||||
newSize = size + (newSize - size) * options.softResizeSpeed * FRAME_TIME.asSeconds();
|
newSize = size + (newSize - size) * options.softResizeSpeed * FRAME_TIME.asSeconds();
|
||||||
}
|
}
|
||||||
|
@ -71,6 +79,12 @@ sf::Vector2f TrackingView::getSize() const
|
||||||
return view->getSize();
|
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
|
sf::Vector2f TrackingView::getCenter() const
|
||||||
{
|
{
|
||||||
return view->getCenter();
|
return view->getCenter();
|
||||||
|
@ -189,8 +203,8 @@ void TrackingView::adjustSizeToTrackables()
|
||||||
newViewSize = restrainToBounds(newViewSize);
|
newViewSize = restrainToBounds(newViewSize);
|
||||||
|
|
||||||
// Extend view to match aspect ratio
|
// Extend view to match aspect ratio
|
||||||
auto currentViewSize = getSize();
|
auto windowSize = getWindowSize();
|
||||||
auto aspectRatio = currentViewSize.x / currentViewSize.y;
|
auto aspectRatio = windowSize.x / windowSize.y;
|
||||||
if (newViewSize.x / newViewSize.y > aspectRatio)
|
if (newViewSize.x / newViewSize.y > aspectRatio)
|
||||||
{
|
{
|
||||||
// Extend x-axis
|
// Extend x-axis
|
||||||
|
@ -251,8 +265,8 @@ float TrackingView::getRadius(float threshold) const
|
||||||
return threshold;
|
return threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto viewSize = getSize();
|
auto windowSize = getWindowSize();
|
||||||
float smallestSide = std::min(viewSize.x, viewSize.y);
|
float smallestSide = std::min(windowSize.x, windowSize.y);
|
||||||
|
|
||||||
// Only half of the side, since we are calculating radius
|
// Only half of the side, since we are calculating radius
|
||||||
return smallestSide / 2.f * threshold;
|
return smallestSide / 2.f * threshold;
|
||||||
|
|
|
@ -55,6 +55,8 @@ private:
|
||||||
sf::Vector2f restrainToBounds(sf::Vector2f viewSize) const;
|
sf::Vector2f restrainToBounds(sf::Vector2f viewSize) const;
|
||||||
|
|
||||||
float getRadius(float threshold) const;
|
float getRadius(float threshold) const;
|
||||||
|
|
||||||
|
sf::Vector2f getWindowSize() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue