libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiPaint.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiPaint.h
5 *
6 * Platform-agnostic description of how a shape looks: fill, outline and
7 * shadow, plus the per-state sets a widget switches between (normal,
8 * focused, pressed, disabled). Paints are plain values that can be copied,
9 * compared and blended, which is what lets a highlight fade in instead of
10 * snapping.
11 ***************************************************************************/
12#pragma once
13#include "GuiGeometry.h"
14
17enum class SHAPE {
22 TRIANGLE_LEFT,
23 TRIANGLE_RIGHT
24};
25
30struct GuiPaint {
31 GuiFill fill;
32 bool hasFill;
33 GuiFill strokeFill;
34 float strokeWidth;
35 STROKE strokeAlign;
36 PixelColor shadowColor;
37 float shadowBlur;
38 float shadowSpread;
39 float shadowDx;
40 float shadowDy;
41
43 GuiPaint();
44
46 GuiPaint& color(PixelColor c);
48 GuiPaint& gradient(PixelColor from, PixelColor to, float angleDeg = 90.0f);
50 GuiPaint& stroke(float width, PixelColor c, STROKE align = STROKE::INSIDE);
52 GuiPaint& shadow(float blur, PixelColor c, float dx = 0.0f, float dy = 0.0f, float spread = 0.0f);
54 GuiPaint& glow(float blur, PixelColor c, float spread = 0.0f);
55
57 bool operator==(const GuiPaint& o) const;
58 bool operator!=(const GuiPaint& o) const { return !(*this == o); }
59
65 static GuiPaint mix(const GuiPaint& a, const GuiPaint& b, float t);
66};
67
71
74enum class SHAPE_STATE {
75 NORMAL,
77 PRESSED,
78 DISABLED
79};
80
84struct GuiShapeStyle {
85 GuiPaint normal;
86 GuiPaint focused;
87 GuiPaint pressed;
88 GuiPaint disabled;
89 bool hasFocused;
90 bool hasPressed;
91 bool hasDisabled;
92
93 GuiShapeStyle(const GuiPaint& normalPaint = GuiPaint());
94 GuiShapeStyle& onFocus(const GuiPaint& p);
95 GuiShapeStyle& onPress(const GuiPaint& p);
96 GuiShapeStyle& onDisable(const GuiPaint& p);
98 const GuiPaint& forState(SHAPE_STATE s) const;
99};
100
105void GuiAddPaintedShape(GuiMesh& mesh, SHAPE shape, const GuiRect& r, const GuiCorners& corners, const GuiPaint& paint);
Accumulates shapes as a triangle list of MeshVertex.
bool hasFill
The look of a shape: an optional fill, an optional outline and an optional shadow or glow.
Definition GuiPaint.h:32
STROKE
Where a stroke sits relative to the shape's geometric edge.
Definition GuiGeometry.h:58
SHAPE_STATE
The states a styled shape distinguishes.
Definition GuiPaint.h:74
void GuiAddPaintedShape(GuiMesh &mesh, SHAPE shape, const GuiRect &r, const GuiCorners &corners, const GuiPaint &paint)
Adds a painted shape to a mesh: shadow first, then fill, then outline.
Definition GuiPaint.cpp:218
SHAPE
Basic shape kinds a paint can be applied to.
Definition GuiPaint.h:17
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
@ INSIDE
Entirely inside the edge (the shape keeps its size)
Definition GuiGeometry.h:59
@ FOCUSED
Highlighted: under the cursor, or selected with the D-pad.
Definition GuiPaint.h:76
@ TRIANGLE_UP
A triangle pointing up, left or right, apex on the middle of one side and base along the opposite sid...
Definition GuiPaint.h:20
@ ELLIPSE
Ellipse inscribed in the rectangle (a circle when it is square)
Definition GuiPaint.h:19
@ TRIANGLE_DOWN
(scroll arrows, the tail of a popover).
Definition GuiPaint.h:21
@ RECTANGLE
Rectangle, with optional rounded corners (see GuiCorners)
Definition GuiPaint.h:18
Per-corner radii, in the order top-left, top-right, bottom-right, bottom-left.
Definition GuiGeometry.h:46
A solid color or a two-color linear gradient.
Definition GuiGeometry.h:66
An axis-aligned rectangle (top-left origin) in design-canvas pixels.
Definition GuiGeometry.h:33
const GuiPaint & forState(SHAPE_STATE s) const
Gets the paint for a state, falling back to normal when none was set.
Definition GuiPaint.cpp:207
8-bit-per-channel RGBA color used by the video interfaces.
Definition Mesh.h:16