void UiWidget::Render()

in agdk/agdktunnel/app/src/main/cpp/ui_scene.cpp [305:349]


void UiWidget::Render(TrivialShader *trivialShader, TextRenderer *textRenderer,
                      ShapeRenderer *shapeRenderer, int focus, float transitionFactor) {
    if (!mVisible) {
        // that was easy.
        return;
    }

    bool pulse = IsClickableButton() && (focus != FOCUS_NO);
    float factor = pulse ? SineWave(1.0f - PULSE_AMOUNT, 1.0f + PULSE_AMOUNT,
                                    PULSE_PERIOD, 0.0f) : 1.0f;
    const float *color = (mIsButton && focus == FOCUS_YES) ? BUTTON_FOCUS_COLOR :
                         (mIsButton && !mEnabled) ? BUTTON_DISABLED_COLOR : mTextColor;
    float borderSize = 0.0f;
    float x = mCenterX;
    float y = mCenterY;
    float w = mWidth;
    float h = mHeight;
    float fontScale = mFontScale;

    _apply_transition(mTransition, transitionFactor, &x, &y, &w, &h, &fontScale);

    // Note: right now, we don't support buttons that have borders AND are transparent.
    // They will be rendered incorrectly (the background will be the border color).

    if (mHasBorder || (focus == FOCUS_YES && !mTransparent)) {
        // draw border
        shapeRenderer->SetColor(color);
        shapeRenderer->RenderRect(x, y, w * factor, h * factor);
        borderSize = BUTTON_BORDER_SIZE;
    }

    // draw background
    if (mIsButton && !mTransparent) {
        shapeRenderer->SetColor(mBackColor);
        shapeRenderer->RenderRect(x, y, w * factor * (1.0f - borderSize),
                                  h * factor * (1.0f - borderSize));
    }

    // draw text
    if (mText) {
        textRenderer->SetColor(color);
        textRenderer->SetFontScale(fontScale * factor);
        textRenderer->RenderText(mText, x, y);
    }
}