diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-09 20:46:10 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-09 20:46:10 +0100 |
commit | 6719ba4fe8ac900b9eebbe54acbcd7ff54f17a9b (patch) | |
tree | 89f6b60a41ef95bf8f86f07a02fcb22dc62a0614 /editor | |
parent | 713ab8991057b5aef75e7dd68992cf812c27fd5a (diff) |
bb
Diffstat (limited to 'editor')
-rw-r--r-- | editor/imgui-editors.cpp | 101 | ||||
-rw-r--r-- | editor/imgui-tiles.cpp | 83 | ||||
-rw-r--r-- | editor/wall-editor.cpp | 2 | ||||
-rw-r--r-- | editor/wall-editor.hpp | 2 |
4 files changed, 81 insertions, 107 deletions
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp index 779e81e7..95e51667 100644 --- a/editor/imgui-editors.cpp +++ b/editor/imgui-editors.cpp @@ -1,6 +1,8 @@ #include "app.hpp" +#include "compat/format.hpp" #include "imgui-raii.hpp" #include "src/anim-atlas.hpp" +#include "src/tile-atlas.hpp" #include "loader/loader.hpp" #include "floormat/main.hpp" #include <Magnum/Math/Color.h> @@ -11,7 +13,12 @@ using namespace floormat::imgui; namespace { -StringView scenery_type_to_string(const scenery_editor::scenery_& sc) +template<typename T> constexpr inline bool do_group_column = false; +template<> constexpr inline bool do_group_column<scenery_editor> = true; +using scenery_ = scenery_editor::scenery_; +using vobj_ = vobj_editor::vobj_; + +StringView scenery_type_to_string(const scenery_& sc) { switch (sc.proto.sc_type) { @@ -22,35 +29,85 @@ StringView scenery_type_to_string(const scenery_editor::scenery_& sc) } } -std::shared_ptr<anim_atlas> get_atlas(const scenery_editor::scenery_& sc) -{ - return sc.proto.atlas; -} +std::shared_ptr<anim_atlas> get_atlas(const scenery_& sc) { return sc.proto.atlas; } +StringView scenery_name(StringView name, const scenery_&) { return name; } +StringView scenery_type_to_string(const vobj_& vobj) { return vobj.name; } +std::shared_ptr<anim_atlas> get_atlas(const vobj_& vobj) { return vobj.factory->atlas(); } +StringView scenery_name(StringView, const vobj_& vobj) { return vobj.descr; } + +} // namespace -StringView scenery_name(StringView name, const scenery_editor::scenery_&) +void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const std::shared_ptr<tile_atlas>& atlas) { - return name; -} + const auto b = push_id("tile-pane"); -template<typename T> constexpr inline bool do_group_column = false; -template<> constexpr inline bool do_group_column<scenery_editor> = true; + const auto dpi = M->dpi_scale(); + constexpr Color4 color_perm_selected{1, 1, 1, .7f}, + color_selected{1, 0.843f, 0, .8f}, + color_hover{0, .8f, 1, .7f}; + const float window_width = ImGui::GetWindowWidth() - 32 * dpi[0]; + char buf[128]; + const auto& style = ImGui::GetStyle(); + const auto N = atlas->num_tiles(); -StringView scenery_type_to_string(const vobj_editor::vobj_& vobj) -{ - return vobj.name; -} + const auto click_event = [&] { + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) + ed.select_tile_permutation(atlas); + else if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) + ed.clear_selection(); + }; + const auto do_caption = [&] { + click_event(); + if (ed.is_atlas_selected(atlas)) + { + ImGui::SameLine(); + text(" (selected)"); + } + const auto len = snformat(buf, "{:d}"_cf, N); + fm_assert(len < std::size(buf)); + ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4*dpi[0]); + text({buf, len}); + }; + if (const auto flags = ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed); + auto b = tree_node(name.data(), flags)) + { + do_caption(); + [[maybe_unused]] const raii_wrapper vars[] = { + push_style_var(ImGuiStyleVar_FramePadding, {2*dpi[0], 2*dpi[1]}), + push_style_color(ImGuiCol_ButtonHovered, color_hover), + }; + const bool perm_selected = ed.is_permutation_selected(atlas); + constexpr size_t per_row = 8; + for (auto i = 0uz; i < N; i++) + { + const bool selected = ed.is_tile_selected(atlas, i); + if (i > 0 && i % per_row == 0) + ImGui::NewLine(); -std::shared_ptr<anim_atlas> get_atlas(const vobj_editor::vobj_& vobj) -{ - return vobj.factory->atlas(); -} + [[maybe_unused]] const raii_wrapper vars[] = { + selected ? push_style_color(ImGuiCol_Button, color_selected) : raii_wrapper{}, + selected ? push_style_color(ImGuiCol_ButtonHovered, color_selected) : raii_wrapper{}, + perm_selected ? push_style_color(ImGuiCol_Button, color_perm_selected) : raii_wrapper{}, + perm_selected ? push_style_color(ImGuiCol_ButtonHovered, color_perm_selected) : raii_wrapper{}, + }; -StringView scenery_name(StringView, const vobj_editor::vobj_& vobj) -{ - return vobj.descr; + 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]), + { uv[3][0], uv[3][1] }, { uv[0][0], uv[0][1] }); + if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) + ed.select_tile(atlas, i); + else + click_event(); + ImGui::SameLine(); + } + ImGui::NewLine(); + } + else + do_caption(); } -} // namespace template<typename T> static void impl_draw_editor_scenery_pane(T& ed, Vector2 dpi) diff --git a/editor/imgui-tiles.cpp b/editor/imgui-tiles.cpp deleted file mode 100644 index b4fc8a9c..00000000 --- a/editor/imgui-tiles.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "app.hpp" -#include "src/tile-atlas.hpp" -#include "floormat/main.hpp" -#include "imgui-raii.hpp" -#include "compat/format.hpp" -#include <Magnum/Math/Color.h> - -namespace floormat { - -using namespace floormat::imgui; - -void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const std::shared_ptr<tile_atlas>& atlas) -{ - const auto b = push_id("tile-pane"); - - const auto dpi = M->dpi_scale(); - constexpr Color4 color_perm_selected{1, 1, 1, .7f}, - color_selected{1, 0.843f, 0, .8f}, - color_hover{0, .8f, 1, .7f}; - const float window_width = ImGui::GetWindowWidth() - 32 * dpi[0]; - char buf[128]; - const auto& style = ImGui::GetStyle(); - const auto N = atlas->num_tiles(); - - const auto click_event = [&] { - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) - ed.select_tile_permutation(atlas); - else if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) - ed.clear_selection(); - }; - const auto do_caption = [&] { - click_event(); - if (ed.is_atlas_selected(atlas)) - { - ImGui::SameLine(); - text(" (selected)"); - } - const auto len = snformat(buf, "{:d}"_cf, N); - fm_assert(len < std::size(buf)); - ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4*dpi[0]); - text({buf, len}); - }; - if (const auto flags = ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed); - auto b = tree_node(name.data(), flags)) - { - do_caption(); - [[maybe_unused]] const raii_wrapper vars[] = { - push_style_var(ImGuiStyleVar_FramePadding, {2*dpi[0], 2*dpi[1]}), - push_style_color(ImGuiCol_ButtonHovered, color_hover), - }; - const bool perm_selected = ed.is_permutation_selected(atlas); - constexpr size_t per_row = 8; - for (auto i = 0uz; i < N; i++) - { - const bool selected = ed.is_tile_selected(atlas, i); - if (i > 0 && i % per_row == 0) - ImGui::NewLine(); - - [[maybe_unused]] const raii_wrapper vars[] = { - selected ? push_style_color(ImGuiCol_Button, color_selected) : raii_wrapper{}, - selected ? push_style_color(ImGuiCol_ButtonHovered, color_selected) : raii_wrapper{}, - perm_selected ? push_style_color(ImGuiCol_Button, color_perm_selected) : raii_wrapper{}, - perm_selected ? push_style_color(ImGuiCol_ButtonHovered, color_perm_selected) : raii_wrapper{}, - }; - - 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]), - { uv[3][0], uv[3][1] }, { uv[0][0], uv[0][1] }); - if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) - ed.select_tile(atlas, i); - else - click_event(); - ImGui::SameLine(); - } - ImGui::NewLine(); - } - else - do_caption(); -} - -} // namespace floormat diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp index b311145a..c7052c69 100644 --- a/editor/wall-editor.cpp +++ b/editor/wall-editor.cpp @@ -51,7 +51,7 @@ void wall_editor::load_atlases() { fm_assert(_atlases.empty()); for (const auto& wa : loader.wall_atlas_list()) - _atlases[wa.name] = wa; + _atlases[wa.name] = &wa; fm_assert(!_atlases.empty()); } diff --git a/editor/wall-editor.hpp b/editor/wall-editor.hpp index 526ac745..4379a909 100644 --- a/editor/wall-editor.hpp +++ b/editor/wall-editor.hpp @@ -13,7 +13,7 @@ class wall_atlas; class wall_editor { - std::map<StringView, wall_info> _atlases; + std::map<StringView, const wall_info*> _atlases; std::shared_ptr<wall_atlas> _selected_atlas; enum rotation _r = rotation::N; |