LibGfx: Use an enumerator macro for color roles

This commit is contained in:
Andreas Kling 2020-08-21 19:51:17 +02:00
parent dfe8adde3f
commit 50076997f4
Notes: sideshowbarker 2024-07-19 03:20:37 +09:00
2 changed files with 91 additions and 129 deletions

View file

@ -98,72 +98,11 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
return &path[0];
};
#define DO_COLOR(x) \
data->color[(int)ColorRole::x] = get_color(#x)
DO_COLOR(DesktopBackground);
DO_COLOR(ThreedHighlight);
DO_COLOR(ThreedShadow1);
DO_COLOR(ThreedShadow2);
DO_COLOR(HoverHighlight);
DO_COLOR(Selection);
DO_COLOR(SelectionText);
DO_COLOR(InactiveSelection);
DO_COLOR(InactiveSelectionText);
DO_COLOR(Window);
DO_COLOR(WindowText);
DO_COLOR(Base);
DO_COLOR(BaseText);
DO_COLOR(Button);
DO_COLOR(ButtonText);
DO_COLOR(DesktopBackground);
DO_COLOR(ActiveWindowBorder1);
DO_COLOR(ActiveWindowBorder2);
DO_COLOR(ActiveWindowTitle);
DO_COLOR(ActiveWindowTitleShadow);
DO_COLOR(ActiveWindowTitleStripes);
DO_COLOR(InactiveWindowBorder1);
DO_COLOR(InactiveWindowBorder2);
DO_COLOR(InactiveWindowTitle);
DO_COLOR(InactiveWindowTitleShadow);
DO_COLOR(InactiveWindowTitleStripes);
DO_COLOR(MovingWindowBorder1);
DO_COLOR(MovingWindowBorder2);
DO_COLOR(MovingWindowTitle);
DO_COLOR(MovingWindowTitleShadow);
DO_COLOR(MovingWindowTitleStripes);
DO_COLOR(HighlightWindowBorder1);
DO_COLOR(HighlightWindowBorder2);
DO_COLOR(HighlightWindowTitle);
DO_COLOR(HighlightWindowTitleShadow);
DO_COLOR(HighlightWindowTitleStripes);
DO_COLOR(MenuStripe);
DO_COLOR(MenuBase);
DO_COLOR(MenuBaseText);
DO_COLOR(MenuSelection);
DO_COLOR(MenuSelectionText);
DO_COLOR(RubberBandFill);
DO_COLOR(RubberBandBorder);
DO_COLOR(Link);
DO_COLOR(ActiveLink);
DO_COLOR(VisitedLink);
DO_COLOR(Ruler);
DO_COLOR(RulerBorder);
DO_COLOR(RulerActiveText);
DO_COLOR(RulerInactiveText);
DO_COLOR(TextCursor);
DO_COLOR(FocusOutline);
DO_COLOR(SyntaxComment);
DO_COLOR(SyntaxNumber);
DO_COLOR(SyntaxString);
DO_COLOR(SyntaxType);
DO_COLOR(SyntaxPunctuation);
DO_COLOR(SyntaxOperator);
DO_COLOR(SyntaxKeyword);
DO_COLOR(SyntaxControlKeyword);
DO_COLOR(SyntaxIdentifier);
DO_COLOR(SyntaxPreprocessorStatement);
DO_COLOR(SyntaxPreprocessorValue);
#undef __ENUMERATE_COLOR_ROLE
#define __ENUMERATE_COLOR_ROLE(role) \
data->color[(int)ColorRole::role] = get_color(#role);
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
#undef __ENUMERATE_COLOR_ROLE
#define DO_METRIC(x) \
data->metric[(int)MetricRole::x] = get_metric(#x, (int)MetricRole::x)

View file

@ -33,77 +33,100 @@
namespace Gfx {
#define ENUMERATE_COLOR_ROLES(C) \
C(ActiveLink) \
C(ActiveWindowBorder1) \
C(ActiveWindowBorder2) \
C(ActiveWindowTitle) \
C(ActiveWindowTitleShadow) \
C(ActiveWindowTitleStripes) \
C(Base) \
C(BaseText) \
C(Button) \
C(ButtonText) \
C(DesktopBackground) \
C(FocusOutline) \
C(HighlightWindowBorder1) \
C(HighlightWindowBorder2) \
C(HighlightWindowTitle) \
C(HighlightWindowTitleShadow) \
C(HighlightWindowTitleStripes) \
C(HoverHighlight) \
C(InactiveSelection) \
C(InactiveSelectionText) \
C(InactiveWindowBorder1) \
C(InactiveWindowBorder2) \
C(InactiveWindowTitle) \
C(InactiveWindowTitleShadow) \
C(InactiveWindowTitleStripes) \
C(Link) \
C(MenuBase) \
C(MenuBaseText) \
C(MenuSelection) \
C(MenuSelectionText) \
C(MenuStripe) \
C(MovingWindowBorder1) \
C(MovingWindowBorder2) \
C(MovingWindowTitle) \
C(MovingWindowTitleShadow) \
C(MovingWindowTitleStripes) \
C(RubberBandBorder) \
C(RubberBandFill) \
C(Ruler) \
C(RulerActiveText) \
C(RulerBorder) \
C(RulerInactiveText) \
C(Selection) \
C(SelectionText) \
C(SyntaxComment) \
C(SyntaxControlKeyword) \
C(SyntaxIdentifier) \
C(SyntaxKeyword) \
C(SyntaxNumber) \
C(SyntaxOperator) \
C(SyntaxPreprocessorStatement) \
C(SyntaxPreprocessorValue) \
C(SyntaxPunctuation) \
C(SyntaxString) \
C(SyntaxType) \
C(TextCursor) \
C(ThreedHighlight) \
C(ThreedShadow1) \
C(ThreedShadow2) \
C(VisitedLink) \
C(Window) \
C(WindowText)
enum class ColorRole {
NoRole,
DesktopBackground,
ActiveWindowBorder1,
ActiveWindowBorder2,
ActiveWindowTitle,
ActiveWindowTitleShadow,
ActiveWindowTitleStripes,
InactiveWindowBorder1,
InactiveWindowBorder2,
InactiveWindowTitle,
InactiveWindowTitleShadow,
InactiveWindowTitleStripes,
MovingWindowBorder1,
MovingWindowBorder2,
MovingWindowTitle,
MovingWindowTitleShadow,
MovingWindowTitleStripes,
HighlightWindowBorder1,
HighlightWindowBorder2,
HighlightWindowTitle,
HighlightWindowTitleStripes,
HighlightWindowTitleShadow,
MenuStripe,
MenuBase,
MenuBaseText,
MenuSelection,
MenuSelectionText,
Window,
WindowText,
Button,
ButtonText,
Base,
BaseText,
ThreedHighlight,
ThreedShadow1,
ThreedShadow2,
HoverHighlight,
Selection,
SelectionText,
InactiveSelection,
InactiveSelectionText,
RubberBandFill,
RubberBandBorder,
Link,
ActiveLink,
VisitedLink,
Ruler,
RulerBorder,
RulerActiveText,
RulerInactiveText,
TextCursor,
FocusOutline,
SyntaxComment,
SyntaxNumber,
SyntaxString,
SyntaxType,
SyntaxPunctuation,
SyntaxOperator,
SyntaxKeyword,
SyntaxControlKeyword,
SyntaxIdentifier,
SyntaxPreprocessorStatement,
SyntaxPreprocessorValue,
__Count,
#undef __ENUMERATE_COLOR_ROLE
#define __ENUMERATE_COLOR_ROLE(role) role,
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
#undef __ENUMERATE_COLOR_ROLE
__Count,
Background = Window,
DisabledText = ThreedShadow1,
};
inline const char* to_string(ColorRole role)
{
switch (role) {
case ColorRole::NoRole:
return "NoRole";
#undef __ENUMERATE_COLOR_ROLE
#define __ENUMERATE_COLOR_ROLE(role) \
case ColorRole::role: \
return #role;
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
#undef __ENUMERATE_COLOR_ROLE
default:
ASSERT_NOT_REACHED();
}
}
enum class MetricRole {
NoRole,
TitleHeight,