Enhance EditorManager: add assembly and palette editors to the view menu, and improve menu initialization for better readability

This commit is contained in:
scawful
2025-02-28 00:48:12 -05:00
parent 4dc09ad5fc
commit a28ad9c516
4 changed files with 77 additions and 54 deletions

View File

@@ -53,11 +53,11 @@ void EditorManager::Initialize(std::string filename) {
if (!filename.empty()) { if (!filename.empty()) {
PRINT_IF_ERROR(rom()->LoadFromFile(filename)); PRINT_IF_ERROR(rom()->LoadFromFile(filename));
} }
gui::kMainMenu.emplace_back("File"); gui::kMainMenu[gui::MenuType::kFile].name = "File";
gui::kMainMenu.emplace_back("Edit"); gui::kMainMenu[gui::MenuType::kEdit].name = "Edit";
gui::kMainMenu.emplace_back("View"); gui::kMainMenu[gui::MenuType::kView].name = "View";
gui::kMainMenu.emplace_back("Tools"); gui::kMainMenu[gui::MenuType::kTools].name = "Tools";
gui::kMainMenu.emplace_back("Help"); gui::kMainMenu[gui::MenuType::kHelp].name = "Help";
gui::AddToFileMenu(absl::StrCat(ICON_MD_FILE_OPEN, " Open"), "Ctrl+O", gui::AddToFileMenu(absl::StrCat(ICON_MD_FILE_OPEN, " Open"), "Ctrl+O",
[&]() { LoadRom(); }); [&]() { LoadRom(); });
@@ -110,6 +110,15 @@ void EditorManager::Initialize(std::string filename) {
[&]() { show_emulator_ = true; }); [&]() { show_emulator_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_MEMORY, " Memory Editor"), "", gui::AddToViewMenu(absl::StrCat(ICON_MD_MEMORY, " Memory Editor"), "",
[&]() { show_memory_editor_ = true; }); [&]() { show_memory_editor_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_CODE, " Assembly Editor"), "",
[&]() { show_asm_editor_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_PALETTE, " Palette Editor"), "",
[&]() { show_palette_editor_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_SIM_CARD, " ROM Metadata"), "",
[&]() { rom_info_ = true; });
gui::AddToHelpMenu(absl::StrCat(ICON_MD_HELP, " About"), "F1",
[&]() { about_ = true; });
overworld_editor_.Initialize(); overworld_editor_.Initialize();
} }

View File

@@ -83,6 +83,8 @@ class EditorManager : public SharedRom {
bool save_as_menu_ = false; bool save_as_menu_ = false;
bool show_emulator_ = false; bool show_emulator_ = false;
bool show_memory_editor_ = false; bool show_memory_editor_ = false;
bool show_asm_editor_ = false;
bool show_palette_editor_ = false;
bool show_status_ = false; bool show_status_ = false;
bool rom_assets_loaded_ = false; bool rom_assets_loaded_ = false;
@@ -92,7 +94,7 @@ class EditorManager : public SharedRom {
emu::Emulator emulator_; emu::Emulator emulator_;
std::vector<Editor *> active_editors_; std::vector<Editor *> active_editors_;
std::vector<std::unique_ptr<Rom>> roms_; std::vector<std::unique_ptr<Rom>> roms_;
Rom* current_rom_ = nullptr; Rom *current_rom_ = nullptr;
Project current_project_; Project current_project_;
EditorContext editor_context_; EditorContext editor_context_;

View File

@@ -77,7 +77,7 @@ struct MenuItem {
std::function<bool()> enabled_condition = kDefaultEnabledCondition; std::function<bool()> enabled_condition = kDefaultEnabledCondition;
std::vector<MenuItem> subitems; std::vector<MenuItem> subitems;
}; };
using Menu = std::vector<MenuItem>; using Menu = std::array<MenuItem, 5>;
void DrawMenu(Menu &params); void DrawMenu(Menu &params);
@@ -124,6 +124,11 @@ inline void AddToViewMenu(const std::string &label, const std::string &shortcut,
kMainMenu[MenuType::kView].subitems.emplace_back(label, shortcut, callback); kMainMenu[MenuType::kView].subitems.emplace_back(label, shortcut, callback);
} }
inline void AddToHelpMenu(const std::string &label, const std::string &shortcut,
std::function<void()> callback) {
kMainMenu[MenuType::kHelp].subitems.emplace_back(label, shortcut, callback);
}
} // namespace gui } // namespace gui
} // namespace yaze } // namespace yaze

