Some cosmetic code cleanup.

This commit is contained in:
Leon Styhre 2021-06-11 17:02:06 +02:00
parent 83799f2208
commit 75430f210a
7 changed files with 85 additions and 97 deletions

View file

@ -21,7 +21,7 @@ GuiInfoPopup::GuiInfoPopup(
: GuiComponent(window),
mMessage(message),
mDuration(duration),
running(true)
mRunning(true)
{
mFrame = new NinePatchComponent(window);
float maxWidth = Renderer::getScreenWidth() * 0.9f;
@ -31,7 +31,7 @@ GuiInfoPopup::GuiInfoPopup(
Font::get(FONT_SIZE_MINI), 0x444444FF, ALIGN_CENTER);
// We do this to force the text container to resize and return the actual expected popup size.
s->setSize(0,0);
s->setSize(0.0f, 0.0f);
s->setText(message);
mSize = s->getSize();
@ -79,7 +79,7 @@ void GuiInfoPopup::render(const Transform4x4f& /*parentTrans*/)
{
// We use Identity() as we want to render on a specific window position, not on the view.
Transform4x4f trans = getTransform() * Transform4x4f::Identity();
if (running && updateState()) {
if (mRunning && updateState()) {
// If we're still supposed to be rendering it.
Renderer::setMatrix(trans);
renderChildren(trans);
@ -97,27 +97,27 @@ bool GuiInfoPopup::updateState()
// Compute fade-in effect.
if (curTime - mStartTime > mDuration) {
// We're past the popup duration, no need to render.
running = false;
mRunning = false;
return false;
}
else if (curTime < mStartTime) {
// If SDL reset.
running = false;
mRunning = false;
return false;
}
else if (curTime - mStartTime <= 500) {
alpha = ((curTime - mStartTime) * 255 / 500);
mAlpha = ((curTime - mStartTime) * 255 / 500);
}
else if (curTime - mStartTime < mDuration - 500) {
alpha = 255;
mAlpha = 255;
}
else {
alpha = ((-(curTime - mStartTime - mDuration) * 255) / 500);
mAlpha = ((-(curTime - mStartTime - mDuration) * 255) / 500);
}
mGrid->setOpacity(static_cast<unsigned char>(alpha));
mGrid->setOpacity(static_cast<unsigned char>(mAlpha));
// Apply fade-in effect to popup frame.
mFrame->setEdgeColor(0xFFFFFF00 | static_cast<unsigned char>(alpha));
mFrame->setCenterColor(0xFFFFFF00 | static_cast<unsigned char>(alpha));
mFrame->setEdgeColor(0xFFFFFF00 | static_cast<unsigned char>(mAlpha));
mFrame->setCenterColor(0xFFFFFF00 | static_cast<unsigned char>(mAlpha));
return true;
}

View file

@ -20,18 +20,21 @@ class GuiInfoPopup : public GuiComponent, public Window::InfoPopup
public:
GuiInfoPopup(Window* window, std::string message, int duration);
~GuiInfoPopup();
void render(const Transform4x4f& parentTrans) override;
inline void stop() override { running = false; };
inline void stop() override { mRunning = false; }
private:
std::string mMessage;
int mDuration;
int alpha;
bool updateState();
int mStartTime;
ComponentGrid* mGrid;
NinePatchComponent* mFrame;
bool running;
std::string mMessage;
int mDuration;
int mAlpha;
int mStartTime;
bool mRunning;
};
#endif // ES_APP_GUIS_GUI_INFO_POPUP_H

View file

@ -407,7 +407,7 @@ bool GuiComponent::finishAnimation(unsigned char slot)
if (anim) {
// Skip to animation's end.
const bool done = anim->update(anim->getAnimation()->getDuration() - anim->getTime());
if(done) {
if (done) {
mAnimationMap[slot] = nullptr;
delete anim; // Will also call finishedCallback.
}

View file

@ -141,12 +141,6 @@ void Window::deinit()
Renderer::deinit();
}
void Window::textInput(const std::string& text)
{
if (peekGui())
peekGui()->textInput(text);
}
void Window::input(InputConfig* config, Input input)
{
mTimeSinceLastInput = 0;
@ -244,6 +238,12 @@ void Window::input(InputConfig* config, Input input)
}
}
void Window::textInput(const std::string& text)
{
if (peekGui())
peekGui()->textInput(text);
}
void Window::logInput(InputConfig* config, Input input)
{
std::string mapname = "";
@ -529,21 +529,6 @@ void Window::render()
}
}
void Window::normalizeNextUpdate()
{
mNormalizeNextUpdate = true;
}
bool Window::getAllowSleep()
{
return mAllowSleep;
}
void Window::setAllowSleep(bool sleep)
{
mAllowSleep = sleep;
}
void Window::renderLoadingScreen(std::string text)
{
Transform4x4f trans = Transform4x4f::Identity();
@ -671,46 +656,6 @@ void Window::stopInfoPopup()
mInfoPopup->stop();
}
void Window::onSleep()
{
Scripting::fireEvent("sleep");
}
void Window::onWake()
{
Scripting::fireEvent("wake");
}
bool Window::isProcessing()
{
return count_if (mGuiStack.cbegin(), mGuiStack.cend(),
[](GuiComponent* c) { return c->isProcessing(); }) > 0;
}
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()
{
// Tell the GUI components that the user is back in ES-DE again.
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
(*it)->onGameLaunchedDeactivate();
mGameLaunchedState = false;
}
void Window::invalidateCachedBackground()
{
mCachedBackground = false;
mInvalidatedCachedBackground = true;
}
void Window::startScreensaver()
{
if (mScreensaver && !mRenderScreensaver) {
@ -788,3 +733,43 @@ int Window::getVideoPlayerCount()
mVideoCountMutex.unlock();
return videoPlayerCount;
};
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()
{
// Tell the GUI components that the user is back in ES-DE again.
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
(*it)->onGameLaunchedDeactivate();
mGameLaunchedState = false;
}
void Window::invalidateCachedBackground()
{
mCachedBackground = false;
mInvalidatedCachedBackground = true;
}
void Window::onSleep()
{
Scripting::fireEvent("sleep");
}
void Window::onWake()
{
Scripting::fireEvent("wake");
}
bool Window::isProcessing()
{
return count_if (mGuiStack.cbegin(), mGuiStack.cend(), [](GuiComponent* c) {
return c->isProcessing(); }) > 0;
}

View file

@ -80,20 +80,20 @@ public:
GuiComponent* peekGui();
inline int getGuiStackSize() { return static_cast<int>(mGuiStack.size()); }
void textInput(const std::string& text);
bool init();
void deinit();
void input(InputConfig* config, Input input);
void textInput(const std::string& text);
void logInput(InputConfig* config, Input input);
void update(int deltaTime);
void render();
bool init();
void deinit();
void normalizeNextUpdate();
void normalizeNextUpdate() { mNormalizeNextUpdate = true; }
bool getAllowSleep() { return mAllowSleep; }
void setAllowSleep(bool sleep) { mAllowSleep = sleep; }
inline bool isSleeping() const { return mSleeping; }
bool getAllowSleep();
void setAllowSleep(bool sleep);
void renderLoadingScreen(std::string text);
// The list scroll overlay is triggered from IList when the highest scrolling tier is reached.
@ -103,20 +103,20 @@ public:
void setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpStyle& style);
void reloadHelpPrompts();
void setScreensaver(Screensaver* screensaver) { mScreensaver = screensaver; }
void setInfoPopup(InfoPopup* infoPopup);
void stopInfoPopup();
void startScreensaver();
bool stopScreensaver();
void renderScreensaver();
void screensaverTriggerNextGame() { mScreensaver->triggerNextGame(); };
bool isScreensaverActive() { return mRenderScreensaver; };
void screensaverTriggerNextGame() { mScreensaver->triggerNextGame(); }
void setScreensaver(Screensaver* screensaver) { mScreensaver = screensaver; }
bool isScreensaverActive() { return mRenderScreensaver; }
void startMediaViewer(FileData* game);
void stopMediaViewer();
void setMediaViewer(MediaViewer* mediaViewer) { mMediaViewer = mediaViewer; }
bool isMediaViewerActive() { return mRenderMediaViewer; };
bool isMediaViewerActive() { return mRenderMediaViewer; }
void increaseVideoPlayerCount();
void decreaseVideoPlayerCount();
@ -126,11 +126,11 @@ public:
void unsetLaunchedGame();
void invalidateCachedBackground();
bool getGameLaunchedState() { return mGameLaunchedState; };
void setAllowTextScrolling(bool setting) { mAllowTextScrolling = setting; };
bool getAllowTextScrolling() { return mAllowTextScrolling; };
bool getGameLaunchedState() { return mGameLaunchedState; }
void setAllowTextScrolling(bool setting) { mAllowTextScrolling = setting; }
bool getAllowTextScrolling() { return mAllowTextScrolling; }
void setChangedThemeSet() { mChangedThemeSet = true; };
void setChangedThemeSet() { mChangedThemeSet = true; }
private:
void onSleep();

View file

@ -547,7 +547,7 @@ void VideoFFmpegComponent::readFrames()
if (mVideoCodecContext && mFormatContext) {
if (mVideoFrameQueue.size() < mVideoTargetQueueSize || (mAudioStreamIndex >= 0 &&
mAudioFrameQueue.size() < mAudioTargetQueueSize)) {
while((readFrameReturn = av_read_frame(mFormatContext, mPacket)) >= 0) {
while ((readFrameReturn = av_read_frame(mFormatContext, mPacket)) >= 0) {
if (mPacket->stream_index == mVideoStreamIndex) {
if (!avcodec_send_packet(mVideoCodecContext, mPacket) &&
!avcodec_receive_frame(mVideoCodecContext, mVideoFrame)) {

View file

@ -195,7 +195,7 @@ namespace Renderer
windowFlags = getWindowFlags();
}
else if (Settings::getInstance()->getString("FullscreenMode") == "borderless") {
if(!userResolution)
if (!userResolution)
windowFlags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALWAYS_ON_TOP | getWindowFlags();
else
// If the user has changed the resolution from the command line, then add a