Centralized palette management system. More...
#include <palette_manager.h>

Public Types | |
| using | ChangeCallback = std::function<void(const PaletteChangeEvent&)> |
Public Member Functions | |
| PaletteManager (const PaletteManager &)=delete | |
| PaletteManager & | operator= (const PaletteManager &)=delete |
| PaletteManager (PaletteManager &&)=delete | |
| PaletteManager & | operator= (PaletteManager &&)=delete |
| void | Initialize (zelda3::GameData *game_data) |
| Initialize the palette manager with GameData. | |
| void | Initialize (Rom *rom) |
| Legacy initialization with ROM (deprecated, use GameData version) | |
| bool | IsInitialized () const |
| Check if manager is initialized. | |
| SnesColor | GetColor (const std::string &group_name, int palette_index, int color_index) const |
| Get a color from a palette. | |
| absl::Status | SetColor (const std::string &group_name, int palette_index, int color_index, const SnesColor &new_color) |
| Set a color in a palette (records change for undo) | |
| absl::Status | ResetColor (const std::string &group_name, int palette_index, int color_index) |
| Reset a single color to its original ROM value. | |
| absl::Status | ResetPalette (const std::string &group_name, int palette_index) |
| Reset an entire palette to original ROM values. | |
| bool | HasUnsavedChanges () const |
| Check if there are ANY unsaved changes. | |
| std::vector< std::string > | GetModifiedGroups () const |
| Get list of modified palette group names. | |
| bool | IsGroupModified (const std::string &group_name) const |
| Check if a specific palette group has modifications. | |
| bool | IsPaletteModified (const std::string &group_name, int palette_index) const |
| Check if a specific palette is modified. | |
| bool | IsColorModified (const std::string &group_name, int palette_index, int color_index) const |
| Check if a specific color is modified. | |
| size_t | GetModifiedColorCount () const |
| Get count of modified colors across all groups. | |
| absl::Status | SaveGroup (const std::string &group_name) |
| Save a specific palette group to ROM. | |
| absl::Status | SaveAllToRom () |
| Save ALL modified palettes to ROM. | |
| void | DiscardGroup (const std::string &group_name) |
| Discard changes for a specific group. | |
| void | DiscardAllChanges () |
| Discard ALL unsaved changes. | |
| absl::Status | ApplyPreviewChanges () |
| Apply preview changes to other editors without saving to ROM. | |
| void | Undo () |
| Undo the most recent change. | |
| void | Redo () |
| Redo the most recently undone change. | |
| bool | CanUndo () const |
| Check if undo is available. | |
| bool | CanRedo () const |
| Check if redo is available. | |
| size_t | GetUndoStackSize () const |
| Get size of undo stack. | |
| size_t | GetRedoStackSize () const |
| Get size of redo stack. | |
| void | ClearHistory () |
| Clear undo/redo history. | |
| int | RegisterChangeListener (ChangeCallback callback) |
| Register a callback for palette change events. | |
| void | UnregisterChangeListener (int callback_id) |
| Unregister a change listener. | |
| void | BeginBatch () |
| Begin a batch operation (groups multiple changes into one undo step) | |
| void | EndBatch () |
| End a batch operation. | |
| bool | InBatch () const |
| Check if currently in a batch operation. | |
Static Public Member Functions | |
| static PaletteManager & | Get () |
| Get the singleton instance. | |
Private Member Functions | |
| PaletteManager ()=default | |
| ~PaletteManager ()=default | |
| PaletteGroup * | GetMutableGroup (const std::string &group_name) |
| Helper: Get mutable palette group. | |
| const PaletteGroup * | GetGroup (const std::string &group_name) const |
| Helper: Get const palette group. | |
| SnesColor | GetOriginalColor (const std::string &group_name, int palette_index, int color_index) const |
| Helper: Get original color from snapshot. | |
| void | RecordChange (const PaletteColorChange &change) |
| Helper: Record a change for undo. | |
| void | NotifyListeners (const PaletteChangeEvent &event) |
| Helper: Notify all listeners of an event. | |
| void | MarkModified (const std::string &group_name, int palette_index, int color_index) |
| Helper: Mark a color as modified. | |
| void | ClearModifiedFlags (const std::string &group_name) |
| Helper: Clear modified flags for a group. | |
Private Attributes | |
| zelda3::GameData * | game_data_ = nullptr |
| GameData instance (not owned) - preferred. | |
| Rom * | rom_ = nullptr |
| ROM instance (not owned) - legacy, used when game_data_ is null. | |
| std::unordered_map< std::string, std::vector< SnesPalette > > | original_palettes_ |
| std::unordered_map< std::string, std::unordered_set< int > > | modified_palettes_ |
| std::unordered_map< std::string, std::unordered_map< int, std::unordered_set< int > > > | modified_colors_ |
| std::deque< PaletteColorChange > | undo_stack_ |
| Undo/redo stacks. | |
| std::deque< PaletteColorChange > | redo_stack_ |
| std::unordered_map< int, ChangeCallback > | change_listeners_ |
| Change listeners. | |
| int | next_callback_id_ = 1 |
| int | batch_depth_ = 0 |
| Batch operation support. | |
| std::vector< PaletteColorChange > | batch_changes_ |
Static Private Attributes | |
| static constexpr size_t | kMaxUndoHistory = 500 |
Centralized palette management system.
Singleton coordinator for ALL palette editing operations. Provides:
Thread-safety: This class is NOT thread-safe. All operations must be called from the main UI thread.
Definition at line 74 of file palette_manager.h.
| using yaze::gfx::PaletteManager::ChangeCallback = std::function<void(const PaletteChangeEvent&)> |
Definition at line 76 of file palette_manager.h.
|
delete |
|
delete |
|
privatedefault |
|
privatedefault |
|
inlinestatic |
Get the singleton instance.
Definition at line 79 of file palette_manager.h.
Referenced by yaze::editor::PaletteGroupPanel::CanRedo(), yaze::editor::PaletteGroupPanel::CanUndo(), yaze::editor::PaletteGroupPanel::ClearHistory(), yaze::editor::PaletteGroupPanel::DiscardChanges(), yaze::editor::PaletteEditor::DrawCategorizedPaletteList(), yaze::editor::PaletteEditor::DrawControlPanel(), yaze::editor::PaletteGroupPanel::DrawToolbar(), yaze::editor::PaletteGroupPanel::GetOriginalColor(), yaze::editor::PaletteGroupPanel::HasUnsavedChanges(), yaze::editor::PaletteGroupPanel::IsColorModified(), yaze::editor::PaletteGroupPanel::IsPaletteModified(), yaze::editor::DungeonEditorV2::Load(), yaze::editor::PaletteEditor::Load(), yaze::editor::PaletteGroupPanel::Redo(), yaze::editor::PaletteEditor::Redo(), yaze::editor::PaletteGroupPanel::ResetColor(), yaze::editor::PaletteGroupPanel::ResetPalette(), yaze::editor::DungeonEditorV2::Save(), yaze::editor::PaletteEditor::Save(), yaze::editor::PaletteGroupPanel::SaveToRom(), yaze::editor::PaletteGroupPanel::SetColor(), yaze::editor::PaletteGroupPanel::Undo(), and yaze::editor::PaletteEditor::Undo().
|
delete |
|
delete |
| void yaze::gfx::PaletteManager::Initialize | ( | zelda3::GameData * | game_data | ) |
Initialize the palette manager with GameData.
| game_data | Pointer to GameData instance (must outlive PaletteManager) |
Definition at line 15 of file palette_manager.cc.
References yaze::gfx::PaletteGroup::clear(), ClearHistory(), game_data_, yaze::gfx::PaletteGroupMap::get_group(), modified_colors_, modified_palettes_, original_palettes_, yaze::zelda3::GameData::palette_groups, and rom_.
Referenced by yaze::editor::DungeonEditorV2::Load(), and yaze::editor::PaletteEditor::Load().

