1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#include "../tests-private.hpp"
#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"
#include "../imgui-raii.hpp"
#include "floormat/main.hpp"
#include "src/critter.hpp"
namespace floormat::tests {
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;
bool handle_key(app& a, const key_event& e, bool is_down) override;
bool handle_mouse_click(app& a, const mouse_button_event& e, bool is_down) override;
bool handle_mouse_move(app& a, const mouse_move_event& e) override;
void draw_overlay(app& a) override;
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)
{
return false;
}
bool hole_test::handle_mouse_click(app& a, const mouse_button_event& e, bool is_down)
{
return false;
}
bool hole_test::handle_mouse_move(app& a, const mouse_move_event& e)
{
return false;
}
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;
constexpr auto igwf = 0;//ImGuiWindowFlags_NoDecoration;
constexpr auto imdf = ImDrawFlags_None;
char buf[32];
ImGui::NewLine();
//ImGui::LabelText("##test-area", "Test area");
//ImGui::NewLine();
ImGui::SetNextWindowSize({width, width});
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(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);
cut_rectangle_result::bbox rect{{}, Vector2ub{tile_size_xy}};
cut_rectangle_result res = cut_rectangle(rect, {st.pos, st.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);
}
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(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;
ImGui::Indent(style.FramePadding.x);
{
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);
}
void hole_test::update_pre(app& a, const Ns& dt)
{
}
} // namespace
Pointer<base_test> tests_data::make_test_hole() { return Pointer<hole_test>{InPlaceInit}; }
} // namespace floormat::tests
|