libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiControllerLayout.cpp
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiControllerLayout.cpp
5 ***************************************************************************/
6
7#include "GuiControllerLayout.h"
8
10{
11 if(id == 0)
12 return nullptr;
13 for(size_t i = 0; i < spots.size(); i++)
14 if(spots[i].id == id)
15 return &spots[i];
16 return nullptr;
17}
18
19static GuiControlSpot circle(int id, float cx, float cy, float d, const char * label)
20{
21 return GuiControlSpot{ id, CTL_SHAPE::CIRCLE, cx - d * 0.5f, cy - d * 0.5f, d, d, 0.0f, label };
22}
23
24static GuiControlSpot rrect(int id, float x, float y, float w, float h, float radius, const char * label)
25{
26 return GuiControlSpot{ id, CTL_SHAPE::ROUNDRECT, x, y, w, h, radius, label };
27}
28
29static GuiControlSpot stick(int id, float cx, float cy, float d)
30{
31 return GuiControlSpot{ id, CTL_SHAPE::STICK, cx - d * 0.5f, cy - d * 0.5f, d, d, 0.0f, nullptr };
32}
33
34static GuiControllerLayout buildPro()
35{
37 l.width = 400.0f;
38 l.height = 290.0f;
39
40 // silhouette: a wide body and two grips leaning outward
41 l.body.push_back(GuiBodyPiece{ 52.0f, 46.0f, 296.0f, 128.0f, 60.0f, 0.0f });
42 l.body.push_back(GuiBodyPiece{ 60.0f, 132.0f, 78.0f, 136.0f, 38.0f, 15.0f });
43 l.body.push_back(GuiBodyPiece{ 262.0f, 132.0f, 78.0f, 136.0f, 38.0f, -15.0f });
44
45 // shoulder buttons and triggers, stacked at the top corners
46 l.spots.push_back(rrect(INPUT_TRIGGER_ZL, 62.0f, 6.0f, 92.0f, 24.0f, 12.0f, "ZL"));
47 l.spots.push_back(rrect(INPUT_TRIGGER_L, 52.0f, 30.0f, 104.0f, 22.0f, 11.0f, "L"));
48 l.spots.push_back(rrect(INPUT_TRIGGER_ZR, 246.0f, 6.0f, 92.0f, 24.0f, 12.0f, "ZR"));
49 l.spots.push_back(rrect(INPUT_TRIGGER_R, 244.0f, 30.0f, 104.0f, 22.0f, 11.0f, "R"));
50
51 // small buttons between the sticks
52 l.spots.push_back(circle(INPUT_BTN_MINUS, 168.0f, 74.0f, 17.0f, "-"));
53 l.spots.push_back(circle(INPUT_BTN_PLUS, 232.0f, 74.0f, 17.0f, "+"));
54 l.spots.push_back(rrect(GUI_CTL_CAPTURE, 170.0f, 98.0f, 16.0f, 16.0f, 3.0f, nullptr));
55 l.spots.push_back(circle(INPUT_BTN_HOME, 222.0f, 106.0f, 17.0f, nullptr));
56
57 // sticks
58 l.spots.push_back(stick(INPUT_THUMB_L, 112.0f, 100.0f, 66.0f));
59 l.spots.push_back(stick(INPUT_THUMB_R, 252.0f, 152.0f, 66.0f));
60
61 // D-pad: four arms around a plate (the plate is decoration)
62 l.spots.push_back(rrect(0, 140.0f, 140.0f, 20.0f, 20.0f, 3.0f, nullptr));
63 l.spots.push_back(rrect(INPUT_BTN_UP, 140.0f, 118.0f, 20.0f, 25.0f, 4.0f, nullptr));
64 l.spots.push_back(rrect(INPUT_BTN_DOWN, 140.0f, 157.0f, 20.0f, 25.0f, 4.0f, nullptr));
65 l.spots.push_back(rrect(INPUT_BTN_LEFT, 118.0f, 140.0f, 25.0f, 20.0f, 4.0f, nullptr));
66 l.spots.push_back(rrect(INPUT_BTN_RIGHT, 157.0f, 140.0f, 25.0f, 20.0f, 4.0f, nullptr));
67
68 // face buttons
69 l.spots.push_back(circle(INPUT_BTN_X, 294.0f, 66.0f, 28.0f, "X"));
70 l.spots.push_back(circle(INPUT_BTN_Y, 266.0f, 94.0f, 28.0f, "Y"));
71 l.spots.push_back(circle(INPUT_BTN_A, 322.0f, 94.0f, 28.0f, "A"));
72 l.spots.push_back(circle(INPUT_BTN_B, 294.0f, 122.0f, 28.0f, "B"));
73 return l;
74}
75
77{
78 static const GuiControllerLayout layout = buildPro();
79 return layout;
80}
const GuiControllerLayout & GuiProControllerLayout()
A Pro-style gamepad: two sticks, D-pad, ABXY, L/R/ZL/ZR, plus, minus, home and capture (Switch Pro,...
@ CIRCLE
A round button.
@ 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.
One rounded rectangle of the silhouette (the pieces are merged into one outline).
One control on a controller drawing.
A controller: its drawing size, silhouette and controls.
const GuiControlSpot * find(int id) const
Finds a control by id (null if the layout has none)