7#include "GuiControllerDraw.h"
11static PixelColor rgb(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
25 c.
r = (uint8_t)(c.
r + (255 - c.
r) * t);
26 c.
g = (uint8_t)(c.
g + (255 - c.
g) * t);
27 c.
b = (uint8_t)(c.
b + (255 - c.
b) * t);
34 const float outline = std::max(1.5f, 2.0f * scale);
38 std::vector<std::vector<GuiPoint> > pieces;
39 for(
size_t i = 0; i < layout.body.size(); i++)
42 GuiRect r = { b.x * scale, b.y * scale, b.w * scale, b.
h * scale };
47 for(
size_t i = 0; i < pieces.size(); i++)
52 for(
size_t i = 0; i < pieces.size(); i++)
56 for(
size_t i = 0; i < layout.spots.size(); i++)
57 if(layout.spots[i].id == 0)
64 const bool lit = state ==
CTL_STATE::LIT || state == CTL_STATE::LIT_HIGHLIGHT;
67 const float stroke = std::max(1.2f, 1.5f * scale);
68 GuiRect r = { spot.x * scale, spot.y * scale, spot.w * scale, spot.
h * scale };
75 edge = mixToWhite(theme.good, 0.35f);
80 const float edgeWidth = hl ? stroke * 1.8f : stroke;
83 const float blur = 8.0f * std::max(scale, 0.8f);
99 const float inset = r.
w * 0.11f;
100 GuiRect inner = { r.
x + inset, r.
y + inset, r.
w - 2.0f * inset, r.
h - 2.0f * inset };
109 const float d = spot.w * scale * 0.56f;
110 const float travel = (spot.w * scale - d) * 0.5f * 0.85f;
112 float dx = x, dy = y;
113 const float len = sqrtf(dx * dx + dy * dy);
119 const float cx = (spot.x + spot.w * 0.5f) * scale + dx * travel;
120 const float cy = (spot.y + spot.
h * 0.5f) * scale + dy * travel;
121 GuiRect r = { cx - d * 0.5f, cy - d * 0.5f, d, d };
123 const PixelColor fill = lit ? theme.good : theme.outline;
124 const PixelColor edge = lit ? mixToWhite(theme.good, 0.35f) : theme.outlineStrong;
Accumulates shapes as a triangle list of MeshVertex.
void addShadow(const GuiRect &r, const GuiCorners &corners, float blur, float spread, float dx, float dy, PixelColor color)
Adds a soft drop shadow or glow for a rounded rectangle.
void strokePolygon(const std::vector< GuiPoint > &pts, float width, STROKE align, const GuiFill &fill)
Adds a polygon outline with mitered corners (the miter is capped on very sharp corners).
void strokeEllipse(const GuiRect &r, float width, STROKE align, const GuiFill &fill)
Adds an ellipse outline.
void addRoundRect(const GuiRect &r, const GuiCorners &corners, const GuiFill &fill, bool edgeFringe=true)
Adds a filled rounded rectangle.
void addPolygon(const std::vector< GuiPoint > &pts, const GuiFill &fill, bool edgeFringe=true)
Adds a filled polygon (triangle, chevron, a controller silhouette, ...).
void strokeRoundRect(const GuiRect &r, const GuiCorners &corners, float width, STROKE align, const GuiFill &fill)
Adds a rounded-rectangle outline.
void addEllipse(const GuiRect &r, const GuiFill &fill, bool edgeFringe=true)
Adds a filled ellipse inscribed in a rectangle (a circle when w == h)
void GuiBuildControllerSpot(GuiMesh &mesh, const GuiControlSpot &spot, CTL_STATE state, float scale)
Builds one control in one state (an analog stick's cap is separate, see GuiBuildControllerStickCap).
void GuiBuildControllerBody(GuiMesh &mesh, const GuiControllerLayout &layout, float scale)
Builds the resting drawing of a controller (silhouette, then every decorative control) in local coord...
void GuiBuildControllerStickCap(GuiMesh &mesh, const GuiControlSpot &spot, float x, float y, bool lit, float scale)
Builds an analog stick's cap, displaced by (x, y) (each -1 to 1) from the middle of its ring.
CTL_STATE
The look a control is drawn in.
@ HIGHLIGHT
Being edited / pointed at.
@ ROUNDRECT
A rounded rectangle: bumpers, triggers, D-pad arms, small square buttons.
@ STICK
An analog stick: an outer ring with a cap that can move.
std::vector< GuiPoint > GuiRoundRectPolygon(const GuiRect &r, float radius, float angleDeg, float tolerance)
A rounded rectangle as a convex polygon, rotated about its center.
PixelColor GuiMixColor(PixelColor a, PixelColor b, float t)
Blends two colors per channel (alpha included): t = 0 gives a, t = 1 gives b.
@ INSIDE
Entirely inside the edge (the shape keeps its size)
@ OUTSIDE
Entirely outside the edge.
One rounded rectangle of the silhouette (the pieces are merged into one outline).
float angle
Rotation about its center, degrees clockwise.
float h
Rectangle before rotation.
One control on a controller drawing.
float radius
Corner radius for ROUNDRECT.
A controller: its drawing size, silhouette and controls.
Per-corner radii, in the order top-left, top-right, bottom-right, bottom-left.
A solid color or a two-color linear gradient.
static GuiFill linear(PixelColor a, PixelColor b, float angleDeg)
A linear gradient across the shape's bounding box.
static GuiFill solid(PixelColor c)
A single flat color.
An axis-aligned rectangle (top-left origin) in design-canvas pixels.
Colors, metrics and the style recipes built from them.
static GuiTheme & current()
The theme the rest of the library reads. Starts as the default dark theme.
8-bit-per-channel RGBA color used by the video interfaces.
uint8_t g
Green color component.
uint8_t r
Red color component.
uint8_t b
Blue color component.
uint8_t a
Alpha component.