diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-06 01:05:18 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-06 02:25:29 +0200 |
commit | 6ffa3333010961c564aa278758bdb8c279e8222a (patch) | |
tree | 0b4835a349135fec00f352d21d23368d9bb90e96 /editor/tests | |
parent | eaaf0682ce80a2fd8407867ee3c41ef8e800e483 (diff) |
hole test should be done
Diffstat (limited to 'editor/tests')
-rw-r--r-- | editor/tests/hole-test.cpp | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/editor/tests/hole-test.cpp b/editor/tests/hole-test.cpp index e053c61c..61b0c931 100644 --- a/editor/tests/hole-test.cpp +++ b/editor/tests/hole-test.cpp @@ -9,6 +9,7 @@ #include "../imgui-raii.hpp" #include "floormat/main.hpp" #include "src/critter.hpp" +#include <mg/Color.h> namespace floormat::tests { namespace { @@ -60,16 +61,31 @@ constexpr ImVec2 to_imvec2(Vector2 val) return {val.x(), val.y()}; } -void hole_test::draw_ui(app& a, float menu_bar_height) +auto to_color(Color4 val) +{ + return ImGui::ColorConvertFloat4ToU32({ val.r(), val.g(), val.b(), val.a() }); +} + +constexpr auto colors = std::array{ + 0x488f31_rgbf, // rect 1 + 0x91ac56_rgbf, // rect 2 + 0xcdca85_rgbf, // rect 3 + 0xffebbc_rgbf, // rect 4 + 0xf8d29d_rgbf, // rect 5 + 0xec9c6d_rgbf, // rect 6 + 0xda58de_rgbf, // rect 7 + 0x6dd4ff_rgbf, // rect 8 +}; + +void hole_test::draw_ui(app& a, float) { 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 gray = ImGui::ColorConvertFloat4ToU32({.7f, .7f, .7f, 1}); const auto& style = ImGui::GetStyle(); //const auto dpi = m.dpi_scale(); constexpr auto igcf = ImGuiChildFlags_None; @@ -82,6 +98,8 @@ void hole_test::draw_ui(app& a, float menu_bar_height) //ImGui::LabelText("##test-area", "Test area"); //ImGui::NewLine(); + auto count = -1u; + ImGui::SetNextWindowSize({width, width}); if (auto b1 = imgui::begin_child("Test area"_s, window_size, igcf, igwf)) { @@ -89,35 +107,44 @@ void hole_test::draw_ui(app& a, float menu_bar_height) const auto min = Vector2{win.Pos.x, win.Pos.y}; const auto max = min + Vector2{width}; const auto maxʹ = max - Vector2{1}; - + constexpr float mult = 2; + const auto center = min + Vector2{width*.5f}; ImDrawList& draw = *win.DrawList; - draw.AddRectFilled(to_imvec2(min), to_imvec2(maxʹ), bgcolor, 0, imdf); - 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); + draw.AddRectFilled(to_imvec2(min), to_imvec2(maxʹ), bgcolor, 0, imdf); // black + draw.AddRect(to_imvec2(center - TILE_SIZE2*.5f*mult), to_imvec2(center + TILE_SIZE2*.5f*mult), gray, 0, imdf); // standard tile + draw.AddRectFilled(to_imvec2(center + (Vector2(st.pos) - Vector2(st.size)/2)*mult), + to_imvec2(center + (Vector2(st.pos) + Vector2(st.size)/2)*mult), red); // hole cut_rectangle_result::bbox rect{{}, Vector2ub{tile_size_xy}}; cut_rectangle_result res = cut_rectangle(rect, {st.pos, st.size}); + count = res.size; 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); + draw.AddRectFilled(to_imvec2(center + Vector2(r.min)*mult), to_imvec2(center + Vector2(r.max)*mult), to_color(colors[i])); // rects filled } 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); + draw.AddRect(to_imvec2(center + Vector2(r.min)*mult), to_imvec2(center + Vector2(r.max)*mult), blue, 0, 0, 3); // rects } - 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); + draw.AddRect(to_imvec2(center + (Vector2(st.pos) - Vector2(st.size)*.5f)*mult), + to_imvec2(center + (Vector2(st.pos) + Vector2(st.size)*.5f)* mult), red, 0, 0, 1); // hole + } + if (count == -1u) + { + cut_rectangle_result::bbox rect{{}, Vector2ub{tile_size_xy}}; + cut_rectangle_result res = cut_rectangle(rect, {st.pos, st.size}); + count = res.size; } - //ImGui::NewLine(); - const auto label_width = ImGui::CalcTextSize("MMMMMMMMM").x; + const auto label_width = ImGui::CalcTextSize("MMMMMM").x; + + ImGui::NewLine(); ImGui::Indent(style.FramePadding.x); { @@ -132,6 +159,10 @@ void hole_test::draw_ui(app& a, float menu_bar_height) label_left("size", buf, label_width); ImGui::InputScalarN("##size", ImGuiDataType_U8, st.size.data(), 2, step_1.data(), step_2.data()); } + { + label_left("count", buf, label_width); + ImGui::Text("%zu", size_t{count}); + } ImGui::Unindent(style.FramePadding.x); } |