update SnesColorEdit4

This commit is contained in:
scawful
2024-07-14 19:34:43 -04:00
parent 01b8441573
commit 0c66c2946e
2 changed files with 8 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
#include "color.h"
#include <gfx/snes_color.h>
#include <imgui/imgui.h>
#include <cmath>
@@ -34,20 +35,16 @@ IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor& color,
return pressed;
}
IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor& color,
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);
ImVec4 displayColor = ConvertSNESColorToImVec4(*color);
// Call the original ImGui::ColorEdit4 with the converted color
bool pressed = ImGui::ColorEdit4(label.data(), (float*)&displayColor, flags);
bool pressed =
ImGui::ColorEdit4(label.data(), (float*)&displayColor.x, 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));
color->set_rgb(displayColor);
color->set_snes(gfx::ConvertRGBtoSNES(displayColor));
return pressed;
}

View File

@@ -25,7 +25,7 @@ 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,
IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor* color,
ImGuiColorEditFlags flags = 0);
absl::Status DisplayPalette(app::gfx::SnesPalette& palette, bool loaded);