| void yaze::gfx::PaletteManager::Initialize | ( | Rom * | rom | ) |
Legacy initialization with ROM (deprecated, use GameData version)
| rom | Pointer to ROM instance (must outlive PaletteManager) |
Definition at line 55 of file palette_manager.cc.
References ClearHistory(), game_data_, modified_colors_, modified_palettes_, and rom_.

|
inline |
Check if manager is initialized.
Definition at line 107 of file palette_manager.h.
References game_data_, and rom_.
Referenced by ApplyPreviewChanges(), DiscardAllChanges(), DiscardGroup(), GetGroup(), GetMutableGroup(), ResetPalette(), SaveAllToRom(), SaveGroup(), and SetColor().
| SnesColor yaze::gfx::PaletteManager::GetColor | ( | const std::string & | group_name, |
| int | palette_index, | ||
| int | color_index ) const |
Get a color from a palette.
| group_name | Palette group name |
| palette_index | Palette index within group |
| color_index | Color index within palette |
Definition at line 72 of file palette_manager.cc.
References GetGroup().
Referenced by yaze::editor::PaletteGroupPanel::GetOriginalColor().

| absl::Status yaze::gfx::PaletteManager::SetColor | ( | const std::string & | group_name, |
| int | palette_index, | ||
| int | color_index, | ||
| const SnesColor & | new_color ) |
Set a color in a palette (records change for undo)
| group_name | Palette group name |
| palette_index | Palette index within group |
| color_index | Color index within palette |
| new_color | The new color value |
Definition at line 87 of file palette_manager.cc.
References batch_changes_, GetMutableGroup(), InBatch(), IsInitialized(), yaze::gfx::PaletteChangeEvent::kColorChanged, MarkModified(), NotifyListeners(), and RecordChange().
Referenced by ResetColor(), and yaze::editor::PaletteGroupPanel::SetColor().
| absl::Status yaze::gfx::PaletteManager::ResetColor | ( | const std::string & | group_name, |
| int | palette_index, | ||
| int | color_index ) |
Reset a single color to its original ROM value.
Definition at line 150 of file palette_manager.cc.
References GetOriginalColor(), and SetColor().
Referenced by yaze::editor::PaletteGroupPanel::ResetColor().