View File

@@ -44,7 +44,7 @@ absl::Status ParseThemeContents(const std::string &key,
return absl::OkStatus(); return absl::OkStatus();
} }
} // namespace } // namespace
absl::StatusOr<Theme> LoadTheme(const std::string &filename) { absl::StatusOr<Theme> LoadTheme(const std::string &filename) {
std::string theme_contents; std::string theme_contents;
@@ -78,18 +78,27 @@ absl::Status SaveTheme(const Theme &theme) {
theme_stream << theme.name << "Theme\n"; theme_stream << theme.name << "Theme\n";
theme_stream << "MenuBarBg=#" << gui::ColorToHexString(theme.menu_bar_bg) theme_stream << "MenuBarBg=#" << gui::ColorToHexString(theme.menu_bar_bg)
<< "\n"; << "\n";
theme_stream << "TitleBg=#" << gui::ColorToHexString(theme.title_bar_bg) << "\n"; theme_stream << "TitleBg=#" << gui::ColorToHexString(theme.title_bar_bg)
<< "\n";
theme_stream << "Header=#" << gui::ColorToHexString(theme.header) << "\n"; theme_stream << "Header=#" << gui::ColorToHexString(theme.header) << "\n";
theme_stream << "HeaderHovered=#" << gui::ColorToHexString(theme.header_hovered) << "\n"; theme_stream << "HeaderHovered=#"
theme_stream << "HeaderActive=#" << gui::ColorToHexString(theme.header_active) << "\n"; << gui::ColorToHexString(theme.header_hovered) << "\n";
theme_stream << "TitleBgActive=#" << gui::ColorToHexString(theme.title_bg_active) << "\n"; theme_stream << "HeaderActive=#" << gui::ColorToHexString(theme.header_active)
theme_stream << "TitleBgCollapsed=#" << gui::ColorToHexString(theme.title_bg_collapsed) << "\n"; << "\n";
theme_stream << "TitleBgActive=#"
<< gui::ColorToHexString(theme.title_bg_active) << "\n";
theme_stream << "TitleBgCollapsed=#"
<< gui::ColorToHexString(theme.title_bg_collapsed) << "\n";
theme_stream << "Tab=#" << gui::ColorToHexString(theme.tab) << "\n"; theme_stream << "Tab=#" << gui::ColorToHexString(theme.tab) << "\n";
theme_stream << "TabHovered=#" << gui::ColorToHexString(theme.tab_hovered) << "\n"; theme_stream << "TabHovered=#" << gui::ColorToHexString(theme.tab_hovered)
theme_stream << "TabActive=#" << gui::ColorToHexString(theme.tab_active) << "\n"; << "\n";
theme_stream << "TabActive=#" << gui::ColorToHexString(theme.tab_active)
<< "\n";
theme_stream << "Button=#" << gui::ColorToHexString(theme.button) << "\n"; theme_stream << "Button=#" << gui::ColorToHexString(theme.button) << "\n";
theme_stream << "ButtonHovered=#" << gui::ColorToHexString(theme.button_hovered) << "\n"; theme_stream << "ButtonHovered=#"
theme_stream << "ButtonActive=#" << gui::ColorToHexString(theme.button_active) << "\n"; << gui::ColorToHexString(theme.button_hovered) << "\n";
theme_stream << "ButtonActive=#" << gui::ColorToHexString(theme.button_active)
<< "\n";
// Save the theme to a file. // Save the theme to a file.
@@ -103,16 +112,22 @@ void ApplyTheme(const Theme &theme) {
colors[ImGuiCol_MenuBarBg] = gui::ConvertColorToImVec4(theme.menu_bar_bg); colors[ImGuiCol_MenuBarBg] = gui::ConvertColorToImVec4(theme.menu_bar_bg);
colors[ImGuiCol_TitleBg] = gui::ConvertColorToImVec4(theme.title_bar_bg); colors[ImGuiCol_TitleBg] = gui::ConvertColorToImVec4(theme.title_bar_bg);
colors[ImGuiCol_Header] = gui::ConvertColorToImVec4(theme.header); colors[ImGuiCol_Header] = gui::ConvertColorToImVec4(theme.header);
colors[ImGuiCol_HeaderHovered] = gui::ConvertColorToImVec4(theme.header_hovered); colors[ImGuiCol_HeaderHovered] =
colors[ImGuiCol_HeaderActive] = gui::ConvertColorToImVec4(theme.header_active); gui::ConvertColorToImVec4(theme.header_hovered);
colors[ImGuiCol_TitleBgActive] = gui::ConvertColorToImVec4(theme.title_bg_active); colors[ImGuiCol_HeaderActive] =
colors[ImGuiCol_TitleBgCollapsed] = gui::ConvertColorToImVec4(theme.title_bg_collapsed); gui::ConvertColorToImVec4(theme.header_active);
colors[ImGuiCol_TitleBgActive] =
gui::ConvertColorToImVec4(theme.title_bg_active);
colors[ImGuiCol_TitleBgCollapsed] =
gui::ConvertColorToImVec4(theme.title_bg_collapsed);
colors[ImGuiCol_Tab] = gui::ConvertColorToImVec4(theme.tab); colors[ImGuiCol_Tab] = gui::ConvertColorToImVec4(theme.tab);
colors[ImGuiCol_TabHovered] = gui::ConvertColorToImVec4(theme.tab_hovered); colors[ImGuiCol_TabHovered] = gui::ConvertColorToImVec4(theme.tab_hovered);
colors[ImGuiCol_TabActive] = gui::ConvertColorToImVec4(theme.tab_active); colors[ImGuiCol_TabActive] = gui::ConvertColorToImVec4(theme.tab_active);
colors[ImGuiCol_Button] = gui::ConvertColorToImVec4(theme.button); colors[ImGuiCol_Button] = gui::ConvertColorToImVec4(theme.button);
colors[ImGuiCol_ButtonHovered] = gui::ConvertColorToImVec4(theme.button_hovered); colors[ImGuiCol_ButtonHovered] =
colors[ImGuiCol_ButtonActive] = gui::ConvertColorToImVec4(theme.button_active); gui::ConvertColorToImVec4(theme.button_hovered);
colors[ImGuiCol_ButtonActive] =
gui::ConvertColorToImVec4(theme.button_active);
} }
void ColorsYaze() { void ColorsYaze() {
@@ -203,7 +218,7 @@ void ColorsYaze() {
colors[ImGuiCol_TableHeaderBg] = alttpDarkGreen; colors[ImGuiCol_TableHeaderBg] = alttpDarkGreen;
colors[ImGuiCol_TableBorderStrong] = alttpMidGreen; colors[ImGuiCol_TableBorderStrong] = alttpMidGreen;
colors[ImGuiCol_TableBorderLight] = colors[ImGuiCol_TableBorderLight] =
ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f); colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
@@ -277,8 +292,7 @@ static const char *const kIdentifiers[] = {
TextEditor::LanguageDefinition GetAssemblyLanguageDef() { TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
TextEditor::LanguageDefinition language_65816; TextEditor::LanguageDefinition language_65816;
for (auto &k : kKeywords) for (auto &k : kKeywords) language_65816.mKeywords.emplace(k);
language_65816.mKeywords.emplace(k);
for (auto &k : kIdentifiers) { for (auto &k : kIdentifiers) {
TextEditor::Identifier id; TextEditor::Identifier id;
@@ -389,24 +403,21 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
// Default to using internal storage as reference // Default to using internal storage as reference
static bool init = true; static bool init = true;
if (init && ref == NULL) if (init && ref == NULL) ref_saved_style = style;
ref_saved_style = style;
init = false; init = false;
if (ref == NULL) if (ref == NULL) ref = &ref_saved_style;
ref = &ref_saved_style;
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f);
if (ImGui::ShowStyleSelector("Colors##Selector")) if (ImGui::ShowStyleSelector("Colors##Selector")) ref_saved_style = style;
ref_saved_style = style;
ImGui::ShowFontSelector("Fonts##Selector"); ImGui::ShowFontSelector("Fonts##Selector");
// Simplified Settings (expose floating-pointer border sizes as boolean // Simplified Settings (expose floating-pointer border sizes as boolean
// representing 0.0f or 1.0f) // representing 0.0f or 1.0f)
if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f,
"%.0f")) "%.0f"))
style.GrabRounding = style.FrameRounding; // Make GrabRounding always the style.GrabRounding = style.FrameRounding; // Make GrabRounding always the
// same value as FrameRounding // same value as FrameRounding
{ {
bool border = (style.WindowBorderSize > 0.0f); bool border = (style.WindowBorderSize > 0.0f);
if (ImGui::Checkbox("WindowBorder", &border)) { if (ImGui::Checkbox("WindowBorder", &border)) {
@@ -429,11 +440,9 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
} }
// Save/Revert button // Save/Revert button
if (ImGui::Button("Save Ref")) if (ImGui::Button("Save Ref")) *ref = ref_saved_style = style;
*ref = ref_saved_style = style;
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Revert Ref")) if (ImGui::Button("Revert Ref")) style = *ref;
style = *ref;
ImGui::SameLine(); ImGui::SameLine();
ImGui::Separator(); ImGui::Separator();
@@ -605,8 +614,7 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
ImGui::PushItemWidth(ImGui::GetFontSize() * -12); ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
for (int i = 0; i < ImGuiCol_COUNT; i++) { for (int i = 0; i < ImGuiCol_COUNT; i++) {
const char *name = ImGui::GetStyleColorName(i); const char *name = ImGui::GetStyleColorName(i);
if (!filter.PassFilter(name)) if (!filter.PassFilter(name)) continue;
continue;
ImGui::PushID(i); ImGui::PushID(i);
ImGui::ColorEdit4("##color", (float *)&style.Colors[i], ImGui::ColorEdit4("##color", (float *)&style.Colors[i],
ImGuiColorEditFlags_AlphaBar | alpha_flags); ImGuiColorEditFlags_AlphaBar | alpha_flags);
@@ -651,11 +659,11 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
if (ImGui::DragFloat( if (ImGui::DragFloat(
"window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE, "window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE,
"%.2f", "%.2f",
ImGuiSliderFlags_AlwaysClamp)) // Scale only this window ImGuiSliderFlags_AlwaysClamp)) // Scale only this window
ImGui::SetWindowFontScale(window_scale); ImGui::SetWindowFontScale(window_scale);
ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE, ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE,
MAX_SCALE, "%.2f", MAX_SCALE, "%.2f",
ImGuiSliderFlags_AlwaysClamp); // Scale everything ImGuiSliderFlags_AlwaysClamp); // Scale everything
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::EndTabItem(); ImGui::EndTabItem();
@@ -683,8 +691,7 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
&style.CircleTessellationMaxError, 0.005f, 0.10f, 5.0f, &style.CircleTessellationMaxError, 0.005f, 0.10f, 5.0f,
"%.2f", ImGuiSliderFlags_AlwaysClamp); "%.2f", ImGuiSliderFlags_AlwaysClamp);
const bool show_samples = ImGui::IsItemActive(); const bool show_samples = ImGui::IsItemActive();
if (show_samples) if (show_samples) ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
if (show_samples && ImGui::BeginTooltip()) { if (show_samples && ImGui::BeginTooltip()) {
ImGui::TextUnformatted("(R = radius, N = number of segments)"); ImGui::TextUnformatted("(R = radius, N = number of segments)");
ImGui::Spacing(); ImGui::Spacing();
@@ -725,10 +732,10 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
ImGui::SameLine(); ImGui::SameLine();
ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f,
"%.2f"); // Not exposing zero here so user doesn't "%.2f"); // Not exposing zero here so user doesn't
// "lose" the UI (zero alpha clips all // "lose" the UI (zero alpha clips all
// widgets). But application code could have a // widgets). But application code could have a
// toggle to switch between zero and non-zero. // toggle to switch between zero and non-zero.
ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f, ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f,
1.0f, "%.2f"); 1.0f, "%.2f");
ImGui::SameLine(); ImGui::SameLine();
@@ -751,16 +758,16 @@ void TextWithSeparators(const absl::string_view &text) {
} }
void DrawFontManager() { void DrawFontManager() {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
ImFontAtlas* atlas = io.Fonts; ImFontAtlas *atlas = io.Fonts;
static ImFont* current_font = atlas->Fonts[0]; static ImFont *current_font = atlas->Fonts[0];
static int current_font_index = 0; static int current_font_index = 0;
static int font_size = 16; static int font_size = 16;
static bool font_selected = false; static bool font_selected = false;
ImGui::Text("Loaded fonts"); ImGui::Text("Loaded fonts");
for (const auto& loaded_font : core::global_font_state.fonts) { for (const auto &loaded_font : core::font_registry.fonts) {
ImGui::Text("%s", loaded_font.font_path); ImGui::Text("%s", loaded_font.font_path);
} }
ImGui::Separator(); ImGui::Separator();
@@ -789,5 +796,5 @@ void DrawFontManager() {
} }
} }
} // namespace gui } // namespace gui
} // namespace yaze } // namespace yaze