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 "app/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(label, &col.x,
39 ImGuiColorEditFlags_NoInputs |
40 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",
60 group_name.c_str(), 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) *palette_id = 0;
79 if (*palette_id > 255) *palette_id = 255;
80
81 // Draw jump button
82 ImGui::SameLine();
83 if (DrawPaletteJumpButton("Jump", group_name, *palette_id, editor)) {
84 // Button clicked, editor will handle jump
85 }
86
87 ImGui::PopID();
88 return changed;
89}
90
92 auto rgb = color.rgb();
93 ImGui::Separator();
94 ImGui::Text("RGB: (%d, %d, %d)",
95 static_cast<int>(rgb.x),
96 static_cast<int>(rgb.y),
97 static_cast<int>(rgb.z));
98 ImGui::Text("SNES: $%04X", color.snes());
99 ImGui::Text("Hex: #%02X%02X%02X",
100 static_cast<int>(rgb.x),
101 static_cast<int>(rgb.y),
102 static_cast<int>(rgb.z));
103}
104
105void DrawPalettePreview(const std::string& group_name, int palette_index,
106 Rom* rom) {
107 if (!rom || !rom->is_loaded()) {
108 ImGui::TextDisabled("(ROM not loaded)");
109 return;
110 }
111
112 auto* group = rom->mutable_palette_group()->get_group(group_name);
113 if (!group || palette_index >= group->size()) {
114 ImGui::TextDisabled("(Palette not found)");
115 return;
116 }
117
118 auto palette = group->palette(palette_index);
119
120 // Draw colors in a row
121 int preview_size = std::min(8, static_cast<int>(palette.size()));
122 for (int i = 0; i < preview_size; i++) {
123 if (i > 0) ImGui::SameLine();
124
125 ImGui::PushID(i);
126 ImVec4 col = gui::ConvertSnesColorToImVec4(palette[i]);
127 ImGui::ColorButton("##preview", col,
128 ImGuiColorEditFlags_NoAlpha |
129 ImGuiColorEditFlags_NoPicker |
130 ImGuiColorEditFlags_NoTooltip,
131 ImVec2(16, 16));
132
133 if (ImGui::IsItemHovered()) {
134 ImGui::BeginTooltip();
135 ImGui::Text("Color %d", i);
136 DrawColorInfoTooltip(palette[i]);
137 ImGui::EndTooltip();
138 }
139
140 ImGui::PopID();
141 }
142}
143
144} // namespace palette_utility
145} // namespace editor
146} // namespace yaze
147
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:74
auto mutable_palette_group()
Definition rom.h:217
bool is_loaded() const
Definition rom.h:200
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:109
constexpr ImVec4 rgb() const
Get RGB values (WARNING: stored as 0-255 in ImVec4)
Definition snes_color.h:182
constexpr uint16_t snes() const
Get SNES 15-bit color.
Definition snes_color.h:192
#define ICON_MD_PALETTE
Definition icons.h:1368
#define ICON_MD_OPEN_IN_NEW
Definition icons.h:1352
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.
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 DrawPalettePreview(const std::string &group_name, int palette_index, Rom *rom)
Draw a small palette preview (8 colors in a row)
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
Main namespace for the application.
Definition controller.cc:20