void DrawBackground(UIContext &dc, float alpha = 1.0f) { static float xbase[100] = {0}; static float ybase[100] = {0}; float xres = dc.GetBounds().w; float yres = dc.GetBounds().h; static int last_xres = 0; static int last_yres = 0; if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) { GMRng rng; for (int i = 0; i < 100; i++) { xbase[i] = rng.F() * xres; ybase[i] = rng.F() * yres; } last_xres = xres; last_yres = yres; } #ifdef GOLD int img = I_BG_GOLD; #else int img = I_BG; #endif ui_draw2d.DrawImageStretch(img, dc.GetBounds()); float t = time_now(); for (int i = 0; i < 100; i++) { float x = xbase[i] + dc.GetBounds().x; float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f); float angle = sinf(i + t); int n = i & 3; ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f)); } }
void DrawGameBackground(UIContext &dc, const std::string &gamePath) { GameInfo *ginfo = g_gameInfoCache->GetInfo(dc.GetThin3DContext(), gamePath, GAMEINFO_WANTBG); dc.Flush(); if (ginfo) { bool hasPic = false; double loadTime; if (ginfo->pic1Texture) { dc.GetThin3DContext()->SetTexture(0, ginfo->pic1Texture); loadTime = ginfo->timePic1WasLoaded; hasPic = true; } else if (ginfo->pic0Texture) { dc.GetThin3DContext()->SetTexture(0, ginfo->pic0Texture); loadTime = ginfo->timePic0WasLoaded; hasPic = true; } if (hasPic) { uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3)) & 0xFFc0c0c0; dc.Draw()->DrawTexRect(dc.GetBounds(), 0,0,1,1, color); dc.Flush(); dc.RebindTexture(); } else { ::DrawBackground(dc, 1.0f); dc.RebindTexture(); dc.Flush(); } } }
void DrawDownloadsOverlay(UIContext &dc) { // Thin bar at the top of the screen like Chrome. std::vector<float> progress = g_DownloadManager.GetCurrentProgress(); if (progress.empty()) { return; } static const uint32_t colors[4] = { 0xFFFFFFFF, 0xFFCCCCCC, 0xFFAAAAAA, 0xFF777777, }; dc.Begin(); int h = 5; for (size_t i = 0; i < progress.size(); i++) { float barWidth = 10 + (dc.GetBounds().w - 10) * progress[i]; Bounds bounds(0, h * i, barWidth, h); UI::Drawable solid(colors[i & 3]); dc.FillRect(solid, bounds); } dc.End(); dc.Flush(); }
void DrawGameBackground(UIContext &dc, const std::string &gamePath) { std::shared_ptr<GameInfo> ginfo; if (gamePath.size()) ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath, GAMEINFO_WANTBG); dc.Flush(); bool hasPic = false; double loadTime; if (ginfo && ginfo->pic1.texture) { dc.GetDrawContext()->BindTexture(0, ginfo->pic1.texture->GetTexture()); loadTime = ginfo->pic1.timeLoaded; hasPic = true; } else if (ginfo && ginfo->pic0.texture) { dc.GetDrawContext()->BindTexture(0, ginfo->pic0.texture->GetTexture()); loadTime = ginfo->pic0.timeLoaded; hasPic = true; } if (hasPic) { uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3)) & 0xFFc0c0c0; dc.Draw()->DrawTexRect(dc.GetBounds(), 0,0,1,1, color); dc.Flush(); dc.RebindTexture(); } else { ::DrawBackground(dc, 1.0f); dc.RebindTexture(); dc.Flush(); } }
void DrawBackground(UIContext &dc, float alpha) { static float xbase[100] = {0}; static float ybase[100] = {0}; float xres = dc.GetBounds().w; float yres = dc.GetBounds().h; static int last_xres = 0; static int last_yres = 0; if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) { GMRng rng; for (int i = 0; i < 100; i++) { xbase[i] = rng.F() * xres; ybase[i] = rng.F() * yres; } last_xres = xres; last_yres = yres; } uint32_t bgColor = whiteAlpha(alpha); if (bgTexture != nullptr) { dc.Flush(); dc.GetDrawContext()->BindTexture(0, bgTexture->GetTexture()); dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, bgColor); dc.Flush(); dc.RebindTexture(); } else { ImageID img = I_BG; ui_draw2d.DrawImageStretch(img, dc.GetBounds(), bgColor); } float t = time_now(); for (int i = 0; i < 100; i++) { float x = xbase[i] + dc.GetBounds().x; float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f); float angle = sinf(i + t); int n = i & 3; ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f)); } }
void DrawBackground(UIContext &dc, float alpha = 1.0f) { static float xbase[100] = {0}; static float ybase[100] = {0}; float xres = dc.GetBounds().w; float yres = dc.GetBounds().h; static int last_xres = 0; static int last_yres = 0; if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) { GMRng rng; for (int i = 0; i < 100; i++) { xbase[i] = rng.F() * xres; ybase[i] = rng.F() * yres; } last_xres = xres; last_yres = yres; } glstate.depthWrite.set(GL_TRUE); glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(0.1f, 0.2f, 0.43f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); int img = I_BG; #ifdef GOLD img = I_BG_GOLD; #endif ui_draw2d.DrawImageStretch(img, dc.GetBounds()); float t = time_now(); for (int i = 0; i < 100; i++) { float x = xbase[i] + dc.GetBounds().x; float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f); float angle = sinf(i + t); int n = i & 3; ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f)); } }
void DrawProfile(UIContext &ui) { #ifdef USE_PROFILER int numCategories = Profiler_GetNumCategories(); int historyLength = Profiler_GetHistoryLength(); ui.SetFontStyle(ui.theme->uiFont); static float lastMaxVal = 1.0f / 60.0f; float legendMinVal = lastMaxVal * (1.0f / 120.0f); std::vector<float> history; std::vector<ProfileCatStatus> catStatus; history.resize(historyLength); catStatus.resize(numCategories); float rowH = 30.0f; float legendHeight = 0.0f; float legendWidth = 80.0f; for (int i = 0; i < numCategories; i++) { const char *name = Profiler_GetCategoryName(i); if (!strcmp(name, "timing")) { catStatus[i] = PROFILE_CAT_IGNORE; continue; } Profiler_GetHistory(i, &history[0], historyLength); catStatus[i] = PROFILE_CAT_NOLEGEND; for (int j = 0; j < historyLength; ++j) { if (history[j] > legendMinVal) { catStatus[i] = PROFILE_CAT_VISIBLE; break; } } // So they don't move horizontally, we always measure. float w = 0.0f, h = 0.0f; ui.MeasureText(ui.GetFontStyle(), name, &w, &h); if (w > legendWidth) { legendWidth = w; } legendHeight += rowH; } legendWidth += 20.0f; float legendStartY = legendHeight > ui.GetBounds().centerY() ? ui.GetBounds().y2() - legendHeight : ui.GetBounds().centerY(); float legendStartX = ui.GetBounds().x2() - std::min(legendWidth, 200.0f); const uint32_t opacity = 140 << 24; int legendNum = 0; for (int i = 0; i < numCategories; i++) { const char *name = Profiler_GetCategoryName(i); uint32_t color = nice_colors[i % ARRAY_SIZE(nice_colors)]; if (catStatus[i] == PROFILE_CAT_VISIBLE) { float y = legendStartY + legendNum++ * rowH; ui.FillRect(UI::Drawable(opacity | color), Bounds(legendStartX, y, rowH - 2, rowH - 2)); ui.DrawTextShadow(name, legendStartX + rowH + 2, y, 0xFFFFFFFF, ALIGN_VBASELINE); } } float graphWidth = ui.GetBounds().x2() - legendWidth - 20.0f; float graphHeight = ui.GetBounds().h * 0.8f; float dx = graphWidth / historyLength; /* ui.Flush(); ui.BeginNoTex(); */ bool area = true; float minVal = 0.0f; float maxVal = lastMaxVal; // TODO - adjust to frame length if (maxVal < 0.001f) maxVal = 0.001f; if (maxVal > 1.0f / 15.0f) maxVal = 1.0f / 15.0f; float scale = (graphHeight) / (maxVal - minVal); float y_60th = ui.GetBounds().y2() - 10 - (1.0f / 60.0f) * scale; float y_1ms = ui.GetBounds().y2() - 10 - (1.0f / 1000.0f) * scale; ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_60th, graphWidth, 2)); ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_1ms, graphWidth, 2)); ui.DrawTextShadow("1/60s", 5, y_60th, 0x80FFFF00); ui.DrawTextShadow("1ms", 5, y_1ms, 0x80FFFF00); std::vector<float> total; total.resize(historyLength); maxVal = 0.0f; float maxTotal = 0.0f; for (int i = 0; i < numCategories; i++) { if (catStatus[i] == PROFILE_CAT_IGNORE) { continue; } Profiler_GetHistory(i, &history[0], historyLength); float x = 10; uint32_t col = nice_colors[i % ARRAY_SIZE(nice_colors)]; if (area) col = opacity | (col & 0xFFFFFF); UI::Drawable color(col); UI::Drawable outline((opacity >> 1) | 0xFFFFFF); if (area) { for (int n = 0; n < historyLength; n++) { float val = history[n]; float valY1 = ui.GetBounds().y2() - 10 - (val + total[n]) * scale; float valY2 = ui.GetBounds().y2() - 10 - total[n] * scale; ui.FillRect(outline, Bounds(x, valY2, dx, 1.0f)); ui.FillRect(color, Bounds(x, valY1, dx, valY2 - valY1)); x += dx; total[n] += val; } } else { for (int n = 0; n < historyLength; n++) { float val = history[n]; if (val > maxVal) maxVal = val; float valY = ui.GetBounds().y2() - 10 - history[n] * scale; ui.FillRect(color, Bounds(x, valY, dx, 5)); x += dx; } } } for (int n = 0; n < historyLength; n++) { if (total[n] > maxTotal) maxTotal = total[n]; } if (area) { maxVal = maxTotal; } lastMaxVal = lastMaxVal * 0.95f + maxVal * 0.05f; #endif }