diff --git a/src/app/editor/code/memory_editor.h b/src/app/editor/code/memory_editor.h new file mode 100644 index 00000000..48d388b3 --- /dev/null +++ b/src/app/editor/code/memory_editor.h @@ -0,0 +1,90 @@ +#ifndef YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H +#define YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H + +#include +#include +#include + +#include "absl/status/status.h" +#include "app/core/common.h" +#include "app/core/constants.h" +#include "app/core/platform/file_dialog.h" +#include "app/core/project.h" +#include "app/editor/code/assembly_editor.h" +#include "app/editor/code/memory_editor.h" +#include "app/editor/context/gfx_context.h" +#include "app/editor/dungeon_editor.h" +#include "app/editor/graphics/graphics_editor.h" +#include "app/editor/graphics/palette_editor.h" +#include "app/editor/graphics/screen_editor.h" +#include "app/editor/music/music_editor.h" +#include "app/editor/overworld_editor.h" +#include "app/editor/sprite/sprite_editor.h" +#include "app/editor/utils/editor.h" +#include "app/editor/utils/recent_files.h" +#include "app/emu/emulator.h" +#include "app/gfx/snes_palette.h" +#include "app/gfx/snes_tile.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/gui/input.h" +#include "app/gui/pipeline.h" +#include "app/gui/style.h" +#include "app/gui/widgets.h" +#include "app/rom.h" + +namespace yaze { +namespace app { +namespace editor { + +using ImGui::SameLine; +using ImGui::Text; + +struct MemoryEditorWithDiffChecker : public SharedRom { + void Update(bool &show_memory_editor) { + static MemoryEditor mem_edit; + static MemoryEditor comp_edit; + static bool show_compare_rom = false; + static Rom comparison_rom; + ImGui::Begin("Hex Editor", &show_memory_editor); + if (ImGui::Button("Compare Rom")) { + auto file_name = FileDialogWrapper::ShowOpenFileDialog(); + PRINT_IF_ERROR(comparison_rom.LoadFromFile(file_name)); + show_compare_rom = true; + } + + static uint64_t convert_address = 0; + gui::InputHex("SNES to PC", (int *)&convert_address, 6, 200.f); + SameLine(); + Text("%x", core::SnesToPc(convert_address)); + + // mem_edit.DrawWindow("Memory Editor", (void*)&(*rom()), rom()->size()); + BEGIN_TABLE("Memory Comparison", 2, ImGuiTableFlags_Resizable); + SETUP_COLUMN("Source") + SETUP_COLUMN("Dest") + + NEXT_COLUMN() + Text("%s", rom()->filename().data()); + mem_edit.DrawContents((void *)&(*rom()), rom()->size()); + + NEXT_COLUMN() + if (show_compare_rom) { + comp_edit.SetComparisonData((void *)&(*rom())); + ImGui::BeginGroup(); + ImGui::BeginChild("Comparison ROM"); + Text("%s", comparison_rom.filename().data()); + comp_edit.DrawContents((void *)&(comparison_rom), comparison_rom.size()); + ImGui::EndChild(); + ImGui::EndGroup(); + } + END_TABLE() + + ImGui::End(); + } +}; + +} // namespace editor +} // namespace app +} // namespace yaze + +#endif // YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H \ No newline at end of file diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index dda9fbce..3c6ff136 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -618,44 +618,7 @@ void MasterEditor::DrawViewMenu() { } if (show_memory_editor) { - static MemoryEditor mem_edit; - static MemoryEditor comp_edit; - static bool show_compare_rom = false; - static Rom comparison_rom; - ImGui::Begin("Hex Editor", &show_memory_editor); - if (ImGui::Button("Compare Rom")) { - auto file_name = FileDialogWrapper::ShowOpenFileDialog(); - PRINT_IF_ERROR(comparison_rom.LoadFromFile(file_name)); - show_compare_rom = true; - } - - static uint64_t convert_address = 0; - gui::InputHex("SNES to PC", (int*)&convert_address, 6, 200.f); - SameLine(); - Text("%x", core::SnesToPc(convert_address)); - - // mem_edit.DrawWindow("Memory Editor", (void*)&(*rom()), rom()->size()); - BEGIN_TABLE("Memory Comparison", 2, ImGuiTableFlags_Resizable); - SETUP_COLUMN("Source") - SETUP_COLUMN("Dest") - - NEXT_COLUMN() - Text("%s", rom()->filename().data()); - mem_edit.DrawContents((void*)&(*rom()), rom()->size()); - - NEXT_COLUMN() - if (show_compare_rom) { - comp_edit.SetComparisonData((void*)&(*rom())); - ImGui::BeginGroup(); - ImGui::BeginChild("Comparison ROM"); - Text("%s", comparison_rom.filename().data()); - comp_edit.DrawContents((void*)&(comparison_rom), comparison_rom.size()); - ImGui::EndChild(); - ImGui::EndGroup(); - } - END_TABLE() - - ImGui::End(); + memory_editor_.Update(show_memory_editor); } if (show_imgui_demo) { @@ -675,7 +638,7 @@ void MasterEditor::DrawViewMenu() { if (BeginMenu("View")) { MenuItem("Emulator", nullptr, &show_emulator); Separator(); - MenuItem("Hex Editor", nullptr, &show_memory_editor); + MenuItem("Memory Editor", nullptr, &show_memory_editor); MenuItem("Assembly Editor", nullptr, &show_asm_editor); MenuItem("Palette Editor", nullptr, &show_palette_editor); Separator(); diff --git a/src/app/editor/master_editor.h b/src/app/editor/master_editor.h index e7669d9d..ecc2ee4e 100644 --- a/src/app/editor/master_editor.h +++ b/src/app/editor/master_editor.h @@ -14,6 +14,7 @@ #include "app/core/constants.h" #include "app/core/project.h" #include "app/editor/code/assembly_editor.h" +#include "app/editor/code/memory_editor.h" #include "app/editor/context/gfx_context.h" #include "app/editor/dungeon_editor.h" #include "app/editor/graphics/graphics_editor.h" @@ -118,6 +119,7 @@ class MasterEditor : public SharedRom, PaletteEditor palette_editor_; ScreenEditor screen_editor_; SpriteEditor sprite_editor_; + MemoryEditorWithDiffChecker memory_editor_; ImVector active_tabs_; std::vector active_editors_;