add sprite canvas, sprite sheets to sprite editor

This commit is contained in:
scawful
2024-07-13 10:23:00 -04:00
parent 215231f367
commit 88207094ce
2 changed files with 97 additions and 34 deletions

View File

@@ -1,5 +1,7 @@
#include "sprite_editor.h" #include "sprite_editor.h"
#include <gui/input.h>
namespace yaze { namespace yaze {
namespace app { namespace app {
namespace editor { namespace editor {
@@ -15,52 +17,101 @@ using ImGui::Text;
absl::Status SpriteEditor::Update() { absl::Status SpriteEditor::Update() {
if (rom()->is_loaded() && !sheets_loaded_) { if (rom()->is_loaded() && !sheets_loaded_) {
// Load the values for current_sheets_ array // Load the values for current_sheets_ array
sheets_loaded_ = true; sheets_loaded_ = true;
} }
// if (ImGui::BeginTable({"Canvas", "Graphics"}, 2, nullptr, ImVec2(0, 0))) { if (ImGui::BeginTable("##SpriteCanvasTable", 2, ImGuiTableFlags_Resizable,
// TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch, ImVec2(0, 0))) {
// ImGui::GetContentRegionAvail().x); TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
// TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256); ImGui::GetContentRegionAvail().x);
// TableHeadersRow(); TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
// TableNextRow(); TableHeadersRow();
// TableNextColumn(); TableNextRow();
// DrawSpriteCanvas(); TableNextColumn();
DrawSpriteCanvas();
// TableNextColumn(); TableNextColumn();
// if (sheets_loaded_) { if (sheets_loaded_) {
// DrawCurrentSheets(); DrawCurrentSheets();
// } }
ImGui::EndTable();
// ImGui::EndTable(); }
// }
return absl::OkStatus(); 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() { void SpriteEditor::DrawCurrentSheets() {
static gui::Canvas graphics_sheet_canvas;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); // ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7); // std::string sheet_label = absl::StrFormat("Sheet %d", i);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, // gui::InputHexByte(sheet_label.c_str(), &current_sheets_[i]);
ImGuiWindowFlags_AlwaysVerticalScrollbar | if (ImGui::BeginChild(gui::GetID("sheet_label"),
ImGuiWindowFlags_AlwaysHorizontalScrollbar)) { ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
graphics_sheet_canvas.DrawBackground(ImVec2(0x200 * 8, 0x200 * 8)); ImGuiWindowFlags_NoDecoration)) {
ImGui::PopStyleVar(2); 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.DrawContextMenu();
graphics_sheet_canvas.DrawBitmap( 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.DrawGrid(64.0f);
graphics_sheet_canvas.DrawOverlay(); graphics_sheet_canvas.DrawOverlay();
ImGui::EndChild();
} }
ImGui::EndChild();
} }
} }

View File

@@ -26,11 +26,6 @@ class SpriteEditor : public SharedRom {
absl::Status Update(); absl::Status Update();
private: private:
/**
* @brief Draws the editor table.
*/
void DrawEditorTable();
/** /**
* @brief Draws the sprite canvas. * @brief Draws the sprite canvas.
*/ */
@@ -44,6 +39,23 @@ class SpriteEditor : public SharedRom {
uint8_t current_sheets_[8]; /**< Array to store the current sheets. */ uint8_t current_sheets_[8]; /**< Array to store the current sheets. */
bool sheets_loaded_ = bool sheets_loaded_ =
false; /**< Flag indicating whether the sheets are loaded or not. */ 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 } // namespace editor