From 88207094ce74e08533c2c5730490ce641fc2e461 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 13 Jul 2024 10:23:00 -0400 Subject: [PATCH] add sprite canvas, sprite sheets to sprite editor --- src/app/editor/sprite_editor.cc | 109 +++++++++++++++++++++++--------- src/app/editor/sprite_editor.h | 22 +++++-- 2 files changed, 97 insertions(+), 34 deletions(-) diff --git a/src/app/editor/sprite_editor.cc b/src/app/editor/sprite_editor.cc index 7083f3b3..3c326dd6 100644 --- a/src/app/editor/sprite_editor.cc +++ b/src/app/editor/sprite_editor.cc @@ -1,5 +1,7 @@ #include "sprite_editor.h" +#include + namespace yaze { namespace app { namespace editor { @@ -15,52 +17,101 @@ using ImGui::Text; absl::Status SpriteEditor::Update() { if (rom()->is_loaded() && !sheets_loaded_) { // Load the values for current_sheets_ array - sheets_loaded_ = true; } - // if (ImGui::BeginTable({"Canvas", "Graphics"}, 2, nullptr, ImVec2(0, 0))) { - // TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch, - // ImGui::GetContentRegionAvail().x); - // TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256); - // TableHeadersRow(); - // TableNextRow(); - // TableNextColumn(); - // DrawSpriteCanvas(); + if (ImGui::BeginTable("##SpriteCanvasTable", 2, ImGuiTableFlags_Resizable, + ImVec2(0, 0))) { + TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch, + ImGui::GetContentRegionAvail().x); + TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256); + TableHeadersRow(); + TableNextRow(); + TableNextColumn(); + DrawSpriteCanvas(); - // TableNextColumn(); - // if (sheets_loaded_) { - // DrawCurrentSheets(); - // } - - // ImGui::EndTable(); - // } + TableNextColumn(); + if (sheets_loaded_) { + DrawCurrentSheets(); + } + ImGui::EndTable(); + } return absl::OkStatus(); } -void SpriteEditor::DrawEditorTable() {} +void SpriteEditor::DrawSpriteCanvas() { + if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"), + ImGui::GetContentRegionAvail(), true, + ImGuiWindowFlags_AlwaysVerticalScrollbar | + ImGuiWindowFlags_AlwaysHorizontalScrollbar)) { + sprite_canvas_.DrawBackground(ImVec2(0x200, 0x200)); + sprite_canvas_.DrawContextMenu(); + // sprite_canvas_.DrawBitmap(oam_bitmap_, 2, 2); + sprite_canvas_.DrawGrid(8.0f); + sprite_canvas_.DrawOverlay(); -void SpriteEditor::DrawSpriteCanvas() {} + // Draw a table with OAM configuration + // X, Y, Tile, Palette, Priority, Flip X, Flip Y + if (ImGui::BeginTable("##OAMTable", 7, ImGuiTableFlags_None, + ImVec2(0, 0))) { + TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Tile", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Palette", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Priority", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Flip X", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Flip Y", ImGuiTableColumnFlags_WidthStretch); + TableHeadersRow(); + TableNextRow(); + + TableNextColumn(); + gui::InputHexWord("", &oam_config_.x); + + TableNextColumn(); + gui::InputHexWord("", &oam_config_.y); + + TableNextColumn(); + gui::InputHexByte("", &oam_config_.tile); + + TableNextColumn(); + gui::InputHexByte("", &oam_config_.palette); + + TableNextColumn(); + gui::InputHexByte("", &oam_config_.priority); + + TableNextColumn(); + ImGui::Checkbox("", &oam_config_.flip_x); + + TableNextColumn(); + ImGui::Checkbox("", &oam_config_.flip_y); + + ImGui::EndTable(); + } + + ImGui::EndChild(); + } +} void SpriteEditor::DrawCurrentSheets() { - static gui::Canvas graphics_sheet_canvas; for (int i = 0; i < 8; i++) { - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7); - ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, - ImGuiWindowFlags_AlwaysVerticalScrollbar | - ImGuiWindowFlags_AlwaysHorizontalScrollbar)) { - graphics_sheet_canvas.DrawBackground(ImVec2(0x200 * 8, 0x200 * 8)); - ImGui::PopStyleVar(2); + // ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + // std::string sheet_label = absl::StrFormat("Sheet %d", i); + // gui::InputHexByte(sheet_label.c_str(), ¤t_sheets_[i]); + if (ImGui::BeginChild(gui::GetID("sheet_label"), + ImVec2(ImGui::GetContentRegionAvail().x, 0), true, + ImGuiWindowFlags_NoDecoration)) { + static gui::Canvas graphics_sheet_canvas; + graphics_sheet_canvas.DrawBackground(ImVec2(0x80 * 2, 0x20 * 2)); + // ImGui::PopStyleVar(2); graphics_sheet_canvas.DrawContextMenu(); graphics_sheet_canvas.DrawBitmap( - *rom()->bitmap_manager()[current_sheets_[i]], 2, 2); + *rom()->bitmap_manager()[current_sheets_[i]], 2, 2, 2); graphics_sheet_canvas.DrawGrid(64.0f); graphics_sheet_canvas.DrawOverlay(); + ImGui::EndChild(); } - ImGui::EndChild(); } } diff --git a/src/app/editor/sprite_editor.h b/src/app/editor/sprite_editor.h index 3e6d24f1..775e4221 100644 --- a/src/app/editor/sprite_editor.h +++ b/src/app/editor/sprite_editor.h @@ -26,11 +26,6 @@ class SpriteEditor : public SharedRom { absl::Status Update(); private: - /** - * @brief Draws the editor table. - */ - void DrawEditorTable(); - /** * @brief Draws the sprite canvas. */ @@ -44,6 +39,23 @@ class SpriteEditor : public SharedRom { uint8_t current_sheets_[8]; /**< Array to store the current sheets. */ bool sheets_loaded_ = false; /**< Flag indicating whether the sheets are loaded or not. */ + + // OAM Configuration + struct OAMConfig { + uint16_t x; /**< X offset. */ + uint16_t y; /**< Y offset. */ + uint8_t tile; /**< Tile number. */ + uint8_t palette; /**< Palette number. */ + uint8_t priority; /**< Priority. */ + bool flip_x; /**< Flip X. */ + bool flip_y; /**< Flip Y. */ + }; + + OAMConfig oam_config_; /**< OAM configuration. */ + gui::Bitmap oam_bitmap_; /**< OAM bitmap. */ + + gui::Canvas sprite_canvas_{ + ImVec2(0x200, 0x200), gui::CanvasGridSize::k32x32}; /**< Sprite canvas. */ }; } // namespace editor