26 ImGuiColorEditFlags flags,
27 const ImVec2& size_arg) {
32 bool pressed = ImGui::ColorButton(
id.data(), displayColor, flags, size_arg);
34 if (ImGui::IsItemHovered()) {
35 ImGui::BeginTooltip();
36 ImGui::Text(
"SNES: $%04X", color.
snes());
57 static ImVec4 color = ImVec4(0, 0, 0, 255.f);
58 ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |
59 ImGuiColorEditFlags_NoDragDrop |
60 ImGuiColorEditFlags_NoOptions;
63 static bool init =
false;
64 static ImVec4 saved_palette[32] = {};
65 if (loaded && !init) {
66 for (
int n = 0; n < palette.
size(); n++) {
68 saved_palette[n].x = color.rgb().x / 255;
69 saved_palette[n].y = color.rgb().y / 255;
70 saved_palette[n].z = color.rgb().z / 255;
71 saved_palette[n].w = 255;
76 static ImVec4 backup_color;
77 ImGui::Text(
"Current ==>");
79 ImGui::Text(
"Previous");
83 ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf,
87 if (ImGui::ColorButton(
88 "##previous", backup_color,
89 ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf,
95 ImGui::Text(
"Palette");
96 for (
int n = 0; n < IM_ARRAYSIZE(saved_palette); n++) {
98 if ((n % 4) != 0) ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
100 ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha |
101 ImGuiColorEditFlags_NoPicker |
102 ImGuiColorEditFlags_NoTooltip;
103 if (ImGui::ColorButton(
"##palette", saved_palette[n], palette_button_flags,
105 color = ImVec4(saved_palette[n].x, saved_palette[n].y, saved_palette[n].z,
108 if (ImGui::BeginDragDropTarget()) {
109 if (
const ImGuiPayload* payload =
110 ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
111 memcpy((
float*)&saved_palette[n], payload->Data,
sizeof(
float) * 3);
112 if (
const ImGuiPayload* payload =
113 ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
114 memcpy((
float*)&saved_palette[n], payload->Data,
sizeof(
float) * 4);
115 ImGui::EndDragDropTarget();
123 ImGui::ColorPicker4(
"##picker", (
float*)&color,
124 misc_flags | ImGuiColorEditFlags_NoSidePreview |
125 ImGuiColorEditFlags_NoSmallPreview);
126 return absl::OkStatus();
131 const auto palette_row_size = 7;
132 if (ImGuiID child_id = ImGui::GetID((
void*)(intptr_t)100);
133 ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(),
true,
134 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
136 ImGui::Text(
"Palette");
137 for (
int n = 0; n < palette.
size(); n++) {
139 if ((n % palette_row_size) != 0)
140 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
143 bool is_selected = (palette_id == n / palette_row_size);
147 ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 1.0f, 0.0f, 1.0f));
148 ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
152 ImGuiColorEditFlags_NoAlpha |
153 ImGuiColorEditFlags_NoPicker |
154 ImGuiColorEditFlags_NoTooltip,
156 palette_id = n / palette_row_size;
157 refresh_graphics =
true;
161 ImGui::PopStyleColor();
162 ImGui::PopStyleVar();