void TextButton::SetActive(bool flag) { if (UIText) { if (flag) { NVBFTextSetString(UIText, ActiveText.c_str()); } else { NVBFTextSetString(UIText, InactiveText.c_str()); } } }
void UI::SetGamerUUID(const std::string& gamerUUID) { if (m_uiLabelFetch) { NVBFTextSetString(m_uiLabelFetch, gamerUUID.c_str()); } }
bool Engine::initUI() { if (m_uiInitialized) return true; m_uiModeTextures[MODE_STARTUP_SCREEN] = NvCreateTextureFromDDSEx("splash_screen.dds", 0, 0, NULL, NULL, NULL, NULL); m_uiModeTextures[MODE_AUTOPAUSE] = NvCreateTextureFromDDSEx("pause_screen.dds", 0, 0, NULL, NULL, NULL, NULL); m_uiModeTextures[MODE_QUIT_CONFIRM] = NvCreateTextureFromDDSEx("quit_screen.dds", 0, 0, NULL, NULL, NULL, NULL); mDrawRect = new NvDrawRect(); #define NUM_FONTS 1 static NvBool fontsSplit[NUM_FONTS] = {1}; /* all are split */ static const char *fontFiles[NUM_FONTS] = { "courier+lucida_256.dds"}; if (NVBFInitialize(NUM_FONTS, (const char**)fontFiles, fontsSplit, 0)) { LOGW("Could not initialize NvBitFont"); return false; } m_clockText = NVBFTextAlloc(); NVBFTextSetFont(m_clockText, 1); // should look up by font file name. NVBFTextSetSize(m_clockText, 32); NVBFTextSetColor(m_clockText, NV_PC_PREDEF_WHITE); NVBFTextSetString(m_clockText, "000:00.00"); m_uiInitialized = true; return true; }
void UI::SetupLabel(void** uiLabel, int font, int size, std::string text) { *uiLabel = NVBFTextAlloc(); NVBFTextSetFont(*uiLabel, font); NVBFTextSetSize(*uiLabel, size); NVBFTextSetColor(*uiLabel, NV_PC_PREDEF_WHITE); NVBFTextSetString(*uiLabel, text.c_str()); }
void UI::SetMessage(const std::string& message) { if (m_uiLabelMessage) { std::string text = "Message: "; text.append(message); NVBFTextSetString(m_uiLabelMessage, text.c_str()); } }
void UI::SetDirections() { if (m_selectedButton) { std::string text; if (std::find(m_products.begin(), m_products.end(), m_selectedButton) != m_products.end()) { text = "Select a product with the DPAD (up/down) | DPAD (right) Return to Purchase"; } else if (m_selectedButton == &m_uiRequestGamerUUID) { text = "Press (O): to fetch the gamer uuid | DPAD (left) Get Products | DPAD (down) Get Receipts"; } else if (m_selectedButton == &m_uiRequestProducts) { if (m_products.size() > 0) { text = "Press (O): Get products | DPAD (left) Select a product | DPAD (down) Purchase | DPAD (right) Fetch gamer uuid"; } else { text = "Press (O): Get products | DPAD (down) Purchase | DPAD (right) Fetch gamer uuid"; } } else if (m_selectedButton == &m_uiRequestPurchase) { if (m_products.size() > 0) { text = "Press (O): to purchase products | DPAD (left) Select a product | DPAD (up) Get products | DPAD (right) Get receipts"; } else { text = "DPAD (up) Get products | DPAD (right) Get receipts"; } } else if (m_selectedButton == &m_uiRequestReceipts) { text = "Press (O): to get receipts | DPAD (left) Purchase a product | DPAD (up) Fetch gamer uuid"; } else if (m_selectedButton == &m_uiPause) { text = "Pause detected | DPAD (up) Get receipts"; } else { return; } NVBFTextSetString(m_uiLabelDirections, text.c_str()); } }
bool Engine::renderFrame(bool allocateIfNeeded) { if (!mEgl.isReadyToRender(allocateIfNeeded)) return false; if (!initUI()) { LOGW("Could not initialize UI - assets may be missing!"); ANativeActivity_finish(mApp->activity); return false; } // We've gotten this far, so EGL is ready for us. Have we loaded our assets? // Note that we cannot use APP_STATUS_GLES_LOADED to imply that EGL is // ready to render. We can have a valid context with all GLES resources loaded // into it but no surface and thus the context not bound. These are semi- // independent states. if (!mGlobeApp) { if (!allocateIfNeeded) return false; mGlobeApp = new GlobeApp; } if (!mGlobeApp->isInitialized()) { if (!allocateIfNeeded) return false; // If we are initializing and we have a new, known size, set that // before the init resizeIfNeeded(); if (!mGlobeApp->init()) return false; } resizeIfNeeded(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mGlobeApp->render((float)mTimeVal); if (m_clockText) { NVBFTextRenderPrep(); NVBFTextRender(m_clockText); NVBFTextRenderDone(); int mins = mTimeVal / 60; float secs = (float)mTimeVal - mins*60; char str[32]; sprintf(str, "%03d:%05.2f", mins, secs); NVBFTextSetString(m_clockText, str); } // Render UI if needed if (m_uiModeTextures[mCurrentMode]) { int w = mEgl.getWidth(); int h = mEgl.getHeight(); mUIHalfSize = 300; mUICenterX = w/2; mUICenterY = h/2; NvDrawRect::setScreenResolution(w, h); static const float s_white[4] = {1.0f, 1.0f, 1.0f, 0.7f}; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); mDrawRect->draw(m_uiModeTextures[mCurrentMode], mUICenterX - mUIHalfSize, mUICenterY - mUIHalfSize, mUICenterX + mUIHalfSize, mUICenterY + mUIHalfSize, s_white); glDisable(GL_BLEND); } if (mForceRender > 0) mForceRender--; mEgl.swap(); // A debug printout every 256 frames so we can see when we're // actively rendering and swapping if (!(mSwapCount++ & 0x00ff)) { DEBUG("Swap count is %d", mSwapCount); } return true; }