yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
palette_utility.cc
Go to the documentation of this file.
1#include "palette_utility.h"
2
3#include "absl/strings/str_format.h"
8#include "imgui/imgui.h"
9#include "rom/rom.h"
10
11namespace yaze {
12namespace editor {
13namespace palette_utility {
14
15bool DrawPaletteJumpButton(const char* label, const std::string& group_name,
16 int palette_index, PaletteEditor* editor) {
17 bool clicked = ImGui::SmallButton(
18 absl::StrFormat("%s %s", ICON_MD_PALETTE, label).c_str());
19
20 if (ImGui::IsItemHovered()) {
21 ImGui::SetTooltip("Jump to palette editor:\n%s - Palette %d",
22 group_name.c_str(), palette_index);
23 }
24
25 if (clicked && editor) {
26 editor->JumpToPalette(group_name, palette_index);
27 }
28
29 return clicked;
30}
31
32bool DrawInlineColorEdit(const char* label, gfx::SnesColor* color,
33 const std::string& group_name, int palette_index,
34 int color_index, PaletteEditor* editor) {
35 ImGui::PushID(label);
36
37 // Draw color button
38 ImVec4 col = gui::ConvertSnesColorToImVec4(*color);
39 bool changed = ImGui::ColorEdit4(
40 label, &col.x,
41 ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
42
43 if (changed) {
45 }
46
47 // Draw jump button
48 ImGui::SameLine();
49 {
50 gui::StyleColorGuard btn_guard(ImGuiCol_Button,
51 ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
52 if (ImGui::SmallButton(ICON_MD_OPEN_IN_NEW)) {
53 if (editor) {
54 editor->JumpToPalette(group_name, palette_index);
55 }
56 }
57 }
58
59 if (ImGui::IsItemHovered()) {
60 ImGui::BeginTooltip();
61 ImGui::Text("Jump to Palette Editor");
62 ImGui::TextDisabled("%s - Palette %d, Color %d", group_name.c_str(),
63 palette_index, color_index);
65 ImGui::EndTooltip();
66 }
67
68 ImGui::PopID();
69 return changed;
70}
71
72bool DrawPaletteIdSelector(const char* label, int* palette_id,
73 const std::string& group_name,
74 PaletteEditor* editor) {
75 ImGui::PushID(label);
76
77 // Draw combo box
78 bool changed = ImGui::InputInt(label, palette_id);
79
80 // Clamp to valid range (0-255 typically)
81 if (*palette_id < 0)
82 *palette_id = 0;
83 if (*palette_id > 255)
84 *palette_id = 255;
85
86 // Draw jump button
87 ImGui::SameLine();
88 if (DrawPaletteJumpButton("Jump", group_name, *palette_id, editor)) {
89 // Button clicked, editor will handle jump
90 }
91
92 ImGui::PopID();
93 return changed;
94}
95
97 auto rgb = color.rgb();
98 ImGui::Separator();
99 ImGui::Text("RGB: (%d, %d, %d)", static_cast<int>(rgb.x),
100 static_cast<int>(rgb.y), static_cast<int>(rgb.z));
101 ImGui::Text("SNES: $%04X", color.snes());
102 ImGui::Text("Hex: #%02X%02X%02X", static_cast<int>(rgb.x),
103 static_cast<int>(rgb.y), static_cast<int>(rgb.z));
104}
105
106void DrawPalettePreview(const std::string& group_name, int palette_index,
107 zelda3::GameData* game_data) {
108 if (!game_data) {
109 ImGui::TextDisabled("(GameData not loaded)");
110 return;
111 }
112
113 auto* group = game_data->palette_groups.get_group(group_name);
114 if (!group || palette_index >= group->size()) {
115 ImGui::TextDisabled("(Palette not found)");
116 return;
117 }
118
119 auto palette = group->palette(palette_index);
120
121 // Draw colors in a row
122 int preview_size = std::min(8, static_cast<int>(palette.size()));
123 for (int i = 0; i < preview_size; i++) {
124 if (i > 0)
125 ImGui::SameLine();
126
127 ImGui::PushID(i);
128 ImVec4 col = gui::ConvertSnesColorToImVec4(palette[i]);
129 ImGui::ColorButton("##preview", col,
130 ImGuiColorEditFlags_NoAlpha |
131 ImGuiColorEditFlags_NoPicker |
132 ImGuiColorEditFlags_NoTooltip,
133 ImVec2(16, 16));
134
135 if (ImGui::IsItemHovered()) {
136 ImGui::BeginTooltip();
137 ImGui::Text("Color %d", i);
138 DrawColorInfoTooltip(palette[i]);
139 ImGui::EndTooltip();
140 }
141
142 ImGui::PopID();
143 }
144}
145
146} // namespace palette_utility
147} // namespace editor
148} // namespace yaze
Allows the user to view and edit in game palettes.
void JumpToPalette(const std::string &group_name, int palette_index)
Jump to a specific palette by group and index.
SNES Color container.
Definition snes_color.h:110
constexpr ImVec4 rgb() const
Get RGB values (WARNING: stored as 0-255 in ImVec4)
Definition snes_color.h:183
constexpr uint16_t snes() const
Get SNES 15-bit color.
Definition snes_color.h:193
RAII guard for ImGui style colors.
Definition style_guard.h:27
#define ICON_MD_PALETTE
Definition icons.h:1370
#define ICON_MD_OPEN_IN_NEW
Definition icons.h:1354
bool DrawPaletteJumpButton(const char *label, const std::string &group_name, int palette_index, PaletteEditor *editor)
Draw a palette selector button that opens palette editor.
bool DrawPaletteIdSelector(const char *label, int *palette_id, const std::string &group_name, PaletteEditor *editor)
Draw a compact palette ID selector with preview.
void DrawPalettePreview(const std::string &group_name, int palette_index, zelda3::GameData *game_data)
Draw a small palette preview (8 colors in a row)
bool DrawInlineColorEdit(const char *label, gfx::SnesColor *color, const std::string &group_name, int palette_index, int color_index, PaletteEditor *editor)
Draw inline color edit with jump to palette.
void DrawColorInfoTooltip(const gfx::SnesColor &color)
Draw color info tooltip on hover.
ImVec4 ConvertSnesColorToImVec4(const gfx::SnesColor &color)
Convert SnesColor to standard ImVec4 for display.
Definition color.cc:22
gfx::SnesColor ConvertImVec4ToSnesColor(const ImVec4 &color)
Convert standard ImVec4 to SnesColor.
Definition color.cc:35
PaletteGroup * get_group(const std::string &group_name)
gfx::PaletteGroupMap palette_groups
Definition game_data.h:89