From b3fc57bd777ad26295fd20cf7af023d6f88e3b9d Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 26 Nov 2023 16:23:05 -0500 Subject: [PATCH] Add full graphics bin view to GraphicsEditor --- src/app/editor/graphics_editor.cc | 66 +++++++++++++++++++++++++++++++ src/app/editor/graphics_editor.h | 9 +++++ 2 files changed, 75 insertions(+) diff --git a/src/app/editor/graphics_editor.cc b/src/app/editor/graphics_editor.cc index bb6579cb..36550ef5 100644 --- a/src/app/editor/graphics_editor.cc +++ b/src/app/editor/graphics_editor.cc @@ -30,6 +30,7 @@ using ImGui::SameLine; absl::Status GraphicsEditor::Update() { TAB_BAR("##TabBar") + status_ = UpdateGfxEdit(); status_ = UpdateScadView(); status_ = UpdateLinkGfxView(); END_TAB_BAR() @@ -37,6 +38,71 @@ absl::Status GraphicsEditor::Update() { return absl::OkStatus(); } +absl::Status GraphicsEditor::UpdateGfxEdit() { + TAB_ITEM("Graphics Editor") + + if (ImGui::BeginTable("##GfxEditTable", 3, + ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | + ImGuiTableFlags_Reorderable | + ImGuiTableFlags_Hideable | + ImGuiTableFlags_SizingFixedFit, + ImVec2(0, 0))) { + for (const auto& name : kGfxEditColumnNames) + ImGui::TableSetupColumn(name.data()); + + ImGui::TableHeadersRow(); + + NEXT_COLUMN() { + graphics_bin_canvas_.DrawBackground(ImVec2(0x100 + 1, 223 * 0x40 + 1)); + graphics_bin_canvas_.DrawContextMenu(); + + for (auto& [key, value] : rom()->bitmap_manager()) { + int offset = 0x40 * (key + 1); + int top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 2; + if (key >= 1) { + top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 0x40 * key; + } + auto texture = value.get()->texture(); + + graphics_bin_canvas_.GetDrawList()->AddImage( + (void*)texture, + ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 2, top_left_y), + ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 0x100, + graphics_bin_canvas_.GetZeroPoint().y + offset)); + + // Add a slightly transparent rectangle behind the text + ImVec2 textPos(graphics_bin_canvas_.GetZeroPoint().x + 2, top_left_y); + ImVec2 textSize = + ImGui::CalcTextSize(absl::StrFormat("%02X", key).c_str()); + ImVec2 rectMin(textPos.x, textPos.y); + ImVec2 rectMax(textPos.x + textSize.x, textPos.y + textSize.y); + graphics_bin_canvas_.GetDrawList()->AddRectFilled( + rectMin, rectMax, IM_COL32(0, 125, 0, 128)); + + graphics_bin_canvas_.GetDrawList()->AddText( + textPos, IM_COL32(255, 255, 255, 255), + absl::StrFormat("%02X", key).c_str()); + } + + graphics_bin_canvas_.DrawGrid(16.0f); + graphics_bin_canvas_.DrawOverlay(); + } + + NEXT_COLUMN() { + // if (rom()->isLoaded()) { + // status_ = DrawTilesetControls(); + // status_ = DrawTilesetCanvas(); + // } + } + + NEXT_COLUMN() { status_ = DrawPaletteControls(); } + } + ImGui::EndTable(); + + END_TAB_ITEM() + return absl::OkStatus(); +} + absl::Status GraphicsEditor::UpdateLinkGfxView() { TAB_ITEM("Player Animations") diff --git a/src/app/editor/graphics_editor.h b/src/app/editor/graphics_editor.h index b7b9f015..a79e8d95 100644 --- a/src/app/editor/graphics_editor.h +++ b/src/app/editor/graphics_editor.h @@ -50,6 +50,12 @@ constexpr const char* kPaletteGroupAddressesKeys[] = { "grass", "3d_object", "ow_mini_map", }; +static constexpr std::string_view kGfxEditColumnNames[] = { + "Tilesheets", + "Current Graphics", + "Palette Controls" +}; + static constexpr absl::string_view kGfxToolsetColumnNames[] = { "#memoryEditor", "##separator_gfx1", @@ -64,6 +70,7 @@ class GraphicsEditor : public SharedROM { absl::Status Update(); private: + absl::Status UpdateGfxEdit(); absl::Status UpdateLinkGfxView(); absl::Status UpdateScadView(); @@ -172,6 +179,8 @@ class GraphicsEditor : public SharedROM { gui::Canvas scr_canvas_; gui::Canvas super_donkey_canvas_; + gui::Canvas graphics_bin_canvas_; + absl::Status status_; };