summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/app.hpp14
-rw-r--r--editor/camera.cpp8
-rw-r--r--editor/draw.cpp12
-rw-r--r--editor/events.cpp152
-rw-r--r--editor/imgui-editors.cpp4
-rw-r--r--editor/imgui-raii.cpp1
-rw-r--r--editor/imgui.cpp10
-rw-r--r--editor/inspect-draw.cpp2
-rw-r--r--editor/inspect-types.cpp2
-rw-r--r--editor/inspect.cpp3
-rw-r--r--editor/scenery-editor.cpp9
-rw-r--r--editor/tests/hole-test.cpp2
-rw-r--r--editor/tests/raycast-test.cpp4
-rw-r--r--editor/vobj-editor.cpp14
14 files changed, 135 insertions, 102 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index b04da7dc..800d3d10 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -108,11 +108,15 @@ private:
void draw() override;
- void on_mouse_move(const mouse_move_event& event) noexcept override;
- void on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept override;
- void on_mouse_scroll(const mouse_scroll_event& event) noexcept override;
- void on_key_up_down(const key_event& event, bool is_down) noexcept override;
- std::tuple<key, int> resolve_keybinding(int k, int mods);
+ [[nodiscard]] bool do_imgui_key(const sdl2::EvKey& ev, bool is_down);
+ [[nodiscard]] bool do_imgui_click(const sdl2::EvClick& ev, bool is_down);
+ [[nodiscard]] bool do_tests_key(const key_event& ev, bool is_down);
+
+ void on_mouse_move(const mouse_move_event& event, const sdl2::EvMove& ev) noexcept override;
+ void on_mouse_up_down(const mouse_button_event& event, bool is_down, const sdl2::EvClick& ev) noexcept override;
+ void on_mouse_scroll(const mouse_scroll_event& event, const sdl2::EvScroll& ev) noexcept override;
+ void on_key_up_down(const key_event& event, bool is_down, const sdl2::EvKey& ev) noexcept override;
+ Pair<key, int> resolve_keybinding(int k, int mods);
void on_text_input_event(const text_input_event& event) noexcept override;
//bool on_text_editing_event(const text_editing_event& event) noexcept override;
void on_viewport_event(const Magnum::Math::Vector2<int>& size) noexcept override;
diff --git a/editor/camera.cpp b/editor/camera.cpp
index 89147946..dfe985b4 100644
--- a/editor/camera.cpp
+++ b/editor/camera.cpp
@@ -102,15 +102,15 @@ object_id app::get_object_colliding_with_cursor()
object_id ret = 0;
rtree->Search(t0.data(), t1.data(), [&](uint64_t data, const rect_type& rect) {
[[maybe_unused]] auto x = std::bit_cast<collision_data>(data);
- if (x.tag == (uint64_t)collision_type::geometry)
+ if (x.type == (uint64_t)collision_type::geometry)
return true;
- Vector2 min(rect.m_min[0], rect.m_min[1]), max(rect.m_max[0], rect.m_max[1]);
+ Vector2 min{rect.m_min}, max{rect.m_max};
if (t0 >= min && t0 <= max)
{
- if (auto e_ = world.find_object(x.data);
+ if (auto e_ = world.find_object(x.id);
e_ && Vector2ui(e_->bbox_size).product() != 0)
{
- ret = x.data;
+ ret = x.id;
return false;
}
}
diff --git a/editor/draw.cpp b/editor/draw.cpp
index f5a906d2..b366deaa 100644
--- a/editor/draw.cpp
+++ b/editor/draw.cpp
@@ -139,11 +139,11 @@ void app::draw_collision_boxes()
if (x.tag == (uint64_t)collision_type::geometry)
return true;
#endif
- if (x.tag == (uint64_t)collision_type::geometry)
+ if (x.type == (uint64_t)collision_type::geometry)
if (x.pass == (uint64_t)pass_mode::pass)
- if (x.data < TILE_COUNT*2+1)
+ if (x.id < TILE_COUNT*2+1)
return true;
- Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]);
+ Vector2 start{rect.m_min}, end{rect.m_max};
auto size = (end - start);
auto center = Vector3(start + size*.5f, 0.f);
shader.set_tint(x.pass == (uint64_t)pass_mode::pass ? pass_tint : tint);
@@ -186,11 +186,11 @@ void app::draw_collision_boxes()
if (x.tag == (uint64_t)collision_type::geometry)
return true;
#endif
- if (x.tag == (uint64_t)collision_type::geometry)
+ if (x.type == (uint64_t)collision_type::geometry)
if (x.pass == (uint64_t)pass_mode::pass)
- if (x.data < TILE_COUNT*2+1)
+ if (x.id < TILE_COUNT*2+1)
return true;
- Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]);
+ Vector2 start{rect.m_min}, end{rect.m_max};
auto size = end - start;
auto center = Vector3(start + size*.5f, 0.f);
_wireframe->rect.draw(shader, { center, size, 3 });
diff --git a/editor/events.cpp b/editor/events.cpp
index 1a259d0e..6aaf1e70 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -2,29 +2,26 @@
#include "floormat/main.hpp"
#include "floormat/events.hpp"
+#include "main/sdl-fwd.inl"
#include "src/world.hpp"
#include "keys.hpp"
#include "editor.hpp"
#include "compat/enum-bitset.hpp"
-#include <tuple>
+#include <Corrade/Containers/Pair.h>
+#include <Corrade/Containers/StructuredBindings.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/ImGuiIntegration/Context.hpp>
namespace floormat {
-void app::on_focus_in() noexcept {}
-void app::on_mouse_enter() noexcept {}
-void app::on_any_event(const any_event&) noexcept {}
-
-#define accessor(type, name) \
- type m_##name = {}; auto name() const noexcept { return m_##name; }
+namespace {
-static constexpr int fixup_mods_(int mods, int value, int mask)
+constexpr int fixup_mods_(int mods, int value, int mask)
{
return !!(mods & mask) * value;
}
-static constexpr int fixup_mods(int mods)
+constexpr int fixup_mods(int mods)
{
int ret = 0;
ret |= fixup_mods_(mods, kmod_ctrl, KMOD_CTRL);
@@ -34,11 +31,49 @@ static constexpr int fixup_mods(int mods)
return ret;
}
+} // namespace
+
+
+using PointerButtons = Platform::Sdl2Application::Pointer;
+using PointerEvent = Platform::Sdl2Application::PointerEvent;
+using PointerMoveEvent = Platform::Sdl2Application::PointerMoveEvent;
+
+void app::on_focus_in() noexcept {}
+void app::on_mouse_enter() noexcept {}
+void app::on_any_event(const any_event&) noexcept {}
+
+#define accessor(type, name) \
+ type m_##name = {}; auto name() const noexcept { return m_##name; }
+
+bool app::do_imgui_key(const sdl2::EvKey& ev, bool is_down)
+{
+ if (is_down)
+ return _imgui->handleKeyPressEvent(ev.val);
+ else
+ return _imgui->handleKeyReleaseEvent(ev.val);
+}
+
+bool app::do_imgui_click(const sdl2::EvClick& ev, bool is_down)
+{
+ if (is_down)
+ return _imgui->handlePointerPressEvent(ev.val);
+ else
+ return _imgui->handlePointerReleaseEvent(ev.val);
+}
+
+bool app::do_tests_key(const key_event& ev, bool is_down)
+{
+ bool ret = _editor->mode() == editor_mode::tests;
+ if (ret)
+ return tests_handle_key(ev, is_down);
+ return ret;
+}
+
void app::clear_keys(key min_inclusive, key max_exclusive)
{
auto& keys = *keys_;
using key_type = std::decay_t<decltype(keys)>::value_type;
- for (key_type i = key_type(min_inclusive); i < key_type(max_exclusive); i++)
+ for (auto i = key_type(min_inclusive); i < key_type(max_exclusive); i++)
{
const auto idx = key(i);
keys[idx] = false;
@@ -52,61 +87,62 @@ void app::clear_keys()
key_modifiers = {};
}
-void app::on_mouse_move(const mouse_move_event& event) noexcept
+void app::on_mouse_move(const mouse_move_event& event, const sdl2::EvMove& ev) noexcept
{
- if (!(event.position >= Vector2i() && event.position < M->window_size()))
- return;
+ do
+ {
+ cursor.in_imgui = _imgui->handlePointerMoveEvent(ev.val);
+ if (cursor.in_imgui)
+ break;
+ if (_editor->mode() == editor_mode::tests)
+ {
+ (void)tests_handle_mouse_move(event);
+ break;
+ }
+ }
+ while (false);
- struct {
- accessor(Vector2i, position)
- } e = {event.position};
-
- if ((cursor.in_imgui = _imgui->handleMouseMoveEvent(e)))
- void();
- else if (_editor->mode() == editor_mode::tests && tests_handle_mouse_move(event))
- void();
- update_cursor_tile(event.position);
+ update_cursor_tile(Vector2i(event.position));
do_mouse_move(fixup_mods(event.mods));
}
-void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept
+void app::on_mouse_up_down(const mouse_button_event& event, bool is_down, const sdl2::EvClick& ev) noexcept
{
- if (!(event.position >= Vector2i() && event.position < M->window_size()))
+ const auto p = Vector2i(event.position);
+
+ if (!(p >= Vector2i{} && p < M->window_size()))
return;
- struct ev {
- enum class Button : std::underlying_type_t<mouse_button> {
- Left = mouse_button_left,
- Right = mouse_button_right,
- Middle = mouse_button_middle,
- };
- accessor(Vector2i, position)
- accessor(Button, button)
- } e = {event.position, ev::Button(event.button)};
-
- if ((cursor.in_imgui = is_down ? _imgui->handleMousePressEvent(e) : _imgui->handleMouseReleaseEvent(e)))
- void();
- else if (_editor->mode() == editor_mode::tests && tests_handle_mouse_click(event, is_down))
- void();
- else
+ do
+ {
+ cursor.in_imgui = do_imgui_click(ev, is_down);
+ if (cursor.in_imgui)
+ break;
+ if (_editor->mode() == editor_mode::tests)
+ if (tests_handle_mouse_click(event, is_down))
+ break;
do_mouse_up_down(event.button, is_down, fixup_mods(event.mods));
+ }
+ while(false);
}
-void app::on_mouse_scroll(const mouse_scroll_event& event) noexcept
+void app::on_mouse_scroll(const mouse_scroll_event& event, const sdl2::EvScroll& ev) noexcept
{
- if (!(event.position >= Vector2i() && event.position < M->window_size()))
- return;
+ const auto p = Vector2i(event.position);
- struct {
- accessor(Vector2, offset)
- accessor(Vector2i, position)
- } e = {event.offset, event.position};
-
- if (!(cursor.in_imgui = _imgui->handleMouseScrollEvent(e)))
- do_mouse_scroll((int)e.offset()[1]);
+ do
+ {
+ if (p >= Vector2i() && p < M->window_size())
+ break;
+ cursor.in_imgui = _imgui->handleScrollEvent(ev.val);
+ if (cursor.in_imgui)
+ break;
+ do_mouse_scroll((int)ev.val.offset()[1]);
+ }
+ while (false);
}
-auto app::resolve_keybinding(int k_, int mods_) -> std::tuple<key, int>
+auto app::resolve_keybinding(int k_, int mods_) -> Pair<key, int>
{
[[maybe_unused]] constexpr int CTRL = kmod_ctrl;
[[maybe_unused]] constexpr int SHIFT = kmod_shift;
@@ -190,23 +226,13 @@ auto app::resolve_keybinding(int k_, int mods_) -> std::tuple<key, int>
void app::clear_non_global_keys() { clear_keys(key_MIN, key_GLOBAL); }
void app::clear_non_repeated_keys() { clear_keys(key_NO_REPEAT, key_COUNT); }
-void app::on_key_up_down(const key_event& event, bool is_down) noexcept
+void app::on_key_up_down(const key_event& event, bool is_down, const sdl2::EvKey& ev) noexcept
{
- using KeyEvent = Platform::Sdl2Application::KeyEvent;
- struct Ev
- {
- using Key = KeyEvent::Key;
- using Modifier = KeyEvent::Modifier;
- using Modifiers = KeyEvent::Modifiers;
- accessor(Key, key)
- accessor(Modifiers, modifiers)
- } e = {Ev::Key(event.key), Ev::Modifier(event.mods)};
-
auto [x, mods] = resolve_keybinding(event.key, event.mods);
static_assert(key_GLOBAL >= key_NO_REPEAT);
- if ((x == key_COUNT || x < key_GLOBAL) && (is_down ? _imgui->handleKeyPressEvent(e) : _imgui->handleKeyReleaseEvent(e)) ||
- (x == key_COUNT || x == key_escape) && _editor->mode() == editor_mode::tests && tests_handle_key(event, is_down))
+ if ((x == key_COUNT || x < key_GLOBAL) && do_imgui_key(ev, is_down) ||
+ (x == key_COUNT || x == key_escape) && do_tests_key(event, is_down))
clear_non_global_keys();
else if (x >= key_NO_REPEAT)
is_down && !event.is_repeated ? do_key(x, mods, event.key & ~SDLK_SCANCODE_MASK) : void();
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp
index 4e331bcf..1dfc18fc 100644
--- a/editor/imgui-editors.cpp
+++ b/editor/imgui-editors.cpp
@@ -114,7 +114,7 @@ void draw_editor_tile_pane_atlas(ground_editor& ed, StringView name, const bptr<
snformat(buf, "##item_{}"_cf, i);
const auto uv = atlas->texcoords_for_id(i);
constexpr ImVec2 size_2 = { TILE_SIZE[0]*.5f, TILE_SIZE[1]*.5f };
- ImGui::ImageButton(buf, (void*)&atlas->texture(), ImVec2(size_2.x * dpi[0], size_2.y * dpi[1]),
+ ImGui::ImageButton(buf, atlas->texture().id(), ImVec2(size_2.x * dpi[0], size_2.y * dpi[1]),
{ uv[3][0], uv[3][1] }, { uv[0][0], uv[0][1] });
if (ImGui::IsItemClicked(ImGuiMouseButton_Left))
ed.select_tile(atlas, i);
@@ -181,7 +181,7 @@ void impl_draw_editor_scenery_pane(T& ed, Vector2 dpi)
const ImVec2 uv0 {texcoords[3][0], texcoords[3][1]}, uv1 {texcoords[0][0], texcoords[0][1]};
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + std::max(0.f, .5f*(thumbnail_width - img_size.x)));
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + .5f*std::max(0.f, row_height - img_size.y));
- ImGui::Image((void*)&atlas.texture(), img_size, uv0, uv1);
+ ImGui::Image(atlas.texture().id(), img_size, uv0, uv1);
click_event();
}
if (ImGui::TableSetColumnIndex(1))
diff --git a/editor/imgui-raii.cpp b/editor/imgui-raii.cpp
index dd341e2e..7c0ccb8c 100644
--- a/editor/imgui-raii.cpp
+++ b/editor/imgui-raii.cpp
@@ -1,6 +1,7 @@
#include "imgui-raii.hpp"
#include "compat/assert.hpp"
#include <cstdio>
+#include <utility>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h>
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 2923c3ea..e25edb1f 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -107,7 +107,7 @@ float app::draw_main_menu()
do_key(key_render_all_z_levels);
}
- main_menu_height = ImGui::GetContentRegionMax().y;
+ main_menu_height = ImGui::GetContentRegionAvail().y;
}
return main_menu_height;
}
@@ -312,7 +312,7 @@ void app::draw_lightmap_test(float main_menu_height)
if (ImGui::Begin("Lightmap", &is_open, flags))
{
- ImGui::Image(&shader.accum_texture(), preview_size, {0, 0}, {1, 1});
+ ImGui::Image(shader.accum_texture().id(), preview_size, {0, 0}, {1, 1});
ImGui::End();
}
else
@@ -338,7 +338,7 @@ void app::do_popup_menu()
{
const auto [id, target] = _popup_target;
auto& w = M->world();
- const auto eʹ = w.find_object(id);
+ auto eʹ = w.find_object(id);
if (target == popup_target_type::none || !eʹ)
{
@@ -372,7 +372,7 @@ void app::do_popup_menu()
if (!exists)
add_inspector(std::exchange(_popup_target, {}));
{
- char buf2[10], buf3[128], buf[sizeof buf2 + sizeof buf3 - 1];
+ char buf2[10], buf3[128], buf[sizeof buf2 + sizeof buf3 + 3 - 1];
entity_inspector_name(buf2, e.id);
entity_friendly_name(buf3, sizeof buf3, e);
std::snprintf(buf, sizeof buf, "%s###%s", buf3, buf2);
@@ -393,7 +393,7 @@ void app::do_popup_menu()
e.destroy_script_pre(eʹ, script_destroy_reason::kill);
e.chunk().remove_object(e.index());
e.destroy_script_post();
- e.gone = true;
+ eʹ.destroy();
}
}
else
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index d5474b8b..ce1e3396 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -33,7 +33,7 @@ void app::draw_inspector()
}
auto& e = *eʹ;
- char buf2[10], buf3[128], buf[sizeof buf2 + sizeof buf3 - 1];
+ char buf2[10], buf3[128], buf[sizeof buf2 + sizeof buf3 + 3 - 1];
ImGui::SetNextWindowSize({375*dpi[0], 0});
entity_inspector_name(buf2, e.id);
entity_friendly_name(buf3, sizeof buf3, e);
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index da5a8c9f..ad621cd3 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -155,13 +155,11 @@ template<> struct entity_accessors<hole, inspect_intent_t>
E::type<uint8_t>::field{"height"_s,
&hole::height,
&hole::set_height,
- [](const hole& x) { return x.flags.is_wall ? st::enabled : st::readonly; },
constantly(constraints::range<uint8_t>{0, tile_size_z}),
},
E::type<uint8_t>::field{"z-offset"_s,
&hole::z_offset,
&hole::set_z_offset,
- [](const hole& x) { return x.flags.is_wall ? st::enabled : st::readonly; },
constantly(constraints::range<uint8_t>{0, tile_size_z}),
},
E::type<bool>::field{ "enabled"_s,
diff --git a/editor/inspect.cpp b/editor/inspect.cpp
index ab177fda..f6fcf980 100644
--- a/editor/inspect.cpp
+++ b/editor/inspect.cpp
@@ -5,6 +5,7 @@
#include "imgui-raii.hpp"
#include <cstdio>
#include <utility>
+#include <Corrade/Containers/StructuredBindings.h>
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/String.h>
#include <Magnum/Math/Functions.h>
@@ -186,7 +187,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r
{
auto* state = ImGui::GetInputTextState(GImGui->ActiveId);
if (state)
- state->ReloadUserBuf = true;
+ state->WantReloadUserBuf = true;
}
return true;
}
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp
index 778a0275..7b95df9e 100644
--- a/editor/scenery-editor.cpp
+++ b/editor/scenery-editor.cpp
@@ -93,12 +93,13 @@ start:
while (auto id = a.get_object_colliding_with_cursor())
{
for (auto i = 0uz; i < sz; i++)
- if (const auto eʹ = es[i]; eʹ->id == id)
+ if (auto eʹ = es[i]; eʹ->id == id)
{
- eʹ->destroy_script_pre(eʹ, script_destroy_reason::kill);
+ auto& e = *eʹ;
+ e.destroy_script_pre(eʹ, script_destroy_reason::kill);
c.remove_object(i);
- eʹ->destroy_script_post();
- eʹ->gone = true;
+ e.destroy_script_post();
+ eʹ.destroy();
goto start;
}
break;
diff --git a/editor/tests/hole-test.cpp b/editor/tests/hole-test.cpp
index b419f7e8..06624b01 100644
--- a/editor/tests/hole-test.cpp
+++ b/editor/tests/hole-test.cpp
@@ -131,7 +131,7 @@ void hole_test::draw_ui(app&, float)
}
{
label_left("found", buf, label_width);
- ImGui::Text("%s", res.found ? "true" : "false");
+ ImGui::Text("%s", res.found() ? "true" : "false");
}
ImGui::Unindent(style.FramePadding.x);
diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp
index 07b44eaf..a8902145 100644
--- a/editor/tests/raycast-test.cpp
+++ b/editor/tests/raycast-test.cpp
@@ -181,7 +181,7 @@ struct raycast_test final : base_test
{
const char* type;
- switch ((collision_type)result.collider.tag)
+ switch ((collision_type)result.collider.type)
{
using enum collision_type;
default: type = "unknown?!"; break;
@@ -199,7 +199,7 @@ struct raycast_test final : base_test
do_column("collider");
std::snprintf(buf, array_size(buf), "%s @ %" PRIu64,
- type, uint64_t{result.collider.data});
+ type, uint64_t{result.collider.id});
{ auto b = push_style_color(ImGuiCol_Text, 0xffff00ff_rgbaf);
text(buf);
}
diff --git a/editor/vobj-editor.cpp b/editor/vobj-editor.cpp
index 6dc8c907..7e7dde15 100644
--- a/editor/vobj-editor.cpp
+++ b/editor/vobj-editor.cpp
@@ -48,18 +48,20 @@ void vobj_editor::place_tile(world& w, global_coords pos, const vobj_* x, struct
if (!x)
{
auto [c, t] = w[pos];
+start:
const auto& es = c.objects();
-start: while (auto id = a.get_object_colliding_with_cursor())
+ while (auto id = a.get_object_colliding_with_cursor())
{
for (auto i = (int)(es.size()-1); i >= 0; i--)
{
- const auto eʹ = es[i];
- if (eʹ->id == id && eʹ->is_virtual())
+ auto eʹ = es[i];
+ auto& e = *eʹ;
+ if (e.id == id && eʹ->is_virtual())
{
- eʹ->destroy_script_pre(eʹ, script_destroy_reason::kill);
+ e.destroy_script_pre(eʹ, script_destroy_reason::kill);
c.remove_object((unsigned)i);
- eʹ->destroy_script_post();
- eʹ->gone = true;
+ e.destroy_script_post();
+ eʹ.destroy();
goto start;
}
}