libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiGlyph.cpp
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiGlyph.cpp
5 ***************************************************************************/
6
7#include "Gui.h"
8
9GuiGlyph::GuiGlyph(GLYPH k, const char * letter) : kind(k), text(nullptr), meshFeather(-1.0f)
10{
11 float w, h;
12 GuiGlyph::size(kind, w, h);
13 width = (int)w;
14 height = (int)h;
15
16 const bool takesLetter = kind == GLYPH::BUTTON || kind == GLYPH::BUMPER || kind == GLYPH::STICK;
17 if(takesLetter && letter && *letter)
18 {
19 const GuiTheme& theme = GuiTheme::current();
20 const int px = (int)strlen(letter) > 1 ? theme.glyphFontSizeSmall : theme.glyphFontSize;
21 text = new GuiText(letter, px, theme.textInverse);
22 text->setParent(this);
23 text->setAlignment(ALIGN_H::CENTRE, ALIGN_V::MIDDLE);
24 // capitals and digits have no descenders, so the font's line box centers them high; this puts the same
25 // padding above the letter as below it
26 // (the bumper pill is shorter than the round glyphs, so its single letter takes one less)
27 text->setNudgeY(kind == GLYPH::BUMPER && px == theme.glyphFontSize ? 1 : 2);
28 }
29}
30
31GuiGlyph::~GuiGlyph()
32{
33 delete text;
34}
35
37{
38 if(!this->isVisible())
39 return;
40
41 const int a = this->getAlpha();
42 if(a > 0)
43 {
44 VideoDriver * video = platform->getVideo();
45 const float uiScale = video->getUIScale();
46 const float feather = uiScale > 0.0f ? 1.0f / uiScale : 1.0f;
47 if(feather != meshFeather)
48 {
49 mesh = GuiMesh(feather);
50 GuiGlyph::build(mesh, kind, (float)width, (float)height);
51 meshFeather = feather;
52 }
53
54 const float ox = (float)this->getLeft(), oy = (float)this->getTop();
55 const std::vector<MeshVertex>& src = mesh.vertices();
56 scratch.resize(src.size());
57 for(size_t i = 0; i < src.size(); i++)
58 {
59 scratch[i] = src[i];
60 scratch[i].x += ox;
61 scratch[i].y += oy;
62 if(a < 255)
63 scratch[i].c.a = (uint8_t)((src[i].c.a * a + 127) / 255);
64 }
65 if(!scratch.empty())
66 video->getImageRenderer()->drawMesh(scratch.data(), scratch.size());
67
68 if(text)
69 text->draw();
70 }
71
72 this->updateEffects();
73}
74
Umbrella header for the platform-agnostic libgui core.
bool isVisible()
Checks whether or not the element is visible.
int getTop()
Gets the current topmost coordinate of the element Considers vertical alignment, y offset,...
int width
Element width.
Definition GuiElement.h:273
int height
Element height.
Definition GuiElement.h:274
void updateEffects()
Updates the element's effects (dynamic values) Called by Draw(), used for animation purposes.
int getLeft()
Gets the current leftmost coordinate of the element Considers horizontal alignment,...
int getAlpha()
Gets the element's alpha value Considers alpha, alphaDyn, and the parent element's GetAlpha() value.
GuiGlyph(GLYPH kind, const char *letter="")
Definition GuiGlyph.cpp:9
void draw() override
Called constantly to redraw the element.
Definition GuiGlyph.cpp:36
Accumulates shapes as a triangle list of MeshVertex.
Display, manage, and manipulate text in the GUI.
Definition GuiText.h:10
virtual void drawMesh(const MeshVertex *vertices, size_t count)=0
Draws a triangle list: three vertices per triangle, each with its own color.
Platform video backend owning the frame lifecycle (init/render/clear, screen size,...
Definition VideoDriver.h:28
virtual ImageRenderer * getImageRenderer()=0
virtual float getUIScale() const
Ratio of physical render-target pixels to design-canvas pixels (the width/height passed to init()).
Definition VideoDriver.h:58
static void size(GLYPH kind, float &w, float &h)
Gets the natural size of a glyph, from the theme (glyphSize, glyphBumperWidth, glyphBumperHeight).
Definition GuiGlyph.h:62
GLYPH
Small control icons for lists and hints (the "A" in a circle, a bumper, a D-pad arrow).
Definition GuiGlyph.h:17
static void build(GuiMesh &mesh, GLYPH kind, float w, float h)
Builds a glyph filling a w x h box at the origin, in the theme's light-on-dark colors.
Definition GuiGlyph.h:72
@ BUMPER
A light rounded rectangle (L, R, ZL, ZR)
Definition GuiGlyph.h:19
@ BUTTON
A light circle (face buttons; the letter goes on it)
Definition GuiGlyph.h:18
@ STICK
A circle with an inner ring (stick click; the letter goes on it)
Definition GuiGlyph.h:26
Colors, metrics and the style recipes built from them.
Definition GuiTheme.h:21
static GuiTheme & current()
The theme the rest of the library reads. The first call fills it in with GuiThemeInit().
Definition GuiTheme.cpp:35