diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index f68a29b47..3fa6fbd74 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -63,6 +63,15 @@ public: Vector2u size; //!< New size, in pixels }; + //////////////////////////////////////////////////////////// + /// \brief WindowMoved event subtype + /// + //////////////////////////////////////////////////////////// + struct WindowMoved + { + Vector2i position; //!< New position, in pixels + }; + //////////////////////////////////////////////////////////// /// \brief Lost focus event subtype /// @@ -355,6 +364,7 @@ private: //////////////////////////////////////////////////////////// std::variant()); @@ -53,6 +58,14 @@ TEST_CASE("[Window] sf::Event") const auto& resized = *event.getIf(); CHECK(resized.size == sf::Vector2u(1, 2)); } + SECTION("Template constructor window move") + { + const sf::Event event = sf::Event::WindowMoved{{1, 2}}; + CHECK(event.is()); + CHECK(event.getIf()); + const auto& windowMoved = *event.getIf(); + CHECK(windowMoved.position == sf::Vector2i(1, 2)); + } } SECTION("Assign all possible values") @@ -67,6 +80,12 @@ TEST_CASE("[Window] sf::Event") const auto& resized = *event.getIf(); CHECK(resized.size == sf::Vector2u(1, 2)); + event = sf::Event::WindowMoved{{3, 4}}; + CHECK(event.is()); + CHECK(event.getIf()); + const auto& windowMoved = *event.getIf(); + CHECK(windowMoved.position == sf::Vector2i(3, 4)); + event = sf::Event::FocusLost{}; CHECK(event.is()); CHECK(event.getIf()); @@ -221,6 +240,9 @@ TEST_CASE("[Window] sf::Event") const sf::Event::Resized resized; CHECK(resized.size == sf::Vector2u()); + const sf::Event::WindowMoved windowMoved; + CHECK(windowMoved.position == sf::Vector2i()); + const sf::Event::TextEntered textEntered; CHECK(textEntered.unicode == 0); @@ -302,12 +324,19 @@ TEST_CASE("[Window] sf::Event") REQUIRE(mouseMoved); mouseMoved->position = sf::Vector2i(6, 9); CHECK(mouseMoved->position == sf::Vector2i(6, 9)); + + event = sf::Event::WindowMoved{{1, 2}}; + auto* windowMoved = event.getIf(); + REQUIRE(windowMoved); + windowMoved->position = sf::Vector2i(3, 4); + CHECK(windowMoved->position == sf::Vector2i(3, 4)); } SECTION("visit()") { CHECK(sf::Event(sf::Event::Closed{}).visit(visitor) == "Closed"); CHECK(sf::Event(sf::Event::Resized{}).visit(visitor) == "Resized"); + CHECK(sf::Event(sf::Event::WindowMoved{}).visit(visitor) == "WindowMoved"); CHECK(sf::Event(sf::Event::FocusLost{}).visit(visitor) == "Other"); CHECK(sf::Event(sf::Event::FocusGained{}).visit(visitor) == "Other"); CHECK(sf::Event(sf::Event::KeyPressed{}).visit(visitor) == "KeyPressed");