Let all show animations take borders into account

0.8
Bruno Van de Velde 2015-12-24 14:12:52 +01:00
parent 86ed793fbb
commit 4fb5fb94f4
2 changed files with 14 additions and 13 deletions

View File

@ -225,8 +225,8 @@ namespace tgui
{
if (getParent())
{
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), sf::Vector2f{getParent()->getSize().x, getPosition().y}, getPosition(), duration));
setPosition({getParent()->getSize().x, getPosition().y});
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), sf::Vector2f{getParent()->getSize().x + getWidgetOffset().x, getPosition().y}, getPosition(), duration));
setPosition({getParent()->getSize().x + getWidgetOffset().x, getPosition().y});
}
else
sf::err() << "TGUI Warning: showWithEffect(SlideToLeft) does not work before widget has a parent." << std::endl;
@ -243,8 +243,8 @@ namespace tgui
{
if (getParent())
{
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), sf::Vector2f{getPosition().x, getParent()->getSize().y}, getPosition(), duration));
setPosition({getPosition().x, getParent()->getSize().y});
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), sf::Vector2f{getPosition().x, getParent()->getSize().y + getWidgetOffset().y}, getPosition(), duration));
setPosition({getPosition().x, getParent()->getSize().y + getWidgetOffset().y});
}
else
sf::err() << "TGUI Warning: showWithEffect(SlideToTop) does not work before widget has a parent." << std::endl;
@ -287,7 +287,7 @@ namespace tgui
case ShowAnimationType::SlideToRight:
{
if (getParent())
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), position, sf::Vector2f{getParent()->getSize().x, position.y}, duration, [=](){ hide(); setPosition(position); }));
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), position, sf::Vector2f{getParent()->getSize().x + getWidgetOffset().x, position.y}, duration, [=](){ hide(); setPosition(position); }));
else
sf::err() << "TGUI Warning: showWithEffect(SlideToRight) does not work before widget has a parent." << std::endl;
@ -301,7 +301,7 @@ namespace tgui
case ShowAnimationType::SlideToBottom:
{
if (getParent())
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), position, sf::Vector2f{position.x, getParent()->getSize().y}, duration, [=](){ hide(); setPosition(position); }));
m_showAnimations.push_back(std::make_shared<priv::MoveAnimation>(shared_from_this(), position, sf::Vector2f{position.x, getParent()->getSize().y + getWidgetOffset().y}, duration, [=](){ hide(); setPosition(position); }));
else
sf::err() << "TGUI Warning: showWithEffect(SlideToBottom) does not work before widget has a parent." << std::endl;

View File

@ -32,7 +32,8 @@ bool compareVector2f(sf::Vector2f left, sf::Vector2f right)
}
TEST_CASE("[Animation]") {
tgui::Widget::Ptr widget = std::make_shared<tgui::Button>();
tgui::Button::Ptr widget = std::make_shared<tgui::Button>();
widget->getRenderer()->setBorders({2, 2, 2, 2});
widget->setPosition(30, 15);
widget->setSize(120, 30);
widget->setOpacity(0.9f);
@ -112,18 +113,18 @@ TEST_CASE("[Animation]") {
SECTION("SlideFromRight") {
widget->showWithEffect(tgui::ShowAnimationType::SlideFromRight, sf::milliseconds(300));
REQUIRE(widget->getPosition() == sf::Vector2f(480, 15));
REQUIRE(widget->getPosition() == sf::Vector2f(482, 15));
widget->update(sf::milliseconds(100));
REQUIRE(compareVector2f(widget->getPosition(), {330, 15}));
REQUIRE(compareVector2f(widget->getPosition(), {482-((482-30)/3.f), 15}));
widget->update(sf::milliseconds(200));
REQUIRE(widget->getPosition() == sf::Vector2f(30, 15));
}
SECTION("SlideFromBottom") {
widget->showWithEffect(tgui::ShowAnimationType::SlideFromBottom, sf::milliseconds(300));
REQUIRE(widget->getPosition() == sf::Vector2f(30, 360));
REQUIRE(widget->getPosition() == sf::Vector2f(30, 362));
widget->update(sf::milliseconds(100));
REQUIRE(compareVector2f(widget->getPosition(), {30, 245}));
REQUIRE(compareVector2f(widget->getPosition(), {30, 362-((362-15)/3.f)}));
widget->update(sf::milliseconds(200));
REQUIRE(widget->getPosition() == sf::Vector2f(30, 15));
}
@ -156,14 +157,14 @@ TEST_CASE("[Animation]") {
widget->hideWithEffect(tgui::ShowAnimationType::SlideToRight, sf::milliseconds(300));
REQUIRE(widget->getPosition() == sf::Vector2f(30, 15));
widget->update(sf::milliseconds(100));
REQUIRE(compareVector2f(widget->getPosition(), {180, 15}));
REQUIRE(compareVector2f(widget->getPosition(), {30+((482-30)/3.f), 15}));
}
SECTION("SlideToBottom") {
widget->hideWithEffect(tgui::ShowAnimationType::SlideToBottom, sf::milliseconds(300));
REQUIRE(widget->getPosition() == sf::Vector2f(30, 15));
widget->update(sf::milliseconds(100));
REQUIRE(compareVector2f(widget->getPosition(), {30, 130}));
REQUIRE(compareVector2f(widget->getPosition(), {30, 15+((362-15)/3.f)}));
}
SECTION("SlideToLeft") {