diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ee37d..7f7b7e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ endif() set(Triangles_SOURCES src/main.cpp + src/state.cpp third_party/imgui/imgui.cpp third_party/imgui/imgui_draw.cpp third_party/imgui/imgui_widgets.cpp diff --git a/src/imgui_helper.hpp b/src/imgui_helper.hpp new file mode 100644 index 0000000..0108e1b --- /dev/null +++ b/src/imgui_helper.hpp @@ -0,0 +1,22 @@ +#ifndef TRIANGLES_IMGUI_HELPER_HPP +#define TRIANGLES_IMGUI_HELPER_HPP + +#include + +#include "state.hpp" + +namespace Tri { + inline void draw_help(Tri::State *state) { + if(state->flags.test(0)) { + ImGui::SetNextWindowPos(sf::Vector2f(10.0f, 10.0f)); + ImGui::SetNextWindowSize(sf::Vector2f( + state->width - 20.0f, + state->height - 20.0f)); + ImGui::Begin("Help Window", nullptr, ImGuiWindowFlags_NoDecoration); + ImGui::Text("This is the help window."); + ImGui::End(); + } + } +} + +#endif diff --git a/src/main.cpp b/src/main.cpp index 72d131a..ed0d420 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,12 +5,19 @@ #include #include +#include "state.hpp" +#include "imgui_helper.hpp" + int main(int argc, char **argv) { // init - sf::RenderWindow window(sf::VideoMode(800, 600), "Triangles"); + Tri::State state{}; + + sf::RenderWindow window( + sf::VideoMode(state.width, state.height), + "Triangles", + sf::Style::Titlebar | sf::Style::Close); ImGui::SFML::Init(window); window.setFramerateLimit(60); - const sf::Time dt = sf::microseconds(16666); // main loop sf::Event event; @@ -20,21 +27,28 @@ int main(int argc, char **argv) { ImGui::SFML::ProcessEvent(event); if(event.type == sf::Event::Closed) { window.close(); + } else if(event.type == sf::Event::KeyPressed) { + if(event.key.code == sf::Keyboard::H) { + state.flags.set(0); + } + } else if(event.type == sf::Event::KeyReleased) { + if(event.key.code == sf::Keyboard::H) { + state.flags.reset(0); + } } // update - ImGui::SFML::Update(window, dt); + ImGui::SFML::Update(window, state.dt); - ImGui::Begin("Test window"); - ImGui::Text("Test text"); + state.update(); - ImGui::End(); ImGui::EndFrame(); // update end // draw window.clear(); ImGui::SFML::Render(window); + state.draw(); window.display(); } diff --git a/src/state.cpp b/src/state.cpp new file mode 100644 index 0000000..97cca0e --- /dev/null +++ b/src/state.cpp @@ -0,0 +1,16 @@ +#include "state.hpp" + +#include "imgui_helper.hpp" + +Tri::State::State() : +width(800), +height(600), +dt(sf::microseconds(16666)) +{} + +void Tri::State::update() { + Tri::draw_help(this); +} + +void Tri::State::draw() { +} diff --git a/src/state.hpp b/src/state.hpp new file mode 100644 index 0000000..c76457f --- /dev/null +++ b/src/state.hpp @@ -0,0 +1,24 @@ +#ifndef TRIANGLES_STATE_HPP +#define TRIANGLES_STATE_HPP + +#include + +#include + +namespace Tri { + struct State { + State(); + /* + * 0 - display help + */ + std::bitset<64> flags; + const unsigned int width; + const unsigned int height; + const sf::Time dt; + + void update(); + void draw(); + }; +} + +#endif