libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiTheme.cpp
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiTheme.cpp
5 *
6 * No colors or numbers that make up a look live here: they come from the
7 * application's GuiThemeInit().
8 ***************************************************************************/
9
10#include <cstring>
11#include "GuiTheme.h"
12
13static PixelColor withAlpha(PixelColor c, uint8_t a)
14{
15 c.a = a;
16 return c;
17}
18
19// the ends the lighten/darken mixes run toward
20static const PixelColor WHITE = { 255, 255, 255, 255 };
21static const PixelColor BLACK = { 0, 0, 0, 255 };
22
24{
25 memset(this, 0, sizeof(*this));
26}
27
28static GuiTheme& makeCurrent()
29{
30 static GuiTheme theme;
31 GuiThemeInit(theme);
32 return theme;
33}
34
36{
37 static GuiTheme& theme = makeCurrent();
38 return theme;
39}
40
42{
43 return GuiShapeStyle(GuiPaint().color(surface).stroke(strokeWidth, outline));
44}
45
47{
48 GuiPaint rest = GuiPaint()
49 .gradient(surfaceRaised, surface)
50 .stroke(strokeWidth, outline)
51 .shadow(shadowBlur, shadow, 0.0f, shadowOffsetY);
52 GuiPaint lit = GuiPaint()
53 .gradient(surfaceRaised, surface)
54 .stroke(strokeWidth, accent)
55 .glow(shadowBlur + glowGrow, withAlpha(accent, focusGlowAlpha), glowGrow);
56 GuiPaint pressed = GuiPaint()
57 .gradient(surface, surfaceRaised)
58 .stroke(strokeWidth, accent)
59 .glow(shadowBlur, withAlpha(accent, pressGlowAlpha));
60 GuiPaint off = GuiPaint()
61 .color(withAlpha(surface, cardDisabledAlpha))
62 .stroke(strokeWidth, withAlpha(outline, cardDisabledAlpha));
63 return GuiShapeStyle(rest).onFocus(lit).onPress(pressed).onDisable(off);
64}
65
67{
68 const PixelColor litStroke = GuiMixColor(accentLight, WHITE, buttonStrokeLight);
69 GuiPaint rest = GuiPaint()
70 .gradient(outlineStrong, outline)
71 .stroke(strokeWidth, outlineStrong);
72 GuiPaint lit = GuiPaint()
73 .gradient(accentLight, accent)
74 .stroke(strokeWidth, litStroke)
75 .glow(buttonGlowBlur, withAlpha(accent, buttonGlowAlpha));
76 GuiPaint pressed = GuiPaint()
77 .gradient(accent, accentDark)
78 .stroke(strokeWidth, litStroke);
79 GuiPaint off = GuiPaint()
80 .color(withAlpha(surface, buttonDisabledAlpha))
81 .stroke(strokeWidth, withAlpha(outline, buttonDisabledAlpha));
82 return GuiShapeStyle(rest).onFocus(lit).onPress(pressed).onDisable(off);
83}
84
86{
87 return GuiShapeStyle(GuiPaint().color(outline));
88}
89
91{
92 GuiPaint lit = GuiPaint().color(highlight);
93 GuiPaint pressed = GuiPaint().color(withAlpha(accent, rowPressAlpha));
94 return GuiShapeStyle(GuiPaint()).onFocus(lit).onPress(pressed);
95}
96
98{
99 return GuiShapeStyle(GuiPaint().color(GuiMixColor(background, BLACK, barDarken)));
100}
void GuiThemeInit(GuiTheme &theme)
Fills in every color and metric of the theme.
PixelColor GuiMixColor(PixelColor a, PixelColor b, float t)
Blends two colors per channel (alpha included): t = 0 gives a, t = 1 gives b.
Definition GuiPaint.cpp:268
A set of paints, one per state. States left unset fall back to the normal paint. GuiShapeStyle(rest)....
Definition GuiPaint.h:84
Colors, metrics and the style recipes built from them.
Definition GuiTheme.h:21
GuiShapeStyle cardStyle() const
A raised card: gradient surface, outline, drop shadow; a glowing accent outline when focused.
Definition GuiTheme.cpp:46
uint8_t cardDisabledAlpha
Opacity of a disabled card.
Definition GuiTheme.h:62
float buttonGlowBlur
Softness of a focused button's glow.
Definition GuiTheme.h:59
PixelColor surface
Panels and resting cards.
Definition GuiTheme.h:24
PixelColor highlight
Selected row or list item (a light tint on a light theme).
Definition GuiTheme.h:36
uint8_t rowPressAlpha
Opacity of a pressed list row's accent tint.
Definition GuiTheme.h:61
GuiShapeStyle panelStyle() const
A quiet container: flat surface with a thin outline.
Definition GuiTheme.cpp:41
float buttonStrokeLight
How far (0..1) a focused or pressed button's outline is lightened toward white.
Definition GuiTheme.h:64
PixelColor outline
Quiet outlines.
Definition GuiTheme.h:26
uint8_t focusGlowAlpha
Peak opacity of a focused card's glow.
Definition GuiTheme.h:57
uint8_t pressGlowAlpha
Peak opacity of a pressed card's glow.
Definition GuiTheme.h:58
GuiShapeStyle chipStyle() const
A small label background (a "chip")
Definition GuiTheme.cpp:85
static GuiTheme & current()
The theme the rest of the library reads. The first call fills it in with GuiThemeInit().
Definition GuiTheme.cpp:35
float glowGrow
How much wider (blur and spread) a focused card's glow is than its shadow.
Definition GuiTheme.h:56
PixelColor accentLight
Light end of the focused-button gradient.
Definition GuiTheme.h:29
PixelColor accent
Highlight: focus outline, focused button.
Definition GuiTheme.h:28
float barDarken
How far (0..1) a bar's fill is darkened from the background toward black.
Definition GuiTheme.h:65
PixelColor shadow
Drop shadow of a resting card; its alpha is the peak opacity.
Definition GuiTheme.h:38
float strokeWidth
Outline width.
Definition GuiTheme.h:42
GuiShapeStyle buttonStyle() const
A capsule or rounded button: lights up in the accent color when focused, darkens when pressed.
Definition GuiTheme.cpp:66
PixelColor outlineStrong
Resting button outline and fill.
Definition GuiTheme.h:27
PixelColor surfaceRaised
Lighter end of a card's gradient, chips.
Definition GuiTheme.h:25
GuiShapeStyle barStyle() const
A dark strip for a hint or status bar.
Definition GuiTheme.cpp:97
GuiTheme()
Every field zero. Nothing here is a look: GuiThemeInit() provides it.
Definition GuiTheme.cpp:23
uint8_t buttonDisabledAlpha
Opacity of a disabled button.
Definition GuiTheme.h:63
PixelColor accentDark
Pressed-button fill.
Definition GuiTheme.h:30
GuiShapeStyle rowStyle() const
A flat list row: invisible at rest, a gray bar when focused, tinted when pressed.
Definition GuiTheme.cpp:90
PixelColor background
Screen background.
Definition GuiTheme.h:23
uint8_t buttonGlowAlpha
Peak opacity of a focused button's glow.
Definition GuiTheme.h:60
float shadowOffsetY
How far a resting card's shadow falls.
Definition GuiTheme.h:55
float shadowBlur
Softness of a resting card's shadow.
Definition GuiTheme.h:45
8-bit-per-channel RGBA color used by the video interfaces.
Definition Mesh.h:16
uint8_t a
Alpha component.
Definition Mesh.h:20