libgui 2.01
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 int px = (int)strlen(letter) > 1 ? 11 : 14;
20 text = new GuiText(letter, px, GuiTheme::current().background);
21 text->setParent(this);
22 text->setAlignment(ALIGN_H::CENTRE, ALIGN_V::MIDDLE);
23 }
24}
25
26GuiGlyph::~GuiGlyph()
27{
28 delete text;
29}
30
32{
33 if(!this->isVisible())
34 return;
35
36 const int a = this->getAlpha();
37 if(a > 0)
38 {
39 VideoDriver * video = platform->getVideo();
40 const float uiScale = video->getUIScale();
41 const float feather = uiScale > 0.0f ? 1.0f / uiScale : 1.0f;
42 if(feather != meshFeather)
43 {
44 mesh = GuiMesh(feather);
45 GuiGlyph::build(mesh, kind, (float)width, (float)height);
46 meshFeather = feather;
47 }
48
49 const float ox = (float)this->getLeft(), oy = (float)this->getTop();
50 const std::vector<MeshVertex>& src = mesh.vertices();
51 scratch.resize(src.size());
52 for(size_t i = 0; i < src.size(); i++)
53 {
54 scratch[i] = src[i];
55 scratch[i].x += ox;
56 scratch[i].y += oy;
57 if(a < 255)
58 scratch[i].c.a = (uint8_t)((src[i].c.a * a + 127) / 255);
59 }
60 if(!scratch.empty())
61 video->getImageRenderer()->drawMesh(scratch.data(), scratch.size());
62
63 if(text)
64 text->draw();
65 }
66
67 this->updateEffects();
68}
69
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:268
int height
Element height.
Definition GuiElement.h:269
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:31
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.
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:71
@ 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
static GuiTheme & current()
The theme the rest of the library reads. Starts as the default dark theme.
Definition GuiTheme.cpp:35