yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
palette_editor_widget.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_WIDGETS_PALETTE_EDITOR_WIDGET_H
2#define YAZE_APP_GUI_WIDGETS_PALETTE_EDITOR_WIDGET_H
3
4#include <functional>
5#include <map>
6#include <optional>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "app/gfx/core/bitmap.h"
12#include "imgui/imgui.h"
13#include "rom/rom.h"
14#include "zelda3/game_data.h"
15
16namespace yaze {
17namespace gui {
18
23
28
29// Keep the 16-slot CGRAM row readable when the widget is embedded in a narrow
30// inspector. Returned values are divisors of 16 so logical rows wrap cleanly.
31int ResolveDungeonRenderPaletteColumns(float available_width,
32 float min_swatch_size = 14.0f,
33 float item_spacing = 2.0f);
34
36 public:
38
39 void Initialize(zelda3::GameData* game_data);
40 void Initialize(Rom* rom); // Legacy, deprecated
41
42 // Embedded drawing function, like the old PaletteEditorWidget
43 void Draw();
44
45 // Modal dialogs from the more feature-rich PaletteWidget
47 const std::string& title = "Palette Editor");
49 void ShowColorAnalysis(const gfx::Bitmap& bitmap,
50 const std::string& title = "Color Analysis");
51
52 bool ApplyROMPalette(gfx::Bitmap* bitmap, int group_index, int palette_index);
54 void SavePaletteBackup(const gfx::SnesPalette& palette);
56
57 // Original palette-id-only callback retained for source compatibility.
58 void SetOnPaletteChanged(std::function<void(int)> callback) {
59 if (!callback) {
61 return;
62 }
63 on_palette_changed_ = [callback](DungeonPaletteChange change) {
64 callback(change.palette_id);
65 };
66 }
67
68 // Typed callback for dungeon rendering consumers that must distinguish
69 // shared HUD edits from palette-scoped dungeon-main edits.
71 std::function<void(DungeonPaletteChange)> callback) {
72 on_palette_changed_ = callback;
73 }
74
75 // Get/Set current editing palette
78 void SetDungeonRenderPaletteMode(bool enabled) {
80 }
81
82 // Apply one editable CGRAM slot from the dungeon render palette. Passing a
83 // color records the edit through PaletteManager; std::nullopt resets the
84 // slot to PaletteManager's original ROM snapshot. The palette-change
85 // callback is fired only after a successful managed edit.
86 absl::Status ApplyDungeonRenderColorEdit(int display_index,
87 std::optional<gfx::SnesColor> color);
88
89 bool IsROMLoaded() const { return rom_ != nullptr; }
92
93 private:
94 void DrawPaletteGrid(gfx::SnesPalette& palette, int cols = 15);
95 void DrawColorEditControls(gfx::SnesColor& color, int color_index);
96 void DrawPaletteAnalysis(const gfx::SnesPalette& palette);
97 void LoadROMPalettes();
98 float ComputeSwatchSize(int columns, float min_size, float max_size) const;
99
100 // For embedded view
101 void DrawPaletteSelector();
102 void DrawColorPicker();
105
107 Rom* rom_ = nullptr; // Legacy, deprecated
108 std::vector<gfx::SnesPalette> rom_palette_groups_;
109 std::vector<std::string> palette_group_names_;
111
113 int current_palette_index_ = 0; // used by ROM palette selector
116 bool show_rom_manager_ = false;
117
118 // State for embedded editor
121 ImVec4 editing_color_{0, 0, 0, 1};
122
123 // Callback for palette changes
125
126 // Color editing state
128 ImVec4 temp_color_ = ImVec4(0, 0, 0, 1);
130};
131
132} // namespace gui
133} // namespace yaze
134
135#endif // YAZE_APP_GUI_WIDGETS_PALETTE_EDITOR_WIDGET_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:69
SNES Color container.
Definition snes_color.h:110
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
std::vector< gfx::SnesPalette > rom_palette_groups_
bool RestorePaletteBackup(gfx::SnesPalette &palette)
void ShowPaletteEditor(gfx::SnesPalette &palette, const std::string &title="Palette Editor")
void SetOnDungeonPaletteChanged(std::function< void(DungeonPaletteChange)> callback)
bool ApplyROMPalette(gfx::Bitmap *bitmap, int group_index, int palette_index)
const gfx::SnesPalette * GetSelectedROMPalette() const
void SetDungeonRenderPaletteMode(bool enabled)
void SavePaletteBackup(const gfx::SnesPalette &palette)
std::function< void(DungeonPaletteChange)> on_palette_changed_
void ShowColorAnalysis(const gfx::Bitmap &bitmap, const std::string &title="Color Analysis")
void Initialize(zelda3::GameData *game_data)
absl::Status ApplyDungeonRenderColorEdit(int display_index, std::optional< gfx::SnesColor > color)
void DrawColorEditControls(gfx::SnesColor &color, int color_index)
void DrawPaletteAnalysis(const gfx::SnesPalette &palette)
void SetOnPaletteChanged(std::function< void(int)> callback)
float ComputeSwatchSize(int columns, float min_size, float max_size) const
std::vector< std::string > palette_group_names_
void DrawPaletteGrid(gfx::SnesPalette &palette, int cols=15)
int ResolveDungeonRenderPaletteColumns(float available_width, float min_swatch_size, float item_spacing)
DungeonRenderPaletteSource source