summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/app.hpp7
-rw-r--r--main/draw.cpp2
-rw-r--r--main/gui.cpp43
-rw-r--r--main/update.cpp2
4 files changed, 33 insertions, 21 deletions
diff --git a/main/app.hpp b/main/app.hpp
index f57aaa4d..861b4193 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -59,9 +59,10 @@ struct app final : Platform::Application
void draw_wireframe_quad(global_coords pt);
void draw_wireframe_box(local_coords pt);
- void do_menu();
- void draw_menu_(tile_type& type, float main_menu_height);
- void draw_fps(float main_menu_height);
+ void draw_ui();
+ float draw_main_menu();
+ void draw_editor_pane(tile_type& type, float main_menu_height);
+ void draw_fps();
void display_menu();
void debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
diff --git a/main/draw.cpp b/main/draw.cpp
index 82c4efc9..2de8ff73 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -18,6 +18,8 @@ void app::drawEvent() {
else
_frame_time = dt;
}
+ else
+ swapBuffers(), timeline.nextFrame();
{
const float dt = std::clamp(timeline.previousFrameDuration(), 1e-3f, 1e-1f);
diff --git a/main/gui.cpp b/main/gui.cpp
index 6bf929dc..37ca1227 100644
--- a/main/gui.cpp
+++ b/main/gui.cpp
@@ -22,12 +22,8 @@ void app::display_menu()
_imgui.drawFrame();
}
-void app::do_menu()
+float app::draw_main_menu()
{
- _imgui.newFrame();
-
- ImGui::StyleColorsDark(&ImGui::GetStyle());
-
float main_menu_height = 0;
if (auto b = begin_main_menu())
{
@@ -50,22 +46,33 @@ void app::do_menu()
main_menu_height = ImGui::GetContentRegionMax().y;
}
- draw_menu_(_editor.floor(), main_menu_height);
- draw_fps(main_menu_height);
+ return main_menu_height;
+}
+
+void app::draw_ui()
+{
+ _imgui.newFrame();
+ ImGui::StyleColorsDark(&ImGui::GetStyle());
+
+ const float main_menu_height = draw_main_menu();
+ draw_editor_pane(_editor.floor(), main_menu_height);
+ draw_fps();
}
-void app::draw_menu_(tile_type& type, float main_menu_height)
+void app::draw_editor_pane(tile_type& type, float main_menu_height)
{
if (ImGui::GetIO().WantTextInput && !isTextInputActive())
startTextInput();
else if (!ImGui::GetIO().WantTextInput && isTextInputActive())
stopTextInput();
- auto c1 = push_style_var(ImGuiStyleVar_WindowPadding, {8, 8});
- auto c2 = push_style_var(ImGuiStyleVar_WindowBorderSize, 0);
- auto c3 = push_style_var(ImGuiStyleVar_FramePadding, {4, 4});
- auto c4 = push_style_color(ImGuiCol_WindowBg, {0, 0, 0, .5});
- auto c5 = push_style_color(ImGuiCol_FrameBg, {0, 0, 0, 0});
+ const raii_wrapper vars[] = {
+ push_style_var(ImGuiStyleVar_WindowPadding, {8, 8}),
+ push_style_var(ImGuiStyleVar_WindowBorderSize, 0),
+ push_style_var(ImGuiStyleVar_FramePadding, {4, 4}),
+ push_style_color(ImGuiCol_WindowBg, {0, 0, 0, .5}),
+ push_style_color(ImGuiCol_FrameBg, {0, 0, 0, 0}),
+ };
const auto& style = ImGui::GetStyle();
@@ -103,9 +110,11 @@ void app::draw_menu_(tile_type& type, float main_menu_height)
{
click_event();
add_tile_count();
- auto c = push_style_var(ImGuiStyleVar_FramePadding, {1, 1});
- auto c2 = push_style_var(ImGuiStyleVar_FrameBorderSize, 3);
- auto c3 = push_style_color(ImGuiCol_Button, {1, 1, 1, 1});
+ const raii_wrapper vars[] = {
+ push_style_var(ImGuiStyleVar_FramePadding, {1, 1}),
+ push_style_var(ImGuiStyleVar_FrameBorderSize, 3),
+ push_style_color(ImGuiCol_Button, {1, 1, 1, 1}),
+ };
constexpr std::size_t per_row = 8;
for (std::size_t i = 0; i < N; i++)
{
@@ -134,7 +143,7 @@ void app::draw_menu_(tile_type& type, float main_menu_height)
}
}
-void app::draw_fps([[maybe_unused]] float main_menu_height)
+void app::draw_fps()
{
const ImVec2 max_size = ImGui::CalcTextSize("999.1 FPS");
auto c1 = push_style_var(ImGuiStyleVar_FramePadding, {0, 0});
diff --git a/main/update.cpp b/main/update.cpp
index 1dbdb0ba..b1f6d945 100644
--- a/main/update.cpp
+++ b/main/update.cpp
@@ -24,7 +24,7 @@ void app::do_mouse_click(const global_coords pos, int button)
void app::update(float dt)
{
do_camera(dt);
- do_menu();
+ draw_ui();
if (keys[key::quit])
Platform::Sdl2Application::exit(0);
}