2020-09-15 19:12:32 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-15 19:12:32 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// Window.cpp
|
|
|
|
//
|
2020-11-11 23:46:59 +00:00
|
|
|
// Window management, screensaver management, and help prompts.
|
2020-09-15 19:12:32 +00:00
|
|
|
// The input stack starts here as well, as this is the first instance called by InputManager.
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
#include "Window.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2014-01-25 23:34:29 +00:00
|
|
|
#include "components/HelpComponent.h"
|
2014-03-04 22:48:33 +00:00
|
|
|
#include "components/ImageComponent.h"
|
2021-03-22 17:12:25 +00:00
|
|
|
#include "components/VideoVlcComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "resources/Font.h"
|
2020-11-12 16:13:24 +00:00
|
|
|
#include "Sound.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "InputManager.h"
|
|
|
|
#include "Log.h"
|
2018-01-30 00:49:08 +00:00
|
|
|
#include "Scripting.h"
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <algorithm>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <iomanip>
|
2013-04-08 14:41:25 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Window::Window()
|
2020-11-10 21:33:57 +00:00
|
|
|
: mScreensaver(nullptr),
|
2020-09-17 20:00:07 +00:00
|
|
|
mInfoPopup(nullptr),
|
|
|
|
mNormalizeNextUpdate(false),
|
2020-06-21 12:25:28 +00:00
|
|
|
mFrameTimeElapsed(0),
|
|
|
|
mFrameCountElapsed(0),
|
|
|
|
mAverageDeltaTime(10),
|
|
|
|
mAllowSleep(true),
|
|
|
|
mSleeping(false),
|
|
|
|
mTimeSinceLastInput(0),
|
2020-11-10 21:33:57 +00:00
|
|
|
mRenderScreensaver(false),
|
2020-07-18 21:07:02 +00:00
|
|
|
mGameLaunchedState(false),
|
2020-09-17 20:00:07 +00:00
|
|
|
mAllowTextScrolling(true),
|
2020-09-13 11:21:38 +00:00
|
|
|
mCachedBackground(false),
|
2020-11-11 23:46:59 +00:00
|
|
|
mInvalidatedCachedBackground(false),
|
2020-09-13 11:21:38 +00:00
|
|
|
mTopOpacity(0),
|
2021-01-12 21:41:28 +00:00
|
|
|
mTopScale(0.5),
|
|
|
|
mListScrollOpacity(0)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mHelp = new HelpComponent(this);
|
|
|
|
mBackgroundOverlay = new ImageComponent(this);
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
delete mBackgroundOverlay;
|
2013-12-12 19:48:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Delete all our GUIs.
|
|
|
|
while (peekGui())
|
|
|
|
delete peekGui();
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2020-10-11 07:59:49 +00:00
|
|
|
if (mInfoPopup)
|
|
|
|
delete mInfoPopup;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
delete mHelp;
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void Window::pushGui(GuiComponent* gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mGuiStack.size() > 0) {
|
|
|
|
auto& top = mGuiStack.back();
|
|
|
|
top->topWindow(false);
|
|
|
|
}
|
|
|
|
mGuiStack.push_back(gui);
|
|
|
|
gui->updateHelpPrompts();
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void Window::removeGui(GuiComponent* gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++) {
|
|
|
|
if (*it == gui) {
|
|
|
|
it = mGuiStack.erase(it);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// We just popped the stack and the stack is not empty.
|
2020-07-18 11:21:44 +00:00
|
|
|
if (it == mGuiStack.cend() && mGuiStack.size()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
mGuiStack.back()->updateHelpPrompts();
|
|
|
|
mGuiStack.back()->topWindow(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
GuiComponent* Window::peekGui()
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mGuiStack.size() == 0)
|
|
|
|
return nullptr;
|
2013-04-08 14:41:25 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return mGuiStack.back();
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 17:42:27 +00:00
|
|
|
bool Window::init()
|
2013-04-08 17:40:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Renderer::init()) {
|
2020-08-30 20:25:38 +00:00
|
|
|
LOG(LogError) << "Renderer failed to initialize.";
|
2020-06-21 12:25:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
InputManager::getInstance()->init();
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
ResourceManager::getInstance()->reloadAll();
|
2013-04-10 17:29:07 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Keep a reference to the default fonts, so they don't keep getting destroyed/recreated.
|
|
|
|
if (mDefaultFonts.empty()) {
|
|
|
|
mDefaultFonts.push_back(Font::get(FONT_SIZE_SMALL));
|
|
|
|
mDefaultFonts.push_back(Font::get(FONT_SIZE_MEDIUM));
|
|
|
|
mDefaultFonts.push_back(Font::get(FONT_SIZE_LARGE));
|
|
|
|
}
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2021-01-12 22:10:06 +00:00
|
|
|
mBackgroundOverlay->setImage(":/graphics/screen_gradient.png");
|
2020-09-17 20:00:07 +00:00
|
|
|
mBackgroundOverlay->setResize(static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()));
|
2014-03-04 22:48:33 +00:00
|
|
|
|
2021-01-12 21:41:28 +00:00
|
|
|
mListScrollFont = Font::get(FONT_SIZE_LARGE);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Update our help because font sizes probably changed.
|
|
|
|
if (peekGui())
|
|
|
|
peekGui()->updateHelpPrompts();
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
2013-04-08 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::deinit()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Hide all GUI elements on uninitialisation - this disable.
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onHide();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
InputManager::getInstance()->deinit();
|
|
|
|
ResourceManager::getInstance()->unloadAll();
|
2021-03-22 17:12:25 +00:00
|
|
|
VideoVlcComponent::deinit();
|
2020-06-21 12:25:28 +00:00
|
|
|
Renderer::deinit();
|
2013-04-08 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 22:59:00 +00:00
|
|
|
void Window::textInput(const std::string& text)
|
2014-04-18 18:07:32 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (peekGui())
|
|
|
|
peekGui()->textInput(text);
|
2014-04-18 18:07:32 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void Window::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-09-18 16:40:22 +00:00
|
|
|
mTimeSinceLastInput = 0;
|
|
|
|
|
2020-09-15 19:12:32 +00:00
|
|
|
if (Settings::getInstance()->getBool("Debug"))
|
|
|
|
logInput(config, input);
|
|
|
|
|
2020-11-10 21:33:57 +00:00
|
|
|
if (mScreensaver) {
|
|
|
|
if (mScreensaver->isScreensaverActive() &&
|
2020-11-05 17:18:11 +00:00
|
|
|
Settings::getInstance()->getBool("ScreensaverControls") &&
|
2020-11-10 21:18:20 +00:00
|
|
|
((Settings::getInstance()->getString("ScreensaverType") == "video") ||
|
|
|
|
(Settings::getInstance()->getString("ScreensaverType") == "slideshow"))) {
|
|
|
|
bool customImageSlideshow = false;
|
|
|
|
if (Settings::getInstance()->getString("ScreensaverType") == "slideshow" &&
|
|
|
|
Settings::getInstance()->getBool("ScreensaverSlideshowCustomImages"))
|
|
|
|
customImageSlideshow = true;
|
|
|
|
|
2020-11-10 21:42:25 +00:00
|
|
|
if ((customImageSlideshow || mScreensaver->getCurrentGame() != nullptr) &&
|
2020-11-12 16:13:24 +00:00
|
|
|
(config->isMappedTo("a", input) || config->isMappedTo("y", input) ||
|
2020-07-27 14:53:54 +00:00
|
|
|
config->isMappedLike("left", input) || config->isMappedLike("right", input))) {
|
|
|
|
// Left or right browses to the next video or image.
|
|
|
|
if (config->isMappedLike("left", input) || config->isMappedLike("right", input)) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (input.value != 0) {
|
|
|
|
// Handle screensaver control.
|
2020-11-10 21:33:57 +00:00
|
|
|
mScreensaver->nextGame();
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 14:53:54 +00:00
|
|
|
else if (config->isMappedTo("a", input) && input.value != 0) {
|
2020-07-14 17:16:21 +00:00
|
|
|
// Launch game.
|
2020-11-12 16:13:24 +00:00
|
|
|
stopScreensaver();
|
2020-11-10 21:33:57 +00:00
|
|
|
mScreensaver->launchGame();
|
2020-06-21 12:25:28 +00:00
|
|
|
// To force handling the wake up process.
|
|
|
|
mSleeping = true;
|
|
|
|
}
|
2020-11-12 16:13:24 +00:00
|
|
|
else if (config->isMappedTo("y", input) && input.value != 0) {
|
|
|
|
// Jump to the game in its gamelist, but do not launch it.
|
|
|
|
stopScreensaver();
|
|
|
|
NavigationSounds::getInstance()->playThemeNavigationSound(SCROLLSOUND);
|
|
|
|
mScreensaver->goToGame();
|
|
|
|
// To force handling the wake up process.
|
|
|
|
mSleeping = true;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSleeping) {
|
|
|
|
// Wake up.
|
2020-11-12 16:13:24 +00:00
|
|
|
stopScreensaver();
|
2020-06-21 12:25:28 +00:00
|
|
|
mSleeping = false;
|
|
|
|
onWake();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:40:22 +00:00
|
|
|
// Any keypress cancels the screensaver.
|
2020-11-10 21:18:20 +00:00
|
|
|
if (input.value != 0 && isScreensaverActive()) {
|
2020-11-12 16:13:24 +00:00
|
|
|
stopScreensaver();
|
2020-09-18 16:40:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_g &&
|
|
|
|
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {
|
|
|
|
// Toggle debug grid with Ctrl-G.
|
|
|
|
Settings::getInstance()->setBool("DebugGrid",
|
|
|
|
!Settings::getInstance()->getBool("DebugGrid"));
|
|
|
|
}
|
|
|
|
else if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_t &&
|
|
|
|
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {
|
|
|
|
// Toggle TextComponent debug view with Ctrl-T.
|
|
|
|
Settings::getInstance()->setBool("DebugText",
|
|
|
|
!Settings::getInstance()->getBool("DebugText"));
|
|
|
|
}
|
|
|
|
else if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_i &&
|
|
|
|
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {
|
2020-11-16 16:46:36 +00:00
|
|
|
// Toggle ImageComponent debug view with Ctrl-I.
|
2020-06-21 12:25:28 +00:00
|
|
|
Settings::getInstance()->setBool("DebugImage",
|
|
|
|
!Settings::getInstance()->getBool("DebugImage"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (peekGui())
|
|
|
|
// This is where the majority of inputs will be consumed: the GuiComponent Stack.
|
|
|
|
this->peekGui()->input(config, input);
|
|
|
|
}
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 19:12:32 +00:00
|
|
|
void Window::logInput(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
std::string mapname = "";
|
|
|
|
std::vector<std::string> maps = config->getMappedTo(input);
|
|
|
|
|
|
|
|
for (auto mn : maps) {
|
|
|
|
mapname += mn;
|
|
|
|
mapname += ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogDebug) << "Window::logInput(" << config->getDeviceName() << "): " <<
|
|
|
|
input.string() << ", isMappedTo=" << mapname << ", value=" << input.value;
|
|
|
|
}
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void Window::update(int deltaTime)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mNormalizeNextUpdate) {
|
|
|
|
mNormalizeNextUpdate = false;
|
2020-09-17 20:00:07 +00:00
|
|
|
mTimeSinceLastInput = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
if (deltaTime > mAverageDeltaTime)
|
|
|
|
deltaTime = mAverageDeltaTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameTimeElapsed += deltaTime;
|
|
|
|
mFrameCountElapsed++;
|
|
|
|
if (mFrameTimeElapsed > 500) {
|
|
|
|
mAverageDeltaTime = mFrameTimeElapsed / mFrameCountElapsed;
|
|
|
|
|
2020-08-15 07:33:08 +00:00
|
|
|
if (Settings::getInstance()->getBool("DisplayGPUStatistics")) {
|
2020-06-21 12:25:28 +00:00
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
// FPS.
|
|
|
|
ss << std::fixed << std::setprecision(1) <<
|
2020-09-17 20:00:07 +00:00
|
|
|
(1000.0f * static_cast<float>(mFrameCountElapsed) /
|
|
|
|
static_cast<float>(mFrameTimeElapsed)) << " FPS (";
|
2020-06-21 12:25:28 +00:00
|
|
|
ss << std::fixed << std::setprecision(2) <<
|
2020-09-17 20:00:07 +00:00
|
|
|
(static_cast<float>(mFrameTimeElapsed) /
|
|
|
|
static_cast<float>(mFrameCountElapsed)) << " ms)";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-08-15 07:33:08 +00:00
|
|
|
// The following calculations are not accurate, and the font calculation is completely
|
|
|
|
// broken. For now, still report the figures as it's somehow useful to locate memory
|
|
|
|
// leaks and similar. But this needs to be completely overhauled later on.
|
2020-06-21 12:25:28 +00:00
|
|
|
// VRAM.
|
2020-08-08 20:33:27 +00:00
|
|
|
float textureVramUsageMiB = TextureResource::getTotalMemUsage() / 1024.0f / 1024.0f;
|
|
|
|
float textureTotalUsageMiB = TextureResource::getTotalTextureSize() / 1024.0f / 1024.0f;
|
|
|
|
float fontVramUsageMiB = Font::getTotalMemUsage() / 1024.0f / 1024.0f;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-08-08 20:33:27 +00:00
|
|
|
ss << "\nFont VRAM: " << fontVramUsageMiB << " MiB\nTexture VRAM: " <<
|
|
|
|
textureVramUsageMiB << " MiB\nMax Texture VRAM: " <<
|
|
|
|
textureTotalUsageMiB << " MiB";
|
2020-06-21 12:25:28 +00:00
|
|
|
mFrameDataText = std::unique_ptr<TextCache>
|
2020-11-16 16:46:36 +00:00
|
|
|
(mDefaultFonts.at(0)->buildTextCache(ss.str(), Renderer::getScreenWidth() *
|
2020-12-29 10:06:01 +00:00
|
|
|
0.02f, Renderer::getScreenHeight() * 0.02f, 0xFF00FFFF, 1.3f));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mFrameTimeElapsed = 0;
|
|
|
|
mFrameCountElapsed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimeSinceLastInput += deltaTime;
|
|
|
|
|
|
|
|
if (peekGui())
|
|
|
|
peekGui()->update(deltaTime);
|
|
|
|
|
|
|
|
// Update the screensaver.
|
2020-11-10 21:33:57 +00:00
|
|
|
if (mScreensaver)
|
|
|
|
mScreensaver->update(deltaTime);
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 06:47:02 +00:00
|
|
|
void Window::render()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Transform4x4f transform = Transform4x4f::Identity();
|
|
|
|
|
|
|
|
mRenderedHelpPrompts = false;
|
|
|
|
|
|
|
|
// Draw only bottom and top of GuiStack (if they are different).
|
|
|
|
if (mGuiStack.size()) {
|
|
|
|
auto& bottom = mGuiStack.front();
|
|
|
|
auto& top = mGuiStack.back();
|
|
|
|
|
2020-11-10 21:33:57 +00:00
|
|
|
if (mRenderScreensaver) {
|
2020-09-17 20:00:07 +00:00
|
|
|
bottom->cancelAllAnimations();
|
|
|
|
bottom->stopAllAnimations();
|
|
|
|
}
|
|
|
|
|
2020-11-18 22:52:29 +00:00
|
|
|
// Don't render the system view or gamelist view if the video or slideshow screensaver
|
2021-03-18 19:07:07 +00:00
|
|
|
// is running, unless the fallback screensaver is active due to lack of images or videos.
|
|
|
|
if ((mRenderScreensaver && mScreensaver->isFallbackScreensaver()) ||
|
|
|
|
(!(mRenderScreensaver && (Settings::getInstance()->getString("ScreensaverType") ==
|
|
|
|
"video" || Settings::getInstance()->getString("ScreensaverType") == "slideshow"))))
|
2020-11-18 22:52:29 +00:00
|
|
|
bottom->render(transform);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (bottom != top) {
|
2020-09-13 11:21:38 +00:00
|
|
|
#if defined(USE_OPENGL_21)
|
|
|
|
if (!mCachedBackground) {
|
|
|
|
// Generate a cache texture of the shaded background when opening the menu, which
|
|
|
|
// will remain valid until the menu is closed. This is way faster than having to
|
|
|
|
// render the shaders for every frame.
|
2021-03-17 19:29:43 +00:00
|
|
|
// const auto backgroundStartTime = std::chrono::system_clock::now();
|
|
|
|
|
2020-09-13 11:21:38 +00:00
|
|
|
std::shared_ptr<TextureResource> mPostprocessedBackground;
|
|
|
|
mPostprocessedBackground = TextureResource::get("");
|
|
|
|
unsigned char* processedTexture = new unsigned char[Renderer::getScreenWidth() *
|
|
|
|
Renderer::getScreenHeight() * 4];
|
|
|
|
|
2021-03-17 19:29:43 +00:00
|
|
|
// Defocus the background using multiple passes of gaussian blur, with the number
|
|
|
|
// of iterations relative to the screen resolution.
|
|
|
|
Renderer::shaderParameters backgroundParameters;
|
2021-03-18 18:46:45 +00:00
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("MenuBlurBackground")) {
|
|
|
|
float heightModifier = Renderer::getScreenHeightModifier();
|
|
|
|
|
|
|
|
if (heightModifier < 1)
|
|
|
|
backgroundParameters.blurPasses = 2; // Below 1080
|
|
|
|
else if (heightModifier >= 4)
|
|
|
|
backgroundParameters.blurPasses = 12; // 8K
|
|
|
|
else if (heightModifier >= 2.9)
|
|
|
|
backgroundParameters.blurPasses = 10; // 6K
|
|
|
|
else if (heightModifier >= 2.6)
|
|
|
|
backgroundParameters.blurPasses = 8; // 5K
|
|
|
|
else if (heightModifier >= 2)
|
|
|
|
backgroundParameters.blurPasses = 5; // 4K
|
|
|
|
else if (heightModifier >= 1.3)
|
|
|
|
backgroundParameters.blurPasses = 3; // 1440
|
|
|
|
else if (heightModifier >= 1)
|
|
|
|
backgroundParameters.blurPasses = 2; // 1080
|
|
|
|
|
|
|
|
// Also dim the background slightly.
|
|
|
|
backgroundParameters.fragmentDimValue = 0.60f;
|
|
|
|
|
|
|
|
Renderer::shaderPostprocessing(Renderer::SHADER_BLUR_HORIZONTAL |
|
|
|
|
Renderer::SHADER_BLUR_VERTICAL | Renderer::SHADER_DIM,
|
|
|
|
backgroundParameters, processedTexture);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Dim the background slightly.
|
|
|
|
backgroundParameters.fragmentDimValue = 0.60f;
|
|
|
|
Renderer::shaderPostprocessing(
|
|
|
|
Renderer::SHADER_DIM, backgroundParameters, processedTexture);
|
|
|
|
}
|
2020-11-11 23:46:59 +00:00
|
|
|
|
|
|
|
mPostprocessedBackground->initFromPixels(processedTexture,
|
|
|
|
Renderer::getScreenWidth(), Renderer::getScreenHeight());
|
|
|
|
|
|
|
|
mBackgroundOverlay->setImage(mPostprocessedBackground);
|
|
|
|
|
|
|
|
// The following is done to avoid fading in if the cached image was
|
|
|
|
// invalidated (rather than the menu being opened).
|
|
|
|
if (mInvalidatedCachedBackground) {
|
|
|
|
mBackgroundOverlayOpacity = 255;
|
|
|
|
mInvalidatedCachedBackground = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mBackgroundOverlayOpacity = 25;
|
|
|
|
}
|
2020-09-13 11:21:38 +00:00
|
|
|
|
|
|
|
delete[] processedTexture;
|
|
|
|
mCachedBackground = true;
|
2021-03-17 19:29:43 +00:00
|
|
|
|
|
|
|
// const auto backgroundEndTime = std::chrono::system_clock::now();
|
|
|
|
// LOG(LogDebug) << "Window::render(): Time to create cached background: " <<
|
|
|
|
// std::chrono::duration_cast<std::chrono::milliseconds>
|
|
|
|
// (backgroundEndTime - backgroundStartTime).count() << " ms";
|
|
|
|
}
|
|
|
|
// Fade in the cached background, unless the menu is set to open without any animation.
|
|
|
|
if (Settings::getInstance()->getString("MenuOpeningEffect") != "none") {
|
|
|
|
mBackgroundOverlay->setOpacity(mBackgroundOverlayOpacity);
|
|
|
|
if (mBackgroundOverlayOpacity < 255)
|
|
|
|
mBackgroundOverlayOpacity = Math::clamp(mBackgroundOverlayOpacity + 30, 0, 255);
|
2020-09-13 11:21:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-11-11 23:46:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mBackgroundOverlay->render(transform);
|
2020-09-13 11:21:38 +00:00
|
|
|
|
|
|
|
#if defined(USE_OPENGL_21)
|
2020-09-13 11:46:34 +00:00
|
|
|
// Menu opening effects (scale-up and fade-in).
|
|
|
|
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up") {
|
2020-09-13 11:21:38 +00:00
|
|
|
if (mTopScale < 1.0)
|
2020-12-29 10:06:01 +00:00
|
|
|
mTopScale = Math::clamp(mTopScale + 0.07f, 0.0f, 1.0f);
|
2020-09-13 11:21:38 +00:00
|
|
|
Vector2f topCenter = top->getCenter();
|
|
|
|
top->setOrigin({0.5, 0.5});
|
|
|
|
top->setPosition({topCenter.x(), topCenter.y(), 0});
|
|
|
|
top->setScale(mTopScale);
|
|
|
|
}
|
2020-09-13 11:46:34 +00:00
|
|
|
if (Settings::getInstance()->getString("MenuOpeningEffect") == "fade-in") {
|
2020-09-13 11:21:38 +00:00
|
|
|
// Fade-in menu.
|
2020-09-27 12:41:59 +00:00
|
|
|
if (mTopOpacity < 255) {
|
2020-09-13 11:21:38 +00:00
|
|
|
mTopOpacity = Math::clamp(mTopOpacity+15, 0, 255);
|
2020-09-27 12:41:59 +00:00
|
|
|
top->setOpacity(mTopOpacity);
|
|
|
|
}
|
2020-09-13 11:21:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
top->render(transform);
|
|
|
|
}
|
2020-09-13 11:21:38 +00:00
|
|
|
else {
|
|
|
|
mCachedBackground = false;
|
|
|
|
mTopOpacity = 0;
|
|
|
|
mTopScale = 0.5;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 22:46:51 +00:00
|
|
|
// Render the quick list scrolling overlay, which is triggered in IList.
|
2021-01-12 21:41:28 +00:00
|
|
|
if (mListScrollOpacity != 0) {
|
|
|
|
Renderer::setMatrix(Transform4x4f::Identity());
|
|
|
|
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()),
|
|
|
|
0x00000000 | mListScrollOpacity, 0x00000000 | mListScrollOpacity);
|
|
|
|
|
|
|
|
Vector2f offset = mListScrollFont->sizeText(mListScrollText);
|
|
|
|
offset[0] = (Renderer::getScreenWidth() - offset.x()) * 0.5f;
|
|
|
|
offset[1] = (Renderer::getScreenHeight() - offset.y()) * 0.5f;
|
|
|
|
|
|
|
|
TextCache* cache = mListScrollFont->buildTextCache(mListScrollText,
|
|
|
|
offset.x(), offset.y(), 0xFFFFFF00 | mListScrollOpacity);
|
|
|
|
mListScrollFont->renderTextCache(cache);
|
|
|
|
delete cache;
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!mRenderedHelpPrompts)
|
|
|
|
mHelp->render(transform);
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
unsigned int screensaverTimer =
|
|
|
|
static_cast<unsigned int>(Settings::getInstance()->getInt("ScreensaverTimer"));
|
|
|
|
if (mTimeSinceLastInput >= screensaverTimer && screensaverTimer != 0) {
|
2020-11-10 21:18:20 +00:00
|
|
|
// If a menu is open, reset the screensaver timer so that the screensaver won't start.
|
|
|
|
if (mGuiStack.front() != mGuiStack.back())
|
2020-07-18 11:21:44 +00:00
|
|
|
mTimeSinceLastInput = 0;
|
2020-11-10 21:18:20 +00:00
|
|
|
// If a game has been launched, reset the screensaver timer as we don't want to start
|
|
|
|
// the screensaver in the background when running a game.
|
|
|
|
else if (mGameLaunchedState)
|
|
|
|
mTimeSinceLastInput = 0;
|
2020-11-10 21:33:57 +00:00
|
|
|
else if (!isProcessing() && !mScreensaver->isScreensaverActive())
|
2020-11-10 21:18:20 +00:00
|
|
|
startScreensaver();
|
2020-07-18 11:21:44 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Always call the screensaver render function regardless of whether the screensaver is active
|
|
|
|
// or not because it may perform a fade on transition.
|
2020-11-10 21:18:20 +00:00
|
|
|
renderScreensaver();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-11-10 21:33:57 +00:00
|
|
|
if (!mRenderScreensaver && mInfoPopup)
|
2020-06-21 12:25:28 +00:00
|
|
|
mInfoPopup->render(transform);
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
if (mTimeSinceLastInput >= screensaverTimer && screensaverTimer != 0) {
|
2020-11-10 21:33:57 +00:00
|
|
|
if (!isProcessing() && mAllowSleep && (!mScreensaver)) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Go to sleep.
|
|
|
|
if (mSleeping == false) {
|
|
|
|
mSleeping = true;
|
|
|
|
onSleep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-13 11:21:38 +00:00
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("DisplayGPUStatistics") && mFrameDataText) {
|
|
|
|
Renderer::setMatrix(Transform4x4f::Identity());
|
|
|
|
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
|
|
|
|
}
|
2013-07-17 06:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::normalizeNextUpdate()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mNormalizeNextUpdate = true;
|
2013-07-17 06:47:02 +00:00
|
|
|
}
|
|
|
|
|
2013-10-13 21:40:36 +00:00
|
|
|
bool Window::getAllowSleep()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mAllowSleep;
|
2013-10-13 21:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setAllowSleep(bool sleep)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mAllowSleep = sleep;
|
2013-10-13 21:40:36 +00:00
|
|
|
}
|
2013-12-12 19:48:29 +00:00
|
|
|
|
2019-01-31 20:19:34 +00:00
|
|
|
void Window::renderLoadingScreen(std::string text)
|
2013-12-12 19:48:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Transform4x4f trans = Transform4x4f::Identity();
|
|
|
|
Renderer::setMatrix(trans);
|
2020-12-29 10:06:01 +00:00
|
|
|
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
ImageComponent splash(this, true);
|
|
|
|
splash.setResize(Renderer::getScreenWidth() * 0.6f, 0.0f);
|
2020-06-21 17:35:43 +00:00
|
|
|
splash.setImage(":/graphics/splash.svg");
|
2020-06-21 12:25:28 +00:00
|
|
|
splash.setPosition((Renderer::getScreenWidth() - splash.getSize().x()) / 2,
|
|
|
|
(Renderer::getScreenHeight() - splash.getSize().y()) / 2 * 0.6f);
|
|
|
|
splash.render(trans);
|
|
|
|
|
|
|
|
auto& font = mDefaultFonts.at(1);
|
|
|
|
TextCache* cache = font->buildTextCache(text, 0, 0, 0x656565FF);
|
|
|
|
|
2020-12-28 10:29:32 +00:00
|
|
|
float x = std::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f);
|
|
|
|
float y = std::round(Renderer::getScreenHeight() * 0.835f);
|
2020-06-21 12:25:28 +00:00
|
|
|
trans = trans.translate(Vector3f(x, y, 0.0f));
|
|
|
|
Renderer::setMatrix(trans);
|
|
|
|
font->renderTextCache(cache);
|
|
|
|
delete cache;
|
|
|
|
|
|
|
|
Renderer::swapBuffers();
|
2013-12-12 19:48:29 +00:00
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2021-01-12 21:41:28 +00:00
|
|
|
void Window::renderListScrollOverlay(unsigned char opacity, const std::string& text)
|
|
|
|
{
|
|
|
|
mListScrollOpacity = static_cast<unsigned char>(opacity * 0.6f);
|
|
|
|
mListScrollText = text;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:58:16 +00:00
|
|
|
void Window::renderHelpPromptsEarly()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mHelp->render(Transform4x4f::Identity());
|
|
|
|
mRenderedHelpPrompts = true;
|
2014-05-15 01:58:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 20:41:47 +00:00
|
|
|
void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpStyle& style)
|
2014-01-25 23:34:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mHelp->clearPrompts();
|
|
|
|
mHelp->setStyle(style);
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> addPrompts;
|
|
|
|
|
|
|
|
std::map<std::string, bool> inputSeenMap;
|
|
|
|
std::map<std::string, int> mappedToSeenMap;
|
|
|
|
for (auto it = prompts.cbegin(); it != prompts.cend(); it++) {
|
|
|
|
// Only add it if the same icon hasn't already been added.
|
|
|
|
if (inputSeenMap.emplace(it->first, true).second) {
|
|
|
|
// This symbol hasn't been seen yet, what about the action name?
|
|
|
|
auto mappedTo = mappedToSeenMap.find(it->second);
|
|
|
|
if (mappedTo != mappedToSeenMap.cend()) {
|
|
|
|
// Yes, it has!
|
|
|
|
|
|
|
|
// Can we combine? (dpad only).
|
|
|
|
if ((it->first == "up/down" &&
|
|
|
|
addPrompts.at(mappedTo->second).first != "left/right") ||
|
|
|
|
(it->first == "left/right" &&
|
|
|
|
addPrompts.at(mappedTo->second).first != "up/down")) {
|
|
|
|
// Yes!
|
|
|
|
addPrompts.at(mappedTo->second).first = "up/down/left/right";
|
|
|
|
// Don't need to add this to addPrompts since we just merged.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No, we can't combine!
|
|
|
|
addPrompts.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No, it hasn't!
|
2020-09-17 20:00:07 +00:00
|
|
|
mappedToSeenMap.emplace(it->second, static_cast<int>(addPrompts.size()));
|
2020-06-21 12:25:28 +00:00
|
|
|
addPrompts.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort prompts so it goes [dpad_all] [dpad_u/d] [dpad_l/r] [a/b/x/y/l/r] [start/select].
|
|
|
|
std::sort(addPrompts.begin(), addPrompts.end(),
|
|
|
|
[](const HelpPrompt& a, const HelpPrompt& b) -> bool {
|
|
|
|
|
2020-12-16 22:59:00 +00:00
|
|
|
static const std::vector<std::string> map = {
|
|
|
|
"up/down/left/right",
|
|
|
|
"up/down",
|
|
|
|
"left/right",
|
|
|
|
"a", "b", "x", "y", "l", "r",
|
|
|
|
"start", "select"
|
2020-06-21 12:25:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
int aVal = 0;
|
|
|
|
int bVal = 0;
|
2020-12-16 22:59:00 +00:00
|
|
|
while (i < map.size()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (a.first == map[i])
|
|
|
|
aVal = i;
|
|
|
|
if (b.first == map[i])
|
|
|
|
bVal = i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aVal > bVal;
|
|
|
|
});
|
|
|
|
|
|
|
|
mHelp->setPrompts(addPrompts);
|
2014-01-25 23:34:29 +00:00
|
|
|
}
|
2014-06-02 00:14:22 +00:00
|
|
|
|
2021-03-21 15:10:09 +00:00
|
|
|
void Window::setInfoPopup(InfoPopup* infoPopup)
|
|
|
|
{
|
|
|
|
delete mInfoPopup;
|
|
|
|
mInfoPopup = infoPopup;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::stopInfoPopup()
|
|
|
|
{
|
|
|
|
if (mInfoPopup)
|
|
|
|
mInfoPopup->stop();
|
|
|
|
}
|
|
|
|
|
2014-06-02 00:14:22 +00:00
|
|
|
void Window::onSleep()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Scripting::fireEvent("sleep");
|
2014-06-02 00:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::onWake()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Scripting::fireEvent("wake");
|
2014-06-02 00:14:22 +00:00
|
|
|
}
|
2016-09-12 11:31:44 +00:00
|
|
|
|
|
|
|
bool Window::isProcessing()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return count_if (mGuiStack.cbegin(), mGuiStack.cend(),
|
|
|
|
[](GuiComponent* c) { return c->isProcessing(); }) > 0;
|
2016-09-12 11:31:44 +00:00
|
|
|
}
|
2016-09-17 13:21:24 +00:00
|
|
|
|
2020-07-18 11:21:44 +00:00
|
|
|
void Window::setLaunchedGame()
|
|
|
|
{
|
|
|
|
// Tell the GUI components that a game has been launched.
|
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onGameLaunchedActivate();
|
|
|
|
|
|
|
|
mGameLaunchedState = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::unsetLaunchedGame()
|
|
|
|
{
|
2021-03-24 19:13:33 +00:00
|
|
|
// Tell the GUI components that the user is back in ES-DE again.
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onGameLaunchedDeactivate();
|
|
|
|
|
|
|
|
mGameLaunchedState = false;
|
|
|
|
}
|
|
|
|
|
2021-03-21 15:10:09 +00:00
|
|
|
void Window::invalidateCachedBackground()
|
|
|
|
{
|
|
|
|
mCachedBackground = false;
|
|
|
|
mInvalidatedCachedBackground = true;
|
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void Window::startScreensaver()
|
2019-04-07 12:52:36 +00:00
|
|
|
{
|
2020-11-10 21:33:57 +00:00
|
|
|
if (mScreensaver && !mRenderScreensaver) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Tell the GUI components the screensaver is starting.
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
2020-11-10 21:33:57 +00:00
|
|
|
(*it)->onScreensaverActivate();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-09-17 20:00:07 +00:00
|
|
|
stopInfoPopup();
|
2020-11-10 21:33:57 +00:00
|
|
|
mScreensaver->startScreensaver(true);
|
|
|
|
mRenderScreensaver = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2019-04-07 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 16:13:24 +00:00
|
|
|
bool Window::stopScreensaver()
|
2019-04-07 12:52:36 +00:00
|
|
|
{
|
2020-11-10 21:33:57 +00:00
|
|
|
if (mScreensaver && mRenderScreensaver) {
|
|
|
|
mScreensaver->stopScreensaver();
|
|
|
|
mRenderScreensaver = false;
|
2019-04-07 12:52:36 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Tell the GUI components the screensaver has stopped.
|
2020-09-27 11:14:50 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++) {
|
2020-11-10 21:33:57 +00:00
|
|
|
(*it)->onScreensaverDeactivate();
|
2020-09-27 11:14:50 +00:00
|
|
|
// If the menu is open, pause the video so it won't start playing beneath the menu.
|
|
|
|
if (mGuiStack.front() != mGuiStack.back())
|
|
|
|
(*it)->onPauseVideo();
|
|
|
|
}
|
2019-04-07 12:54:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-07 12:54:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return false;
|
2019-04-07 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void Window::renderScreensaver()
|
2019-04-07 12:52:36 +00:00
|
|
|
{
|
2020-11-10 21:33:57 +00:00
|
|
|
if (mScreensaver)
|
|
|
|
mScreensaver->renderScreensaver();
|
2019-04-07 12:52:36 +00:00
|
|
|
}
|