2022-07-25 14:36:05 +08:00
|
|
|
#include <SFML/Graphics/RenderWindow.hpp>
|
|
|
|
|
2023-03-10 08:38:14 +08:00
|
|
|
// Other 1st party headers
|
|
|
|
#include <SFML/Graphics/Image.hpp>
|
|
|
|
#include <SFML/Graphics/Texture.hpp>
|
2023-04-24 20:13:52 +08:00
|
|
|
|
2023-03-10 08:38:14 +08:00
|
|
|
#include <SFML/Window/VideoMode.hpp>
|
|
|
|
|
2023-04-24 20:13:52 +08:00
|
|
|
#include <SFML/System/String.hpp>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2023-03-10 08:38:14 +08:00
|
|
|
|
|
|
|
#include <GraphicsUtil.hpp>
|
2024-02-08 21:28:57 +08:00
|
|
|
#include <WindowUtil.hpp>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests())
|
2023-03-10 08:38:14 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
2024-01-09 02:31:33 +08:00
|
|
|
STATIC_CHECK(std::has_virtual_destructor_v<sf::RenderWindow>);
|
2023-01-18 12:51:08 +08:00
|
|
|
STATIC_CHECK(!std::is_copy_constructible_v<sf::RenderWindow>);
|
|
|
|
STATIC_CHECK(!std::is_copy_assignable_v<sf::RenderWindow>);
|
2023-12-27 07:31:08 +08:00
|
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::RenderWindow>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RenderWindow>);
|
2023-01-18 12:51:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Construction")
|
2023-03-10 08:38:14 +08:00
|
|
|
{
|
2024-01-02 06:38:14 +08:00
|
|
|
SECTION("Style, state, and settings")
|
|
|
|
{
|
|
|
|
const sf::RenderWindow window(sf::VideoMode(sf::Vector2u(256, 256), 24),
|
|
|
|
"Window Title",
|
|
|
|
sf::Style::Default,
|
|
|
|
sf::State::Windowed,
|
2024-05-25 02:36:42 +08:00
|
|
|
sf::ContextSettings{});
|
2024-01-02 06:38:14 +08:00
|
|
|
CHECK(window.isOpen());
|
|
|
|
CHECK(window.getSize() == sf::Vector2u(256, 256));
|
|
|
|
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
|
|
|
CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
|
|
|
|
CHECK(!window.isSrgb());
|
|
|
|
CHECK(window.getView().getCenter() == sf::Vector2f(128, 128));
|
|
|
|
CHECK(window.getView().getSize() == sf::Vector2f(256, 256));
|
|
|
|
CHECK(window.getView().getRotation() == sf::Angle::Zero);
|
|
|
|
CHECK(window.getView().getViewport() == sf::FloatRect({0, 0}, {1, 1}));
|
|
|
|
CHECK(window.getView().getTransform() == sf::Transform(0.0078125f, 0, -1, 0, -0.0078125f, 1, 0, 0, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("State and settings")
|
|
|
|
{
|
|
|
|
const sf::RenderWindow window(sf::VideoMode(sf::Vector2u(240, 300), 24),
|
|
|
|
"Window Title",
|
|
|
|
sf::State::Windowed,
|
2024-05-25 02:36:42 +08:00
|
|
|
sf::ContextSettings{});
|
2024-01-02 06:38:14 +08:00
|
|
|
CHECK(window.isOpen());
|
|
|
|
CHECK(window.getSize() == sf::Vector2u(240, 300));
|
|
|
|
CHECK(window.getNativeHandle() != sf::WindowHandle());
|
|
|
|
CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
|
|
|
|
CHECK(!window.isSrgb());
|
|
|
|
CHECK(window.getView().getCenter() == sf::Vector2f(120, 150));
|
|
|
|
CHECK(window.getView().getSize() == sf::Vector2f(240, 300));
|
|
|
|
CHECK(window.getView().getRotation() == sf::Angle::Zero);
|
|
|
|
CHECK(window.getView().getViewport() == sf::FloatRect({0, 0}, {1, 1}));
|
|
|
|
CHECK(window.getView().getTransform() ==
|
|
|
|
Approx(sf::Transform(0.00833333f, 0, -1, 0, -0.00666667f, 1, 0, 0, 1)));
|
|
|
|
}
|
2023-03-10 08:38:14 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Clear")
|
2023-03-10 08:38:14 +08:00
|
|
|
{
|
|
|
|
sf::RenderWindow window(sf::VideoMode(sf::Vector2u(256, 256), 24),
|
|
|
|
"Window Title",
|
|
|
|
sf::Style::Default,
|
2024-01-02 06:38:14 +08:00
|
|
|
sf::State::Windowed,
|
2024-05-25 02:36:42 +08:00
|
|
|
sf::ContextSettings{});
|
2023-03-10 08:38:14 +08:00
|
|
|
REQUIRE(window.getSize() == sf::Vector2u(256, 256));
|
|
|
|
|
2024-07-06 10:24:00 +08:00
|
|
|
sf::Texture texture(window.getSize());
|
2023-03-10 08:38:14 +08:00
|
|
|
|
|
|
|
window.clear(sf::Color::Red);
|
|
|
|
texture.update(window);
|
|
|
|
CHECK(texture.copyToImage().getPixel(sf::Vector2u(64, 64)) == sf::Color::Red);
|
|
|
|
|
|
|
|
window.clear(sf::Color::Green);
|
|
|
|
texture.update(window);
|
|
|
|
CHECK(texture.copyToImage().getPixel(sf::Vector2u(128, 128)) == sf::Color::Green);
|
|
|
|
|
|
|
|
window.clear(sf::Color::Blue);
|
|
|
|
texture.update(window);
|
|
|
|
CHECK(texture.copyToImage().getPixel(sf::Vector2u(196, 196)) == sf::Color::Blue);
|
|
|
|
}
|
|
|
|
}
|