feat(editor): add entity operations for overworld editing
- Introduced new `entity_operations.cc` and `entity_operations.h` files to handle the insertion of entrances, exits, sprites, and items in the overworld editor. - Updated `map_properties.cc` to include a context menu for entity insertion, allowing users to add various entities directly from the canvas. - Enhanced `overworld_editor.cc` to manage entity insertion callbacks and streamline the editing process. Benefits: - Improves the functionality of the overworld editor by enabling direct manipulation of entities. - Provides a more intuitive user experience with context-sensitive menus for entity operations.
This commit is contained in:
@@ -163,44 +163,35 @@ void Canvas::Cleanup() {
|
||||
|
||||
void Canvas::InitializeEnhancedComponents() {
|
||||
// Initialize modals system
|
||||
modals_ = std::make_unique<canvas::CanvasModals>();
|
||||
modals_ = std::make_unique<CanvasModals>();
|
||||
|
||||
// Initialize context menu system
|
||||
context_menu_ = std::make_unique<canvas::CanvasContextMenu>();
|
||||
context_menu_ = std::make_unique<CanvasContextMenu>();
|
||||
context_menu_->Initialize(canvas_id_);
|
||||
|
||||
// Initialize usage tracker
|
||||
usage_tracker_ = std::make_shared<canvas::CanvasUsageTracker>();
|
||||
usage_tracker_->Initialize(canvas_id_);
|
||||
canvas::CanvasUsageManager::Get().RegisterTracker(canvas_id_, usage_tracker_);
|
||||
// Initialize usage tracker (optional, controlled by config.enable_metrics)
|
||||
if (config_.enable_metrics) {
|
||||
usage_tracker_ = std::make_shared<CanvasUsageTracker>();
|
||||
usage_tracker_->Initialize(canvas_id_);
|
||||
usage_tracker_->StartSession();
|
||||
|
||||
// Initialize performance integration
|
||||
performance_integration_ =
|
||||
std::make_shared<canvas::CanvasPerformanceIntegration>();
|
||||
performance_integration_->Initialize(canvas_id_);
|
||||
performance_integration_->SetUsageTracker(usage_tracker_);
|
||||
canvas::CanvasPerformanceManager::Get().RegisterIntegration(
|
||||
canvas_id_, performance_integration_);
|
||||
|
||||
// Start performance monitoring
|
||||
performance_integration_->StartMonitoring();
|
||||
usage_tracker_->StartSession();
|
||||
// Initialize performance integration
|
||||
performance_integration_ =
|
||||
std::make_shared<CanvasPerformanceIntegration>();
|
||||
performance_integration_->Initialize(canvas_id_);
|
||||
performance_integration_->SetUsageTracker(usage_tracker_);
|
||||
performance_integration_->StartMonitoring();
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::SetUsageMode(canvas::CanvasUsage usage) {
|
||||
void Canvas::SetUsageMode(CanvasUsage usage) {
|
||||
if (usage_tracker_) {
|
||||
usage_tracker_->SetUsageMode(usage);
|
||||
}
|
||||
if (context_menu_) {
|
||||
context_menu_->SetUsageMode(usage);
|
||||
}
|
||||
}
|
||||
|
||||
canvas::CanvasUsage Canvas::GetUsageMode() const {
|
||||
if (usage_tracker_) {
|
||||
return usage_tracker_->GetCurrentStats().usage_mode;
|
||||
}
|
||||
return canvas::CanvasUsage::kUnknown;
|
||||
config_.usage_mode = usage;
|
||||
}
|
||||
|
||||
void Canvas::RecordCanvasOperation(const std::string& operation_name,
|
||||
@@ -210,7 +201,7 @@ void Canvas::RecordCanvasOperation(const std::string& operation_name,
|
||||
}
|
||||
if (performance_integration_) {
|
||||
performance_integration_->RecordOperation(operation_name, time_ms,
|
||||
GetUsageMode());
|
||||
usage_mode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +446,7 @@ void Canvas::DrawContextMenu() {
|
||||
|
||||
// Use enhanced context menu if available
|
||||
if (context_menu_) {
|
||||
canvas::CanvasConfig snapshot;
|
||||
CanvasConfig snapshot;
|
||||
snapshot.canvas_size = canvas_sz_;
|
||||
snapshot.content_size = config_.content_size;
|
||||
snapshot.global_scale = global_scale_;
|
||||
@@ -476,78 +467,78 @@ void Canvas::DrawContextMenu() {
|
||||
context_menu_->Render(
|
||||
context_id_, mouse_pos, rom_, bitmap_,
|
||||
bitmap_ ? bitmap_->mutable_palette() : nullptr,
|
||||
[this](canvas::CanvasContextMenu::Command command,
|
||||
const canvas::CanvasConfig& updated_config) {
|
||||
[this](CanvasContextMenu::Command command,
|
||||
const CanvasConfig& updated_config) {
|
||||
switch (command) {
|
||||
case canvas::CanvasContextMenu::Command::kResetView:
|
||||
case CanvasContextMenu::Command::kResetView:
|
||||
ResetView();
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kZoomToFit:
|
||||
case CanvasContextMenu::Command::kZoomToFit:
|
||||
if (bitmap_) {
|
||||
SetZoomToFit(*bitmap_);
|
||||
}
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kZoomIn:
|
||||
case CanvasContextMenu::Command::kZoomIn:
|
||||
SetGlobalScale(config_.global_scale * 1.25f);
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kZoomOut:
|
||||
case CanvasContextMenu::Command::kZoomOut:
|
||||
SetGlobalScale(config_.global_scale * 0.8f);
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kToggleGrid:
|
||||
case CanvasContextMenu::Command::kToggleGrid:
|
||||
config_.enable_grid = !config_.enable_grid;
|
||||
enable_grid_ = config_.enable_grid;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kToggleHexLabels:
|
||||
case CanvasContextMenu::Command::kToggleHexLabels:
|
||||
config_.enable_hex_labels = !config_.enable_hex_labels;
|
||||
enable_hex_tile_labels_ = config_.enable_hex_labels;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kToggleCustomLabels:
|
||||
case CanvasContextMenu::Command::kToggleCustomLabels:
|
||||
config_.enable_custom_labels = !config_.enable_custom_labels;
|
||||
enable_custom_labels_ = config_.enable_custom_labels;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kToggleContextMenu:
|
||||
case CanvasContextMenu::Command::kToggleContextMenu:
|
||||
config_.enable_context_menu = !config_.enable_context_menu;
|
||||
enable_context_menu_ = config_.enable_context_menu;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kToggleAutoResize:
|
||||
case CanvasContextMenu::Command::kToggleAutoResize:
|
||||
config_.auto_resize = !config_.auto_resize;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kToggleDraggable:
|
||||
case CanvasContextMenu::Command::kToggleDraggable:
|
||||
config_.is_draggable = !config_.is_draggable;
|
||||
draggable_ = config_.is_draggable;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kSetGridStep:
|
||||
case CanvasContextMenu::Command::kSetGridStep:
|
||||
config_.grid_step = updated_config.grid_step;
|
||||
custom_step_ = config_.grid_step;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kSetScale:
|
||||
case CanvasContextMenu::Command::kSetScale:
|
||||
config_.global_scale = updated_config.global_scale;
|
||||
global_scale_ = config_.global_scale;
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kOpenAdvancedProperties:
|
||||
case CanvasContextMenu::Command::kOpenAdvancedProperties:
|
||||
if (modals_) {
|
||||
canvas::CanvasConfig modal_config = updated_config;
|
||||
CanvasConfig modal_config = updated_config;
|
||||
modal_config.on_config_changed =
|
||||
[this](const canvas::CanvasConfig& cfg) {
|
||||
[this](const CanvasConfig& cfg) {
|
||||
ApplyConfigSnapshot(cfg);
|
||||
};
|
||||
modal_config.on_scale_changed =
|
||||
[this](const canvas::CanvasConfig& cfg) {
|
||||
[this](const CanvasConfig& cfg) {
|
||||
ApplyScaleSnapshot(cfg);
|
||||
};
|
||||
modals_->ShowAdvancedProperties(canvas_id_, modal_config,
|
||||
bitmap_);
|
||||
}
|
||||
break;
|
||||
case canvas::CanvasContextMenu::Command::kOpenScalingControls:
|
||||
case CanvasContextMenu::Command::kOpenScalingControls:
|
||||
if (modals_) {
|
||||
canvas::CanvasConfig modal_config = updated_config;
|
||||
CanvasConfig modal_config = updated_config;
|
||||
modal_config.on_config_changed =
|
||||
[this](const canvas::CanvasConfig& cfg) {
|
||||
[this](const CanvasConfig& cfg) {
|
||||
ApplyConfigSnapshot(cfg);
|
||||
};
|
||||
modal_config.on_scale_changed =
|
||||
[this](const canvas::CanvasConfig& cfg) {
|
||||
[this](const CanvasConfig& cfg) {
|
||||
ApplyScaleSnapshot(cfg);
|
||||
};
|
||||
modals_->ShowScalingControls(canvas_id_, modal_config, bitmap_);
|
||||
@@ -695,7 +686,7 @@ void Canvas::ResetView() {
|
||||
scrolling_ = ImVec2(0, 0);
|
||||
}
|
||||
|
||||
void Canvas::ApplyConfigSnapshot(const canvas::CanvasConfig& snapshot) {
|
||||
void Canvas::ApplyConfigSnapshot(const CanvasConfig& snapshot) {
|
||||
config_.enable_grid = snapshot.enable_grid;
|
||||
config_.enable_hex_labels = snapshot.enable_hex_labels;
|
||||
config_.enable_custom_labels = snapshot.enable_custom_labels;
|
||||
@@ -719,7 +710,7 @@ void Canvas::ApplyConfigSnapshot(const canvas::CanvasConfig& snapshot) {
|
||||
scrolling_ = snapshot.scrolling;
|
||||
}
|
||||
|
||||
void Canvas::ApplyScaleSnapshot(const canvas::CanvasConfig& snapshot) {
|
||||
void Canvas::ApplyScaleSnapshot(const CanvasConfig& snapshot) {
|
||||
config_.global_scale = snapshot.global_scale;
|
||||
global_scale_ = config_.global_scale;
|
||||
scrolling_ = snapshot.scrolling;
|
||||
@@ -1586,7 +1577,7 @@ void TableCanvasPipeline(gui::Canvas& canvas, gfx::Bitmap& bitmap,
|
||||
void Canvas::ShowAdvancedCanvasProperties() {
|
||||
// Use the new modal system if available
|
||||
if (modals_) {
|
||||
canvas::CanvasConfig modal_config;
|
||||
CanvasConfig modal_config;
|
||||
modal_config.canvas_size = canvas_sz_;
|
||||
modal_config.content_size = config_.content_size;
|
||||
modal_config.global_scale = global_scale_;
|
||||
@@ -1599,14 +1590,14 @@ void Canvas::ShowAdvancedCanvasProperties() {
|
||||
modal_config.auto_resize = config_.auto_resize;
|
||||
modal_config.scrolling = scrolling_;
|
||||
modal_config.on_config_changed =
|
||||
[this](const canvas::CanvasConfig& updated_config) {
|
||||
[this](const CanvasConfig& updated_config) {
|
||||
// Update legacy variables when config changes
|
||||
enable_grid_ = updated_config.enable_grid;
|
||||
enable_hex_tile_labels_ = updated_config.enable_hex_labels;
|
||||
enable_custom_labels_ = updated_config.enable_custom_labels;
|
||||
};
|
||||
modal_config.on_scale_changed =
|
||||
[this](const canvas::CanvasConfig& updated_config) {
|
||||
[this](const CanvasConfig& updated_config) {
|
||||
global_scale_ = updated_config.global_scale;
|
||||
scrolling_ = updated_config.scrolling;
|
||||
};
|
||||
@@ -1709,7 +1700,7 @@ void Canvas::ShowAdvancedCanvasProperties() {
|
||||
void Canvas::ShowScalingControls() {
|
||||
// Use the new modal system if available
|
||||
if (modals_) {
|
||||
canvas::CanvasConfig modal_config;
|
||||
CanvasConfig modal_config;
|
||||
modal_config.canvas_size = canvas_sz_;
|
||||
modal_config.content_size = config_.content_size;
|
||||
modal_config.global_scale = global_scale_;
|
||||
@@ -1722,7 +1713,7 @@ void Canvas::ShowScalingControls() {
|
||||
modal_config.auto_resize = config_.auto_resize;
|
||||
modal_config.scrolling = scrolling_;
|
||||
modal_config.on_config_changed =
|
||||
[this](const canvas::CanvasConfig& updated_config) {
|
||||
[this](const CanvasConfig& updated_config) {
|
||||
// Update legacy variables when config changes
|
||||
enable_grid_ = updated_config.enable_grid;
|
||||
enable_hex_tile_labels_ = updated_config.enable_hex_labels;
|
||||
@@ -1730,7 +1721,7 @@ void Canvas::ShowScalingControls() {
|
||||
enable_context_menu_ = updated_config.enable_context_menu;
|
||||
};
|
||||
modal_config.on_scale_changed =
|
||||
[this](const canvas::CanvasConfig& updated_config) {
|
||||
[this](const CanvasConfig& updated_config) {
|
||||
draggable_ = updated_config.is_draggable;
|
||||
custom_step_ = updated_config.grid_step;
|
||||
global_scale_ = updated_config.global_scale;
|
||||
|
||||
@@ -187,11 +187,11 @@ class Canvas {
|
||||
std::unique_ptr<gui::BppComparisonTool> bpp_comparison_tool_;
|
||||
|
||||
// Enhanced canvas components
|
||||
std::unique_ptr<canvas::CanvasModals> modals_;
|
||||
std::unique_ptr<canvas::CanvasContextMenu> context_menu_;
|
||||
std::shared_ptr<canvas::CanvasUsageTracker> usage_tracker_;
|
||||
std::shared_ptr<canvas::CanvasPerformanceIntegration> performance_integration_;
|
||||
canvas::CanvasInteractionHandler interaction_handler_;
|
||||
std::unique_ptr<CanvasModals> modals_;
|
||||
std::unique_ptr<CanvasContextMenu> context_menu_;
|
||||
std::shared_ptr<CanvasUsageTracker> usage_tracker_;
|
||||
std::shared_ptr<CanvasPerformanceIntegration> performance_integration_;
|
||||
CanvasInteractionHandler interaction_handler_;
|
||||
|
||||
void AddContextMenuItem(const ContextMenuItem& item);
|
||||
void ClearContextMenuItems();
|
||||
@@ -207,8 +207,8 @@ class Canvas {
|
||||
void ShowScalingControls();
|
||||
void SetZoomToFit(const gfx::Bitmap& bitmap);
|
||||
void ResetView();
|
||||
void ApplyConfigSnapshot(const canvas::CanvasConfig& snapshot);
|
||||
void ApplyScaleSnapshot(const canvas::CanvasConfig& snapshot);
|
||||
void ApplyConfigSnapshot(const CanvasConfig& snapshot);
|
||||
void ApplyScaleSnapshot(const CanvasConfig& snapshot);
|
||||
|
||||
// Modular component access
|
||||
CanvasConfig& GetConfig() { return config_; }
|
||||
@@ -231,15 +231,16 @@ class Canvas {
|
||||
|
||||
// Enhanced canvas management
|
||||
void InitializeEnhancedComponents();
|
||||
void SetUsageMode(canvas::CanvasUsage usage);
|
||||
canvas::CanvasUsage GetUsageMode() const;
|
||||
void SetUsageMode(CanvasUsage usage);
|
||||
auto usage_mode() const { return config_.usage_mode; }
|
||||
|
||||
void RecordCanvasOperation(const std::string& operation_name, double time_ms);
|
||||
void ShowPerformanceUI();
|
||||
void ShowUsageReport();
|
||||
|
||||
// Interaction handler access
|
||||
canvas::CanvasInteractionHandler& GetInteractionHandler() { return interaction_handler_; }
|
||||
const canvas::CanvasInteractionHandler& GetInteractionHandler() const { return interaction_handler_; }
|
||||
CanvasInteractionHandler& GetInteractionHandler() { return interaction_handler_; }
|
||||
const CanvasInteractionHandler& GetInteractionHandler() const { return interaction_handler_; }
|
||||
|
||||
// Automation API access (Phase 4A)
|
||||
CanvasAutomationAPI* GetAutomationAPI();
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
namespace {
|
||||
inline void Dispatch(
|
||||
@@ -506,6 +505,7 @@ std::string CanvasContextMenu::GetUsageModeName(CanvasUsage usage) const {
|
||||
case CanvasUsage::kPaletteEditing: return "Palette Editing";
|
||||
case CanvasUsage::kBppConversion: return "BPP Conversion";
|
||||
case CanvasUsage::kPerformanceMode: return "Performance Mode";
|
||||
case CanvasUsage::kEntityManipulation: return "Entity Manipulation";
|
||||
case CanvasUsage::kUnknown: return "Unknown";
|
||||
default: return "Unknown";
|
||||
}
|
||||
@@ -521,6 +521,7 @@ ImVec4 CanvasContextMenu::GetUsageModeColor(CanvasUsage usage) const {
|
||||
case CanvasUsage::kPaletteEditing: return ImVec4(0.8F, 0.2F, 1.0F, 1.0F); // Purple
|
||||
case CanvasUsage::kBppConversion: return ImVec4(0.2F, 1.0F, 1.0F, 1.0F); // Cyan
|
||||
case CanvasUsage::kPerformanceMode: return ImVec4(1.0F, 0.2F, 0.2F, 1.0F); // Red
|
||||
case CanvasUsage::kEntityManipulation: return ImVec4(0.4F, 0.8F, 1.0F, 1.0F); // Light Blue
|
||||
case CanvasUsage::kUnknown: return ImVec4(0.7F, 0.7F, 0.7F, 1.0F); // Gray
|
||||
default: return ImVec4(0.7F, 0.7F, 0.7F, 1.0F); // Gray
|
||||
}
|
||||
@@ -578,36 +579,35 @@ void CanvasContextMenu::CreateDefaultMenuItems() {
|
||||
usage_specific_items_[CanvasUsage::kPerformanceMode].push_back(perf_item);
|
||||
}
|
||||
|
||||
canvas::CanvasContextMenu::ContextMenuItem canvas::CanvasContextMenu::CreateViewMenuItem(const std::string& label,
|
||||
CanvasContextMenu::ContextMenuItem CanvasContextMenu::CreateViewMenuItem(const std::string& label,
|
||||
const std::string& icon,
|
||||
std::function<void()> callback) {
|
||||
return ContextMenuItem(label, icon, callback);
|
||||
}
|
||||
|
||||
canvas::CanvasContextMenu::ContextMenuItem canvas::CanvasContextMenu::CreateBitmapMenuItem(const std::string& label,
|
||||
CanvasContextMenu::ContextMenuItem CanvasContextMenu::CreateBitmapMenuItem(const std::string& label,
|
||||
const std::string& icon,
|
||||
std::function<void()> callback) {
|
||||
return ContextMenuItem(label, icon, callback);
|
||||
}
|
||||
|
||||
canvas::CanvasContextMenu::ContextMenuItem canvas::CanvasContextMenu::CreatePaletteMenuItem(const std::string& label,
|
||||
CanvasContextMenu::ContextMenuItem CanvasContextMenu::CreatePaletteMenuItem(const std::string& label,
|
||||
const std::string& icon,
|
||||
std::function<void()> callback) {
|
||||
return ContextMenuItem(label, icon, callback);
|
||||
}
|
||||
|
||||
canvas::CanvasContextMenu::ContextMenuItem canvas::CanvasContextMenu::CreateBppMenuItem(const std::string& label,
|
||||
CanvasContextMenu::ContextMenuItem CanvasContextMenu::CreateBppMenuItem(const std::string& label,
|
||||
const std::string& icon,
|
||||
std::function<void()> callback) {
|
||||
return ContextMenuItem(label, icon, callback);
|
||||
}
|
||||
|
||||
canvas::CanvasContextMenu::ContextMenuItem canvas::CanvasContextMenu::CreatePerformanceMenuItem(const std::string& label,
|
||||
CanvasContextMenu::ContextMenuItem CanvasContextMenu::CreatePerformanceMenuItem(const std::string& label,
|
||||
const std::string& icon,
|
||||
std::function<void()> callback) {
|
||||
return ContextMenuItem(label, icon, callback);
|
||||
}
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
@@ -19,8 +19,6 @@ namespace gui {
|
||||
// Forward declarations
|
||||
class PaletteEditorWidget;
|
||||
|
||||
namespace canvas {
|
||||
|
||||
class CanvasContextMenu {
|
||||
public:
|
||||
enum class Command {
|
||||
@@ -71,7 +69,7 @@ class CanvasContextMenu {
|
||||
Rom* rom,
|
||||
const gfx::Bitmap* bitmap,
|
||||
const gfx::SnesPalette* palette,
|
||||
const std::function<void(Command, const canvas::CanvasConfig&)>& command_handler,
|
||||
const std::function<void(Command, const CanvasConfig&)>& command_handler,
|
||||
CanvasConfig current_config);
|
||||
|
||||
bool ShouldShowContextMenu() const;
|
||||
@@ -159,7 +157,6 @@ class CanvasContextMenu {
|
||||
std::function<void()> callback);
|
||||
};
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -364,6 +363,5 @@ bool CanvasInteractionHandler::IsMouseReleased(ImGuiMouseButton button) {
|
||||
return ImGui::IsMouseReleased(button);
|
||||
}
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
/**
|
||||
* @brief Tile interaction mode for canvas
|
||||
@@ -201,7 +200,6 @@ class CanvasInteractionHandler {
|
||||
bool IsMouseReleased(ImGuiMouseButton button);
|
||||
};
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -13,21 +13,17 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
// Helper functions for dispatching config callbacks
|
||||
namespace {
|
||||
void DispatchConfigCallback(const std::function<void(const CanvasConfig&)>& callback,
|
||||
const CanvasConfig& config) {
|
||||
if (callback) {
|
||||
callback(config);
|
||||
}
|
||||
inline void DispatchConfig(const std::function<void(const CanvasConfig&)>& callback,
|
||||
const CanvasConfig& config) {
|
||||
if (callback) callback(config);
|
||||
}
|
||||
|
||||
void DispatchScaleCallback(const std::function<void(const CanvasConfig&)>& callback,
|
||||
const CanvasConfig& config) {
|
||||
if (callback) {
|
||||
callback(config);
|
||||
}
|
||||
inline void DispatchScale(const std::function<void(const CanvasConfig&)>& callback,
|
||||
const CanvasConfig& config) {
|
||||
if (callback) callback(config);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -214,7 +210,7 @@ void CanvasModals::RenderAdvancedPropertiesModal(const std::string& canvas_id,
|
||||
if (i > 0) ImGui::SameLine();
|
||||
if (ImGui::Button(preset_labels[i])) {
|
||||
config.global_scale = preset_values[i];
|
||||
DispatchConfigCallback(config.on_config_changed, config);
|
||||
DispatchConfig(config.on_config_changed, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,14 +221,14 @@ void CanvasModals::RenderAdvancedPropertiesModal(const std::string& canvas_id,
|
||||
|
||||
if (ImGui::Button("Reset Scroll")) {
|
||||
config.scrolling = ImVec2(0, 0);
|
||||
DispatchConfigCallback(config.on_config_changed, config);
|
||||
DispatchConfig(config.on_config_changed, config);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Center View") && bitmap) {
|
||||
config.scrolling = ImVec2(-(bitmap->width() * config.global_scale - config.canvas_size.x) / 2.0f,
|
||||
-(bitmap->height() * config.global_scale - config.canvas_size.y) / 2.0f);
|
||||
DispatchConfigCallback(config.on_config_changed, config);
|
||||
DispatchConfig(config.on_config_changed, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +258,7 @@ void CanvasModals::RenderAdvancedPropertiesModal(const std::string& canvas_id,
|
||||
ImGui::Spacing();
|
||||
|
||||
if (ImGui::Button("Apply Changes", ImVec2(120, 0))) {
|
||||
DispatchConfigCallback(config.on_config_changed, config);
|
||||
DispatchConfig(config.on_config_changed, config);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
@@ -282,7 +278,7 @@ void CanvasModals::RenderAdvancedPropertiesModal(const std::string& canvas_id,
|
||||
config.is_draggable = false;
|
||||
config.auto_resize = false;
|
||||
config.scrolling = ImVec2(0, 0);
|
||||
DispatchConfigCallback(config.on_config_changed, config);
|
||||
DispatchConfig(config.on_config_changed, config);
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
@@ -316,7 +312,7 @@ void CanvasModals::RenderScalingControlsModal(const std::string& canvas_id,
|
||||
if (i > 0) ImGui::SameLine();
|
||||
if (ImGui::Button(preset_labels[i])) {
|
||||
config.global_scale = preset_values[i];
|
||||
DispatchScaleCallback(config.on_scale_changed, config);
|
||||
DispatchScale(config.on_scale_changed, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +331,7 @@ void CanvasModals::RenderScalingControlsModal(const std::string& canvas_id,
|
||||
if (i > 0) ImGui::SameLine();
|
||||
if (ImGui::Button(grid_labels[i])) {
|
||||
config.grid_step = grid_values[i];
|
||||
DispatchScaleCallback(config.on_scale_changed, config);
|
||||
DispatchScale(config.on_scale_changed, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +356,7 @@ void CanvasModals::RenderScalingControlsModal(const std::string& canvas_id,
|
||||
ImGui::Spacing();
|
||||
|
||||
if (ImGui::Button("Apply", ImVec2(120, 0))) {
|
||||
DispatchScaleCallback(config.on_scale_changed, config);
|
||||
DispatchScale(config.on_scale_changed, config);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
@@ -586,6 +582,5 @@ void CanvasModals::RenderSliderWithIcon(const std::string& label, const std::str
|
||||
ImGui::SliderFloat(("##" + label).c_str(), value, min_val, max_val, format);
|
||||
}
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
@@ -12,33 +12,9 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
void DispatchConfigCallback(const std::function<void(const CanvasConfig&)>& callback,
|
||||
const CanvasConfig& config);
|
||||
void DispatchScaleCallback(const std::function<void(const CanvasConfig&)>& callback,
|
||||
const CanvasConfig& config);
|
||||
|
||||
/**
|
||||
* @brief Canvas configuration options for modals
|
||||
*/
|
||||
struct CanvasConfig {
|
||||
ImVec2 canvas_size = ImVec2(0, 0);
|
||||
ImVec2 content_size = ImVec2(0, 0);
|
||||
float global_scale = 1.0f;
|
||||
float grid_step = 32.0f;
|
||||
bool enable_grid = true;
|
||||
bool enable_hex_labels = false;
|
||||
bool enable_custom_labels = false;
|
||||
bool enable_context_menu = true;
|
||||
bool is_draggable = false;
|
||||
bool auto_resize = false;
|
||||
ImVec2 scrolling = ImVec2(0, 0);
|
||||
|
||||
// Callbacks provide updated configuration state
|
||||
std::function<void(const CanvasConfig&)> on_config_changed;
|
||||
std::function<void(const CanvasConfig&)> on_scale_changed;
|
||||
};
|
||||
// Note: DispatchConfigCallback and DispatchScaleCallback are internal helpers
|
||||
// defined in canvas_modals.cc (not part of public API)
|
||||
|
||||
/**
|
||||
* @brief BPP conversion options
|
||||
@@ -175,7 +151,6 @@ class CanvasModals {
|
||||
const char* format = "%.2f");
|
||||
};
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
void CanvasPerformanceIntegration::Initialize(const std::string& canvas_id) {
|
||||
canvas_id_ = canvas_id;
|
||||
@@ -607,6 +606,5 @@ void CanvasPerformanceManager::ClearAllIntegrations() {
|
||||
LOG_DEBUG("CanvasPerformance", "Cleared all canvas performance integrations");
|
||||
}
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
/**
|
||||
* @brief Canvas performance metrics
|
||||
@@ -262,7 +261,6 @@ class CanvasPerformanceManager {
|
||||
std::unordered_map<std::string, std::shared_ptr<CanvasPerformanceIntegration>> integrations_;
|
||||
};
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
void CanvasUsageTracker::Initialize(const std::string& canvas_id) {
|
||||
canvas_id_ = canvas_id;
|
||||
@@ -127,6 +126,7 @@ std::string CanvasUsageTracker::GetUsageModeName(CanvasUsage usage) const {
|
||||
case CanvasUsage::kPaletteEditing: return "Palette Editing";
|
||||
case CanvasUsage::kBppConversion: return "BPP Conversion";
|
||||
case CanvasUsage::kPerformanceMode: return "Performance Mode";
|
||||
case CanvasUsage::kEntityManipulation: return "Entity Manipulation";
|
||||
case CanvasUsage::kUnknown: return "Unknown";
|
||||
default: return "Unknown";
|
||||
}
|
||||
@@ -142,6 +142,7 @@ ImVec4 CanvasUsageTracker::GetUsageModeColor(CanvasUsage usage) const {
|
||||
case CanvasUsage::kPaletteEditing: return ImVec4(0.8F, 0.2F, 1.0F, 1.0F); // Purple
|
||||
case CanvasUsage::kBppConversion: return ImVec4(0.2F, 1.0F, 1.0F, 1.0F); // Cyan
|
||||
case CanvasUsage::kPerformanceMode: return ImVec4(1.0F, 0.2F, 0.2F, 1.0F); // Red
|
||||
case CanvasUsage::kEntityManipulation: return ImVec4(0.4F, 0.8F, 1.0F, 1.0F); // Light Blue
|
||||
case CanvasUsage::kUnknown: return ImVec4(0.7F, 0.7F, 0.7F, 1.0F); // Gray
|
||||
default: return ImVec4(0.7F, 0.7F, 0.7F, 1.0F); // Gray
|
||||
}
|
||||
@@ -424,6 +425,5 @@ void CanvasUsageManager::ClearAllTrackers() {
|
||||
LOG_DEBUG("CanvasUsage", "Cleared all canvas usage trackers");
|
||||
}
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
namespace canvas {
|
||||
|
||||
/**
|
||||
* @brief Canvas usage patterns and tracking
|
||||
@@ -24,6 +23,7 @@ enum class CanvasUsage {
|
||||
kPaletteEditing, // Palette editing mode
|
||||
kBppConversion, // BPP format conversion
|
||||
kPerformanceMode, // Performance monitoring mode
|
||||
kEntityManipulation, // Generic entity manipulation (insertion/editing/deletion)
|
||||
kUnknown // Unknown or mixed usage
|
||||
};
|
||||
|
||||
@@ -242,7 +242,6 @@ class CanvasUsageManager {
|
||||
std::unordered_map<std::string, std::shared_ptr<CanvasUsageTracker>> trackers_;
|
||||
};
|
||||
|
||||
} // namespace canvas
|
||||
} // namespace gui
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -6,15 +6,20 @@
|
||||
#include "app/gfx/resource/arena.h"
|
||||
#include "app/gfx/types/snes_palette.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/gui/canvas/canvas_usage_tracker.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gui {
|
||||
|
||||
/**
|
||||
* @brief Configuration for canvas display and interaction
|
||||
* @brief Unified configuration for canvas display and interaction
|
||||
*
|
||||
* Consolidates all canvas configuration into a single struct, including
|
||||
* display settings, interaction state, and optional callbacks for updates.
|
||||
*/
|
||||
struct CanvasConfig {
|
||||
// Display settings
|
||||
bool enable_grid = true;
|
||||
bool enable_hex_labels = false;
|
||||
bool enable_custom_labels = false;
|
||||
@@ -23,11 +28,22 @@ struct CanvasConfig {
|
||||
bool auto_resize = false;
|
||||
bool clamp_rect_to_local_maps = true; // Prevent rectangle wrap across 512x512 boundaries
|
||||
bool use_theme_sizing = true; // Use theme-aware sizing instead of fixed sizes
|
||||
bool enable_metrics = false; // Enable performance/usage tracking
|
||||
|
||||
// Sizing and scale
|
||||
float grid_step = 32.0f;
|
||||
float global_scale = 1.0f;
|
||||
ImVec2 canvas_size = ImVec2(0, 0);
|
||||
ImVec2 content_size = ImVec2(0, 0); // Size of actual content (bitmap, etc.)
|
||||
ImVec2 scrolling = ImVec2(0, 0);
|
||||
bool custom_canvas_size = false;
|
||||
|
||||
// Usage tracking
|
||||
CanvasUsage usage_mode = CanvasUsage::kUnknown;
|
||||
|
||||
// Callbacks for configuration changes (used by modals)
|
||||
std::function<void(const CanvasConfig&)> on_config_changed;
|
||||
std::function<void(const CanvasConfig&)> on_scale_changed;
|
||||
|
||||
// Get theme-aware canvas toolbar height (when use_theme_sizing is true)
|
||||
float GetToolbarHeight() const;
|
||||
|
||||
Reference in New Issue
Block a user