feat: moved view management to CHANGEME.cpp

This commit is contained in:
Sara Gerretsen 2025-09-11 11:46:12 +02:00
parent 54bc6b9415
commit 561fdbbb6b

View file

@ -1,14 +1,17 @@
#include "defs.h" #include "defs.h"
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/RenderStates.hpp> #include <SFML/Graphics/RenderStates.hpp>
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <SFML/Window/Event.hpp>
#include <imgui-SFML.h> #include <imgui-SFML.h>
#include <imgui.h> #include <imgui.h>
#include <print> #include <print>
void configure(AppConfig &config) { void configure(AppConfig &config) {
config.window_title = "My Project"; config.window_title = "CHANGEME";
config.frame_rate_limit = std::nullopt; config.frame_rate_limit = std::nullopt;
config.vsync = true; config.vsync = true;
} }
@ -19,6 +22,20 @@ void setup() {
| ImGuiConfigFlags_NavEnableGamepad | ImGuiConfigFlags_NavEnableGamepad
| ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_DockingEnable
); );
sf::View view{ get_window().getView() };
view.setCenter( { 0.f, 0.f } );
set_render_view(view);
}
void handle_input_event(sf::Event const &event) {
}
void handle_window_event(sf::Event const &event) {
if (sf::Event::Resized const *resized{ event.getIf<sf::Event::Resized>()}) {
sf::View view{ get_window().getView() };
view.setSize({ static_cast<float>(resized->size.x), static_cast<float>(resized->size.y) });
set_render_view(view);
}
} }
void loop(double delta) { void loop(double delta) {
@ -27,7 +44,7 @@ void loop(double delta) {
void draw_scene(sf::RenderTarget &target, sf::RenderStates const &states) { void draw_scene(sf::RenderTarget &target, sf::RenderStates const &states) {
static sf::RectangleShape rect{ { 300, 300 } }; static sf::RectangleShape rect{ { 300, 300 } };
sf::RenderStates n_states{states}; sf::RenderStates n_states{states};
n_states.transform.translate({ 20, 20 }); n_states.transform.translate({ -150, -150 });
target.draw(rect, n_states); target.draw(rect, n_states);
} }
@ -55,3 +72,6 @@ void draw_gui() {
ImGui::End(); ImGui::End();
} }
} }
void shutdown() {
}