Update SnesColorButton and PaletteEditor

This commit is contained in:
scawful
2024-02-02 23:58:52 -05:00
parent 427b7f6f41
commit 626d38ec0d
8 changed files with 79 additions and 39 deletions

View File

@@ -21,7 +21,7 @@ ImVec4 ConvertSNESColorToImVec4(const SnesColor& color) {
);
}
IMGUI_API bool SNESColorButton(absl::string_view id, SnesColor& color,
IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor& color,
ImGuiColorEditFlags flags,
const ImVec2& size_arg) {
// Convert the SNES color values to ImGui color values (normalized to 0-1
@@ -34,6 +34,24 @@ IMGUI_API bool SNESColorButton(absl::string_view id, SnesColor& color,
return pressed;
}
IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor& color,
ImGuiColorEditFlags flags) {
// Convert the SNES color values to ImGui color values (normalized to 0-1
// range)
ImVec4 displayColor = ConvertSNESColorToImVec4(color);
// Call the original ImGui::ColorEdit4 with the converted color
bool pressed = ImGui::ColorEdit4(label.data(), (float*)&displayColor, flags);
// Convert the ImGui color values back to SNES color values (normalized to
// 0-255 range)
color = SnesColor(static_cast<uint8_t>(displayColor.x * 255.0f),
static_cast<uint8_t>(displayColor.y * 255.0f),
static_cast<uint8_t>(displayColor.z * 255.0f));
return pressed;
}
void DisplayPalette(app::gfx::SnesPalette& palette, bool loaded) {
static ImVec4 color = ImVec4(0, 0, 0, 255.f);
ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |

View File

@@ -20,10 +20,13 @@ using gfx::SnesColor;
ImVec4 ConvertSNESColorToImVec4(const SnesColor& color);
// The wrapper function for ImGui::ColorButton that takes a SnesColor reference
IMGUI_API bool SNESColorButton(absl::string_view id, SnesColor& color,
IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor& color,
ImGuiColorEditFlags flags = 0,
const ImVec2& size_arg = ImVec2(0, 0));
IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor& color,
ImGuiColorEditFlags flags = 0);
void DisplayPalette(app::gfx::SnesPalette& palette, bool loaded);
} // namespace gui

View File

@@ -43,7 +43,7 @@ void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics,
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
}
if (gui::SNESColorButton("##palette", palette[n],
if (gui::SnesColorButton("##palette", palette[n],
ImGuiColorEditFlags_NoAlpha |
ImGuiColorEditFlags_NoPicker |
ImGuiColorEditFlags_NoTooltip,