Plasma Engine  2.0
Loading...
Searching...
No Matches
ColorScheme.h
1#pragma once
2
3#include <Foundation/Math/Color.h>
4
10class PL_FOUNDATION_DLL plColorScheme
11{
12public:
13 enum Enum
14 {
15 Red,
16 Pink,
17 Grape,
18 Violet,
19 Indigo,
20 Blue,
21 Cyan,
22 Teal,
23 Green,
24 Lime,
25 Yellow,
26 Orange,
27 Gray,
28 PlasmaBranding,
29 Black,
30 Count
31 };
32
34 constexpr static float s_fIndexNormalizer = 1.0f / (Count - 2);
35
37 PL_FORCE_INLINE static plColor GetColor(Enum schemeColor, plUInt8 uiBrightness, float fSaturation = 1.0f, float fAlpha = 1.0f)
38 {
39 PL_ASSERT_DEV(uiBrightness <= 9, "Brightness is too large");
40 const plColor c = s_Colors[schemeColor][uiBrightness];
41 const float l = c.GetLuminance();
42 return plMath::Lerp(plColor(l, l, l), c, fSaturation).WithAlpha(fAlpha);
43 }
44
47 static plColor GetColor(float fIndex, plUInt8 uiBrightness, float fSaturation = 1.0f, float fAlpha = 1.0f);
48
50 PL_ALWAYS_INLINE static plColor DarkUI(Enum schemeColor)
51 {
52 return s_DarkUIColors[schemeColor];
53 }
54
56 PL_FORCE_INLINE static plColor DarkUI(float fIndex)
57 {
58 plUInt32 uiIndexA, uiIndexB;
59 float fFrac;
60 GetInterpolation(fIndex, uiIndexA, uiIndexB, fFrac);
61
62 return plMath::Lerp(s_DarkUIColors[uiIndexA], s_DarkUIColors[uiIndexB], fFrac);
63 }
64
66 PL_ALWAYS_INLINE static plColor LightUI(Enum schemeColor)
67 {
68 return s_LightUIColors[schemeColor];
69 }
70
72 PL_FORCE_INLINE static plColor LightUI(float fIndex)
73 {
74 plUInt32 uiIndexA, uiIndexB;
75 float fFrac;
76 GetInterpolation(fIndex, uiIndexA, uiIndexB, fFrac);
77
78 return plMath::Lerp(s_LightUIColors[uiIndexA], s_LightUIColors[uiIndexB], fFrac);
79 }
80
83 {
84 ViewportIcon, // shape icons in 3D viewport
85 MenuEntryIcon, // tint color for icons in a menu
86 SceneTreeIcon, // tint color for icons in a scene tree
87 OverlayIcon, // tint color for overlay icons on top of thumbnails (asset browser)
88 BorderColor, // color for a border frame around UI elements
89 BorderIconColor, // color for icons embedded in a border frame
90 AssetMenuIcon, // tint color for icons in asset browser menus
91 };
92
93 using CategoryColorFunc = plColor (*)(plStringView sCategory, CategoryColorUsage usage);
94
95 static CategoryColorFunc s_CategoryColorFunc;
96
108 static plColor GetCategoryColor(plStringView sCategory, CategoryColorUsage usage);
109
110private:
111 PL_ALWAYS_INLINE constexpr static void GetInterpolation(float fIndex, plUInt32& out_uiIndexA, plUInt32& out_uiIndexB, float& out_fFrac)
112 {
113 fIndex = plMath::Saturate(fIndex);
114
115 constexpr plUInt32 uiCountWithoutGray = Count - 1;
116 constexpr plUInt32 uiMaxIndex = uiCountWithoutGray - 1;
117 out_uiIndexA = plUInt32(fIndex * uiMaxIndex);
118 out_uiIndexB = (out_uiIndexA + 1) % uiCountWithoutGray;
119 out_fFrac = (fIndex * uiMaxIndex) - out_uiIndexA;
120 }
121
122 static plColor s_Colors[Count][10];
123 static plColor s_DarkUIColors[Count];
124 static plColor s_LightUIColors[Count];
125};
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
float GetLuminance() const
Computes the perceived luminance. Assumes linear color space (http://en.wikipedia....
Definition Color_inl.h:65
A color scheme based on https://github.com/yeun/open-color version 1.9.1.
Definition ColorScheme.h:11
static PL_ALWAYS_INLINE plColor DarkUI(Enum schemeColor)
Get a scheme color with predefined brightness and saturation to look good with the PL tools dark UI s...
Definition ColorScheme.h:50
static PL_FORCE_INLINE plColor LightUI(float fIndex)
Get a scheme color by index with predefined brightness and saturation to look good as highlight color...
Definition ColorScheme.h:72
static PL_ALWAYS_INLINE plColor LightUI(Enum schemeColor)
Get a scheme color with predefined brightness and saturation to look good as highlight color in PL to...
Definition ColorScheme.h:66
static PL_FORCE_INLINE plColor DarkUI(float fIndex)
Gets a scheme color by index with predefined brightness and saturation to look good with the PL tools...
Definition ColorScheme.h:56
static PL_FORCE_INLINE plColor GetColor(Enum schemeColor, plUInt8 uiBrightness, float fSaturation=1.0f, float fAlpha=1.0f)
Get the scheme color with the given brightness (0..9) and with optional saturation and alpha.
Definition ColorScheme.h:37
CategoryColorUsage
Definition ColorScheme.h:83
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
PL_FORCE_INLINE T Lerp(T f1, T f2, float fFactor)
Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1.
Definition Math_inl.h:230
constexpr PL_ALWAYS_INLINE T Saturate(T value)
Clamps "value" to the range [0; 1]. Returns "value", if it is inside the range already.
Definition Math_inl.h:57