Add SNESColorButton and ConvertSNESColorToImVec4

This commit is contained in:
scawful
2023-11-10 23:22:43 -05:00
parent e4b23b9b26
commit dbcd47ba68
2 changed files with 33 additions and 2 deletions

View File

@@ -10,9 +10,30 @@
namespace yaze {
namespace app {
namespace gui {
ImVec4 ConvertSNESColorToImVec4(const SNESColor& color) {
return ImVec4(static_cast<float>(color.GetRGB().x) / 255.0f,
static_cast<float>(color.GetRGB().y) / 255.0f,
static_cast<float>(color.GetRGB().z) / 255.0f,
1.0f // Assuming alpha is always fully opaque for SNES colors,
// adjust if necessary
);
}
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
// range)
ImVec4 displayColor = ConvertSNESColorToImVec4(color);
// Call the original ImGui::ColorButton with the converted color
bool pressed = ImGui::ColorButton(id.data(), displayColor, flags, size_arg);
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

@@ -11,9 +11,19 @@
namespace yaze {
namespace app {
namespace gui {
using gfx::SNESColor;
// A utility function to convert an SNESColor object to an ImVec4 with
// normalized color values
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,
ImGuiColorEditFlags flags = 0,
const ImVec2& size_arg = ImVec2(0, 0));
void DisplayPalette(app::gfx::SNESPalette& palette, bool loaded);
} // namespace gui