diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-10-26 14:30:52 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-31 18:39:13 +0100 |
commit | 4f42e4ba90f5a024df0fb3a43b9abc94ee147d51 (patch) | |
tree | f83e82a4ece08a30d5162ec898871f46e5a1a1d5 /Userland | |
parent | 2eaed880b114adb5e2698345126b4924d0d7f2bb (diff) | |
download | serenity-4f42e4ba90f5a024df0fb3a43b9abc94ee147d51.zip |
LibGfx: Add 'IsDark' flag to SystemTheme and Palette
This explicitly states whether a given theme is a dark theme, so that
applications not using the system palette colors can still attempt to
match the overall theme.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGfx/Palette.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Palette.h | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/SystemTheme.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/SystemTheme.h | 16 |
4 files changed, 48 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Palette.cpp b/Userland/Libraries/LibGfx/Palette.cpp index d45b6c0881..37fde562c9 100644 --- a/Userland/Libraries/LibGfx/Palette.cpp +++ b/Userland/Libraries/LibGfx/Palette.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -56,6 +57,14 @@ void Palette::set_color(ColorRole role, Color color) theme.color[(int)role] = color.value(); } +void Palette::set_flag(FlagRole role, bool value) +{ + if (m_impl->ref_count() != 1) + m_impl = m_impl->clone(); + auto& theme = const_cast<SystemTheme&>(impl().theme()); + theme.flag[(int)role] = value; +} + void Palette::set_metric(MetricRole role, int value) { if (m_impl->ref_count() != 1) diff --git a/Userland/Libraries/LibGfx/Palette.h b/Userland/Libraries/LibGfx/Palette.h index 929503de14..f6bfdc7e9b 100644 --- a/Userland/Libraries/LibGfx/Palette.h +++ b/Userland/Libraries/LibGfx/Palette.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -30,6 +31,12 @@ public: return Color::from_rgba(theme().color[(int)role]); } + bool flag(FlagRole role) const + { + VERIFY((int)role < (int)FlagRole::__Count); + return theme().flag[(int)role]; + } + int metric(MetricRole) const; String path(PathRole) const; const SystemTheme& theme() const { return *m_theme_buffer.data<SystemTheme>(); } @@ -118,6 +125,8 @@ public: Color syntax_preprocessor_statement() const { return color(ColorRole::SyntaxPreprocessorStatement); } Color syntax_preprocessor_value() const { return color(ColorRole::SyntaxPreprocessorValue); } + bool is_dark() const { return flag(FlagRole::IsDark); } + int window_title_height() const { return metric(MetricRole::TitleHeight); } int window_title_button_width() const { return metric(MetricRole::TitleButtonWidth); } int window_title_button_height() const { return metric(MetricRole::TitleButtonHeight); } @@ -130,10 +139,12 @@ public: String tooltip_shadow_path() const { return path(PathRole::TooltipShadow); } Color color(ColorRole role) const { return m_impl->color(role); } + bool flag(FlagRole role) const { return m_impl->flag(role); } int metric(MetricRole role) const { return m_impl->metric(role); } String path(PathRole role) const { return m_impl->path(role); } void set_color(ColorRole, Color); + void set_flag(FlagRole, bool); void set_metric(MetricRole, int); void set_path(PathRole, String); diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp index 261daf3f23..db2c4ae3e4 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.cpp +++ b/Userland/Libraries/LibGfx/SystemTheme.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -40,6 +41,11 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file) return color.value(); }; + auto get_flag = [&](auto& name) { + auto flag_string = file.read_entry("Flags", name); + return flag_string.equals_ignoring_case("true"); + }; + auto get_metric = [&](auto& name, auto role) { int metric = file.read_num_entry("Metrics", name, -1); if (metric == -1) { @@ -77,6 +83,12 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file) ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE) #undef __ENUMERATE_COLOR_ROLE +#undef __ENUMERATE_FLAG_ROLE +#define __ENUMERATE_FLAG_ROLE(role) \ + data->flag[(int)FlagRole::role] = get_flag(#role); + ENUMERATE_FLAG_ROLES(__ENUMERATE_FLAG_ROLE) +#undef __ENUMERATE_FLAG_ROLE + #undef __ENUMERATE_METRIC_ROLE #define __ENUMERATE_METRIC_ROLE(role) \ data->metric[(int)MetricRole::role] = get_metric(#role, (int)MetricRole::role); diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h index ea589d732c..c922963037 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.h +++ b/Userland/Libraries/LibGfx/SystemTheme.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -89,6 +90,9 @@ namespace Gfx { C(Window) \ C(WindowText) +#define ENUMERATE_FLAG_ROLES(C) \ + C(IsDark) + #define ENUMERATE_METRIC_ROLES(C) \ C(TitleHeight) \ C(TitleButtonWidth) \ @@ -132,6 +136,17 @@ inline const char* to_string(ColorRole role) } } +enum class FlagRole { + NoRole, + +#undef __ENUMERATE_FLAG_ROLE +#define __ENUMERATE_FLAG_ROLE(role) role, + ENUMERATE_FLAG_ROLES(__ENUMERATE_FLAG_ROLE) +#undef __ENUMERATE_FLAG_ROLE + + __Count, +}; + enum class MetricRole { NoRole, @@ -188,6 +203,7 @@ inline const char* to_string(PathRole role) struct SystemTheme { RGBA32 color[(int)ColorRole::__Count]; + bool flag[(int)FlagRole::__Count]; int metric[(int)MetricRole::__Count]; char path[(int)PathRole::__Count][256]; // TODO: PATH_MAX? }; |