mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
LibGfx: Support color schemes
This commit is contained in:
parent
05334169cf
commit
8eb402f8e5
3 changed files with 82 additions and 17 deletions
|
@ -140,8 +140,30 @@ public:
|
||||||
Color syntax_member() const { return color(ColorRole::SyntaxMember); }
|
Color syntax_member() const { return color(ColorRole::SyntaxMember); }
|
||||||
Color syntax_parameter() const { return color(ColorRole::SyntaxParameter); }
|
Color syntax_parameter() const { return color(ColorRole::SyntaxParameter); }
|
||||||
|
|
||||||
|
Color background() const { return color(ColorRole::ColorSchemeBackground); }
|
||||||
|
Color foreground() const { return color(ColorRole::ColorSchemeForeground); }
|
||||||
|
|
||||||
|
Color black() const { return color(ColorRole::Black); }
|
||||||
|
Color red() const { return color(ColorRole::Red); }
|
||||||
|
Color green() const { return color(ColorRole::Green); }
|
||||||
|
Color yellow() const { return color(ColorRole::Yellow); }
|
||||||
|
Color blue() const { return color(ColorRole::Blue); }
|
||||||
|
Color magenta() const { return color(ColorRole::Magenta); }
|
||||||
|
Color cyan() const { return color(ColorRole::Cyan); }
|
||||||
|
Color white() const { return color(ColorRole::White); }
|
||||||
|
|
||||||
|
Color bright_black() const { return color(ColorRole::BrightBlack); }
|
||||||
|
Color bright_red() const { return color(ColorRole::BrightRed); }
|
||||||
|
Color bright_green() const { return color(ColorRole::BrightGreen); }
|
||||||
|
Color bright_yellow() const { return color(ColorRole::BrightYellow); }
|
||||||
|
Color bright_blue() const { return color(ColorRole::BrightBlue); }
|
||||||
|
Color bright_magenta() const { return color(ColorRole::BrightMagenta); }
|
||||||
|
Color bright_cyan() const { return color(ColorRole::BrightCyan); }
|
||||||
|
Color bright_white() const { return color(ColorRole::BrightWhite); }
|
||||||
|
|
||||||
Gfx::TextAlignment title_alignment() const { return alignment(AlignmentRole::TitleAlignment); }
|
Gfx::TextAlignment title_alignment() const { return alignment(AlignmentRole::TitleAlignment); }
|
||||||
|
|
||||||
|
bool bold_text_as_bright() const { return flag(FlagRole::BoldTextAsBright); }
|
||||||
bool is_dark() const { return flag(FlagRole::IsDark); }
|
bool is_dark() const { return flag(FlagRole::IsDark); }
|
||||||
bool title_buttons_icon_only() const { return flag(FlagRole::TitleButtonsIconOnly); }
|
bool title_buttons_icon_only() const { return flag(FlagRole::TitleButtonsIconOnly); }
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,23 @@ ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
||||||
auto get_color = [&](auto& name) {
|
auto get_color = [&](auto& name) {
|
||||||
auto color_string = file.read_entry("Colors", name);
|
auto color_string = file.read_entry("Colors", name);
|
||||||
auto color = Color::from_string(color_string);
|
auto color = Color::from_string(color_string);
|
||||||
if (!color.has_value())
|
if (!color.has_value()) {
|
||||||
return Color(Color::Black);
|
auto maybe_color_config = Core::ConfigFile::open(data->path[(int)PathRole::ColorScheme]);
|
||||||
|
if (maybe_color_config.is_error())
|
||||||
|
maybe_color_config = Core::ConfigFile::open("/res/color-schemes/Default.ini");
|
||||||
|
auto color_config = maybe_color_config.release_value();
|
||||||
|
if (name == "ColorSchemeBackground"sv)
|
||||||
|
color = Gfx::Color::from_string(color_config->read_entry("Primary", "Background"));
|
||||||
|
else if (name == "ColorSchemeForeground"sv)
|
||||||
|
color = Gfx::Color::from_string(color_config->read_entry("Primary", "Foreground"));
|
||||||
|
else if (strncmp(name, "Bright", 6) == 0)
|
||||||
|
color = Gfx::Color::from_string(color_config->read_entry("Bright", name + 6));
|
||||||
|
else
|
||||||
|
color = Gfx::Color::from_string(color_config->read_entry("Normal", name));
|
||||||
|
|
||||||
|
if (!color.has_value())
|
||||||
|
return Color(Color::Black);
|
||||||
|
}
|
||||||
return color.value();
|
return color.value();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -107,6 +122,21 @@ ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
||||||
return &path[0];
|
return &path[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define ENCODE_PATH(x, allow_empty) \
|
||||||
|
do { \
|
||||||
|
auto path = get_path(#x, (int)PathRole::x, allow_empty); \
|
||||||
|
memcpy(data->path[(int)PathRole::x], path, min(strlen(path) + 1, sizeof(data->path[(int)PathRole::x]))); \
|
||||||
|
data->path[(int)PathRole::x][sizeof(data->path[(int)PathRole::x]) - 1] = '\0'; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
ENCODE_PATH(TitleButtonIcons, false);
|
||||||
|
ENCODE_PATH(ActiveWindowShadow, true);
|
||||||
|
ENCODE_PATH(InactiveWindowShadow, true);
|
||||||
|
ENCODE_PATH(TaskbarShadow, true);
|
||||||
|
ENCODE_PATH(MenuShadow, true);
|
||||||
|
ENCODE_PATH(TooltipShadow, true);
|
||||||
|
ENCODE_PATH(ColorScheme, true);
|
||||||
|
|
||||||
#undef __ENUMERATE_COLOR_ROLE
|
#undef __ENUMERATE_COLOR_ROLE
|
||||||
#define __ENUMERATE_COLOR_ROLE(role) \
|
#define __ENUMERATE_COLOR_ROLE(role) \
|
||||||
data->color[(int)ColorRole::role] = get_color(#role).value();
|
data->color[(int)ColorRole::role] = get_color(#role).value();
|
||||||
|
@ -131,19 +161,12 @@ ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
||||||
ENUMERATE_METRIC_ROLES(__ENUMERATE_METRIC_ROLE)
|
ENUMERATE_METRIC_ROLES(__ENUMERATE_METRIC_ROLE)
|
||||||
#undef __ENUMERATE_METRIC_ROLE
|
#undef __ENUMERATE_METRIC_ROLE
|
||||||
|
|
||||||
#define ENCODE_PATH(x, allow_empty) \
|
data->flag[(int)FlagRole::BoldTextAsBright] = true;
|
||||||
do { \
|
auto maybe_color_config = Core::ConfigFile::open(data->path[(int)PathRole::ColorScheme]);
|
||||||
auto path = get_path(#x, (int)PathRole::x, allow_empty); \
|
if (!maybe_color_config.is_error()) {
|
||||||
memcpy(data->path[(int)PathRole::x], path, min(strlen(path) + 1, sizeof(data->path[(int)PathRole::x]))); \
|
auto color_config = maybe_color_config.release_value();
|
||||||
data->path[(int)PathRole::x][sizeof(data->path[(int)PathRole::x]) - 1] = '\0'; \
|
data->flag[(int)FlagRole::BoldTextAsBright] = color_config->read_bool_entry("Options", "ShowBoldTextAsBright", true);
|
||||||
} while (0)
|
}
|
||||||
|
|
||||||
ENCODE_PATH(TitleButtonIcons, false);
|
|
||||||
ENCODE_PATH(ActiveWindowShadow, true);
|
|
||||||
ENCODE_PATH(InactiveWindowShadow, true);
|
|
||||||
ENCODE_PATH(TaskbarShadow, true);
|
|
||||||
ENCODE_PATH(MenuShadow, true);
|
|
||||||
ENCODE_PATH(TooltipShadow, true);
|
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,26 @@ namespace Gfx {
|
||||||
C(ActiveWindowTitleStripes) \
|
C(ActiveWindowTitleStripes) \
|
||||||
C(Base) \
|
C(Base) \
|
||||||
C(BaseText) \
|
C(BaseText) \
|
||||||
|
C(Black) \
|
||||||
|
C(Blue) \
|
||||||
|
C(BrightBlack) \
|
||||||
|
C(BrightBlue) \
|
||||||
|
C(BrightCyan) \
|
||||||
|
C(BrightGreen) \
|
||||||
|
C(BrightMagenta) \
|
||||||
|
C(BrightRed) \
|
||||||
|
C(BrightWhite) \
|
||||||
|
C(BrightYellow) \
|
||||||
C(Button) \
|
C(Button) \
|
||||||
C(ButtonText) \
|
C(ButtonText) \
|
||||||
|
C(ColorSchemeBackground) \
|
||||||
|
C(ColorSchemeForeground) \
|
||||||
|
C(Cyan) \
|
||||||
C(DisabledTextFront) \
|
C(DisabledTextFront) \
|
||||||
C(DisabledTextBack) \
|
C(DisabledTextBack) \
|
||||||
C(DesktopBackground) \
|
C(DesktopBackground) \
|
||||||
C(FocusOutline) \
|
C(FocusOutline) \
|
||||||
|
C(Green) \
|
||||||
C(Gutter) \
|
C(Gutter) \
|
||||||
C(GutterBorder) \
|
C(GutterBorder) \
|
||||||
C(HighlightWindowBorder1) \
|
C(HighlightWindowBorder1) \
|
||||||
|
@ -53,6 +67,7 @@ namespace Gfx {
|
||||||
C(InactiveWindowTitleShadow) \
|
C(InactiveWindowTitleShadow) \
|
||||||
C(InactiveWindowTitleStripes) \
|
C(InactiveWindowTitleStripes) \
|
||||||
C(Link) \
|
C(Link) \
|
||||||
|
C(Magenta) \
|
||||||
C(MenuBase) \
|
C(MenuBase) \
|
||||||
C(MenuBaseText) \
|
C(MenuBaseText) \
|
||||||
C(MenuSelection) \
|
C(MenuSelection) \
|
||||||
|
@ -64,6 +79,7 @@ namespace Gfx {
|
||||||
C(MovingWindowTitleShadow) \
|
C(MovingWindowTitleShadow) \
|
||||||
C(MovingWindowTitleStripes) \
|
C(MovingWindowTitleStripes) \
|
||||||
C(PlaceholderText) \
|
C(PlaceholderText) \
|
||||||
|
C(Red) \
|
||||||
C(RubberBandBorder) \
|
C(RubberBandBorder) \
|
||||||
C(RubberBandFill) \
|
C(RubberBandFill) \
|
||||||
C(Ruler) \
|
C(Ruler) \
|
||||||
|
@ -98,13 +114,16 @@ namespace Gfx {
|
||||||
C(Tray) \
|
C(Tray) \
|
||||||
C(TrayText) \
|
C(TrayText) \
|
||||||
C(VisitedLink) \
|
C(VisitedLink) \
|
||||||
|
C(White) \
|
||||||
C(Window) \
|
C(Window) \
|
||||||
C(WindowText)
|
C(WindowText) \
|
||||||
|
C(Yellow)
|
||||||
|
|
||||||
#define ENUMERATE_ALIGNMENT_ROLES(C) \
|
#define ENUMERATE_ALIGNMENT_ROLES(C) \
|
||||||
C(TitleAlignment)
|
C(TitleAlignment)
|
||||||
|
|
||||||
#define ENUMERATE_FLAG_ROLES(C) \
|
#define ENUMERATE_FLAG_ROLES(C) \
|
||||||
|
C(BoldTextAsBright) \
|
||||||
C(IsDark) \
|
C(IsDark) \
|
||||||
C(TitleButtonsIconOnly)
|
C(TitleButtonsIconOnly)
|
||||||
|
|
||||||
|
@ -121,7 +140,8 @@ namespace Gfx {
|
||||||
C(ActiveWindowShadow) \
|
C(ActiveWindowShadow) \
|
||||||
C(TaskbarShadow) \
|
C(TaskbarShadow) \
|
||||||
C(MenuShadow) \
|
C(MenuShadow) \
|
||||||
C(TooltipShadow)
|
C(TooltipShadow) \
|
||||||
|
C(ColorScheme)
|
||||||
|
|
||||||
enum class ColorRole {
|
enum class ColorRole {
|
||||||
NoRole,
|
NoRole,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue