MCPcopy Create free account
hub / github.com/android/ndk-samples / Render

Method Render

endless-tunnel/app/src/main/cpp/ui_scene.cpp:313–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313void UiWidget::Render(TrivialShader*, TextRenderer* textRenderer,
314 ShapeRenderer* shapeRenderer, int focus,
315 float transitionFactor) {
316 if (!mVisible) {
317 // that was easy.
318 return;
319 }
320
321 bool pulse = IsClickableButton() && (focus != FOCUS_NO);
322 float factor = pulse ? SineWave(1.0f - PULSE_AMOUNT, 1.0f + PULSE_AMOUNT,
323 PULSE_PERIOD, 0.0f)
324 : 1.0f;
325 const float* color = (mIsButton && focus == FOCUS_YES) ? BUTTON_FOCUS_COLOR
326 : (mIsButton && !mEnabled) ? BUTTON_DISABLED_COLOR
327 : mTextColor;
328 float borderSize = 0.0f;
329 float x = mCenterX;
330 float y = mCenterY;
331 float w = mWidth;
332 float h = mHeight;
333 float fontScale = mFontScale;
334
335 _apply_transition(mTransition, transitionFactor, &x, &y, &w, &h, &fontScale);
336
337 // Note: right now, we don't support buttons that have borders AND are
338 // transparent. They will be rendered incorrectly (the background will be the
339 // border color).
340
341 if (mHasBorder || (focus == FOCUS_YES && !mTransparent)) {
342 // draw border
343 shapeRenderer->SetColor(color);
344 shapeRenderer->RenderRect(x, y, w * factor, h * factor);
345 borderSize = BUTTON_BORDER_SIZE;
346 }
347
348 // draw background
349 if (mIsButton && !mTransparent) {
350 shapeRenderer->SetColor(mBackColor);
351 shapeRenderer->RenderRect(x, y, w * factor * (1.0f - borderSize),
352 h * factor * (1.0f - borderSize));
353 }
354
355 // draw text
356 if (mText) {
357 textRenderer->SetColor(color);
358 textRenderer->SetFontScale(fontScale * factor);
359 textRenderer->RenderText(mText, x, y);
360 }
361}
362
363void UiScene::OnCreateWidgets() {}

Callers 1

DoFrameMethod · 0.45

Calls 6

SineWaveFunction · 0.85
_apply_transitionFunction · 0.85
RenderRectMethod · 0.80
RenderTextMethod · 0.80
SetColorMethod · 0.45
SetFontScaleMethod · 0.45

Tested by

no test coverage detected