diff --git a/src/app/editor/dungeon/dungeon_editor.cc b/src/app/editor/dungeon/dungeon_editor.cc index cbb15489..81b9cdad 100644 --- a/src/app/editor/dungeon/dungeon_editor.cc +++ b/src/app/editor/dungeon/dungeon_editor.cc @@ -6,6 +6,7 @@ #include "app/core/labeling.h" #include "app/gfx/snes_palette.h" #include "app/gui/canvas.h" +#include "app/gui/color.h" #include "app/gui/icons.h" #include "app/gui/input.h" #include "app/gui/pipeline.h" diff --git a/src/app/editor/graphics/graphics_editor.cc b/src/app/editor/graphics/graphics_editor.cc index 1479151a..9575b5cd 100644 --- a/src/app/editor/graphics/graphics_editor.cc +++ b/src/app/editor/graphics/graphics_editor.cc @@ -16,6 +16,7 @@ #include "app/gfx/snes_tile.h" #include "app/gui/asset_browser.h" #include "app/gui/canvas.h" +#include "app/gui/color.h" #include "app/gui/input.h" #include "app/gui/pipeline.h" #include "app/gui/style.h" @@ -523,10 +524,12 @@ absl::Status GraphicsEditor::DrawCgxImport() { is_open_ = true; cgx_loaded_ = true; }); - gui::ButtonPipe("Copy CGX Path", - [this]() { ImGui::SetClipboardText(cgx_file_path_); }); - gui::ButtonPipe("Load CGX Data", [this]() { + if (ImGui::Button("Copy CGX Path")) { + ImGui::SetClipboardText(cgx_file_path_); + } + + if (ImGui::Button("Load CGX Data")) { status_ = gfx::scad_format::LoadCgx(current_bpp_, cgx_file_path_, cgx_data_, decoded_cgx_, extra_cgx_data_); @@ -535,7 +538,7 @@ absl::Status GraphicsEditor::DrawCgxImport() { cgx_bitmap_.ApplyPalette(decoded_col_); rom()->RenderBitmap(&cgx_bitmap_); } - }); + } return absl::OkStatus(); } @@ -557,7 +560,7 @@ absl::Status GraphicsEditor::DrawScrImport() { InputInt("SCR Mod", &scr_mod_value_); - gui::ButtonPipe("Load Scr Data", [this]() { + if (ImGui::Button("Load Scr Data")) { status_ = gfx::scad_format::LoadScr(scr_file_path_, scr_mod_value_, scr_data_); @@ -570,7 +573,7 @@ absl::Status GraphicsEditor::DrawScrImport() { scr_bitmap_.ApplyPalette(decoded_col_); rom()->RenderBitmap(&scr_bitmap_); } - }); + } return absl::OkStatus(); } @@ -607,8 +610,9 @@ absl::Status GraphicsEditor::DrawPaletteControls() { is_open_ = true; }); - gui::ButtonPipe("Copy COL Path", - [this]() { ImGui::SetClipboardText(col_file_path_); }); + if (ImGui::Button("Copy Col Path")) { + ImGui::SetClipboardText(col_file_path_); + } if (rom()->is_loaded()) { gui::TextWithSeparators("ROM Palette"); @@ -680,8 +684,9 @@ absl::Status GraphicsEditor::DrawFileImport() { is_open_ = true; }); - gui::ButtonPipe("Copy File Path", - [this]() { ImGui::SetClipboardText(file_path_); }); + if (Button("Copy File Path")) { + ImGui::SetClipboardText(file_path_); + } gui::InputHex("BIN Offset", ¤t_offset_); gui::InputHex("BIN Size", &bin_size_); @@ -700,7 +705,7 @@ absl::Status GraphicsEditor::DrawFileImport() { absl::Status GraphicsEditor::DrawClipboardImport() { gui::TextWithSeparators("Clipboard Import"); - gui::ButtonPipe("Paste from Clipboard", [this]() { + if (Button("Paste From Clipboard")) { const char* text = ImGui::GetClipboardText(); if (text) { const auto clipboard_data = Bytes(text, text + strlen(text)); @@ -709,12 +714,12 @@ absl::Status GraphicsEditor::DrawClipboardImport() { is_open_ = true; open_memory_editor_ = true; } - }); + } gui::InputHex("Offset", &clipboard_offset_); gui::InputHex("Size", &clipboard_size_); gui::InputHex("Num Sheets", &num_sheets_to_load_); - gui::ButtonPipe("Decompress Clipboard Data", [this]() { + if (Button("Decompress Clipboard Data")) { if (temp_rom_.is_loaded()) { status_ = DecompressImportData(0x40000); } else { @@ -722,7 +727,7 @@ absl::Status GraphicsEditor::DrawClipboardImport() { "Please paste data into the clipboard before " "decompressing."); } - }); + } return absl::OkStatus(); } diff --git a/src/app/editor/graphics/tile16_editor.cc b/src/app/editor/graphics/tile16_editor.cc index 81ec5a48..eb5ecbbe 100644 --- a/src/app/editor/graphics/tile16_editor.cc +++ b/src/app/editor/graphics/tile16_editor.cc @@ -1,5 +1,6 @@ #include "tile16_editor.h" +#include #include #include diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index 9bb9cdba..9cf5d2d6 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -1,5 +1,6 @@ #include "overworld_editor.h" +#include #include #include diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index b1a6f1ac..ef37f639 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -2,7 +2,6 @@ #define YAZE_APP_EDITOR_OVERWORLDEDITOR_H #include -#include #include #include @@ -290,6 +289,8 @@ class OverworldEditor : public Editor, gfx::BitmapTable sprite_previews_; gfx::BitmapTable animated_maps_; + OWBlockset refresh_blockset_; + gui::zeml::Node layout_node_; absl::Status status_; }; diff --git a/src/app/gui/canvas.cc b/src/app/gui/canvas.cc index 9e867eb4..91e7ae99 100644 --- a/src/app/gui/canvas.cc +++ b/src/app/gui/canvas.cc @@ -7,6 +7,7 @@ #include "app/editor/graphics/graphics_editor.h" #include "app/gfx/bitmap.h" +#include "app/gui/color.h" #include "app/gui/input.h" #include "app/gui/style.h" #include "app/rom.h" @@ -761,6 +762,61 @@ void Canvas::DrawLayeredElements() { } } +void GraphicsBinCanvasPipeline(int width, int height, int tile_size, + int num_sheets_to_load, int canvas_id, + bool is_loaded, gfx::BitmapTable &graphics_bin) { + gui::Canvas canvas; + if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)canvas_id); + ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, + ImGuiWindowFlags_AlwaysVerticalScrollbar)) { + canvas.DrawBackground(ImVec2(width + 1, num_sheets_to_load * height + 1)); + canvas.DrawContextMenu(); + if (is_loaded) { + for (const auto &[key, value] : graphics_bin) { + int offset = height * (key + 1); + int top_left_y = canvas.zero_point().y + 2; + if (key >= 1) { + top_left_y = canvas.zero_point().y + height * key; + } + canvas.draw_list()->AddImage( + (void *)value.texture(), + ImVec2(canvas.zero_point().x + 2, top_left_y), + ImVec2(canvas.zero_point().x + 0x100, + canvas.zero_point().y + offset)); + } + } + canvas.DrawTileSelector(tile_size); + canvas.DrawGrid(tile_size); + canvas.DrawOverlay(); + } + ImGui::EndChild(); +} + +void BitmapCanvasPipeline(gui::Canvas &canvas, const gfx::Bitmap &bitmap, + int width, int height, int tile_size, bool is_loaded, + bool scrollbar, int canvas_id) { + auto draw_canvas = [](gui::Canvas &canvas, const gfx::Bitmap &bitmap, + int width, int height, int tile_size, bool is_loaded) { + canvas.DrawBackground(ImVec2(width + 1, height + 1)); + canvas.DrawContextMenu(); + canvas.DrawBitmap(bitmap, 2, is_loaded); + canvas.DrawTileSelector(tile_size); + canvas.DrawGrid(tile_size); + canvas.DrawOverlay(); + }; + + if (scrollbar) { + if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)canvas_id); + ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, + ImGuiWindowFlags_AlwaysVerticalScrollbar)) { + draw_canvas(canvas, bitmap, width, height, tile_size, is_loaded); + } + ImGui::EndChild(); + } else { + draw_canvas(canvas, bitmap, width, height, tile_size, is_loaded); + } +} + } // namespace gui } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/gui/canvas.h b/src/app/gui/canvas.h index c094b06d..e199a44a 100644 --- a/src/app/gui/canvas.h +++ b/src/app/gui/canvas.h @@ -221,6 +221,14 @@ class Canvas : public SharedRom { std::vector selected_tiles_; }; +void GraphicsBinCanvasPipeline(int width, int height, int tile_size, + int num_sheets_to_load, int canvas_id, + bool is_loaded, BitmapTable& graphics_bin); + +void BitmapCanvasPipeline(gui::Canvas& canvas, const gfx::Bitmap& bitmap, + int width, int height, int tile_size, bool is_loaded, + bool scrollbar, int canvas_id); + } // namespace gui } // namespace app } // namespace yaze diff --git a/src/app/gui/color.cc b/src/app/gui/color.cc index aaa22b24..9e6c2481 100644 --- a/src/app/gui/color.cc +++ b/src/app/gui/color.cc @@ -125,6 +125,49 @@ absl::Status DisplayPalette(app::gfx::SnesPalette& palette, bool loaded) { ImGuiColorEditFlags_NoSmallPreview); } +void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics, + gfx::SnesPalette& palette) { + const auto palette_row_size = 7; + if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)100); + ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, + ImGuiWindowFlags_AlwaysVerticalScrollbar)) { + ImGui::BeginGroup(); // Lock X position + ImGui::Text("Palette"); + for (int n = 0; n < palette.size(); n++) { + ImGui::PushID(n); + if ((n % palette_row_size) != 0) + ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y); + + // Check if the current row is selected + bool is_selected = (palette_id == n / palette_row_size); + + // Add outline rectangle to the selected row + if (is_selected) { + ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 1.0f, 0.0f, 1.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); + } + + if (gui::SnesColorButton("##palette", palette[n], + ImGuiColorEditFlags_NoAlpha | + ImGuiColorEditFlags_NoPicker | + ImGuiColorEditFlags_NoTooltip, + ImVec2(20, 20))) { + palette_id = n / palette_row_size; + refresh_graphics = true; + } + + if (is_selected) { + ImGui::PopStyleColor(); + ImGui::PopStyleVar(); + } + + ImGui::PopID(); + } + ImGui::EndGroup(); + } + ImGui::EndChild(); +} + } // namespace gui } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/gui/color.h b/src/app/gui/color.h index e843a36a..821bb9a1 100644 --- a/src/app/gui/color.h +++ b/src/app/gui/color.h @@ -30,6 +30,9 @@ IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor* color, absl::Status DisplayPalette(app::gfx::SnesPalette& palette, bool loaded); +void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics, + gfx::SnesPalette& palette); + } // namespace gui } // namespace app } // namespace yaze diff --git a/src/app/gui/input.cc b/src/app/gui/input.cc index b10a65e7..8649cd46 100644 --- a/src/app/gui/input.cc +++ b/src/app/gui/input.cc @@ -1,12 +1,20 @@ #include "input.h" +#include #include #include #include +#include +#include #include #include "absl/strings/string_view.h" +#include "app/core/common.h" +#include "app/gfx/bitmap.h" +#include "app/gfx/snes_palette.h" +#include "app/gui/canvas.h" +#include "app/gui/color.h" namespace ImGui { @@ -243,6 +251,24 @@ bool ListBox(const char* label, int* current_item, ImGuiID GetID(const std::string& id) { return ImGui::GetID(id.c_str()); } +void FileDialogPipeline(absl::string_view display_key, + absl::string_view file_extensions, + std::optional button_text, + std::function callback) { + if (button_text.has_value() && ImGui::Button(button_text->data())) { + ImGuiFileDialog::Instance()->OpenDialog(display_key.data(), "Choose File", + file_extensions.data(), "."); + } + + if (ImGuiFileDialog::Instance()->Display( + display_key.data(), ImGuiWindowFlags_NoCollapse, ImVec2(600, 400))) { + if (ImGuiFileDialog::Instance()->IsOk()) { + callback(); + } + ImGuiFileDialog::Instance()->Close(); + } +} + } // namespace gui } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/gui/input.h b/src/app/gui/input.h index 08a059e1..7b574809 100644 --- a/src/app/gui/input.h +++ b/src/app/gui/input.h @@ -1,13 +1,25 @@ #ifndef YAZE_APP_CORE_INPUT_H #define YAZE_APP_CORE_INPUT_H +#define IMGUI_DEFINE_MATH_OPERATORS + #include +#include +#include #include #include +#include +#include +#include #include #include "absl/strings/string_view.h" +#include "app/core/common.h" +#include "app/gfx/bitmap.h" +#include "app/gfx/snes_palette.h" +#include "app/gui/canvas.h" +#include "app/gui/color.h" namespace yaze { namespace app { @@ -48,6 +60,11 @@ IMGUI_API void ItemLabel(absl::string_view title, ItemLabelFlags flags); IMGUI_API ImGuiID GetID(const std::string& id); +void FileDialogPipeline(absl::string_view display_key, + absl::string_view file_extensions, + std::optional button_text, + std::function callback); + } // namespace gui } // namespace app } // namespace yaze diff --git a/src/app/gui/pipeline.cc b/src/app/gui/pipeline.cc index c4dab89c..09ce2e51 100644 --- a/src/app/gui/pipeline.cc +++ b/src/app/gui/pipeline.cc @@ -1,179 +1,12 @@ #include "pipeline.h" -#include -#include -#include -#include - -#include -#include - -#include "absl/strings/string_view.h" -#include "app/core/common.h" -#include "app/gfx/bitmap.h" -#include "app/gfx/snes_palette.h" -#include "app/gui/canvas.h" -#include "app/gui/color.h" -#include "app/gui/input.h" - namespace yaze { namespace app { namespace gui { -void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics, - gfx::SnesPalette& palette) { - const auto palette_row_size = 7; - if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)100); - ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, - ImGuiWindowFlags_AlwaysVerticalScrollbar)) { - ImGui::BeginGroup(); // Lock X position - ImGui::Text("Palette"); - for (int n = 0; n < palette.size(); n++) { - ImGui::PushID(n); - if ((n % palette_row_size) != 0) - ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y); - // Check if the current row is selected - bool is_selected = (palette_id == n / palette_row_size); - // Add outline rectangle to the selected row - if (is_selected) { - ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 1.0f, 0.0f, 1.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); - } - if (gui::SnesColorButton("##palette", palette[n], - ImGuiColorEditFlags_NoAlpha | - ImGuiColorEditFlags_NoPicker | - ImGuiColorEditFlags_NoTooltip, - ImVec2(20, 20))) { - palette_id = n / palette_row_size; - refresh_graphics = true; - } - - if (is_selected) { - ImGui::PopStyleColor(); - ImGui::PopStyleVar(); - } - - ImGui::PopID(); - } - ImGui::EndGroup(); - } - ImGui::EndChild(); -} - -void GraphicsBinCanvasPipeline(int width, int height, int tile_size, - int num_sheets_to_load, int canvas_id, - bool is_loaded, gfx::BitmapTable& graphics_bin) { - gui::Canvas canvas; - - if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)canvas_id); - ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, - ImGuiWindowFlags_AlwaysVerticalScrollbar)) { - canvas.DrawBackground(ImVec2(width + 1, num_sheets_to_load * height + 1)); - canvas.DrawContextMenu(); - if (is_loaded) { - for (const auto& [key, value] : graphics_bin) { - int offset = height * (key + 1); - int top_left_y = canvas.zero_point().y + 2; - if (key >= 1) { - top_left_y = canvas.zero_point().y + height * key; - } - canvas.draw_list()->AddImage( - (void*)value.texture(), - ImVec2(canvas.zero_point().x + 2, top_left_y), - ImVec2(canvas.zero_point().x + 0x100, - canvas.zero_point().y + offset)); - } - } - canvas.DrawTileSelector(tile_size); - canvas.DrawGrid(tile_size); - canvas.DrawOverlay(); - } - ImGui::EndChild(); -} - -void GraphicsManagerCanvasPipeline(int width, int height, int tile_size, - int num_sheets, int canvas_id, - bool is_loaded, - const gfx::BitmapManager& graphics_manager) { - gui::Canvas canvas; - - if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)canvas_id); - ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, - ImGuiWindowFlags_AlwaysVerticalScrollbar)) { - canvas.DrawBackground(ImVec2(width + 1, num_sheets * height + 1)); - canvas.DrawContextMenu(); - if (is_loaded) { - for (const auto& [key, value] : graphics_manager) { - int offset = height * (key + 1); - int top_left_y = canvas.zero_point().y + 2; - if (key >= 1) { - top_left_y = canvas.zero_point().y + height * key; - } - canvas.draw_list()->AddImage( - (void*)value.texture(), - ImVec2(canvas.zero_point().x + 2, top_left_y), - ImVec2(canvas.zero_point().x + 0x100, - canvas.zero_point().y + offset)); - } - } - canvas.DrawTileSelector(tile_size); - canvas.DrawGrid(tile_size); - canvas.DrawOverlay(); - } - ImGui::EndChild(); -} - -void ButtonPipe(absl::string_view button_text, std::function callback) { - if (ImGui::Button(button_text.data())) { - callback(); - } -} - -void BitmapCanvasPipeline(gui::Canvas& canvas, const gfx::Bitmap& bitmap, - int width, int height, int tile_size, bool is_loaded, - bool scrollbar, int canvas_id) { - auto draw_canvas = [](gui::Canvas& canvas, const gfx::Bitmap& bitmap, - int width, int height, int tile_size, bool is_loaded) { - canvas.DrawBackground(ImVec2(width + 1, height + 1)); - canvas.DrawContextMenu(); - canvas.DrawBitmap(bitmap, 2, is_loaded); - canvas.DrawTileSelector(tile_size); - canvas.DrawGrid(tile_size); - canvas.DrawOverlay(); - }; - - if (scrollbar) { - if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)canvas_id); - ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, - ImGuiWindowFlags_AlwaysVerticalScrollbar)) { - draw_canvas(canvas, bitmap, width, height, tile_size, is_loaded); - } - ImGui::EndChild(); - } else { - draw_canvas(canvas, bitmap, width, height, tile_size, is_loaded); - } -} - -void FileDialogPipeline(absl::string_view display_key, - absl::string_view file_extensions, - std::optional button_text, - std::function callback) { - if (button_text.has_value() && ImGui::Button(button_text->data())) { - ImGuiFileDialog::Instance()->OpenDialog(display_key.data(), "Choose File", - file_extensions.data(), "."); - } - - if (ImGuiFileDialog::Instance()->Display( - display_key.data(), ImGuiWindowFlags_NoCollapse, ImVec2(600, 400))) { - if (ImGuiFileDialog::Instance()->IsOk()) { - callback(); - } - ImGuiFileDialog::Instance()->Close(); - } -} } // namespace gui } // namespace app diff --git a/src/app/gui/pipeline.h b/src/app/gui/pipeline.h index 7cfbbe35..5d6e8eb6 100644 --- a/src/app/gui/pipeline.h +++ b/src/app/gui/pipeline.h @@ -1,48 +1,13 @@ #ifndef YAZE_APP_CORE_PIPELINE_H #define YAZE_APP_CORE_PIPELINE_H -#include -#include -#include -#include - -#include -#include - -#include "absl/strings/string_view.h" -#include "app/core/constants.h" -#include "app/gfx/bitmap.h" -#include "app/gfx/snes_palette.h" -#include "app/gui/canvas.h" - namespace yaze { namespace app { namespace gui { -void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics, - gfx::SnesPalette& palette); -void GraphicsBinCanvasPipeline(int width, int height, int tile_size, - int num_sheets_to_load, int canvas_id, - bool is_loaded, gfx::BitmapTable& graphics_bin); -void ButtonPipe(absl::string_view button_text, std::function callback); - -void BitmapCanvasPipeline(gui::Canvas& canvas, const gfx::Bitmap& bitmap, - int width, int height, int tile_size, bool is_loaded, - bool scrollbar, int canvas_id); - -void GraphicsManagerCanvasPipeline(int width, int height, int tile_size, - int num_sheets, int canvas_id, - bool is_loaded, - const gfx::BitmapManager& graphics_manager); - -void FileDialogPipeline(absl::string_view display_key, - absl::string_view file_extensions, - std::optional button_text, - std::function callback); - -} // namespace core +} // namespace gui } // namespace app } // namespace yaze