Triangles/src/imgui_helper.hpp

56 lines
1.9 KiB
C++
Raw Normal View History

2020-07-21 11:34:39 +00:00
#ifndef TRIANGLES_IMGUI_HELPER_HPP
#define TRIANGLES_IMGUI_HELPER_HPP
#include <imgui.h>
#include "state.hpp"
#define SHOW_HELP_WIDTH (state->get_width() / 2.0f)
#define SHOW_HELP_HEIGHT (state->get_height() / 2.0f)
#ifndef NDEBUG
# include <cstdio>
#endif
2020-07-21 11:34:39 +00:00
namespace Tri {
2020-07-22 06:19:37 +00:00
// Seems misleading, but imgui handles setting up the window during update
// so this should be called during update, not draw
2020-07-21 11:34:39 +00:00
inline void draw_help(Tri::State *state) {
2020-07-22 06:19:37 +00:00
if(state->get_flags().test(0)) {
2020-07-21 11:34:39 +00:00
ImGui::SetNextWindowPos(sf::Vector2f(10.0f, 10.0f));
ImGui::SetNextWindowSize(sf::Vector2f(
2020-07-22 06:19:37 +00:00
state->get_width() - 20.0f,
state->get_height() - 20.0f));
ImGui::SetNextWindowBgAlpha(0.7f);
2020-07-21 11:34:39 +00:00
ImGui::Begin("Help Window", nullptr, ImGuiWindowFlags_NoDecoration);
ImGui::Text("This is the help window. Press \"H\" to toggle this window.");
ImGui::Text("Click anywhere to create triangles, one point at a time");
ImGui::Text("Press \"U\" to undo. Clicking will remove all future undo history");
ImGui::Text("Press \"R\" to undo.");
ImGui::End();
}
}
inline void draw_show_help(Tri::State *state) {
float alpha = state->get_starting_help_alpha();
if(alpha > 0.0f) {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha);
ImGui::SetNextWindowPos(sf::Vector2f(
(state->get_width() - SHOW_HELP_WIDTH) / 2.0f,
(state->get_height() - SHOW_HELP_HEIGHT) / 2.0f));
ImGui::SetNextWindowSize(sf::Vector2f(
SHOW_HELP_WIDTH,
SHOW_HELP_HEIGHT));
ImGui::Begin("Use Help Window", nullptr, ImGuiWindowFlags_NoDecoration);
ImGui::SetWindowFontScale(3.0f);
ImGui::Text("Press \"H\" for help");
2020-07-21 11:34:39 +00:00
ImGui::End();
ImGui::PopStyleVar();
2020-07-21 11:34:39 +00:00
}
}
}
#endif