Palette.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/Forward.h>
  10. #include <AK/Noncopyable.h>
  11. #include <AK/RefCounted.h>
  12. #include <AK/RefPtr.h>
  13. #include <LibGUI/Forward.h>
  14. #include <LibGfx/SystemTheme.h>
  15. namespace Gfx {
  16. class PaletteImpl : public RefCounted<PaletteImpl> {
  17. AK_MAKE_NONCOPYABLE(PaletteImpl);
  18. AK_MAKE_NONMOVABLE(PaletteImpl);
  19. public:
  20. ~PaletteImpl() = default;
  21. static NonnullRefPtr<PaletteImpl> create_with_anonymous_buffer(Core::AnonymousBuffer);
  22. NonnullRefPtr<PaletteImpl> clone() const;
  23. Color color(ColorRole role) const
  24. {
  25. VERIFY((int)role < (int)ColorRole::__Count);
  26. return Color::from_argb(theme().color[(int)role]);
  27. }
  28. Gfx::TextAlignment alignment(AlignmentRole role) const
  29. {
  30. VERIFY((int)role < (int)AlignmentRole::__Count);
  31. return theme().alignment[(int)role];
  32. }
  33. bool flag(FlagRole role) const
  34. {
  35. VERIFY((int)role < (int)FlagRole::__Count);
  36. return theme().flag[(int)role];
  37. }
  38. int metric(MetricRole) const;
  39. ByteString path(PathRole) const;
  40. SystemTheme const& theme() const { return *m_theme_buffer.data<SystemTheme>(); }
  41. void replace_internal_buffer(Badge<GUI::Application>, Core::AnonymousBuffer buffer);
  42. private:
  43. explicit PaletteImpl(Core::AnonymousBuffer);
  44. Core::AnonymousBuffer m_theme_buffer;
  45. };
  46. class Palette {
  47. public:
  48. explicit Palette(NonnullRefPtr<PaletteImpl>);
  49. ~Palette() = default;
  50. Color accent() const { return color(ColorRole::Accent); }
  51. Color window() const { return color(ColorRole::Window); }
  52. Color window_text() const { return color(ColorRole::WindowText); }
  53. Color selection() const { return color(ColorRole::Selection); }
  54. Color selection_text() const { return color(ColorRole::SelectionText); }
  55. Color inactive_selection() const { return color(ColorRole::InactiveSelection); }
  56. Color inactive_selection_text() const { return color(ColorRole::InactiveSelectionText); }
  57. Color desktop_background() const { return color(ColorRole::DesktopBackground); }
  58. Color active_window_border1() const { return color(ColorRole::ActiveWindowBorder1); }
  59. Color active_window_border2() const { return color(ColorRole::ActiveWindowBorder2); }
  60. Color active_window_title() const { return color(ColorRole::ActiveWindowTitle); }
  61. Color active_window_title_stripes() const { return color(ColorRole::ActiveWindowTitleStripes); }
  62. Color active_window_title_shadow() const { return color(ColorRole::ActiveWindowTitleShadow); }
  63. Color inactive_window_border1() const { return color(ColorRole::InactiveWindowBorder1); }
  64. Color inactive_window_border2() const { return color(ColorRole::InactiveWindowBorder2); }
  65. Color inactive_window_title() const { return color(ColorRole::InactiveWindowTitle); }
  66. Color inactive_window_title_stripes() const { return color(ColorRole::InactiveWindowTitleStripes); }
  67. Color inactive_window_title_shadow() const { return color(ColorRole::InactiveWindowTitleShadow); }
  68. Color moving_window_border1() const { return color(ColorRole::MovingWindowBorder1); }
  69. Color moving_window_border2() const { return color(ColorRole::MovingWindowBorder2); }
  70. Color moving_window_title() const { return color(ColorRole::MovingWindowTitle); }
  71. Color moving_window_title_stripes() const { return color(ColorRole::MovingWindowTitleStripes); }
  72. Color moving_window_title_shadow() const { return color(ColorRole::MovingWindowTitleShadow); }
  73. Color highlight_window_border1() const { return color(ColorRole::HighlightWindowBorder1); }
  74. Color highlight_window_border2() const { return color(ColorRole::HighlightWindowBorder2); }
  75. Color highlight_window_title() const { return color(ColorRole::HighlightWindowTitle); }
  76. Color highlight_window_title_stripes() const { return color(ColorRole::HighlightWindowTitleStripes); }
  77. Color highlight_window_title_shadow() const { return color(ColorRole::HighlightWindowTitleShadow); }
  78. Color highlight_searching() const { return color(ColorRole::HighlightSearching); }
  79. Color highlight_searching_text() const { return color(ColorRole::HighlightSearchingText); }
  80. Color menu_stripe() const { return color(ColorRole::MenuStripe); }
  81. Color menu_base() const { return color(ColorRole::MenuBase); }
  82. Color menu_base_text() const { return color(ColorRole::MenuBaseText); }
  83. Color menu_selection() const { return color(ColorRole::MenuSelection); }
  84. Color menu_selection_text() const { return color(ColorRole::MenuSelectionText); }
  85. Color base() const { return color(ColorRole::Base); }
  86. Color base_text() const { return color(ColorRole::BaseText); }
  87. Color disabled_text_front() const { return color(ColorRole::DisabledTextFront); }
  88. Color disabled_text_back() const { return color(ColorRole::DisabledTextBack); }
  89. Color button() const { return color(ColorRole::Button); }
  90. Color button_text() const { return color(ColorRole::ButtonText); }
  91. Color threed_highlight() const { return color(ColorRole::ThreedHighlight); }
  92. Color threed_shadow1() const { return color(ColorRole::ThreedShadow1); }
  93. Color threed_shadow2() const { return color(ColorRole::ThreedShadow2); }
  94. Color hover_highlight() const { return color(ColorRole::HoverHighlight); }
  95. Color rubber_band_fill() const { return color(ColorRole::RubberBandFill); }
  96. Color rubber_band_border() const { return color(ColorRole::RubberBandBorder); }
  97. Color gutter() const { return color(ColorRole::Gutter); }
  98. Color gutter_border() const { return color(ColorRole::GutterBorder); }
  99. Color ruler() const { return color(ColorRole::Ruler); }
  100. Color ruler_border() const { return color(ColorRole::RulerBorder); }
  101. Color ruler_active_text() const { return color(ColorRole::RulerActiveText); }
  102. Color ruler_inactive_text() const { return color(ColorRole::RulerInactiveText); }
  103. Color text_cursor() const { return color(ColorRole::TextCursor); }
  104. Color focus_outline() const { return color(ColorRole::FocusOutline); }
  105. Color tray() const { return color(ColorRole::Tray); }
  106. Color tray_text() const { return color(ColorRole::TrayText); }
  107. Color link() const { return color(ColorRole::Link); }
  108. Color active_link() const { return color(ColorRole::ActiveLink); }
  109. Color visited_link() const { return color(ColorRole::VisitedLink); }
  110. Color syntax_comment() const { return color(ColorRole::SyntaxComment); }
  111. Color syntax_number() const { return color(ColorRole::SyntaxNumber); }
  112. Color syntax_string() const { return color(ColorRole::SyntaxString); }
  113. Color syntax_identifier() const { return color(ColorRole::SyntaxIdentifier); }
  114. Color syntax_type() const { return color(ColorRole::SyntaxType); }
  115. Color syntax_punctuation() const { return color(ColorRole::SyntaxPunctuation); }
  116. Color syntax_operator() const { return color(ColorRole::SyntaxOperator); }
  117. Color syntax_keyword() const { return color(ColorRole::SyntaxKeyword); }
  118. Color syntax_control_keyword() const { return color(ColorRole::SyntaxControlKeyword); }
  119. Color syntax_preprocessor_statement() const { return color(ColorRole::SyntaxPreprocessorStatement); }
  120. Color syntax_preprocessor_value() const { return color(ColorRole::SyntaxPreprocessorValue); }
  121. Color syntax_function() const { return color(ColorRole::SyntaxFunction); }
  122. Color syntax_variable() const { return color(ColorRole::SyntaxVariable); }
  123. Color syntax_custom_type() const { return color(ColorRole::SyntaxCustomType); }
  124. Color syntax_namespace() const { return color(ColorRole::SyntaxNamespace); }
  125. Color syntax_member() const { return color(ColorRole::SyntaxMember); }
  126. Color syntax_parameter() const { return color(ColorRole::SyntaxParameter); }
  127. Color background() const { return color(ColorRole::ColorSchemeBackground); }
  128. Color foreground() const { return color(ColorRole::ColorSchemeForeground); }
  129. Color black() const { return color(ColorRole::Black); }
  130. Color red() const { return color(ColorRole::Red); }
  131. Color green() const { return color(ColorRole::Green); }
  132. Color yellow() const { return color(ColorRole::Yellow); }
  133. Color blue() const { return color(ColorRole::Blue); }
  134. Color magenta() const { return color(ColorRole::Magenta); }
  135. Color cyan() const { return color(ColorRole::Cyan); }
  136. Color white() const { return color(ColorRole::White); }
  137. Color bright_black() const { return color(ColorRole::BrightBlack); }
  138. Color bright_red() const { return color(ColorRole::BrightRed); }
  139. Color bright_green() const { return color(ColorRole::BrightGreen); }
  140. Color bright_yellow() const { return color(ColorRole::BrightYellow); }
  141. Color bright_blue() const { return color(ColorRole::BrightBlue); }
  142. Color bright_magenta() const { return color(ColorRole::BrightMagenta); }
  143. Color bright_cyan() const { return color(ColorRole::BrightCyan); }
  144. Color bright_white() const { return color(ColorRole::BrightWhite); }
  145. Gfx::TextAlignment title_alignment() const { return alignment(AlignmentRole::TitleAlignment); }
  146. bool bold_text_as_bright() const { return flag(FlagRole::BoldTextAsBright); }
  147. bool is_dark() const { return flag(FlagRole::IsDark); }
  148. bool title_buttons_icon_only() const { return flag(FlagRole::TitleButtonsIconOnly); }
  149. int window_border_thickness() const { return metric(MetricRole::BorderThickness); }
  150. int window_border_radius() const { return metric(MetricRole::BorderRadius); }
  151. int window_title_height() const { return metric(MetricRole::TitleHeight); }
  152. int window_title_button_width() const { return metric(MetricRole::TitleButtonWidth); }
  153. int window_title_button_height() const { return metric(MetricRole::TitleButtonHeight); }
  154. ByteString title_button_icons_path() const { return path(PathRole::TitleButtonIcons); }
  155. ByteString active_window_shadow_path() const { return path(PathRole::ActiveWindowShadow); }
  156. ByteString inactive_window_shadow_path() const { return path(PathRole::InactiveWindowShadow); }
  157. ByteString menu_shadow_path() const { return path(PathRole::MenuShadow); }
  158. ByteString taskbar_shadow_path() const { return path(PathRole::TaskbarShadow); }
  159. ByteString tooltip_shadow_path() const { return path(PathRole::TooltipShadow); }
  160. ByteString color_scheme_path() const { return path(PathRole::ColorScheme); }
  161. Color color(ColorRole role) const { return m_impl->color(role); }
  162. Gfx::TextAlignment alignment(AlignmentRole role) const { return m_impl->alignment(role); }
  163. bool flag(FlagRole role) const { return m_impl->flag(role); }
  164. int metric(MetricRole role) const { return m_impl->metric(role); }
  165. ByteString path(PathRole role) const { return m_impl->path(role); }
  166. void set_color(ColorRole, Color);
  167. void set_alignment(AlignmentRole, Gfx::TextAlignment);
  168. void set_flag(FlagRole, bool);
  169. void set_metric(MetricRole, int);
  170. void set_path(PathRole, ByteString);
  171. SystemTheme const& theme() const { return m_impl->theme(); }
  172. PaletteImpl& impl() { return *m_impl; }
  173. PaletteImpl const& impl() const { return *m_impl; }
  174. private:
  175. NonnullRefPtr<PaletteImpl> m_impl;
  176. };
  177. }
  178. using Gfx::Palette;