diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-23 10:05:55 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-23 10:05:55 +0200 |
commit | db2a8661d5dc8cecb4fea80d5cfec237af67ea24 (patch) | |
tree | 71399da7d004402863e8f7872f9cf554a93de381 /main | |
parent | 6e3610344e9af648874e560a364ce62a424e8e15 (diff) |
add atlas selected indicator
Diffstat (limited to 'main')
-rw-r--r-- | main/editor.cpp | 21 | ||||
-rw-r--r-- | main/editor.hpp | 1 | ||||
-rw-r--r-- | main/imgui.cpp | 42 |
3 files changed, 42 insertions, 22 deletions
diff --git a/main/editor.cpp b/main/editor.cpp index 709ab13b..f3c8b157 100644 --- a/main/editor.cpp +++ b/main/editor.cpp @@ -79,15 +79,28 @@ void tile_type::select_tile_permutation(const std::shared_ptr<tile_atlas>& atlas bool tile_type::is_tile_selected(const std::shared_ptr<const tile_atlas>& atlas, std::size_t variant) const { - fm_assert(atlas); - return _selection_mode == sel_tile && _selected_tile && + return atlas && _selection_mode == sel_tile && _selected_tile && atlas == _selected_tile.atlas && variant == _selected_tile.variant; } bool tile_type::is_permutation_selected(const std::shared_ptr<const tile_atlas>& atlas) const { - fm_assert(atlas); - return _selection_mode == sel_perm && std::get<0>(_permutation) == atlas; + const auto& [perm, _] = _permutation; + return atlas && _selection_mode == sel_perm && perm == atlas; +} + +bool tile_type::is_atlas_selected(const std::shared_ptr<const tile_atlas>& atlas) const +{ + switch (_selection_mode) + { + default: + case sel_none: + return false; + case sel_perm: + return is_permutation_selected(atlas); + case sel_tile: + return atlas && _selected_tile && atlas == _selected_tile.atlas; + } } template<std::random_access_iterator T> diff --git a/main/editor.hpp b/main/editor.hpp index c156d0b9..28ba153c 100644 --- a/main/editor.hpp +++ b/main/editor.hpp @@ -37,6 +37,7 @@ struct tile_type final void select_tile_permutation(const std::shared_ptr<tile_atlas>& atlas); bool is_tile_selected(const std::shared_ptr<const tile_atlas>& atlas, std::size_t variant) const; bool is_permutation_selected(const std::shared_ptr<const tile_atlas>& atlas) const; + bool is_atlas_selected(const std::shared_ptr<const tile_atlas>& atlas) const; tile_image get_selected(); void place_tile(world& world, global_coords pos, tile_image& img); diff --git a/main/imgui.cpp b/main/imgui.cpp index 04dc49ed..85661760 100644 --- a/main/imgui.cpp +++ b/main/imgui.cpp @@ -105,26 +105,35 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) ///const auto& k_ = k; const auto& v_ = v; const auto click_event = [&] { - if (ed) + if (ed) + { + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) + ed->select_tile_permutation(v_); + else if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) + ed->clear_selection(); + } + }; + const auto do_caption = [&] { + if (ed) + { + click_event(); + if (ed->is_atlas_selected(v)) + { + ImGui::SameLine(); + ImGui::Text(" (selected)"); + } + } { - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) - ed->select_tile_permutation(v_); - else if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) - ed->clear_selection(); + snprintf(buf, sizeof(buf), "%zu", (std::size_t)v_->num_tiles()); + ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4); + ImGui::Text("%s", buf); } }; - const auto add_tile_count = [&] { - snprintf(buf, sizeof(buf), "%zu", (std::size_t)v_->num_tiles()); - ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4); - ImGui::Text("%s", buf); - }; const auto N = v->num_tiles(); - std::snprintf(buf, sizeof(buf), "%s%s", k.data(), ed && ed->is_permutation_selected(v) ? " (selected)" : ""); if (const auto flags = ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed); - auto b = tree_node(buf, flags)) + auto b = tree_node(k.data(), flags)) { - click_event(); - add_tile_count(); + do_caption(); [[maybe_unused]] const raii_wrapper vars[] = { push_style_var(ImGuiStyleVar_FramePadding, {2, 2}), push_style_color(ImGuiCol_ButtonHovered, color_hover), @@ -161,10 +170,7 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) ImGui::NewLine(); } else - { - click_event(); - add_tile_count(); - } + do_caption(); } } } |