Impl some structure to the project
This commit is contained in:
parent
26c7aacea0
commit
1434948db9
5 changed files with 83 additions and 6 deletions
|
@ -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
|
||||
|
|
22
src/imgui_helper.hpp
Normal file
22
src/imgui_helper.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef TRIANGLES_IMGUI_HELPER_HPP
|
||||
#define TRIANGLES_IMGUI_HELPER_HPP
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#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
|
26
src/main.cpp
26
src/main.cpp
|
@ -5,12 +5,19 @@
|
|||
#include <imgui.h>
|
||||
#include <imgui-SFML.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
|
|
16
src/state.cpp
Normal file
16
src/state.cpp
Normal file
|
@ -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() {
|
||||
}
|
24
src/state.hpp
Normal file
24
src/state.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef TRIANGLES_STATE_HPP
|
||||
#define TRIANGLES_STATE_HPP
|
||||
|
||||
#include <bitset>
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
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
|
Loading…
Reference in a new issue