libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiElement.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2009-2026
4 * GuiElement.h
5 ***************************************************************************/
6#pragma once
7
8#include <vector>
9#include <cstdint>
10
11#define MAX_TRIGGERS 5
12
13typedef void (*UpdateCallback)(void * e);
14
15class GuiTrigger;
16class InputController;
17
20enum class ALIGN_V {
21 TOP,
22 BOTTOM,
23 MIDDLE
24};
25
28enum class ALIGN_H {
29 LEFT,
30 RIGHT,
31 CENTRE
32};
33
36enum class STATE {
37 DEFAULT,
38 SELECTED,
39 CLICKED,
40 HELD,
41 DISABLED
42};
43
46enum EFFECT {
47 SLIDE_TOP = (1u << 0),
48 SLIDE_BOTTOM = (1u << 1),
49 SLIDE_RIGHT = (1u << 2),
50 SLIDE_LEFT = (1u << 3),
51 SLIDE_IN = (1u << 4),
52 SLIDE_OUT = (1u << 5),
53 FADE = (1u << 6),
54 SCALE = (1u << 7),
55 COLOR_TRANSITION = (1u << 8)
56};
57
61{
62 public:
64 GuiElement();
66 virtual ~GuiElement();
69 void setParent(GuiElement * e);
74 virtual void remove(GuiElement*) {}
76 void setRemoveOnDestroy(bool autoRemove) { removeOnDestroy = autoRemove; }
80 int getLeft();
84 int getTop();
87 void setMinY(int y);
90 int getMinY();
93 void setMaxY(int y);
96 int getMaxY();
99 void setMinX(int x);
102 int getMinX();
105 void setMaxX(int x);
108 int getMaxX();
111 int getWidth();
114 int getHeight();
118 void setSize(int w, int h);
121 bool isVisible();
124 bool isSelectable();
127 bool isClickable();
130 bool isHoldable();
133 void setSelectable(bool s);
136 void setClickable(bool c);
139 void setHoldable(bool h);
142 STATE getState();
145 int getStateChan();
148 void setAlpha(int a);
152 int getAlpha();
155 void setScale(float s);
158 void setScaleX(float s);
161 void setScaleY(float s);
165 void setScale(int w, int h);
168 float getScale();
171 float getScaleX();
174 float getScaleY();
177 void setTrigger(GuiTrigger * t);
181 void setTrigger(uint8_t i, GuiTrigger * t);
184 bool isRumble();
187 void setRumble(bool r);
192 void setEffect(int e, int a, int t=0);
197 void setEffectOnOver(int e, int a, int t=0);
199 void setEffectGrow();
202 int getEffect();
207 bool isInside(int x, int y);
211 void setPosition(int x, int y);
214 void updateEffects();
217 void setUpdateCallback(UpdateCallback u);
220 int isFocused();
223 virtual void setVisible(bool v);
226 virtual void setFocus(int f);
230 virtual void setState(STATE s, int c = -1);
232 virtual void resetState();
235 virtual int getSelected();
239 virtual void setAlignment(ALIGN_H hor, ALIGN_V vert);
243 virtual void getNaturalSize(int& w, int& h);
246 virtual void setLayoutPosition(int x, int y);
248 virtual void setLayoutSize(int w, int h);
251 virtual void layout();
254 virtual void collectNavigable(std::vector<GuiElement*>& out);
256 virtual void resetText();
259 virtual void update(InputController * c);
261 virtual void draw() = 0;
262 protected:
263 GuiTrigger * trigger[MAX_TRIGGERS];
264 UpdateCallback updateCB;
267 int focus;
268 int width;
269 int height;
272 int ymin;
273 int ymax;
274 int xmin;
275 int xmax;
278 int alpha;
280 float xscale;
281 float yscale;
282 float scaleDyn;
295 bool holdable;
296 bool visible;
297 bool rumble;
298};
void setEffect(int e, int a, int t=0)
Set an effect for the element.
bool isVisible()
Checks whether or not the element is visible.
int effectTarget
Effect target amount.
Definition GuiElement.h:285
void setMaxX(int x)
Sets the maximum x offset of the element.
void setEffectOnOver(int e, int a, int t=0)
Sets an effect to be enabled on wiimote cursor over.
float xscale
Element X scale (1 = 100%)
Definition GuiElement.h:280
int ymax
Element's max Y offset allowed.
Definition GuiElement.h:273
int alphaDyn
Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
Definition GuiElement.h:279
int getTop()
Gets the current topmost coordinate of the element Considers vertical alignment, y offset,...
int xmax
Element's max X offset allowed.
Definition GuiElement.h:275
virtual int getSelected()
Gets whether or not the element is in STATE::SELECTED.
int xmin
Element's min X offset allowed.
Definition GuiElement.h:274
float getScaleX()
Gets the element's current x scale Considers scale, scaleDyn, and the parent element's GetScale() val...
int isFocused()
Checks whether the element is in focus.
int effectAmount
Effect amount.
Definition GuiElement.h:284
int ymin
Element's min Y offset allowed.
Definition GuiElement.h:272
int alpha
Element alpha value (0-255)
Definition GuiElement.h:278
void setRemoveOnDestroy(bool autoRemove)
Whether to notify parent on destruction to allow removal.
Definition GuiElement.h:76
virtual void resetText()
Called when the language has changed, to obtain new text values for all text elements.
int getStateChan()
Gets the controller channel that last changed the element's state.
bool selectable
Whether or not this element selectable (can change to SELECTED state)
Definition GuiElement.h:293
void setClickable(bool c)
Sets whether or not the element is clickable.
STATE getState()
Gets the element's current state.
int yoffsetDyn
Element Y offset, dynamic (added to yoffset value for animation effects)
Definition GuiElement.h:277
int stateChan
Which controller channel is responsible for the last change in state.
Definition GuiElement.h:292
virtual void resetState()
Resets the element's state to STATE::DEFAULT.
int effectAmountOver
EffectAmount to set when wiimote cursor is over this element.
Definition GuiElement.h:287
void setTrigger(GuiTrigger *t)
Set a new GuiTrigger for the element.
int width
Element width.
Definition GuiElement.h:268
ALIGN_H alignmentHor
Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE)
Definition GuiElement.h:289
virtual void setState(STATE s, int c=-1)
Sets the element's state.
void setRumble(bool r)
Sets whether or not the element is requesting a rumble event.
float scaleDyn
Element scale, dynamic (multiplied by alpha value for blending/fading effects)
Definition GuiElement.h:282
int effectsOver
Effects to enable when wiimote cursor is over this element.
Definition GuiElement.h:286
UpdateCallback updateCB
Callback function to call when this element is updated.
Definition GuiElement.h:264
int effects
Currently enabled effect(s).
Definition GuiElement.h:283
virtual void setFocus(int f)
Sets the element's focus.
void setMaxY(int y)
Sets the maximum y offset of the element.
int height
Element height.
Definition GuiElement.h:269
bool holdable
Whether or not this element is holdable (can change to HELD state)
Definition GuiElement.h:295
bool clickable
Whether or not this element is clickable (can change to CLICKED state)
Definition GuiElement.h:294
bool isClickable()
Checks whether or not the element is clickable.
GuiElement * parentElement
Parent element.
Definition GuiElement.h:265
float getScaleY()
Gets the element's current y scale Considers scale, scaleDyn, and the parent element's GetScale() val...
virtual void setVisible(bool v)
Sets the element's visibility.
bool isRumble()
Checks whether rumble was requested by the element.
void updateEffects()
Updates the element's effects (dynamic values) Called by Draw(), used for animation purposes.
virtual void update(InputController *c)
Called constantly to allow the element to respond to the current input data.
int getEffect()
Gets the current element effects.
GuiTrigger * trigger[MAX_TRIGGERS]
GuiTriggers (input actions) that this element responds to.
Definition GuiElement.h:263
void setSize(int w, int h)
Sets the size (width/height) of the element.
int getWidth()
Gets the current width of the element.
bool rumble
Wiimote rumble (on/off) - set to on when this element requests a rumble event.
Definition GuiElement.h:297
GuiElement * getParent()
Gets the element's parent.
void setAlpha(int a)
Sets the element's alpha value.
GuiElement()
Constructor.
Definition GuiElement.cpp:9
bool visible
Visibility of the element.
Definition GuiElement.h:296
virtual void layout()
Brings the element's own layout up to date.
int getLeft()
Gets the current leftmost coordinate of the element Considers horizontal alignment,...
void setMinX(int x)
Sets the minimum x offset of the element.
void setScaleX(float s)
Sets the element's x scale.
virtual void setLayoutPosition(int x, int y)
Places the element so its top-left corner is at (x, y) relative to its parent's top-left (default: LE...
ALIGN_V alignmentVert
Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE)
Definition GuiElement.h:290
int getMaxY()
Gets the maximum y offset of the element.
void setParent(GuiElement *e)
Set the element's parent.
virtual void draw()=0
Called constantly to redraw the element.
int focus
Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
Definition GuiElement.h:267
int getMinX()
Gets the minimum x offset of the element.
void setScale(float s)
Sets the element's x and y scale.
int getMaxX()
Gets the maximum x offset of the element.
float yscale
Element Y scale (1 = 100%)
Definition GuiElement.h:281
int yoffset
Element Y offset.
Definition GuiElement.h:271
void setMinY(int y)
Sets the minimum y offset of the element.
int effectTargetOver
EffectTarget to set when wiimote cursor is over this element.
Definition GuiElement.h:288
STATE state
Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
Definition GuiElement.h:291
bool isInside(int x, int y)
Checks whether the specified coordinates are within the element's boundaries.
int getMinY()
Gets the minimum y offset of the element.
virtual void remove(GuiElement *)
Removes the specified child.
Definition GuiElement.h:74
bool isSelectable()
Checks whether or not the element is selectable.
int xoffsetDyn
Element X offset, dynamic (added to xoffset value for animation effects)
Definition GuiElement.h:276
void setHoldable(bool h)
Sets whether or not the element is holdable.
bool removeOnDestroy
Whether to instruct parent to remove this element when it is destroyed.
Definition GuiElement.h:266
void setUpdateCallback(UpdateCallback u)
Sets a function to called after after Update() Callback function can be used to response to changes i...
void setPosition(int x, int y)
Sets the element's position.
float getScale()
Gets the element's current scale Considers scale, scaleDyn, and the parent element's GetScale() value...
bool isHoldable()
Checks whether or not the element is holdable.
virtual void collectNavigable(std::vector< GuiElement * > &out)
Appends the elements that selection can move between (default: this element; layout containers add th...
virtual ~GuiElement()
Destructor.
void setEffectGrow()
Shortcut to SetEffectOnOver(EFFECT::SCALE, 4, 110)
virtual void setLayoutSize(int w, int h)
Gives the element a size chosen by a container (default: sets width and height)
void setSelectable(bool s)
Sets whether or not the element is selectable.
virtual void getNaturalSize(int &w, int &h)
Layout protocol: how a layout container (GuiRow, GuiColumn, GuiGrid, GuiOverlay) asks about and arran...
int getHeight()
Gets the height of the element.
void setScaleY(float s)
Sets the element's y scale.
int getAlpha()
Gets the element's alpha value Considers alpha, alphaDyn, and the parent element's GetAlpha() value.
virtual void setAlignment(ALIGN_H hor, ALIGN_V vert)
Sets the element's alignment respective to its parent element.
int xoffset
Element X offset.
Definition GuiElement.h:270
Input-condition matcher attached to a GuiElement (via setSimpleTrigger() etc.) and evaluated against ...
Definition GuiTrigger.h:34
Logical controller for one input channel.
STATE
Interaction state of a GuiElement (default, selected, clicked, held, disabled).
Definition GuiElement.h:36
EFFECT
Bitmask of transition effects (slide, fade, scale, color) applied to a GuiElement.
Definition GuiElement.h:46
ALIGN_V
Vertical alignment of a GuiElement relative to its parent.
Definition GuiElement.h:20
ALIGN_H
Horizontal alignment of a GuiElement relative to its parent.
Definition GuiElement.h:28