fix: view scaling with window

This commit is contained in:
Sara Gerretsen 2025-09-04 22:17:56 +02:00
parent b9cdef76c0
commit 4aaecd5365

View file

@ -7,6 +7,7 @@
static sf::RenderWindow window{}; static sf::RenderWindow window{};
static sf::Clock deltaClock{}; static sf::Clock deltaClock{};
static AppConfig cfg{}; static AppConfig cfg{};
static sf::View view{};
extern void configure(AppConfig &config); extern void configure(AppConfig &config);
@ -16,6 +17,7 @@ void initialize_window() {
if (cfg.frame_rate_limit) if (cfg.frame_rate_limit)
window.setFramerateLimit(cfg.frame_rate_limit.value_or(0)); window.setFramerateLimit(cfg.frame_rate_limit.value_or(0));
window.setVerticalSyncEnabled(cfg.vsync); window.setVerticalSyncEnabled(cfg.vsync);
view = window.getDefaultView();
} }
void initialize_imgui() { void initialize_imgui() {
@ -28,8 +30,12 @@ void poll_events() {
{ {
ImGui::SFML::ProcessEvent(window, *event); ImGui::SFML::ProcessEvent(window, *event);
// "close requested" event: we close the window // "close requested" event: we close the window
if (event->is<sf::Event::Closed>()) if (event->is<sf::Event::Closed>()) {
window.close(); window.close();
} else if (sf::Event::Resized const *resized{ event->getIf<sf::Event::Resized>()}) {
view.setSize({ static_cast<float>(resized->size.x), static_cast<float>(resized->size.y) });
window.setView(view);
}
} }
} }