diff options
Diffstat (limited to 'editor/imgui-scenery.cpp')
| -rw-r--r-- | editor/imgui-scenery.cpp | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/editor/imgui-scenery.cpp b/editor/imgui-scenery.cpp index 08a51d81..41dc8a6e 100644 --- a/editor/imgui-scenery.cpp +++ b/editor/imgui-scenery.cpp @@ -12,21 +12,14 @@ using namespace floormat::imgui; void app::draw_editor_scenery_pane(scenery_editor& ed) { + const auto& style = ImGui::GetStyle(); const auto dpi = M->dpi_scale(); constexpr ImGuiTableFlags flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_ScrollY; constexpr int ncolumns = 4; const auto size = ImGui::GetWindowSize(); auto b = imgui::begin_table("scenery-table", ncolumns, flags, size); - const auto font_size = ImGui::GetCurrentContext()->FontSize; - const auto min_row_height = font_size; - constexpr auto thumbnail_width = 40; -#if 0 - if (!_scenery_table) - { - _scenery_table = new ImGuiTable{}; - ImGui::TableBeginInitMemory(_scenery_table, ncolumns); - } -#endif + const auto row_height = ImGui::GetCurrentContext()->FontSize; + constexpr auto thumbnail_width = 50; const auto colwidth_type = ImGui::CalcTextSize("generic").x; const auto colwidth_group = ImGui::CalcTextSize("MMMMMMMMMMMMMMM").x; ImGui::TableSetupScrollFreeze(1, 1); @@ -38,24 +31,48 @@ void app::draw_editor_scenery_pane(scenery_editor& ed) ImGui::TableSetupColumn("Group", colflags, colwidth_group); ImGui::TableHeadersRow(); + const auto click_event = [&] { + if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) + ed.clear_selection(); + }; + click_event(); + for (const auto& [name, scenery] : ed) { - char buf[128]; - bool selected = false; + bool selected = ed.is_item_selected(scenery); fm_debug_assert(scenery.proto.atlas != nullptr); - ImGui::TableNextRow(ImGuiTableRowFlags_None, min_row_height); + ImGui::TableNextRow(ImGuiTableRowFlags_None, row_height); + if (ImGui::TableSetColumnIndex(0)) { - ImGui::TableSetColumnIndex(0); - snformat(buf, "##sc_{}"_cf, name.data()); - ImGui::Selectable(buf, &selected, ImGuiSelectableFlags_SpanAllColumns); + auto& atlas = *scenery.proto.atlas; + const auto r = atlas.next_rotation_from(rotation_COUNT); + const auto& frame = atlas.frame(r, 0); + fm_debug_assert(frame.size.product() != 0); + const auto size = Vector2(frame.size); + const float c = std::min(thumbnail_width / size[0], row_height / size[1]); + const auto texcoords = atlas.texcoords_for_frame(r, 0, !atlas.group(r).mirror_from.isEmpty()); + const ImVec2 img_size = {size[0]*c, size[1]*c}; + 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() + style.FramePadding.y + .5f*dpi + std::max(0.f, row_height - img_size.y)); + ImGui::Image((void*)&atlas.texture(), img_size, uv0, uv1); + click_event(); } + if (ImGui::TableSetColumnIndex(1)) { - ImGui::TableNextColumn(); - text(name); + ImGui::AlignTextToFramePadding(); + if (constexpr ImGuiSelectableFlags flags = ImGuiSelectableFlags_SpanAllColumns; + ImGui::Selectable(name.data(), &selected, flags, ImVec2{0, row_height})) + { + if (selected) + ed.select_tile(scenery); + } + click_event(); } + if (ImGui::TableSetColumnIndex(2)) { - ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); switch (scenery.proto.frame.type) { case scenery_type::none: text("none"); break; @@ -63,9 +80,10 @@ void app::draw_editor_scenery_pane(scenery_editor& ed) case scenery_type::door: text("door"); break; default: text("unknown"); break; } + click_event(); } + if (ImGui::TableSetColumnIndex(3)) { - ImGui::TableNextColumn(); StringView name = scenery.proto.atlas->name(); if (name.hasPrefix(loader.SCENERY_PATH)) name = name.exceptPrefix(loader.SCENERY_PATH.size()); @@ -73,12 +91,11 @@ void app::draw_editor_scenery_pane(scenery_editor& ed) name = name.prefix(last.data()); else name = {}; + ImGui::AlignTextToFramePadding(); text(name); + click_event(); } - if (selected) - ed.select_tile(scenery); } - //ImGui::TableUpdateColumnsWeightFromWidth(_scenery_table); } } // namespace floormat |