| absl::Status yaze::gfx::PaletteManager::ResetPalette | ( | const std::string & | group_name, |
| int | palette_index ) |
Reset an entire palette to original ROM values.
Definition at line 156 of file palette_manager.cc.
References GetMutableGroup(), IsInitialized(), yaze::gfx::PaletteChangeEvent::kPaletteReset, modified_colors_, modified_palettes_, NotifyListeners(), and original_palettes_.
Referenced by yaze::editor::PaletteGroupPanel::ResetPalette().

| bool yaze::gfx::PaletteManager::HasUnsavedChanges | ( | ) | const |
Check if there are ANY unsaved changes.
Definition at line 190 of file palette_manager.cc.
References modified_palettes_.
Referenced by yaze::editor::PaletteEditor::DrawControlPanel().
| std::vector< std::string > yaze::gfx::PaletteManager::GetModifiedGroups | ( | ) | const |
Get list of modified palette group names.
Definition at line 194 of file palette_manager.cc.
References modified_palettes_.
Referenced by ApplyPreviewChanges(), DiscardAllChanges(), and SaveAllToRom().
| bool yaze::gfx::PaletteManager::IsGroupModified | ( | const std::string & | group_name | ) | const |
Check if a specific palette group has modifications.
Definition at line 202 of file palette_manager.cc.
References modified_palettes_.
Referenced by yaze::editor::PaletteGroupPanel::DrawToolbar(), and yaze::editor::PaletteGroupPanel::HasUnsavedChanges().
| bool yaze::gfx::PaletteManager::IsPaletteModified | ( | const std::string & | group_name, |
| int | palette_index ) const |
Check if a specific palette is modified.
Definition at line 207 of file palette_manager.cc.
References modified_palettes_.
Referenced by yaze::editor::PaletteGroupPanel::IsPaletteModified().
| bool yaze::gfx::PaletteManager::IsColorModified | ( | const std::string & | group_name, |
| int | palette_index, | ||
| int | color_index ) const |
Check if a specific color is modified.
Definition at line 216 of file palette_manager.cc.
References modified_colors_.
Referenced by yaze::editor::PaletteGroupPanel::IsColorModified().
| size_t yaze::gfx::PaletteManager::GetModifiedColorCount | ( | ) | const |
Get count of modified colors across all groups.
Definition at line 231 of file palette_manager.cc.
References modified_colors_.
Referenced by yaze::editor::PaletteEditor::DrawControlPanel().
| absl::Status yaze::gfx::PaletteManager::SaveGroup | ( | const std::string & | group_name | ) |
Save a specific palette group to ROM.
Definition at line 243 of file palette_manager.cc.
References ClearModifiedFlags(), yaze::gfx::Arena::Get(), GetMutableGroup(), yaze::gfx::GetPaletteAddress(), IsInitialized(), yaze::gfx::PaletteChangeEvent::kGroupSaved, modified_colors_, modified_palettes_, NotifyListeners(), yaze::gfx::Arena::NotifyPaletteModified(), original_palettes_, rom_, yaze::Rom::set_dirty(), and yaze::Rom::WriteShort().
Referenced by SaveAllToRom(), and yaze::editor::PaletteGroupPanel::SaveToRom().
| absl::Status yaze::gfx::PaletteManager::SaveAllToRom | ( | ) |
Save ALL modified palettes to ROM.
Definition at line 302 of file palette_manager.cc.
References GetModifiedGroups(), IsInitialized(), yaze::gfx::PaletteChangeEvent::kAllSaved, NotifyListeners(), RETURN_IF_ERROR, and SaveGroup().
Referenced by yaze::editor::PaletteEditor::DrawControlPanel(), and yaze::editor::DungeonEditorV2::Save().

