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