From 489a7324d66aacbf55330f55c80b3a2cde49f705 Mon Sep 17 00:00:00 2001 From: profezzorn Date: Sun, 17 Mar 2024 20:50:20 -0700 Subject: [PATCH] color editing menues --- modes/color_menues.h | 140 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 modes/color_menues.h diff --git a/modes/color_menues.h b/modes/color_menues.h new file mode 100644 index 000000000..280e72f95 --- /dev/null +++ b/modes/color_menues.h @@ -0,0 +1,140 @@ +#ifndef MODE_COLOR_MENUES_H +#define MODE_COLOR_MENUES_H + +#include "mode.h" +#include "../common/color.h" +#include "style_argument_helpers.h" + +namespace mode { + +// Note, the currently edited color is stored in ShowColorStyle. + +template +struct HSLMode : public SPEC::SmoothMode { +public: + void activate(bool onreturn) override { + SPEC::SmoothMode::activate(onreturn); + getSL()->SayRotate(); + hsl_color = ShowColorStyle::getColor().toHSL(); + } + + HSL hsl_color; +}; + +template +struct ColorHueMode : public SPEC::HSLMode { +public: + int get() override { + return this->hsl_color.H * 32767.0; + } + + void set(int x) override { + // Say number?? + this->hsl_color.H = x / 32767.0; + ShowColorStyle::SetColor(Color16(this->hsl_color)); + } +}; + +#ifndef COLOR_MENU_GAMMA +#define COLOR_MENU_GAMMA 2.2 +#endif + +template +struct ColorBrightnessMode : public SPEC::HSLMode { +public: + int get() override { + return this->hsl_color.L; + } + + void set(int x) override { + this->hsl_color.L = x / 32767.0; + if (this->hsl_color.L > 0.5) { + this->hsl_color.L = pow( (this->hsl_color.L - 0.5) * 2.0, 1.0/COLOR_MENU_GAMMA) / 2.0 + 0.5; + this->hsl_color.S = 1.0; + } else { + this->hsl_color.S = this->hsl_color.L * 2.0f; + } + ShowColorStyle::SetColor(Color16(this->hsl_color)); + } +}; + +template +struct ColorGammaMode : public SPEC::SmoothMode { + uint16_t* value() = 0; + void activate(bool onreturn) override { + SPEC::SmoothMode::activate(onreturn); + getSL()->SayRotate(); + } + int get() override { + return powf(*value() / 65535.0, COLOR_MENU_GAMMA) * 32767; + } + + void set(int x) override { + *value()= powf(x / 32767.0, 1.0/COLOR_MENU_GAMMA) * 65535.0; + } +}; + +template +struct ColorRedMode : public SPEC::GammaMode { + uint16_t* value() override { return &ShowColorStyle::getColor().r; } +}; + +template +struct ColorGreenMode : public SPEC::GammaMode { + uint16_t* value() override { return &ShowColorStyle::getColor().g; } +}; + +template +struct ColorBlueMode : public SPEC::GammaMode { + uint16_t* value() override { return &ShowColorStyle::getColor().b; } +}; + +template +struct SaveColorMenuEntry : public MenuEntry { + void say(int entry) override { + getSL->SaySave(); + } + void select(int entry) override { + getPtr()->save(); + } +}; + +template +using ColorSelectList = typename SPEC::template MenuEntryMenu< + SubMenuEntry, + SubMenuEntry, + SubMenuEntry, + SubMenuEntry, + SubMenuEntry, + SaveColorMenuEntry>; + +template +struct ColorSelectMode : public ColorSelectList> { + + virtual void load() { + ShowColorStyle::SetColor(GetColorArg(menu_current_blade, menu_current_arg)); + } + + virtual void save() { + SetColorArg(menu_current_blade, menu_current_arg, ShowColorStyle::getColor()); + } + + void mode_activate(bool onreturn) override { + if (!onreturn) { + load(); + show_color_all_.Start(); + } + ColorSelectList>::activate(onreturn); + } + + virtual void mode_exit() { + show_color_all_.Stop(); + ColorSelectList>::exit(); + } + + ShowColorAllBladesTemplate show_color_all_; +}; + +} // namespace mode + +#endif