#include "imgui.h" #include "imgui-SFML.h" #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include using namespace ImGui; constexpr int FPS=30; constexpr int X_DIM = 1920 / 2; constexpr int Y_DIM = 1080 / 2; bool window_active_out = false; void ImGui_setup(sf::RenderWindow &window) { bool res = SFML::Init(window); fmt::println("IMGUI returned {}", res); } void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tick) { sf::Vector2u size = window.getSize(); SFML::Update(window, deltaClock.restart()); SetNextWindowPos(ImVec2(0, size.y / 2)); SetNextWindowSize(ImVec2(size.x, size.y / 2)); Begin("Build Status", &window_active_out); TextColored(ImVec4(1,1,0,1), "Build Log"); BeginChild("Scrolling"); for(int n = 0; n < 50; n++) { TextWrapped("%04d: Some Text", n); } EndChild(); End(); } void Window_update(sf::RenderWindow &window, sf::Sprite &background) { window.clear(); window.draw(background); if(window_active_out) { fmt::println(">>>> RENDER"); SFML::Render(window); } window.display(); } void Handle_events(sf::RenderWindow &window) { sf::Event event; // is this a main event loop while (window.pollEvent(event)) { if(window_active_out) { fmt::println(">>> EVENTS"); SFML::ProcessEvent(window, event); } switch(event.type) { case sf::Event::Closed: fmt::print("Exiting...\n"); window.close(); break; case sf::Event::KeyPressed: if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { window.close(); } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { fmt::println(">>> SET TRUE"); window_active_out = true; } break; default: // do nothing break; } } } sf::Time Update_entities(sf::RenderWindow &window, sf::Sprite &background, sf::Clock &clock, sf::Clock &deltaClock, sf::Time &tick) { sf::Vector2u winSize = window.getSize(); float timeStep = 1.0f / FPS; sf::Time since = clock.getElapsedTime(); sf::Time nextTick = since - tick > sf::seconds(1) ? since : tick; background.setPosition(0, 0); if(window_active_out) { fmt::println("<<< UPDATE"); ImGui_update(window, deltaClock, tick); } Window_update(window, background); return nextTick; } int main() { fmt::print("Setting up a window for you...\n"); sf::ContextSettings settings; settings.antialiasingLevel = 8; sf::RenderWindow window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings); window.setPosition({.x=0,.y=0}); window.setFramerateLimit(FPS); window.setVerticalSyncEnabled(true); ImGui_setup(window); sf::Clock deltaClock; sf::Clock clock; sf::Time tick = clock.getElapsedTime(); sf::Texture texture; sf::Sprite background; // fake image here if(!texture.loadFromFile("./assets/turing_tarpit_main_screen.png")) { fmt::println("Error loading sprite!"); } texture.setSmooth(true); background.setTexture(texture); while (window.isOpen()) { fmt::println(">>>>>>>>>>>>>>>>>> WINDOW LOOP"); Handle_events(window); // preparing for refactoring this into a class or struct for everything tick = Update_entities(window, background, clock, deltaClock, tick); fmt::println("<<<<<<<<<<<<<<<< EXIT WINDOW LOOP"); } SFML::Shutdown(); }