diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-06 00:54:25 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-06 00:54:25 +0200 |
commit | eaaf0682ce80a2fd8407867ee3c41ef8e800e483 (patch) | |
tree | 9a38038ade7b67e3437a17ca51f6dd68e09d1b30 /editor | |
parent | fd0b4fd2cb54a1e1c06737bfabedac36e2786a27 (diff) |
wip
Diffstat (limited to 'editor')
-rw-r--r-- | editor/tests/hole-test.cpp | 71 |
1 files changed, 56 insertions, 15 deletions
diff --git a/editor/tests/hole-test.cpp b/editor/tests/hole-test.cpp index 60c75dcf..e053c61c 100644 --- a/editor/tests/hole-test.cpp +++ b/editor/tests/hole-test.cpp @@ -2,6 +2,7 @@ #include "compat/shared-ptr-wrapper.hpp" #include "src/tile-constants.hpp" #include "src/chunk-region.hpp" +#include "src/hole.hpp" #include "src/object.hpp" #include "src/world.hpp" #include "../app.hpp" @@ -14,6 +15,12 @@ namespace { using namespace floormat::imgui; +struct State +{ + Vector2i pos; + Vector2ub size{tile_size_xy/4}; +}; + struct hole_test final : base_test { ~hole_test() noexcept override = default; @@ -25,6 +32,8 @@ struct hole_test final : base_test void draw_ui(app& a, float menu_bar_height) override; void update_pre(app& a, const Ns& dt) override; void update_post(app&, const Ns&) override {} + + State st; }; bool hole_test::handle_key(app& a, const key_event& e, bool is_down) @@ -46,12 +55,21 @@ void hole_test::draw_overlay(app& a) { } +constexpr ImVec2 to_imvec2(Vector2 val) +{ + return {val.x(), val.y()}; +} + void hole_test::draw_ui(app& a, float menu_bar_height) { const auto& m = a.main(); const auto width = Math::min(ImGui::GetWindowSize().x, 400.f); const auto window_size = ImVec2{width, width}; const auto bgcolor = ImGui::ColorConvertFloat4ToU32({0, 0, 0, 1}); + const auto bgrect = ImGui::ColorConvertFloat4ToU32({.25f, .25f, .25f, 1.f}); + const auto blue = ImGui::ColorConvertFloat4ToU32({0, .5f, 1, 1}); + const auto red = ImGui::ColorConvertFloat4ToU32({1, 0, 0, 1}); + const auto gray = ImGui::ColorConvertFloat4ToU32({.7f, .7f, .7f, .6f}); const auto& style = ImGui::GetStyle(); //const auto dpi = m.dpi_scale(); constexpr auto igcf = ImGuiChildFlags_None; @@ -68,29 +86,52 @@ void hole_test::draw_ui(app& a, float menu_bar_height) if (auto b1 = imgui::begin_child("Test area"_s, window_size, igcf, igwf)) { const auto& win = *ImGui::GetCurrentWindow(); + const auto min = Vector2{win.Pos.x, win.Pos.y}; + const auto max = min + Vector2{width}; + const auto maxʹ = max - Vector2{1}; + ImDrawList& draw = *win.DrawList; - draw.AddRectFilled({win.Pos.x, win.Pos.y}, {win.Pos.x+width-1, win.Pos.y+width-1}, bgcolor, 0, imdf); - } - //ImGui::NewLine(); + draw.AddRectFilled(to_imvec2(min), to_imvec2(maxʹ), bgcolor, 0, imdf); - const auto label_width = ImGui::CalcTextSize("MMMMMMMMM").x; + const auto center = Vector2{width*.5f}; + constexpr auto size = TILE_SIZE2; + draw.AddRect(to_imvec2(min + center - size*.5f), to_imvec2(min + center + size*.5f), gray, 0, imdf); - ImGui::Indent(style.FramePadding.x); + cut_rectangle_result::bbox rect{{}, Vector2ub{tile_size_xy}}; + cut_rectangle_result res = cut_rectangle(rect, {st.pos, st.size}); - label_left("width", buf, label_width); - ImGui::NewLine(); + for (auto i = 0u; i < res.size; i++) + { + auto r = res.array[i]; + draw.AddRectFilled(to_imvec2(min + center + Vector2(r.min)), to_imvec2(min + center + Vector2(r.max)), bgrect); + } - label_left("height", buf, label_width); - ImGui::NewLine(); + for (auto i = 0u; i < res.size; i++) + { + auto r = res.array[i]; + draw.AddRect(to_imvec2(min + center + Vector2(r.min)), to_imvec2(min + center + Vector2(r.max)), blue); + } - label_left("x", buf, label_width); - ImGui::NewLine(); + draw.AddRect(to_imvec2(min + center + Vector2(st.pos) - Vector2(st.size/2)), + to_imvec2(min + center + Vector2(st.pos) + Vector2(st.size / 2)), red); + } + //ImGui::NewLine(); + const auto label_width = ImGui::CalcTextSize("MMMMMMMMM").x; - label_left("y", buf, label_width); - ImGui::NewLine(); + ImGui::Indent(style.FramePadding.x); - label_left("z", buf, label_width); - ImGui::NewLine(); + { + constexpr auto step_1 = Vector2i{1}; + constexpr auto step_2 = Vector2i{tile_size_xy/4}; + label_left("pos", buf, label_width); + ImGui::InputScalarN("##pos", ImGuiDataType_S32, st.pos.data(), 2, step_1.data(), step_2.data()); + } + { + constexpr auto step_1 = Vector2i{1}; + constexpr auto step_2 = Vector2i{4}; + label_left("size", buf, label_width); + ImGui::InputScalarN("##size", ImGuiDataType_U8, st.size.data(), 2, step_1.data(), step_2.data()); + } ImGui::Unindent(style.FramePadding.x); } |