4CST_Color Button::colors[2] = {
 
    5    { 0x00, 0x00, 0x00, 0xff }, 
 
    6    { 0xff, 0xff, 0xff, 0xff }, 
 
    9Button::Button(std::string message, 
int button, 
bool dark, 
int size, 
int width)
 
   12    , icon(getControllerButtonImageForPlatform(button, !dark, false))
 
   13    , text(message, (size / SCALER), &colors[dark])
 
   20    myLastSeenGamepad = 
"";
 
   22    icon.resize(text.height*1.5, text.height*1.5);
 
   24    if (shouldRenderGlossy()) {
 
   32    this->touchable = 
true;
 
   33    this->hasBackground = 
true;
 
   36    text.isProtected = icon.isProtected = 
true;
 
   40        backgroundColor = RootDisplay::mainDisplay->backgroundColor;
 
   41        backgroundColor.r += 0x25/255.0;
 
   42        backgroundColor.g += 0x25/255.0;
 
   43        backgroundColor.b += 0x25/255.0;
 
   47        backgroundColor = (
rgb){ 0xee/255.0, 0xee/255.0, 0xee/255.0 };
 
   50void Button::updateBounds()
 
   52    int PADDING = 10 / SCALER;
 
   54    int bWidth = PADDING * 0.5 * (icon.
width != 0); 
 
   56    if (shouldRenderGlossy()) {
 
   60        icon.
position(PADDING * 1.7, PADDING + (text.height - icon.height) / 2);
 
   63    this->width = (fixedWidth > 0) ? fixedWidth : text.
width + PADDING * 4 + bWidth + (icon.
hidden ? 0 : icon.
width);
 
   64    this->height = text.height + PADDING * 2;
 
   66    if (shouldRenderGlossy()) {
 
   71void Button::updateText(
const char* inc_text)
 
   73    this->text.setText(inc_text);
 
   78std::string Button::getControllerButtonImageForPlatform(
int button, 
bool isGray, 
bool isOutline)
 
   81    GamepadInfo& gamepad = InputEvents::getLastGamepadInfo();
 
   85    if (gamepad.buttons != 
nullptr) {
 
   86        for (
int i = 0; i < TOTAL_BUTTONS; i++)
 
   88            if (gamepad.buttons[i] == button)
 
   90                auto outlineSuffix = isOutline ? 
"_outline" : 
"";
 
   91                auto graySuffix = isGray ? 
"_gray" : 
"";
 
   92                auto retVal = RAMFS 
"res/controllers/buttons/" + gamepad.prefix + 
"_" + gamepad.names[i] + outlineSuffix + graySuffix + 
".svg";
 
   98    printf(
"Button %d not found in gamepad, returning empty string\n", button);
 
  106    CST_SetDrawBlend(RootDisplay::renderer, 
true);
 
  108    this->recalcPosition(
parent);
 
  110    if (shouldRenderGlossy()) {
 
  112        auto r = backgroundColor.r * 0xff;
 
  113        auto g = backgroundColor.g * 0xff;
 
  114        auto b = backgroundColor.b * 0xff;
 
  117            RootDisplay::renderer,
 
  118            xAbs, yAbs, xAbs + 
width, yAbs + height, cornerRadius,
 
  122        auto darkenOffset = dark ? 0x10 : 0x00; 
 
  124            RootDisplay::renderer,
 
  125            xAbs, yAbs + height / 2, xAbs + 
width, yAbs + height, cornerRadius,
 
  126            0x00, 0x00, 0x00, 0x15 + darkenOffset
 
  130        CST_roundedRectangleRGBA(
 
  131            RootDisplay::renderer,
 
  132            xAbs+2*p, yAbs+2*p, xAbs + 
width - p, yAbs + height - p, cornerRadius,
 
  133            0xff, 0xff, 0xff, 0x40
 
  136        CST_roundedRectangleRGBA(
 
  137            RootDisplay::renderer,
 
  138            xAbs, yAbs, xAbs + 
width, yAbs + height, cornerRadius,
 
  139            0x00, 0x00, 0x00, 0x80
 
  146    CST_SetDrawBlend(RootDisplay::renderer, 
false);
 
  151    if (event->isKeyDown() && this->physical != 0 && event->
held(this->physical))
 
  161    if (myLastSeenGamepad != InputEvents::lastGamepadKey)
 
  163        if (shouldRenderGlossy()) {
 
  165            hasBackground = 
false; 
 
  166            cornerRadius = fmin(25, height / 4); 
 
  168            auto newPath = getControllerButtonImageForPlatform(this->physical, !dark, 
false);
 
  170            hasBackground = 
true;
 
  172            icon.
resize(text.height*1.5, text.height*1.5);
 
  174        myLastSeenGamepad = InputEvents::lastGamepadKey;
 
  180const std::string Button::getText()
 
  182    return this->text.text;
 
  185bool Button::shouldRenderGlossy()
 
  191    return InputEvents::lastGamepadKey == 
"Wii Remote" || InputEvents::lastGamepadKey == 
"Wii Remote and Nunchuk";
 
virtual bool process(InputEvents *event)
process any input that is received for this element
 
bool hidden
whether this element should skip rendering or not
 
std::function< void()> action
the action to call (from binded callback) on touch or button selection https://stackoverflow....
 
virtual void render(Element *parent)
display the current state of the display
 
void position(int x, int y)
position the element
 
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
 
Element * parent
the parent element (can sometimes be null if it isn't set)
 
void update(bool forceUpdate=false)
update TextElement with changes
 
void resize(int w, int h)
Resizes the texture.
 
void loadPath(std::string &path, bool forceReload=false)
update and load or reload the texture