15using namespace std::literals;
20static constexpr std::array<uint16_t, 16> fixedPalette = {
21 0x000, 0x000, 0x611, 0x733,
22 0x117, 0x327, 0x151, 0x627,
23 0x171, 0x373, 0x661, 0x664,
24 0x411, 0x265, 0x555, 0x777,
30 customPalette = fixedPalette;
37 buf.append(
"customPalette=");
38 for (
auto i :
xrange(16)) {
39 if (i) buf.append(
",");
40 buf.appendf(
"%d", customPalette[i]);
49 }
else if (name ==
"customPalette") {
52 if (
auto v = StringOp::stringTo<uint16_t>(s)) {
53 customPalette[i] = *v;
60static std::array<int, 3> extractRGB(uint16_t grb)
62 auto r = (grb >> 4) & 7;
63 auto g = (grb >> 8) & 7;
64 auto b = (grb >> 0) & 7;
68static void insertRGB(std::span<uint16_t, 16> msxPalette,
unsigned index, std::array<int, 3> rgb)
71 msxPalette[index] = narrow<int16_t>(((rgb[1] & 7) << 8) | ((rgb[0] & 7) << 4) | ((rgb[2] & 7) << 0));
76 auto [r,
g, b] = extractRGB(msxColor);
77 static constexpr float scale = 1.0f / 7.0f;
78 return ImColor(
float(r) * scale,
float(
g) * scale,
float(b) * scale);
81static bool coloredButton(
const char*
id, ImU32 color, ImVec2 size)
84 auto col = ImGui::ColorConvertU32ToFloat4(color);
86 ImGuiCol_ButtonHovered, col,
87 ImGuiCol_ButtonActive, col, [&]{
88 result = ImGui::Button(
id, size);
108 VDP* vdp = motherBoard ?
dynamic_cast<VDP*
>(motherBoard->
findDevice(
"VDP")) :
nullptr;
111 ImGui::RadioButton(
"VDP palette", &whichPalette, PALETTE_VDP);
114 ImGui::RadioButton(
"Custom palette", &
whichPalette, PALETTE_CUSTOM);
116 ImGui::RadioButton(
"Fixed palette", &
whichPalette, PALETTE_FIXED);
118 std::array<uint16_t, 16> paletteCopy;
119 std::span<uint16_t, 16> palette = customPalette;
123 palette = std::span<uint16_t, 16>{
const_cast<uint16_t*
>(fixedPalette.data()), 16};
126 palette = paletteCopy;
130 ImGui::TableSetupColumn(
"left", ImGuiTableColumnFlags_WidthFixed, 200.0f);
131 ImGui::TableSetupColumn(
"right", ImGuiTableColumnFlags_WidthFixed, 150.0f);
133 if (ImGui::TableNextColumn()) {
136 if (ImGui::TableNextColumn()) {
137 if (i == selectedColor) {
138 ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ImGui::GetColorU32(ImGuiCol_HeaderActive));
140 auto color =
toRGBA(palette[i]);
141 if (coloredButton(
"", color, {44.0f, 30.0f})) {
148 if (ImGui::TableNextColumn()) {
152 coloredButton(
"##color",
toRGBA(palette[selectedColor]), {150.0f, 30.0f});
157 static constexpr std::array names = {
"R"sv,
"G"sv,
"B"sv};
158 auto rgb = extractRGB(palette[selectedColor]);
160 ImGui::AlignTextToFramePadding();
164 ImGuiCol_FrameBg,
static_cast<ImVec4
>(ImColor::HSV(
float(i) * (1.0f / 3.0f), 0.5f, 0.5f)),
165 ImGuiCol_FrameBgHovered,
static_cast<ImVec4
>(ImColor::HSV(
float(i) * (1.0f / 3.0f), 0.6f, 0.5f)),
166 ImGuiCol_FrameBgActive,
static_cast<ImVec4
>(ImColor::HSV(
float(i) * (1.0f / 3.0f), 0.7f, 0.5f)),
167 ImGuiCol_SliderGrab,
static_cast<ImVec4
>(ImColor::HSV(
float(i) * (1.0f / 3.0f), 0.9f, 0.9f)), [&]{
168 ImGui::SetNextItemWidth(-FLT_MIN);
169 if (ImGui::SliderInt(
"##v", &rgb[i], 0, 7,
"%d", ImGuiSliderFlags_AlwaysClamp)) {
171 insertRGB(palette, selectedColor, rgb);
174 vdp->
setPalette(selectedColor, palette[selectedColor], time);
void save(ImGuiTextBuffer &buf) override
std::span< const uint16_t, 16 > getPalette(const VDP *vdp) const
static uint32_t toRGBA(uint16_t msxColor)
void loadLine(std::string_view name, zstring_view value) override
void paint(MSXMotherBoard *motherBoard) override
ImGuiPalette(ImGuiManager &manager_)
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
MSXDevice * findDevice(std::string_view name)
Find a MSXDevice by name.
Unified implementation of MSX Video Display Processors (VDPs).
void setPalette(unsigned index, word grb, EmuTime::param time)
Sets a palette entry.
uint16_t getPalette(unsigned index) const
Gets a palette entry.
bool isMSX1VDP() const
Is this an MSX1 VDP?
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
void TextUnformatted(const std::string &str)
auto split_view(std::string_view str, Separators separators)
void Table(const char *str_id, int column, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, std::invocable<> auto next)
void Window(const char *name, bool *p_open, ImGuiWindowFlags flags, std::invocable<> auto next)
void StyleColor(bool active, Args &&...args)
void Disabled(bool b, std::invocable<> auto next)
void ID_for_range(std::integral auto count, std::invocable< int > auto next)
This file implemented 3 utility functions:
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
constexpr auto copy(InputRange &&range, OutputIter out)
constexpr auto xrange(T e)