2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
|
2021-10-26 14:30:52 +01:00
|
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
2022-01-01 18:26:19 +01:00
|
|
|
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-12-24 20:57:54 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-14 23:02:47 +01:00
|
|
|
#include <AK/Forward.h>
|
2019-12-29 00:47:49 +01:00
|
|
|
#include <AK/Noncopyable.h>
|
2020-02-14 23:28:42 +01:00
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
|
#include <AK/RefPtr.h>
|
2020-02-06 12:04:00 +01:00
|
|
|
#include <LibGfx/SystemTheme.h>
|
2019-12-24 20:57:54 +01:00
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
namespace Gfx {
|
|
|
|
|
|
2019-12-29 00:47:49 +01:00
|
|
|
class PaletteImpl : public RefCounted<PaletteImpl> {
|
2020-08-26 21:52:24 +02:00
|
|
|
AK_MAKE_NONCOPYABLE(PaletteImpl);
|
|
|
|
|
AK_MAKE_NONMOVABLE(PaletteImpl);
|
|
|
|
|
|
2019-12-24 20:57:54 +01:00
|
|
|
public:
|
2022-02-06 23:10:42 +02:00
|
|
|
~PaletteImpl() = default;
|
2021-01-16 17:20:53 +01:00
|
|
|
static NonnullRefPtr<PaletteImpl> create_with_anonymous_buffer(Core::AnonymousBuffer);
|
2019-12-29 00:47:49 +01:00
|
|
|
NonnullRefPtr<PaletteImpl> clone() const;
|
|
|
|
|
|
2021-02-07 16:52:53 +01:00
|
|
|
Color color(ColorRole role) const
|
|
|
|
|
{
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY((int)role < (int)ColorRole::__Count);
|
2022-03-04 22:28:59 +01:00
|
|
|
return Color::from_argb(theme().color[(int)role]);
|
2021-02-07 16:52:53 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-01 18:26:19 +01:00
|
|
|
Gfx::TextAlignment alignment(AlignmentRole role) const
|
|
|
|
|
{
|
|
|
|
|
VERIFY((int)role < (int)AlignmentRole::__Count);
|
|
|
|
|
return theme().alignment[(int)role];
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 14:30:52 +01:00
|
|
|
bool flag(FlagRole role) const
|
|
|
|
|
{
|
|
|
|
|
VERIFY((int)role < (int)FlagRole::__Count);
|
|
|
|
|
return theme().flag[(int)role];
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-17 10:27:55 +10:00
|
|
|
int metric(MetricRole) const;
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString path(PathRole) const;
|
2022-04-01 20:58:27 +03:00
|
|
|
SystemTheme const& theme() const { return *m_theme_buffer.data<SystemTheme>(); }
|
2019-12-29 00:47:49 +01:00
|
|
|
|
2024-06-02 20:26:56 +02:00
|
|
|
void replace_internal_buffer(Core::AnonymousBuffer);
|
2019-12-29 00:47:49 +01:00
|
|
|
|
|
|
|
|
private:
|
2021-01-16 17:20:53 +01:00
|
|
|
explicit PaletteImpl(Core::AnonymousBuffer);
|
2019-12-29 00:47:49 +01:00
|
|
|
|
2021-01-16 17:20:53 +01:00
|
|
|
Core::AnonymousBuffer m_theme_buffer;
|
2019-12-29 00:47:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Palette {
|
|
|
|
|
|
|
|
|
|
public:
|
2023-03-15 22:55:50 +01:00
|
|
|
explicit Palette(NonnullRefPtr<PaletteImpl>);
|
2022-02-06 23:10:42 +02:00
|
|
|
~Palette() = default;
|
2019-12-24 20:57:54 +01:00
|
|
|
|
2021-07-28 20:20:57 +02:00
|
|
|
Color accent() const { return color(ColorRole::Accent); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color window() const { return color(ColorRole::Window); }
|
|
|
|
|
Color window_text() const { return color(ColorRole::WindowText); }
|
|
|
|
|
Color selection() const { return color(ColorRole::Selection); }
|
|
|
|
|
Color selection_text() const { return color(ColorRole::SelectionText); }
|
2020-02-15 16:20:26 +01:00
|
|
|
Color inactive_selection() const { return color(ColorRole::InactiveSelection); }
|
|
|
|
|
Color inactive_selection_text() const { return color(ColorRole::InactiveSelectionText); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color desktop_background() const { return color(ColorRole::DesktopBackground); }
|
|
|
|
|
Color active_window_border1() const { return color(ColorRole::ActiveWindowBorder1); }
|
|
|
|
|
Color active_window_border2() const { return color(ColorRole::ActiveWindowBorder2); }
|
|
|
|
|
Color active_window_title() const { return color(ColorRole::ActiveWindowTitle); }
|
2020-08-01 13:09:18 -04:00
|
|
|
Color active_window_title_stripes() const { return color(ColorRole::ActiveWindowTitleStripes); }
|
|
|
|
|
Color active_window_title_shadow() const { return color(ColorRole::ActiveWindowTitleShadow); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color inactive_window_border1() const { return color(ColorRole::InactiveWindowBorder1); }
|
|
|
|
|
Color inactive_window_border2() const { return color(ColorRole::InactiveWindowBorder2); }
|
|
|
|
|
Color inactive_window_title() const { return color(ColorRole::InactiveWindowTitle); }
|
2020-08-01 13:09:18 -04:00
|
|
|
Color inactive_window_title_stripes() const { return color(ColorRole::InactiveWindowTitleStripes); }
|
|
|
|
|
Color inactive_window_title_shadow() const { return color(ColorRole::InactiveWindowTitleShadow); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color moving_window_border1() const { return color(ColorRole::MovingWindowBorder1); }
|
|
|
|
|
Color moving_window_border2() const { return color(ColorRole::MovingWindowBorder2); }
|
|
|
|
|
Color moving_window_title() const { return color(ColorRole::MovingWindowTitle); }
|
2020-08-01 13:09:18 -04:00
|
|
|
Color moving_window_title_stripes() const { return color(ColorRole::MovingWindowTitleStripes); }
|
|
|
|
|
Color moving_window_title_shadow() const { return color(ColorRole::MovingWindowTitleShadow); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color highlight_window_border1() const { return color(ColorRole::HighlightWindowBorder1); }
|
|
|
|
|
Color highlight_window_border2() const { return color(ColorRole::HighlightWindowBorder2); }
|
|
|
|
|
Color highlight_window_title() const { return color(ColorRole::HighlightWindowTitle); }
|
2020-08-01 13:09:18 -04:00
|
|
|
Color highlight_window_title_stripes() const { return color(ColorRole::HighlightWindowTitleStripes); }
|
|
|
|
|
Color highlight_window_title_shadow() const { return color(ColorRole::HighlightWindowTitleShadow); }
|
2020-10-20 10:02:23 -06:00
|
|
|
Color highlight_searching() const { return color(ColorRole::HighlightSearching); }
|
|
|
|
|
Color highlight_searching_text() const { return color(ColorRole::HighlightSearchingText); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color menu_stripe() const { return color(ColorRole::MenuStripe); }
|
|
|
|
|
Color menu_base() const { return color(ColorRole::MenuBase); }
|
2019-12-26 00:58:46 +01:00
|
|
|
Color menu_base_text() const { return color(ColorRole::MenuBaseText); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color menu_selection() const { return color(ColorRole::MenuSelection); }
|
2019-12-26 00:58:46 +01:00
|
|
|
Color menu_selection_text() const { return color(ColorRole::MenuSelectionText); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color base() const { return color(ColorRole::Base); }
|
2019-12-24 22:01:32 +01:00
|
|
|
Color base_text() const { return color(ColorRole::BaseText); }
|
2022-03-05 01:28:03 +01:00
|
|
|
Color disabled_text_front() const { return color(ColorRole::DisabledTextFront); }
|
|
|
|
|
Color disabled_text_back() const { return color(ColorRole::DisabledTextBack); }
|
2019-12-24 20:57:54 +01:00
|
|
|
Color button() const { return color(ColorRole::Button); }
|
|
|
|
|
Color button_text() const { return color(ColorRole::ButtonText); }
|
|
|
|
|
Color threed_highlight() const { return color(ColorRole::ThreedHighlight); }
|
|
|
|
|
Color threed_shadow1() const { return color(ColorRole::ThreedShadow1); }
|
|
|
|
|
Color threed_shadow2() const { return color(ColorRole::ThreedShadow2); }
|
2020-06-10 15:17:12 -04:00
|
|
|
Color hover_highlight() const { return color(ColorRole::HoverHighlight); }
|
2020-01-06 01:47:55 +02:00
|
|
|
Color rubber_band_fill() const { return color(ColorRole::RubberBandFill); }
|
|
|
|
|
Color rubber_band_border() const { return color(ColorRole::RubberBandBorder); }
|
2021-06-12 04:50:23 +03:00
|
|
|
Color gutter() const { return color(ColorRole::Gutter); }
|
2022-02-02 19:33:27 -05:00
|
|
|
Color gutter_border() const { return color(ColorRole::GutterBorder); }
|
2020-02-19 11:07:12 +01:00
|
|
|
Color ruler() const { return color(ColorRole::Ruler); }
|
|
|
|
|
Color ruler_border() const { return color(ColorRole::RulerBorder); }
|
|
|
|
|
Color ruler_active_text() const { return color(ColorRole::RulerActiveText); }
|
|
|
|
|
Color ruler_inactive_text() const { return color(ColorRole::RulerInactiveText); }
|
2020-02-20 09:01:48 +01:00
|
|
|
Color text_cursor() const { return color(ColorRole::TextCursor); }
|
2020-02-20 13:36:58 +01:00
|
|
|
Color focus_outline() const { return color(ColorRole::FocusOutline); }
|
2023-01-29 09:05:27 -05:00
|
|
|
Color tray() const { return color(ColorRole::Tray); }
|
|
|
|
|
Color tray_text() const { return color(ColorRole::TrayText); }
|
2019-12-24 20:57:54 +01:00
|
|
|
|
2020-01-13 20:33:15 +01:00
|
|
|
Color link() const { return color(ColorRole::Link); }
|
|
|
|
|
Color active_link() const { return color(ColorRole::ActiveLink); }
|
|
|
|
|
Color visited_link() const { return color(ColorRole::VisitedLink); }
|
|
|
|
|
|
2020-03-16 01:05:06 +02:00
|
|
|
Color syntax_comment() const { return color(ColorRole::SyntaxComment); }
|
|
|
|
|
Color syntax_number() const { return color(ColorRole::SyntaxNumber); }
|
|
|
|
|
Color syntax_string() const { return color(ColorRole::SyntaxString); }
|
|
|
|
|
Color syntax_identifier() const { return color(ColorRole::SyntaxIdentifier); }
|
|
|
|
|
Color syntax_type() const { return color(ColorRole::SyntaxType); }
|
|
|
|
|
Color syntax_punctuation() const { return color(ColorRole::SyntaxPunctuation); }
|
|
|
|
|
Color syntax_operator() const { return color(ColorRole::SyntaxOperator); }
|
|
|
|
|
Color syntax_keyword() const { return color(ColorRole::SyntaxKeyword); }
|
|
|
|
|
Color syntax_control_keyword() const { return color(ColorRole::SyntaxControlKeyword); }
|
|
|
|
|
Color syntax_preprocessor_statement() const { return color(ColorRole::SyntaxPreprocessorStatement); }
|
|
|
|
|
Color syntax_preprocessor_value() const { return color(ColorRole::SyntaxPreprocessorValue); }
|
2022-02-06 23:10:42 +02:00
|
|
|
Color syntax_function() const { return color(ColorRole::SyntaxFunction); }
|
|
|
|
|
Color syntax_variable() const { return color(ColorRole::SyntaxVariable); }
|
|
|
|
|
Color syntax_custom_type() const { return color(ColorRole::SyntaxCustomType); }
|
|
|
|
|
Color syntax_namespace() const { return color(ColorRole::SyntaxNamespace); }
|
|
|
|
|
Color syntax_member() const { return color(ColorRole::SyntaxMember); }
|
|
|
|
|
Color syntax_parameter() const { return color(ColorRole::SyntaxParameter); }
|
2020-03-16 01:05:06 +02:00
|
|
|
|
2022-12-02 18:15:28 +02:00
|
|
|
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); }
|
|
|
|
|
|
2022-01-01 18:26:19 +01:00
|
|
|
Gfx::TextAlignment title_alignment() const { return alignment(AlignmentRole::TitleAlignment); }
|
|
|
|
|
|
2022-12-02 18:15:28 +02:00
|
|
|
bool bold_text_as_bright() const { return flag(FlagRole::BoldTextAsBright); }
|
2021-10-26 14:30:52 +01:00
|
|
|
bool is_dark() const { return flag(FlagRole::IsDark); }
|
2022-04-23 15:23:22 +01:00
|
|
|
bool title_buttons_icon_only() const { return flag(FlagRole::TitleButtonsIconOnly); }
|
2021-10-26 14:30:52 +01:00
|
|
|
|
2021-12-28 22:44:12 +01:00
|
|
|
int window_border_thickness() const { return metric(MetricRole::BorderThickness); }
|
|
|
|
|
int window_border_radius() const { return metric(MetricRole::BorderRadius); }
|
2020-07-17 10:27:55 +10:00
|
|
|
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); }
|
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString title_button_icons_path() const { return path(PathRole::TitleButtonIcons); }
|
|
|
|
|
ByteString active_window_shadow_path() const { return path(PathRole::ActiveWindowShadow); }
|
|
|
|
|
ByteString inactive_window_shadow_path() const { return path(PathRole::InactiveWindowShadow); }
|
|
|
|
|
ByteString menu_shadow_path() const { return path(PathRole::MenuShadow); }
|
|
|
|
|
ByteString taskbar_shadow_path() const { return path(PathRole::TaskbarShadow); }
|
|
|
|
|
ByteString tooltip_shadow_path() const { return path(PathRole::TooltipShadow); }
|
|
|
|
|
ByteString color_scheme_path() const { return path(PathRole::ColorScheme); }
|
2020-07-29 16:09:04 -04:00
|
|
|
|
2019-12-29 00:47:49 +01:00
|
|
|
Color color(ColorRole role) const { return m_impl->color(role); }
|
2022-01-01 18:26:19 +01:00
|
|
|
Gfx::TextAlignment alignment(AlignmentRole role) const { return m_impl->alignment(role); }
|
2021-10-26 14:30:52 +01:00
|
|
|
bool flag(FlagRole role) const { return m_impl->flag(role); }
|
2020-07-17 10:27:55 +10:00
|
|
|
int metric(MetricRole role) const { return m_impl->metric(role); }
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString path(PathRole role) const { return m_impl->path(role); }
|
2020-01-06 01:47:55 +02:00
|
|
|
|
2019-12-29 00:47:49 +01:00
|
|
|
void set_color(ColorRole, Color);
|
2022-01-01 18:26:19 +01:00
|
|
|
void set_alignment(AlignmentRole, Gfx::TextAlignment);
|
2021-10-26 14:30:52 +01:00
|
|
|
void set_flag(FlagRole, bool);
|
2020-07-17 10:27:55 +10:00
|
|
|
void set_metric(MetricRole, int);
|
2023-12-16 17:49:34 +03:30
|
|
|
void set_path(PathRole, ByteString);
|
2019-12-24 20:57:54 +01:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
SystemTheme const& theme() const { return m_impl->theme(); }
|
2019-12-24 20:57:54 +01:00
|
|
|
|
2019-12-29 00:47:49 +01:00
|
|
|
PaletteImpl& impl() { return *m_impl; }
|
2022-04-01 20:58:27 +03:00
|
|
|
PaletteImpl const& impl() const { return *m_impl; }
|
2019-12-24 20:57:54 +01:00
|
|
|
|
|
|
|
|
private:
|
2019-12-29 00:47:49 +01:00
|
|
|
NonnullRefPtr<PaletteImpl> m_impl;
|
2019-12-24 20:57:54 +01:00
|
|
|
};
|
2020-02-06 11:56:38 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using Gfx::Palette;
|