| void yaze::gfx::PaletteManager::DiscardGroup | ( | const std::string & | group_name | ) |
Discard changes for a specific group.
Definition at line 343 of file palette_manager.cc.
References ClearModifiedFlags(), GetMutableGroup(), IsInitialized(), yaze::gfx::PaletteChangeEvent::kGroupDiscarded, modified_palettes_, NotifyListeners(), and original_palettes_.
Referenced by DiscardAllChanges(), and yaze::editor::PaletteGroupPanel::DiscardChanges().

| void yaze::gfx::PaletteManager::DiscardAllChanges | ( | ) |
Discard ALL unsaved changes.
Definition at line 378 of file palette_manager.cc.
References ClearHistory(), DiscardGroup(), GetModifiedGroups(), IsInitialized(), yaze::gfx::PaletteChangeEvent::kAllDiscarded, and NotifyListeners().
Referenced by yaze::editor::PaletteEditor::DrawControlPanel().
| absl::Status yaze::gfx::PaletteManager::ApplyPreviewChanges | ( | ) |
Apply preview changes to other editors without saving to ROM.
This triggers bitmap propagation notification so other editors can refresh their visuals with the modified palettes. Use this for "live preview" functionality before committing to ROM.
Definition at line 319 of file palette_manager.cc.
References yaze::gfx::Arena::Get(), GetModifiedGroups(), IsInitialized(), yaze::gfx::PaletteChangeEvent::kAllSaved, NotifyListeners(), and yaze::gfx::Arena::NotifyPaletteModified().
Referenced by yaze::editor::PaletteEditor::DrawControlPanel().
| void yaze::gfx::PaletteManager::Undo | ( | ) |
Undo the most recent change.
Definition at line 398 of file palette_manager.cc.
References CanUndo(), GetMutableGroup(), yaze::gfx::PaletteChangeEvent::group_name, yaze::gfx::PaletteChangeEvent::kColorChanged, NotifyListeners(), redo_stack_, and undo_stack_.
Referenced by yaze::editor::PaletteGroupPanel::Undo(), and yaze::editor::PaletteEditor::Undo().

| void yaze::gfx::PaletteManager::Redo | ( | ) |
Redo the most recently undone change.
Definition at line 425 of file palette_manager.cc.
References CanRedo(), GetMutableGroup(), yaze::gfx::PaletteChangeEvent::group_name, yaze::gfx::PaletteChangeEvent::kColorChanged, NotifyListeners(), redo_stack_, and undo_stack_.
Referenced by yaze::editor::PaletteGroupPanel::Redo(), and yaze::editor::PaletteEditor::Redo().

|
inline |
Check if undo is available.
Definition at line 225 of file palette_manager.h.
References undo_stack_.
Referenced by yaze::editor::PaletteGroupPanel::CanUndo(), and Undo().
|
inline |
Check if redo is available.
Definition at line 230 of file palette_manager.h.
References redo_stack_.
Referenced by yaze::editor::PaletteGroupPanel::CanRedo(), and Redo().
|
inline |
|
inline |
| void yaze::gfx::PaletteManager::ClearHistory | ( | ) |
Clear undo/redo history.
Definition at line 452 of file palette_manager.cc.
References redo_stack_, and undo_stack_.
Referenced by yaze::editor::PaletteGroupPanel::ClearHistory(), DiscardAllChanges(), Initialize(), and Initialize().
| int yaze::gfx::PaletteManager::RegisterChangeListener | ( | ChangeCallback | callback | ) |
Register a callback for palette change events.
Definition at line 459 of file palette_manager.cc.
References change_listeners_, and next_callback_id_.
| void yaze::gfx::PaletteManager::UnregisterChangeListener | ( | int | callback_id | ) |
Unregister a change listener.
Definition at line 465 of file palette_manager.cc.
References change_listeners_.
| void yaze::gfx::PaletteManager::BeginBatch | ( | ) |
Begin a batch operation (groups multiple changes into one undo step)
Definition at line 471 of file palette_manager.cc.
References batch_changes_, and batch_depth_.
| void yaze::gfx::PaletteManager::EndBatch | ( | ) |
End a batch operation.
Definition at line 478 of file palette_manager.cc.
References batch_changes_, batch_depth_, yaze::gfx::PaletteChangeEvent::group_name, yaze::gfx::PaletteChangeEvent::kColorChanged, NotifyListeners(), and RecordChange().

