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"
7#include "rom/rom.h"
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace editor {
12namespace palette_utility {
13
14bool DrawPaletteJumpButton(const char* label, const std::string& group_name,
15 int palette_index, PaletteEditor* editor) {
16 bool clicked = ImGui::SmallButton(
17 absl::StrFormat("%s %s", ICON_MD_PALETTE, label).c_str());
18
19 if (ImGui::IsItemHovered()) {
20 ImGui::SetTooltip("Jump to palette editor:\n%s - Palette %d",
21 group_name.c_str(), palette_index);
22 }
23
24 if (clicked && editor) {
25 editor->JumpToPalette(group_name, palette_index);
26 }
27
28 return clicked;
29}
30
31bool DrawInlineColorEdit(const char* label, gfx::SnesColor* color,
32 const std::string& group_name, int palette_index,
33 int color_index, PaletteEditor* editor) {
34 ImGui::PushID(label);
35
36 // Draw color button
37 ImVec4 col = gui::ConvertSnesColorToImVec4(*color);
38 bool changed = ImGui::ColorEdit4(
39 label, &col.x,
40 ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
41
42 if (changed) {
44 }
45
46 // Draw jump button
47 ImGui::SameLine();
48 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
49 if (ImGui::SmallButton(ICON_MD_OPEN_IN_NEW)) {
50 if (editor) {
51 editor->JumpToPalette(group_name, palette_index);
52 }
53 }
54 ImGui::PopStyleColor();
55
56 if (ImGui::IsItemHovered()) {
57 ImGui::BeginTooltip();
58 ImGui::Text("Jump to Palette Editor");
59 ImGui::TextDisabled("%s - Palette %d, Color %d", group_name.c_str(),
60 palette_index, color_index);
62 ImGui::EndTooltip();
63 }
64
65 ImGui::PopID();
66 return changed;
67}
68
69bool DrawPaletteIdSelector(const char* label, int* palette_id,
70 const std::string& group_name,
71 PaletteEditor* editor) {
72 ImGui::PushID(label);
73
74 // Draw combo box
75 bool changed = ImGui::InputInt(label, palette_id);
76
77 // Clamp to valid range (0-255 typically)
78 if (*palette_id < 0)
79 *palette_id = 0;
80 if (*palette_id > 255)
81 *palette_id = 255;
82
83 // Draw jump button
84 ImGui::SameLine();
85 if (DrawPaletteJumpButton("Jump", group_name, *palette_id, editor)) {
86 // Button clicked, editor will handle jump
87 }
88
89 ImGui::PopID();
90 return changed;
91}
92
94 auto rgb = color.rgb();
95 ImGui::Separator();
96 ImGui::Text("RGB: (%d, %d, %d)", static_cast<int>(rgb.x),
97 static_cast<int>(rgb.y), static_cast<int>(rgb.z));
98 ImGui::Text("SNES: $%04X", color.snes());
99 ImGui::Text("Hex: #%02X%02X%02X", static_cast<int>(rgb.x),
100 static_cast<int>(rgb.y), static_cast<int>(rgb.z));
101}
102
103void DrawPalettePreview(const std::string& group_name, int palette_index,
104 zelda3::GameData* game_data) {
105 if (!game_data) {
106 ImGui::TextDisabled("(GameData not loaded)");
107 return;
108 }
109
110 auto* group = game_data->palette_groups.get_group(group_name);
111 if (!group || palette_index >= group->size()) {
112 ImGui::TextDisabled("(Palette not found)");
113 return;
114 }
115
116 auto palette = group->palette(palette_index);
117
118 // Draw colors in a row
119 int preview_size = std::min(8, static_cast<int>(palette.size()));
120 for (int i = 0; i < preview_size; i++) {
121 if (i > 0)
122 ImGui::SameLine();
123
124 ImGui::PushID(i);
125 ImVec4 col = gui::ConvertSnesColorToImVec4(palette[i]);
126 ImGui::ColorButton("##preview", col,
127 ImGuiColorEditFlags_NoAlpha |
128 ImGuiColorEditFlags_NoPicker |
129 ImGuiColorEditFlags_NoTooltip,
130 ImVec2(16, 16));
131
132 if (ImGui::IsItemHovered()) {
133 ImGui::BeginTooltip();
134 ImGui::Text("Color %d", i);
135 DrawColorInfoTooltip(palette[i]);
136 ImGui::EndTooltip();
137 }
138
139 ImGui::PopID();
140 }
141}
142
143} // namespace palette_utility
144} // namespace editor
145} // 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
#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:19
gfx::SnesColor ConvertImVec4ToSnesColor(const ImVec4 &color)
Convert standard ImVec4 to SnesColor.
Definition color.cc:32
PaletteGroup * get_group(const std::string &group_name)
gfx::PaletteGroupMap palette_groups
Definition game_data.h:89