yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
color.h
Go to the documentation of this file.
1#ifndef YAZE_GUI_COLOR_H
2#define YAZE_GUI_COLOR_H
3
4#include <string>
5
6#include "absl/status/status.h"
7#include "absl/strings/str_format.h"
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace gui {
13
14struct Color {
15 float red;
16 float green;
17 float blue;
18 float alpha;
19
20 operator ImVec4() const { return ImVec4(red, green, blue, alpha); }
21};
22
23inline ImVec4 ConvertColorToImVec4(const Color& color) {
24 return ImVec4(color.red, color.green, color.blue, color.alpha);
25}
26
27inline std::string ColorToHexString(const Color& color) {
28 return absl::StrFormat("%02X%02X%02X%02X", static_cast<int>(color.red * 255),
29 static_cast<int>(color.green * 255),
30 static_cast<int>(color.blue * 255),
31 static_cast<int>(color.alpha * 255));
32}
33
34// A utility function to convert an SnesColor object to an ImVec4 with
35// normalized color values
36ImVec4 ConvertSnesColorToImVec4(const gfx::SnesColor& color);
37
38// A utility function to convert an ImVec4 to an SnesColor object
39gfx::SnesColor ConvertImVec4ToSnesColor(const ImVec4& color);
40
41// The wrapper function for ImGui::ColorButton that takes a SnesColor reference
42IMGUI_API bool SnesColorButton(absl::string_view id, gfx::SnesColor& color,
43 ImGuiColorEditFlags flags = 0,
44 const ImVec2& size_arg = ImVec2(0, 0));
45
46IMGUI_API bool SnesColorEdit4(absl::string_view label, gfx::SnesColor* color,
47 ImGuiColorEditFlags flags = 0);
48
49// ============================================================================
50// Palette Widget Functions
51// ============================================================================
52
60IMGUI_API bool InlinePaletteSelector(gfx::SnesPalette& palette,
61 int num_colors = 8,
62 int* selected_index = nullptr);
63
71IMGUI_API absl::Status InlinePaletteEditor(gfx::SnesPalette& palette,
72 const std::string& title = "",
73 ImGuiColorEditFlags flags = 0);
74
82IMGUI_API bool PopupPaletteEditor(const char* popup_id,
83 gfx::SnesPalette& palette,
84 ImGuiColorEditFlags flags = 0);
85
86// Legacy functions (kept for compatibility, will be deprecated)
87IMGUI_API bool DisplayPalette(gfx::SnesPalette& palette, bool loaded);
88
89IMGUI_API absl::Status DisplayEditablePalette(gfx::SnesPalette& palette,
90 const std::string& title = "",
91 bool show_color_picker = false,
92 int colors_per_row = 8,
93 ImGuiColorEditFlags flags = 0);
94
95void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics,
96 gfx::SnesPalette& palette);
97
98// Palette color button with selection and modification indicators
99IMGUI_API bool PaletteColorButton(const char* id, const gfx::SnesColor& color,
100 bool is_selected, bool is_modified,
101 const ImVec2& size = ImVec2(28, 28),
102 ImGuiColorEditFlags flags = 0);
103
104} // namespace gui
105} // namespace yaze
106
107#endif
SNES Color container.
Definition snes_color.h:110
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:23
IMGUI_API bool InlinePaletteSelector(gfx::SnesPalette &palette, int num_colors, int *selected_index)
Small inline palette selector - just color buttons for selection.
Definition color.cc:78
IMGUI_API bool SnesColorButton(absl::string_view id, gfx::SnesColor &color, ImGuiColorEditFlags flags, const ImVec2 &size_arg)
Definition color.cc:37
IMGUI_API bool PopupPaletteEditor(const char *popup_id, gfx::SnesPalette &palette, ImGuiColorEditFlags flags)
Popup palette editor - same as inline but in a popup.
Definition color.cc:184
IMGUI_API absl::Status InlinePaletteEditor(gfx::SnesPalette &palette, const std::string &title, ImGuiColorEditFlags flags)
Full inline palette editor with color picker and copy options.
Definition color.cc:118
IMGUI_API bool PaletteColorButton(const char *id, const gfx::SnesColor &color, bool is_selected, bool is_modified, const ImVec2 &size, ImGuiColorEditFlags flags)
Definition color.cc:449
ImVec4 ConvertSnesColorToImVec4(const gfx::SnesColor &color)
Convert SnesColor to standard ImVec4 for display.
Definition color.cc:19
void SelectablePalettePipeline(uint64_t &palette_id, bool &refresh_graphics, gfx::SnesPalette &palette)
Definition color.cc:309
IMGUI_API bool SnesColorEdit4(absl::string_view label, gfx::SnesColor *color, ImGuiColorEditFlags flags)
Definition color.cc:54
std::string ColorToHexString(const Color &color)
Definition color.h:27
IMGUI_API bool DisplayPalette(gfx::SnesPalette &palette, bool loaded)
Definition color.cc:235
gfx::SnesColor ConvertImVec4ToSnesColor(const ImVec4 &color)
Convert standard ImVec4 to SnesColor.
Definition color.cc:32
absl::Status DisplayEditablePalette(gfx::SnesPalette &palette, const std::string &title, bool show_color_picker, int colors_per_row, ImGuiColorEditFlags flags)
Definition color.cc:352
float alpha
Definition color.h:18
float green
Definition color.h:16