|
inline |
Check if currently in a batch operation.
Definition at line 276 of file palette_manager.h.
References batch_depth_.
Referenced by SetColor().
|
private |
Helper: Get mutable palette group.
Definition at line 503 of file palette_manager.cc.
References game_data_, yaze::gfx::PaletteGroupMap::get_group(), IsInitialized(), and yaze::zelda3::GameData::palette_groups.
Referenced by DiscardGroup(), Redo(), ResetPalette(), SaveGroup(), SetColor(), and Undo().

|
private |
Helper: Get const palette group.
Definition at line 517 of file palette_manager.cc.
References game_data_, IsInitialized(), and yaze::zelda3::GameData::palette_groups.
Referenced by GetColor().

|
private |
Helper: Get original color from snapshot.
Definition at line 533 of file palette_manager.cc.
References original_palettes_.
Referenced by ResetColor().
|
private |
Helper: Record a change for undo.
Definition at line 549 of file palette_manager.cc.
References kMaxUndoHistory, redo_stack_, and undo_stack_.
Referenced by EndBatch(), and SetColor().
|
private |
Helper: Notify all listeners of an event.
Definition at line 561 of file palette_manager.cc.
References change_listeners_.
Referenced by ApplyPreviewChanges(), DiscardAllChanges(), DiscardGroup(), EndBatch(), Redo(), ResetPalette(), SaveAllToRom(), SaveGroup(), SetColor(), and Undo().
|
private |
Helper: Mark a color as modified.
Definition at line 567 of file palette_manager.cc.
References modified_colors_, and modified_palettes_.
Referenced by SetColor().
|
private |
Helper: Clear modified flags for a group.
Definition at line 573 of file palette_manager.cc.
References modified_colors_, and modified_palettes_.
Referenced by DiscardGroup(), and SaveGroup().
|
private |
GameData instance (not owned) - preferred.
Definition at line 308 of file palette_manager.h.
Referenced by GetGroup(), GetMutableGroup(), Initialize(), Initialize(), and IsInitialized().
|
private |
ROM instance (not owned) - legacy, used when game_data_ is null.
Definition at line 311 of file palette_manager.h.
Referenced by Initialize(), Initialize(), IsInitialized(), and SaveGroup().
|
private |
Original palette snapshots (loaded from ROM for reset/comparison) Key: group_name, Value: vector of original palettes
Definition at line 315 of file palette_manager.h.
Referenced by DiscardGroup(), GetOriginalColor(), Initialize(), ResetPalette(), and SaveGroup().
|
private |
Modified tracking Key: group_name, Value: set of modified palette indices
Definition at line 319 of file palette_manager.h.
Referenced by ClearModifiedFlags(), DiscardGroup(), GetModifiedGroups(), HasUnsavedChanges(), Initialize(), Initialize(), IsGroupModified(), IsPaletteModified(), MarkModified(), ResetPalette(), and SaveGroup().
|
private |
Detailed color modification tracking Key: group_name, Value: map of palette_index -> set of color indices
Definition at line 325 of file palette_manager.h.
Referenced by ClearModifiedFlags(), GetModifiedColorCount(), Initialize(), Initialize(), IsColorModified(), MarkModified(), ResetPalette(), and SaveGroup().
|
private |
Undo/redo stacks.
Definition at line 328 of file palette_manager.h.
Referenced by CanUndo(), ClearHistory(), GetUndoStackSize(), RecordChange(), Redo(), and Undo().
|
private |
Definition at line 329 of file palette_manager.h.
Referenced by CanRedo(), ClearHistory(), GetRedoStackSize(), RecordChange(), Redo(), and Undo().
|
staticconstexprprivate |
Definition at line 330 of file palette_manager.h.
Referenced by RecordChange().
|
private |
Change listeners.
Definition at line 333 of file palette_manager.h.
Referenced by NotifyListeners(), RegisterChangeListener(), and UnregisterChangeListener().
|
private |
Definition at line 334 of file palette_manager.h.
Referenced by RegisterChangeListener().
|
private |
Batch operation support.
Definition at line 337 of file palette_manager.h.
Referenced by BeginBatch(), EndBatch(), and InBatch().
|
private |
Definition at line 338 of file palette_manager.h.
Referenced by BeginBatch(), EndBatch(), and SetColor().