Refactor color handling: update SnesColor references to gfx::SnesColor and add Color struct with utility functions
This commit is contained in:
@@ -1,18 +1,17 @@
|
|||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
|
||||||
#include "imgui/imgui.h"
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
|
||||||
#include "app/gfx/snes_color.h"
|
#include "app/gfx/snes_color.h"
|
||||||
|
#include "app/gfx/snes_palette.h"
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
ImVec4 ConvertSnesColorToImVec4(const SnesColor& color) {
|
ImVec4 ConvertSnesColorToImVec4(const gfx::SnesColor& color) {
|
||||||
return ImVec4(static_cast<float>(color.rgb().x) / 255.0f,
|
return ImVec4(static_cast<float>(color.rgb().x) / 255.0f,
|
||||||
static_cast<float>(color.rgb().y) / 255.0f,
|
static_cast<float>(color.rgb().y) / 255.0f,
|
||||||
static_cast<float>(color.rgb().z) / 255.0f,
|
static_cast<float>(color.rgb().z) / 255.0f,
|
||||||
@@ -21,7 +20,7 @@ ImVec4 ConvertSnesColorToImVec4(const SnesColor& color) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor& color,
|
IMGUI_API bool SnesColorButton(absl::string_view id, gfx::SnesColor& color,
|
||||||
ImGuiColorEditFlags flags,
|
ImGuiColorEditFlags flags,
|
||||||
const ImVec2& size_arg) {
|
const ImVec2& size_arg) {
|
||||||
// Convert the SNES color values to ImGui color values
|
// Convert the SNES color values to ImGui color values
|
||||||
@@ -38,7 +37,7 @@ IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor& color,
|
|||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor* color,
|
IMGUI_API bool SnesColorEdit4(absl::string_view label, gfx::SnesColor* color,
|
||||||
ImGuiColorEditFlags flags) {
|
ImGuiColorEditFlags flags) {
|
||||||
ImVec4 displayColor = ConvertSnesColorToImVec4(*color);
|
ImVec4 displayColor = ConvertSnesColorToImVec4(*color);
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,45 @@
|
|||||||
#ifndef YAZE_GUI_COLOR_H
|
#ifndef YAZE_GUI_COLOR_H
|
||||||
#define YAZE_GUI_COLOR_H
|
#define YAZE_GUI_COLOR_H
|
||||||
|
|
||||||
#include "imgui/imgui.h"
|
#include <format>
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/gfx/bitmap.h"
|
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
using gfx::SnesColor;
|
struct Color {
|
||||||
|
float red;
|
||||||
|
float blue;
|
||||||
|
float green;
|
||||||
|
float alpha;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ImVec4 ConvertColorToImVec4(const Color &color) {
|
||||||
|
return ImVec4(color.red, color.green, color.blue, color.alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string ColorToHexString(const Color &color) {
|
||||||
|
return std::format(
|
||||||
|
"{:02X}{:02X}{:02X}{:02X}", static_cast<int>(color.red * 255),
|
||||||
|
static_cast<int>(color.green * 255), static_cast<int>(color.blue * 255),
|
||||||
|
static_cast<int>(color.alpha * 255));
|
||||||
|
}
|
||||||
|
|
||||||
// A utility function to convert an SnesColor object to an ImVec4 with
|
// A utility function to convert an SnesColor object to an ImVec4 with
|
||||||
// normalized color values
|
// normalized color values
|
||||||
ImVec4 ConvertSnesColorToImVec4(const SnesColor& color);
|
ImVec4 ConvertSnesColorToImVec4(const gfx::SnesColor &color);
|
||||||
|
|
||||||
// The wrapper function for ImGui::ColorButton that takes a SnesColor reference
|
// 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, gfx::SnesColor &color,
|
||||||
ImGuiColorEditFlags flags = 0,
|
ImGuiColorEditFlags flags = 0,
|
||||||
const ImVec2 &size_arg = ImVec2(0, 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, gfx::SnesColor *color,
|
||||||
ImGuiColorEditFlags flags = 0);
|
ImGuiColorEditFlags flags = 0);
|
||||||
|
|
||||||
absl::Status DisplayPalette(gfx::SnesPalette &palette, bool loaded);
|
absl::Status DisplayPalette(gfx::SnesPalette &palette, bool loaded);
|
||||||
@@ -33,7 +48,6 @@ void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics,
|
|||||||
gfx::SnesPalette &palette);
|
gfx::SnesPalette &palette);
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user