summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/app.cpp2
-rw-r--r--main/app.hpp2
-rw-r--r--main/debug.cpp2
-rw-r--r--main/editor.hpp15
-rw-r--r--main/menu.cpp80
5 files changed, 68 insertions, 33 deletions
diff --git a/main/app.cpp b/main/app.cpp
index ffebcc35..0c29abf1 100644
--- a/main/app.cpp
+++ b/main/app.cpp
@@ -23,7 +23,7 @@ app::app(const Arguments& arguments):
reset_camera_offset();
update_window_scale(windowSize());
setMinimalLoopPeriod(5);
- _imgui = ImGuiIntegration::Context(Vector2{windowSize()}/dpiScaling(), windowSize(), framebufferSize());
+ _imgui = ImGuiIntegration::Context(Vector2{windowSize()}, windowSize(), framebufferSize());
setup_menu();
timeline.start();
}
diff --git a/main/app.hpp b/main/app.hpp
index 3efc390f..389dbef3 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -9,6 +9,7 @@
#include "draw/wireframe-quad.hpp"
#include "draw/wireframe-box.hpp"
#include "compat/enum-bitset.hpp"
+#include "editor.hpp"
#include <Magnum/Timeline.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/GL/DebugOutput.h>
@@ -74,6 +75,7 @@ struct app final : Platform::Application
Vector2 camera_offset;
enum_bitset<key> keys;
Magnum::Timeline timeline;
+ editor_mode _editor_mode = editor_mode{};
};
} // namespace floormat
diff --git a/main/debug.cpp b/main/debug.cpp
index ebf3c124..24deb775 100644
--- a/main/debug.cpp
+++ b/main/debug.cpp
@@ -71,7 +71,7 @@ void* app::register_debug_callback()
GL::DebugOutput::setCallback(_debug_callback, this);
GL::DebugOutput::setEnabled(true);
-#if 0
+#if 1
/* Disable rather spammy "Buffer detailed info" debug messages on NVidia drivers */
GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, false);
#endif
diff --git a/main/editor.hpp b/main/editor.hpp
new file mode 100644
index 00000000..af3934eb
--- /dev/null
+++ b/main/editor.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+namespace floormat {
+
+enum class editor_mode : unsigned char {
+ select, floors, walls,
+};
+
+struct editor_state final
+{
+ editor_mode mode = {};
+ bool dirty = false;
+};
+
+} // namespace floormat
diff --git a/main/menu.cpp b/main/menu.cpp
index 92f1b980..4762198f 100644
--- a/main/menu.cpp
+++ b/main/menu.cpp
@@ -4,29 +4,47 @@
namespace floormat {
-template<typename F>
+constexpr inline auto noop = []{};
+
struct raii_wrapper final
{
- raii_wrapper(F&& fn) : dtor{fn} {}
- [[no_unique_address]] F dtor;
+ using F = void(*)(void);
+ raii_wrapper(bool ok = false, F fn = noop) : dtor{fn}, ok{ok} {}
inline ~raii_wrapper() { dtor(); }
- raii_wrapper(const raii_wrapper<F>&) = delete;
- raii_wrapper<F>& operator=(const raii_wrapper<F>&) = delete;
+ raii_wrapper(const raii_wrapper&) = delete;
+ raii_wrapper& operator=(const raii_wrapper&) = delete;
+ raii_wrapper(raii_wrapper&& other) noexcept : dtor{other.dtor}, ok{other.ok} { other.dtor = noop; }
+ inline operator bool() const noexcept { return ok; }
+
+ [[no_unique_address]] F dtor;
+ const bool ok;
};
constexpr inline const auto* imgui_name = "floormat editor";
-[[nodiscard]] static auto gui_begin() {
- ImGui::Begin(imgui_name, nullptr, ImGuiWindowFlags_::ImGuiWindowFlags_NoMove);
- return raii_wrapper{[]{ ImGui::End(); }};
+#if 0
+[[nodiscard]] static raii_wrapper gui_begin() {
+ using f = ImGuiWindowFlags_;
+ int flags = 0;
+ //flags |= ImGuiWindowFlags_AlwaysAutoResize;
+ flags |= f::ImGuiWindowFlags_NoDecoration;
+ if (ImGui::Begin(imgui_name, nullptr, flags))
+ return {true, []{ ImGui::End(); }};
+ else
+ return {};
}
-[[nodiscard]] static auto begin_main_menu() {
- ImGui::BeginMainMenuBar();
- return raii_wrapper{[] { ImGui::EndMainMenuBar(); }};
+#endif
+[[nodiscard]] static raii_wrapper begin_main_menu() {
+ if (ImGui::BeginMainMenuBar())
+ return raii_wrapper{true, [] { ImGui::EndMainMenuBar(); }};
+ else
+ return {};
}
-[[nodiscard]] static auto begin_menu(const char* name, bool enabled = true) {
- ImGui::BeginMenu(name, enabled);
- return raii_wrapper{[] { ImGui::EndMenu(); }};
+[[nodiscard]] static raii_wrapper begin_menu(const char* name, bool enabled = true) {
+ if (ImGui::BeginMenu(name, enabled))
+ return raii_wrapper{true, [] { ImGui::EndMenu(); }};
+ else
+ return {};
}
void app::setup_menu()
@@ -54,29 +72,29 @@ void app::draw_menu()
else if (!ImGui::GetIO().WantTextInput && isTextInputActive())
stopTextInput();
- auto b = gui_begin();
draw_menu_bar();
}
void app::draw_menu_bar()
{
- auto bm = begin_main_menu();
- {
- auto m = begin_menu("File");
- ImGui::MenuItem("Open");
- ImGui::MenuItem("Recent");
- ImGui::Separator();
- ImGui::MenuItem("Save");
- ImGui::MenuItem("Save as...");
- ImGui::Separator();
- ImGui::MenuItem("Close");
- }
+ if (auto b = begin_main_menu())
{
- auto m = begin_menu("Mode");
- ImGui::MenuItem("Select", "F1");
- ImGui::MenuItem("Floors", "F2");
- ImGui::MenuItem("Walls", "F3");
- ImGui::MenuItem("Floors", "F4");
+ if (auto b = begin_menu("File"))
+ {
+ ImGui::MenuItem("Open", "Ctrl+O");
+ ImGui::MenuItem("Recent");
+ ImGui::Separator();
+ ImGui::MenuItem("Save", "Ctrl+S");
+ ImGui::MenuItem("Save as...", "Ctrl+Shift+S");
+ ImGui::Separator();
+ ImGui::MenuItem("Close");
+ }
+ if (auto b = begin_menu("Mode"))
+ {
+ ImGui::MenuItem("Select", "F1", _editor_mode == editor_mode::select);
+ ImGui::MenuItem("Floors", "F2", _editor_mode == editor_mode::floors);
+ ImGui::MenuItem("Walls", "F3", _editor_mode == editor_mode::walls);
+ }
}
}