mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37: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_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); }
|
||||
|
||||
bool bold_text_as_bright() const { return flag(FlagRole::BoldTextAsBright); }
|
||||
bool is_dark() const { return flag(FlagRole::IsDark); }
|
||||
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 color_string = file.read_entry("Colors", name);
|
||||
auto color = Color::from_string(color_string);
|
||||
if (!color.has_value())
|
||||
return Color(Color::Black);
|
||||
if (!color.has_value()) {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -107,6 +122,21 @@ ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
|||
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
|
||||
#define __ENUMERATE_COLOR_ROLE(role) \
|
||||
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)
|
||||
#undef __ENUMERATE_METRIC_ROLE
|
||||
|
||||
#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);
|
||||
data->flag[(int)FlagRole::BoldTextAsBright] = true;
|
||||
auto maybe_color_config = Core::ConfigFile::open(data->path[(int)PathRole::ColorScheme]);
|
||||
if (!maybe_color_config.is_error()) {
|
||||
auto color_config = maybe_color_config.release_value();
|
||||
data->flag[(int)FlagRole::BoldTextAsBright] = color_config->read_bool_entry("Options", "ShowBoldTextAsBright", true);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
@ -29,12 +29,26 @@ namespace Gfx {
|
|||
C(ActiveWindowTitleStripes) \
|
||||
C(Base) \
|
||||
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(ButtonText) \
|
||||
C(ColorSchemeBackground) \
|
||||
C(ColorSchemeForeground) \
|
||||
C(Cyan) \
|
||||
C(DisabledTextFront) \
|
||||
C(DisabledTextBack) \
|
||||
C(DesktopBackground) \
|
||||
C(FocusOutline) \
|
||||
C(Green) \
|
||||
C(Gutter) \
|
||||
C(GutterBorder) \
|
||||
C(HighlightWindowBorder1) \
|
||||
|
@ -53,6 +67,7 @@ namespace Gfx {
|
|||
C(InactiveWindowTitleShadow) \
|
||||
C(InactiveWindowTitleStripes) \
|
||||
C(Link) \
|
||||
C(Magenta) \
|
||||
C(MenuBase) \
|
||||
C(MenuBaseText) \
|
||||
C(MenuSelection) \
|
||||
|
@ -64,6 +79,7 @@ namespace Gfx {
|
|||
C(MovingWindowTitleShadow) \
|
||||
C(MovingWindowTitleStripes) \
|
||||
C(PlaceholderText) \
|
||||
C(Red) \
|
||||
C(RubberBandBorder) \
|
||||
C(RubberBandFill) \
|
||||
C(Ruler) \
|
||||
|
@ -98,13 +114,16 @@ namespace Gfx {
|
|||
C(Tray) \
|
||||
C(TrayText) \
|
||||
C(VisitedLink) \
|
||||
C(White) \
|
||||
C(Window) \
|
||||
C(WindowText)
|
||||
C(WindowText) \
|
||||
C(Yellow)
|
||||
|
||||
#define ENUMERATE_ALIGNMENT_ROLES(C) \
|
||||
C(TitleAlignment)
|
||||
|
||||
#define ENUMERATE_FLAG_ROLES(C) \
|
||||
C(BoldTextAsBright) \
|
||||
C(IsDark) \
|
||||
C(TitleButtonsIconOnly)
|
||||
|
||||
|
@ -121,7 +140,8 @@ namespace Gfx {
|
|||
C(ActiveWindowShadow) \
|
||||
C(TaskbarShadow) \
|
||||
C(MenuShadow) \
|
||||
C(TooltipShadow)
|
||||
C(TooltipShadow) \
|
||||
C(ColorScheme)
|
||||
|
||||
enum class ColorRole {
|
||||
NoRole,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue