diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-15 11:40:19 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-15 11:40:19 +0200 |
commit | 4e77740facb23e1c392f180381ccb5446d445724 (patch) | |
tree | d629c4d2960546dab2ed759d756674533baac536 /main | |
parent | a99c6ebd1c24e3f645e2c07591cfcfa97a162a6b (diff) |
a
Diffstat (limited to 'main')
-rw-r--r-- | main/app.cpp | 5 | ||||
-rw-r--r-- | main/app.hpp | 3 | ||||
-rw-r--r-- | main/keyboard.cpp | 2 | ||||
-rw-r--r-- | main/menu.cpp | 59 |
4 files changed, 46 insertions, 23 deletions
diff --git a/main/app.cpp b/main/app.cpp index 0c29abf1..33b89231 100644 --- a/main/app.cpp +++ b/main/app.cpp @@ -31,8 +31,7 @@ void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event) { update_window_scale(event.windowSize()); GL::defaultFramebuffer.setViewport({{}, event.windowSize()}); - _imgui.relayout(Vector2{event.windowSize()}/event.dpiScaling(), - event.windowSize(), event.framebufferSize()); + _imgui.relayout(Vector2{event.windowSize()}, event.windowSize(), event.framebufferSize()); } @@ -63,7 +62,7 @@ void app::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event) void app::textInputEvent(Platform::Sdl2Application::TextInputEvent& event) { if (_imgui.handleTextInputEvent(event)) - return event.setAccepted(); + return keys = {}, event.setAccepted(); } void app::update(float dt) diff --git a/main/app.hpp b/main/app.hpp index 389dbef3..876ad8fe 100644 --- a/main/app.hpp +++ b/main/app.hpp @@ -43,7 +43,6 @@ struct app final : Platform::Application void update_window_scale(Vector2i window_size); void viewportEvent(ViewportEvent& event) override; void draw_menu(); - void draw_menu_bar(); void setup_menu(); void display_menu(); void debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, @@ -75,7 +74,7 @@ struct app final : Platform::Application Vector2 camera_offset; enum_bitset<key> keys; Magnum::Timeline timeline; - editor_mode _editor_mode = editor_mode{}; + editor_state _editor; }; } // namespace floormat diff --git a/main/keyboard.cpp b/main/keyboard.cpp index 041af2c8..66dafa7e 100644 --- a/main/keyboard.cpp +++ b/main/keyboard.cpp @@ -42,7 +42,7 @@ void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event) void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event) { if (_imgui.handleKeyReleaseEvent(event)) - return event.setAccepted(); + return keys = {}, event.setAccepted(); do_key(event.key(), event.modifiers(), false, false); } diff --git a/main/menu.cpp b/main/menu.cpp index 07626032..bd107611 100644 --- a/main/menu.cpp +++ b/main/menu.cpp @@ -23,27 +23,29 @@ struct raii_wrapper final constexpr inline const auto* imgui_name = "floormat editor"; -#if 0 -[[nodiscard]] static raii_wrapper gui_begin() { - using f = ImGuiWindowFlags_; - int flags = 0; - //flags |= ImGuiWindowFlags_AlwaysAutoResize; - flags |= f::ImGuiWindowFlags_NoDecoration; +[[nodiscard]] static raii_wrapper begin_window(int flags = 0) { if (ImGui::Begin(imgui_name, nullptr, flags)) - return {&ImGui::End; }; + return {&ImGui::End}; else return {}; } -#endif + [[nodiscard]] static raii_wrapper begin_main_menu() { if (ImGui::BeginMainMenuBar()) - return raii_wrapper{&ImGui::EndMainMenuBar}; + return {&ImGui::EndMainMenuBar}; else return {}; } [[nodiscard]] static raii_wrapper begin_menu(const char* name, bool enabled = true) { if (ImGui::BeginMenu(name, enabled)) - return raii_wrapper{&ImGui::EndMenu}; + return {&ImGui::EndMenu}; + else + return {}; +} + +[[nodiscard]] static raii_wrapper begin_list_box(const char* name, ImVec2 size = {}) { + if (ImGui::BeginListBox(name, size)) + return {&ImGui::EndListBox}; else return {}; } @@ -73,11 +75,8 @@ void app::draw_menu() else if (!ImGui::GetIO().WantTextInput && isTextInputActive()) stopTextInput(); - draw_menu_bar(); -} + ImVec2 main_menu_pos; -void app::draw_menu_bar() -{ if (auto b = begin_main_menu()) { if (auto b = begin_menu("File")) @@ -92,9 +91,35 @@ void app::draw_menu_bar() } 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); + 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); + } + main_menu_pos = ImGui::GetContentRegionMax(); + } + if (main_menu_pos.y > 0) + { + auto& style = ImGui::GetStyle(); + ImGui::StyleColorsDark(&style); + style.WindowPadding = {8, 8}; + style.WindowBorderSize = {}; + style.Colors[ImGuiCol_WindowBg] = {0, 0, 0, .5}; + style.Colors[ImGuiCol_FrameBg] = {0, 0, 0, 0}; + + ImGui::SetNextWindowPos({0, main_menu_pos.y+style.WindowPadding.y}); + ImGui::SetNextFrameWantCaptureKeyboard(false); + if (auto b = begin_window(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings)) + { + ImGui::Text("Items:"); + //ImGui::SetNextWindowBgAlpha(.2f); + + if (auto b = begin_list_box("##tiles", {-FLT_MIN, 100})) + { + for (const auto& label : {"foo", "bar", "baz"}) + { + ImGui::Selectable(label); + } + } } } } |