feat: Introduce UI Helper Functions and Refactor Color Management
- Added ui_helpers.cc and ui_helpers.h to centralize UI-related helper functions, improving code organization and reducing boilerplate in ImGui usage. - Refactored color management in BppFormatUI to utilize new helper functions for success, warning, and error colors, enhancing theming consistency. - Updated AgentChatWidget and CanvasContextMenu to streamline UI rendering and improve maintainability by removing redundant code and enhancing functionality. - Removed canvas_utils_moved.cc and canvas_utils_moved.h to clean up the project structure, consolidating utility functions into more appropriate locations.
This commit is contained in:
@@ -405,7 +405,7 @@ void Canvas::DrawContextMenu() {
|
||||
enable_context_menu_, draggable_, config_.auto_resize, scrolling_);
|
||||
|
||||
context_menu_->Render(
|
||||
context_id_, mouse_pos, bitmap_,
|
||||
context_id_, mouse_pos, rom_, bitmap_,
|
||||
bitmap_ ? bitmap_->mutable_palette() : nullptr,
|
||||
[this](canvas::CanvasContextMenu::Command command,
|
||||
const canvas::CanvasConfig& updated_config) {
|
||||
@@ -497,187 +497,7 @@ void Canvas::DrawContextMenu() {
|
||||
return;
|
||||
}
|
||||
|
||||
static bool show_bitmap_data = false;
|
||||
if (show_bitmap_data && bitmap_ != nullptr) {
|
||||
static MemoryEditor mem_edit;
|
||||
mem_edit.DrawWindow("Bitmap Data", (void*)bitmap_->data(), bitmap_->size(),
|
||||
0);
|
||||
}
|
||||
|
||||
// Context menu (under default mouse threshold)
|
||||
if (ImVec2 drag_delta = GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
enable_context_menu_ && drag_delta.x == 0.0f && drag_delta.y == 0.0f)
|
||||
OpenPopupOnItemClick(context_id_.c_str(), ImGuiPopupFlags_MouseButtonRight);
|
||||
|
||||
// Contents of the Context Menu
|
||||
if (ImGui::BeginPopup(context_id_.c_str())) {
|
||||
// Draw custom context menu items first
|
||||
for (const auto& item : context_menu_items_) {
|
||||
DrawContextMenuItem(item);
|
||||
}
|
||||
|
||||
// Add separator if there are custom items
|
||||
if (!context_menu_items_.empty()) {
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
// Default canvas menu items
|
||||
if (MenuItem("Reset View", nullptr, false)) {
|
||||
ResetView();
|
||||
}
|
||||
if (MenuItem("Zoom to Fit", nullptr, false) && bitmap_) {
|
||||
SetZoomToFit(*bitmap_);
|
||||
}
|
||||
if (MenuItem("Advanced Properties", nullptr, false)) {
|
||||
ImGui::OpenPopup("Advanced Canvas Properties");
|
||||
}
|
||||
ImGui::Separator();
|
||||
MenuItem("Show Grid", nullptr, &enable_grid_);
|
||||
Selectable("Show Position Labels", &enable_hex_tile_labels_);
|
||||
if (MenuItem("Edit Palette", nullptr, false) && bitmap_) {
|
||||
ShowPaletteEditor();
|
||||
}
|
||||
if (MenuItem("Color Analysis", nullptr, false) && bitmap_) {
|
||||
ShowColorAnalysis();
|
||||
}
|
||||
if (MenuItem("Scaling Controls", nullptr, false)) {
|
||||
ImGui::OpenPopup("Scaling Controls");
|
||||
}
|
||||
if (BeginMenu("Canvas Properties")) {
|
||||
Text("Canvas Size: %.0f x %.0f", canvas_sz_.x, canvas_sz_.y);
|
||||
Text("Global Scale: %.1f", global_scale_);
|
||||
Text("Mouse Position: %.0f x %.0f", mouse_pos.x, mouse_pos.y);
|
||||
EndMenu();
|
||||
}
|
||||
if (bitmap_ != nullptr) {
|
||||
if (BeginMenu("Bitmap Properties")) {
|
||||
Text("Size: %.0f x %.0f", scaled_sz.x, scaled_sz.y);
|
||||
Text("Pitch: %d", bitmap_->surface()->pitch);
|
||||
Text("BitsPerPixel: %d", bitmap_->surface()->format->BitsPerPixel);
|
||||
Text("BytesPerPixel: %d", bitmap_->surface()->format->BytesPerPixel);
|
||||
MenuItem("Data", nullptr, &show_bitmap_data);
|
||||
if (BeginMenu("Format")) {
|
||||
if (MenuItem("Indexed")) {
|
||||
bitmap_->Reformat(gfx::BitmapFormat::kIndexed);
|
||||
Renderer::Get().UpdateBitmap(bitmap_);
|
||||
}
|
||||
if (MenuItem("4BPP")) {
|
||||
bitmap_->Reformat(gfx::BitmapFormat::k4bpp);
|
||||
Renderer::Get().UpdateBitmap(bitmap_);
|
||||
}
|
||||
if (MenuItem("8BPP")) {
|
||||
bitmap_->Reformat(gfx::BitmapFormat::k8bpp);
|
||||
Renderer::Get().UpdateBitmap(bitmap_);
|
||||
}
|
||||
|
||||
EndMenu();
|
||||
}
|
||||
if (BeginMenu("ROM Palette Selection") && rom_) {
|
||||
Text("Select ROM Palette Group:");
|
||||
|
||||
// Enhanced ROM palette group selection
|
||||
if (palette_editor_) {
|
||||
// Use our enhanced palette editor's ROM selection
|
||||
if (MenuItem("Open Enhanced Palette Manager")) {
|
||||
palette_editor_->ShowROMPaletteManager();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
// Quick palette group selection
|
||||
const char* palette_groups[] = {
|
||||
"Overworld Main", "Overworld Aux", "Overworld Animated",
|
||||
"Dungeon Main", "Global Sprites", "Armor",
|
||||
"Swords"};
|
||||
|
||||
if (ImGui::Combo("Quick Palette Group",
|
||||
(int*)&edit_palette_group_name_index_,
|
||||
palette_groups, IM_ARRAYSIZE(palette_groups))) {
|
||||
// Group selection changed
|
||||
}
|
||||
|
||||
ImGui::SetNextItemWidth(100.f);
|
||||
if (ImGui::SliderInt("Palette Index", (int*)&edit_palette_index_, 0,
|
||||
7)) {
|
||||
// Palette index changed
|
||||
}
|
||||
|
||||
// Apply button with enhanced functionality
|
||||
if (ImGui::Button("Apply to Canvas") && bitmap_) {
|
||||
if (palette_editor_->ApplyROMPalette(
|
||||
bitmap_, edit_palette_group_name_index_,
|
||||
edit_palette_index_)) {
|
||||
// LOG_INFO(
|
||||
// "Applied ROM palette group %d, index %d via context menu",
|
||||
// edit_palette_group_name_index_, edit_palette_index_);
|
||||
}
|
||||
}
|
||||
|
||||
// Direct palette editing with SelectablePalettePipeline
|
||||
if (ImGui::TreeNode("Interactive Palette Editor")) {
|
||||
if (rom_ && bitmap_) {
|
||||
ImGui::Text("Interactive ROM Palette Editing");
|
||||
ImGui::Text("Selected Group: %s",
|
||||
palette_groups[edit_palette_group_name_index_]);
|
||||
|
||||
// Get the enhanced palette editor's ROM palette if available
|
||||
if (const auto* rom_palette =
|
||||
palette_editor_->GetSelectedROMPalette()) {
|
||||
auto editable_palette =
|
||||
const_cast<gfx::SnesPalette&>(*rom_palette);
|
||||
|
||||
if (ImGui::BeginChild("SelectablePalette", ImVec2(0, 200),
|
||||
true)) {
|
||||
// Use the existing SelectablePalettePipeline for interactive editing
|
||||
gui::SelectablePalettePipeline(edit_palette_sub_index_,
|
||||
refresh_graphics_,
|
||||
editable_palette);
|
||||
|
||||
if (refresh_graphics_) {
|
||||
bitmap_->SetPaletteWithTransparent(
|
||||
editable_palette, edit_palette_sub_index_);
|
||||
Renderer::Get().UpdateBitmap(bitmap_);
|
||||
refresh_graphics_ = false;
|
||||
// LOG_INFO is undefined or missing required arguments; removed or fix as needed.
|
||||
}
|
||||
ImGui::Text(
|
||||
"Load ROM palettes first using Enhanced Palette "
|
||||
"Manager");
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
EndMenu();
|
||||
}
|
||||
if (BeginMenu("View Palette")) {
|
||||
(void)DisplayEditablePalette(*bitmap_->mutable_palette(), "Palette",
|
||||
true, 8);
|
||||
EndMenu();
|
||||
}
|
||||
EndMenu();
|
||||
}
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (BeginMenu("Grid Tile Size")) {
|
||||
if (MenuItem("8x8", nullptr, custom_step_ == 8.0f)) {
|
||||
custom_step_ = 8.0f;
|
||||
}
|
||||
if (MenuItem("16x16", nullptr, custom_step_ == 16.0f)) {
|
||||
custom_step_ = 16.0f;
|
||||
}
|
||||
if (MenuItem("32x32", nullptr, custom_step_ == 32.0f)) {
|
||||
custom_step_ = 32.0f;
|
||||
}
|
||||
if (MenuItem("64x64", nullptr, custom_step_ == 64.0f)) {
|
||||
custom_step_ = 64.0f;
|
||||
}
|
||||
EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Draw enhanced property dialogs
|
||||
ShowAdvancedCanvasProperties();
|
||||
|
||||
Reference in New Issue
Block a user