summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-08 09:04:14 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-08 09:04:14 +0200
commit22f1e92d16dbf7986977c323c0a2985fead88bfd (patch)
tree0fb1d9de02e3f187eb40f3bfe4763e25c283b45a /editor
parent3e5b43638dac74a88918fecc139b4533bd1c0643 (diff)
a
Diffstat (limited to 'editor')
-rw-r--r--editor/app.hpp11
-rw-r--r--editor/camera.cpp1
-rw-r--r--editor/events.cpp4
-rw-r--r--editor/imgui-misc.cpp20
-rw-r--r--editor/imgui.cpp1
-rw-r--r--editor/update.cpp5
6 files changed, 38 insertions, 4 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index c9bfa966..c5e9f67a 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -98,6 +98,7 @@ private:
void do_mouse_move(int modifiers);
void do_mouse_up_down(uint8_t button, bool is_down, int modifiers);
+ void do_mouse_scroll(int offset);
void do_camera(float dt, const key_set& cmds, int mods);
void reset_camera_offset();
@@ -122,6 +123,7 @@ private:
float draw_main_menu();
void draw_fps();
void draw_tile_under_cursor();
+ void draw_z_level();
void do_popup_menu();
void kill_popups(bool hard);
void render_menu();
@@ -155,9 +157,12 @@ private:
cursor_state cursor;
popup_target _popup_target;
- bool _pending_popup : 1 = false;
- bool _render_bboxes : 1 = false;
- bool _render_clickables : 1 = false;
+ int8_t _z_level = 0;
+
+ bool _pending_popup : 1 = false;
+ bool _render_bboxes : 1 = false;
+ bool _render_clickables : 1 = false;
+ bool _render_all_z_levels : 1 = true;
};
} // namespace floormat
diff --git a/editor/camera.cpp b/editor/camera.cpp
index 2df3dd20..b43c7af8 100644
--- a/editor/camera.cpp
+++ b/editor/camera.cpp
@@ -53,6 +53,7 @@ void app::reset_camera_offset()
constexpr Vector3d size = TILE_MAX_DIM20d*dTILE_SIZE*-.5;
constexpr auto projected = tile_shader::project(size);
M->shader().set_camera_offset(projected, 0);
+ _z_level = 0;
update_cursor_tile(cursor.pixel);
}
diff --git a/editor/events.cpp b/editor/events.cpp
index 4e0a2503..89bdf4a3 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -97,7 +97,9 @@ void app::on_mouse_scroll(const mouse_scroll_event& event) noexcept
accessor(Vector2, offset)
accessor(Vector2i, position)
} e = {event.offset, event.position};
- _imgui.handleMouseScrollEvent(e);
+
+ if (!(cursor.in_imgui = _imgui.handleMouseScrollEvent(e)))
+ do_mouse_scroll((int)e.offset()[1]);
}
auto app::resolve_keybinding(int k_, int mods_) const -> std::tuple<key, int>
diff --git a/editor/imgui-misc.cpp b/editor/imgui-misc.cpp
index 82320244..9acd906e 100644
--- a/editor/imgui-misc.cpp
+++ b/editor/imgui-misc.cpp
@@ -48,4 +48,24 @@ void app::draw_tile_under_cursor()
{window_size[0]*.5f - size.x/2, 3*dpi[1]}, (unsigned)-1, buf);
}
+void app::draw_z_level()
+{
+ if (_z_level == 0)
+ return;
+
+ if (cursor.pixel && cursor.tile && !cursor.in_imgui)
+ {
+ const auto dpi = M->dpi_scale();
+ const auto offset = Vector2(4, -3) * dpi;
+ char buf[32];
+ ImDrawList& draw = *ImGui::GetForegroundDrawList();
+ snformat(buf, " +{:d}"_cf, _z_level);
+ const auto font_size = ImGui::GetCurrentContext()->FontSize+3;
+ auto shadow_offset = Vector2(1, 1)/* * dpi */;
+ auto px = Vector2(*cursor.pixel) + offset, px2 = px + shadow_offset;
+ draw.AddText(nullptr, font_size, {px2[0], px2[1]}, ImGui::ColorConvertFloat4ToU32({0, 0, 0, 1}), buf);
+ draw.AddText(nullptr, font_size, {px[0], px[1]}, ImGui::ColorConvertFloat4ToU32({1, 0, 1, 1}), buf);
+ }
+}
+
} // namespace floormat
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 6f1e1d29..b3863f06 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -106,6 +106,7 @@ void app::draw_ui()
draw_tile_under_cursor();
if (_editor.mode() == editor_mode::none)
draw_inspector();
+ draw_z_level();
do_popup_menu();
ImGui::EndFrame();
}
diff --git a/editor/update.cpp b/editor/update.cpp
index eb4029dc..97d77ffb 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -98,6 +98,11 @@ void app::do_mouse_up_down(uint8_t button, bool is_down, int mods)
_editor.on_release();
}
+void app::do_mouse_scroll(int offset)
+{
+ _z_level = (int8_t)Math::clamp(_z_level + offset, 0, 2);
+}
+
void app::do_rotate(bool backward)
{
if (auto* ed = _editor.current_tile_editor())