summaryrefslogtreecommitdiffhomepage
path: root/editor/tests.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-20 12:33:00 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-20 12:33:00 +0200
commit275cb79a1857fff08ce1b642bbfab6d7377bcaef (patch)
treeb8671ed206fc27d4762779cf64113ef7d9ce8fd9 /editor/tests.cpp
parent5be116ea43231c747f09c4d43a75d45984b54a66 (diff)
aa
Diffstat (limited to 'editor/tests.cpp')
-rw-r--r--editor/tests.cpp80
1 files changed, 52 insertions, 28 deletions
diff --git a/editor/tests.cpp b/editor/tests.cpp
index 04489ddc..706c15eb 100644
--- a/editor/tests.cpp
+++ b/editor/tests.cpp
@@ -2,11 +2,11 @@
#include "app.hpp"
#include "floormat/events.hpp"
#include "imgui-raii.hpp"
+#include <SDL_keycode.h>
namespace floormat {
using namespace floormat::tests;
-using namespace floormat::imgui;
tests_data_::~tests_data_() noexcept = default;
tests_data_::tests_data_() = default;
@@ -14,6 +14,22 @@ tests_data_::tests_data_() = default;
tests_data::~tests_data() noexcept = default;
tests_data::tests_data() = default;
+base_test::~base_test() noexcept = default;
+base_test::base_test() = default;
+
+using namespace floormat::imgui;
+
+void tests_data::switch_to(size_t i)
+{
+ constexpr auto size = std::variant_size_v<tests::variant>;
+ fm_assert(i < size);
+ switch (i)
+ {
+ case 0: *this = std::monostate{}; break;
+ case 1: *this = path_test{}; break;
+ }
+}
+
Pointer<tests_data_> tests_data_::make()
{
return Pointer<tests_data>{InPlaceInit};
@@ -21,51 +37,51 @@ Pointer<tests_data_> tests_data_::make()
void app::tests_pre_update()
{
+ std::visit(overloaded {
+ [](std::monostate) {},
+ [&](base_test& x) { return x.update_pre(*this); }
+ }, tests());
}
void app::tests_post_update()
{
+ std::visit(overloaded {
+ [](std::monostate) {},
+ [&](base_test& x) { return x.update_post(*this); }
+ }, tests());
}
bool app::tests_handle_mouse_click(const mouse_button_event& e)
{
update_cursor_tile(cursor.pixel);
- auto& var = tests();
- if (e.button == mouse_button_left)
- {
- std::visit(overloaded {
- [](std::monostate) {},
- [&](path_test& t) {
- // todo
- }
- }, var);
-
- return true;
- }
- else if (e.button == mouse_button_right)
- {
- bool ret = false;
- std::visit(overloaded {
- [](std::monostate) {},
- [&](path_test& t) {
- ret = t.active;
- t = {};
- },
- }, var);
- return ret;
- }
- return false;
+ return std::visit(overloaded {
+ [](std::monostate) { return false; },
+ [&](base_test& x) { return x.handle_mouse_click(*this, e); }
+ }, tests());
}
bool app::tests_handle_key(const key_event& e)
{
- return false;
+ switch (e.key)
+ {
+ case SDLK_ESCAPE:
+ tests().switch_to(0);
+ return true;
+ default:
+ return std::visit(overloaded {
+ [](std::monostate) { return false; },
+ [&](base_test& x) { return x.handle_key(*this, e); }
+ }, tests());
+ }
}
bool app::tests_handle_mouse_move(const mouse_move_event& e)
{
- return false;
+ return std::visit(overloaded {
+ [](std::monostate) { return false; },
+ [&](base_test& x) { return x.handle_mouse_move(*this, e); }
+ }, tests());
}
tests_data& app::tests()
@@ -81,10 +97,18 @@ void app::tests_reset_mode()
void app::draw_tests_pane()
{
+ constexpr int selectable_flags = ImGuiSelectableFlags_SpanAvailWidth;
+ for (auto [str, i] : tests_data::fields)
+ if (ImGui::Selectable(str.data(), i == tests().index(), selectable_flags))
+ tests().switch_to(i);
}
void app::draw_tests_overlay()
{
+ std::visit(overloaded {
+ [](std::monostate) {},
+ [&](base_test& x) { return x.draw_overlay(*this); }
+ }, tests());
}
} // namespace floormat