Changed the opacity data type and functions from unsigned char to float.

This commit is contained in:
Leon Styhre 2022-02-11 22:10:25 +01:00
parent 8fd05bb2a2
commit 2c2e624160
37 changed files with 159 additions and 174 deletions

View file

@ -27,7 +27,7 @@
#include <cstring>
#endif
#define FADE_TIME 300
#define FADE_TIME 300.0f
Screensaver::Screensaver()
: mWindow {Window::getInstance()}
@ -255,7 +255,7 @@ void Screensaver::renderScreensaver()
// Only render the image if the state requires it.
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
if (mImageScreensaver->hasImage()) {
mImageScreensaver->setOpacity(255 - static_cast<unsigned char>(mOpacity * 255));
mImageScreensaver->setOpacity(1.0f - mOpacity);
glm::mat4 trans {Renderer::getIdentity()};
mImageScreensaver->render(trans);
}

View file

@ -299,8 +299,10 @@ void GuiMenu::openUIOptions()
}
if (!selectedSet->second.capabilities.legacyTheme && selectableVariants > 0) {
themeVariant->setEnabled(true);
themeVariant->setOpacity(255);
themeVariant->getParent()->getChild(themeVariant->getChildIndex() - 1)->setOpacity(255);
themeVariant->setOpacity(1.0f);
themeVariant->getParent()
->getChild(themeVariant->getChildIndex() - 1)
->setOpacity(1.0f);
}
else {
themeVariant->setEnabled(false);
@ -313,10 +315,10 @@ void GuiMenu::openUIOptions()
if (!selectedSet->second.capabilities.legacyTheme &&
selectedSet->second.capabilities.aspectRatios.size() > 0) {
themeAspectRatio->setEnabled(true);
themeAspectRatio->setOpacity(255);
themeAspectRatio->setOpacity(1.0f);
themeAspectRatio->getParent()
->getChild(themeAspectRatio->getChildIndex() - 1)
->setOpacity(255);
->setOpacity(1.0f);
}
else {
themeAspectRatio->setEnabled(false);
@ -340,16 +342,16 @@ void GuiMenu::openUIOptions()
}
else {
gamelist_view_style->setEnabled(true);
gamelist_view_style->setOpacity(255);
gamelist_view_style->setOpacity(1.0f);
gamelist_view_style->getParent()
->getChild(gamelist_view_style->getChildIndex() - 1)
->setOpacity(255);
->setOpacity(1.0f);
transition_style->setEnabled(true);
transition_style->setOpacity(255);
transition_style->setOpacity(1.0f);
transition_style->getParent()
->getChild(transition_style->getChildIndex() - 1)
->setOpacity(255);
->setOpacity(1.0f);
}
};

View file

@ -915,10 +915,10 @@ void GuiScraperMenu::openOtherOptions()
}
else {
scraper_semiautomatic->setEnabled(true);
scraper_semiautomatic->setOpacity(255);
scraper_semiautomatic->setOpacity(1.0f);
scraper_semiautomatic->getParent()
->getChild(scraper_semiautomatic->getChildIndex() - 1)
->setOpacity(255);
->setOpacity(1.0f);
}
};
@ -932,10 +932,10 @@ void GuiScraperMenu::openOtherOptions()
}
else {
scraper_exclude_recursively->setEnabled(true);
scraper_exclude_recursively->setOpacity(255);
scraper_exclude_recursively->setOpacity(1.0f);
scraper_exclude_recursively->getParent()
->getChild(scraper_exclude_recursively->getChildIndex() - 1)
->setOpacity(255);
->setOpacity(1.0f);
}
};

View file

@ -70,8 +70,8 @@ GuiScraperMulti::GuiScraperMulti(const std::queue<ScraperSearchParams>& searches
mSearchComp->setSkipCallback(std::bind(&GuiScraperMulti::skip, this));
mSearchComp->setCancelCallback(std::bind(&GuiScraperMulti::finish, this));
mSearchComp->setRefineCallback([&] {
mScrollUp->setOpacity(0);
mScrollDown->setOpacity(0);
mScrollUp->setOpacity(0.0f);
mScrollDown->setOpacity(0.0f);
mResultList->resetScrollIndicatorStatus();
});
@ -230,8 +230,8 @@ void GuiScraperMulti::doNextSearch()
scrapeName = Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath());
}
mScrollUp->setOpacity(0);
mScrollDown->setOpacity(0);
mScrollUp->setOpacity(0.0f);
mScrollDown->setOpacity(0.0f);
mResultList->resetScrollIndicatorStatus();
// Extract possible subfolders from the path.

View file

@ -557,7 +557,7 @@ void GuiScraperSearch::updateInfoPane()
// Metadata.
if (mScrapeRatings) {
mMD_Rating->setValue(Utils::String::toUpper(res.mdl.get("rating")));
mMD_Rating->setOpacity(255);
mMD_Rating->setOpacity(1.0f);
}
mMD_ReleaseDate->setValue(Utils::String::toUpper(res.mdl.get("releasedate")));
mMD_Developer->setText(Utils::String::toUpper(res.mdl.get("developer")));
@ -574,7 +574,7 @@ void GuiScraperSearch::updateInfoPane()
// Metadata.
if (mScrapeRatings) {
mMD_Rating->setValue("");
mMD_Rating->setOpacity(0);
mMD_Rating->setOpacity(0.0f);
}
// Set the release date to this value to force DateTimeEditComponent to put a
// blank instead of the text 'unknown' prior to the scrape result being returned.

View file

@ -113,8 +113,8 @@ GuiScraperSingle::GuiScraperSingle(ScraperSearchParams& params,
});
mSearch->setCancelCallback([&] { delete this; });
mSearch->setRefineCallback([&] {
mScrollUp->setOpacity(0);
mScrollDown->setOpacity(0);
mScrollUp->setOpacity(0.0f);
mScrollDown->setOpacity(0.0f);
mResultList->resetScrollIndicatorStatus();
});

View file

@ -466,8 +466,8 @@ void GamelistView::legacyUpdateInfoPanel()
if (mViewStyle == ViewController::DETAILED) {
// Fade in the game image.
auto func = [this](float t) {
mImageComponents[LegacyImage::MD_IMAGE]->setOpacity(static_cast<unsigned char>(
glm::mix(static_cast<float>(FADE_IN_START_OPACITY), 1.0f, t) * 255));
mImageComponents[LegacyImage::MD_IMAGE]->setOpacity(
glm::mix(FADE_IN_START_OPACITY, 1.0f, t));
};
mImageComponents[LegacyImage::MD_IMAGE]->setAnimation(
new LambdaAnimation(func, FADE_IN_TIME), 0, nullptr, false);
@ -475,8 +475,7 @@ void GamelistView::legacyUpdateInfoPanel()
else if (mViewStyle == ViewController::VIDEO) {
// Fade in the static image.
auto func = [this](float t) {
mVideoComponents.front()->setOpacity(static_cast<unsigned char>(
glm::mix(static_cast<float>(FADE_IN_START_OPACITY), 1.0f, t) * 255));
mVideoComponents.front()->setOpacity(glm::mix(FADE_IN_START_OPACITY, 1.0f, t));
};
mVideoComponents.front()->setAnimation(new LambdaAnimation(func, FADE_IN_TIME), 0,
nullptr, false);
@ -560,10 +559,8 @@ void GamelistView::legacyUpdateInfoPanel()
// An animation is playing, then animate if reverse != fadingOut.
// An animation is not playing, then animate if opacity != our target opacity.
if ((comp->isAnimationPlaying(0) && comp->isAnimationReversed(0) != fadingOut) ||
(!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0 : 255))) {
auto func = [comp](float t) {
comp->setOpacity(static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
};
(!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0.0f : 1.0f))) {
auto func = [comp](float t) { comp->setOpacity(glm::mix(0.0f, 1.0f, t)); };
comp->setAnimation(new LambdaAnimation(func, 150), 0, nullptr, fadingOut);
}
}

View file

@ -210,7 +210,7 @@ void GamelistView::update(int deltaTime)
video->onHide();
else if (!video->hasStaticImage())
video->onHide();
else if (video->getOpacity() == 0)
else if (video->getOpacity() == 0.0f)
video->onHide();
}
else if (mVideoPlaying && !video->isVideoPaused() && !mWindow->isScreensaverActive()) {
@ -562,8 +562,7 @@ void GamelistView::updateInfoPanel()
for (auto& image : mImageComponents) {
if (image->getScrollFadeIn()) {
auto func = [&image](float t) {
image->setOpacity(static_cast<unsigned char>(
glm::mix(static_cast<float>(FADE_IN_START_OPACITY), 1.0f, t) * 255));
image->setOpacity(glm::mix(FADE_IN_START_OPACITY, 1.0f, t));
};
image->setAnimation(new LambdaAnimation(func, FADE_IN_TIME), 0, nullptr, false);
}
@ -573,8 +572,7 @@ void GamelistView::updateInfoPanel()
for (auto& video : mVideoComponents) {
if (video->getScrollFadeIn()) {
auto func = [&video](float t) {
video->setOpacity(static_cast<unsigned char>(
glm::mix(static_cast<float>(FADE_IN_START_OPACITY), 1.0f, t) * 255));
video->setOpacity(glm::mix(FADE_IN_START_OPACITY, 1.0f, t));
};
video->setAnimation(new LambdaAnimation(func, FADE_IN_TIME), 0, nullptr, false);
}
@ -762,10 +760,8 @@ void GamelistView::updateInfoPanel()
// An animation is playing, then animate if reverse != fadingOut.
// An animation is not playing, then animate if opacity != our target opacity.
if ((comp->isAnimationPlaying(0) && comp->isAnimationReversed(0) != fadingOut) ||
(!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0 : 255))) {
auto func = [comp](float t) {
comp->setOpacity(static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
};
(!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0.0f : 1.0f))) {
auto func = [comp](float t) { comp->setOpacity(glm::mix(0.0f, 1.0f, t)); };
comp->setAnimation(new LambdaAnimation(func, 150), 0, nullptr, fadingOut);
}
}

View file

@ -19,7 +19,6 @@
GuiComponent::GuiComponent()
: mWindow {Window::getInstance()}
, mParent {nullptr}
, mOpacity {255}
, mColor {0}
, mSaturation {1.0f}
, mColorShift {0}
@ -31,6 +30,7 @@ GuiComponent::GuiComponent()
, mOrigin {0.0f, 0.0f}
, mRotationOrigin {0.5f, 0.5f}
, mSize {0.0f, 0.0f}
, mOpacity {1.0f}
, mRotation {0.0f}
, mScale {1.0f}
, mDefaultZIndex {0.0f}
@ -180,7 +180,7 @@ const int GuiComponent::getChildIndex() const
return -1;
}
void GuiComponent::setOpacity(unsigned char opacity)
void GuiComponent::setOpacity(float opacity)
{
if (mOpacity == opacity)
return;

View file

@ -25,7 +25,7 @@
#define ICONCOLOR_USERMARKED 0x7777FFFF
#define TEXTCOLOR_SCRAPERMARKED 0x992222FF
#define TEXTCOLOR_USERMARKED 0x222299FF
#define DISABLED_OPACITY 80
#define DISABLED_OPACITY 0.314f
class Animation;
class AnimationController;
@ -191,8 +191,8 @@ public:
virtual bool isListScrolling() { return false; }
virtual void stopListScrolling() {}
virtual unsigned char getOpacity() const { return mOpacity; }
virtual void setOpacity(unsigned char opacity);
virtual float getOpacity() const { return mOpacity; }
virtual void setOpacity(float opacity);
virtual unsigned int getColor() const { return mColor; }
virtual unsigned int getColorShift() const { return mColorShift; }
virtual float getLineSpacing() { return 0.0f; }
@ -277,7 +277,6 @@ protected:
std::string mMetadataField;
unsigned char mOpacity;
unsigned int mColor;
float mSaturation;
unsigned int mColorShift;
@ -291,6 +290,7 @@ protected:
glm::vec2 mRotationOrigin;
glm::vec2 mSize;
float mOpacity;
float mRotation;
float mScale;
float mDefaultZIndex;

View file

@ -29,7 +29,7 @@ Window::Window() noexcept
, mMediaViewer {nullptr}
, mLaunchScreen {nullptr}
, mInfoPopup {nullptr}
, mListScrollOpacity {0}
, mListScrollOpacity {0.0f}
, mFrameTimeElapsed {0}
, mFrameCountElapsed {0}
, mAverageDeltaTime {10}
@ -121,7 +121,7 @@ bool Window::init()
mHelp = new HelpComponent;
mBackgroundOverlay = new ImageComponent;
mBackgroundOverlayOpacity = 0;
mBackgroundOverlayOpacity = 0.0f;
// Keep a reference to the default fonts, so they don't keep getting destroyed/recreated.
if (mDefaultFonts.empty()) {
@ -443,7 +443,7 @@ void Window::render()
// a new cached background has been generated.
if (mGuiStack.size() > 1 && mCachedBackground) {
if ((Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up" &&
mBackgroundOverlayOpacity == 255) ||
mBackgroundOverlayOpacity == 1.0f) ||
Settings::getInstance()->getString("MenuOpeningEffect") != "scale-up")
renderBottom = false;
}
@ -509,11 +509,11 @@ void Window::render()
// The following is done to avoid fading in if the cached image was
// invalidated (rather than the menu being opened).
if (mInvalidatedCachedBackground) {
mBackgroundOverlayOpacity = 255;
mBackgroundOverlayOpacity = 1.0f;
mInvalidatedCachedBackground = false;
}
else {
mBackgroundOverlayOpacity = 25;
mBackgroundOverlayOpacity = 0.1f;
}
delete[] processedTexture;
@ -530,8 +530,9 @@ void Window::render()
// Fade in the cached background if the menu opening effect has been set to scale-up.
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up") {
mBackgroundOverlay->setOpacity(mBackgroundOverlayOpacity);
if (mBackgroundOverlayOpacity < 255)
mBackgroundOverlayOpacity = glm::clamp(mBackgroundOverlayOpacity + 30, 0, 255);
if (mBackgroundOverlayOpacity < 1.0f)
mBackgroundOverlayOpacity =
glm::clamp(mBackgroundOverlayOpacity + 0.118f, 0.0f, 1.0f);
}
#endif // USE_OPENGL_21
@ -558,18 +559,20 @@ void Window::render()
}
// Render the quick list scrolling overlay, which is triggered in IList.
if (mListScrollOpacity != 0) {
if (mListScrollOpacity != 0.0f) {
Renderer::setMatrix(Renderer::getIdentity());
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()),
0x00000000 | mListScrollOpacity, 0x00000000 | mListScrollOpacity);
0x00000000 | static_cast<unsigned char>(mListScrollOpacity * 255.0f),
0x00000000 | static_cast<unsigned char>(mListScrollOpacity * 255.0f));
glm::vec2 offset {mListScrollFont->sizeText(mListScrollText)};
offset.x = (Renderer::getScreenWidth() - offset.x) * 0.5f;
offset.y = (Renderer::getScreenHeight() - offset.y) * 0.5f;
TextCache* cache = mListScrollFont->buildTextCache(mListScrollText, offset.x, offset.y,
0xFFFFFF00 | mListScrollOpacity);
TextCache* cache {mListScrollFont->buildTextCache(
mListScrollText, offset.x, offset.y,
0xFFFFFF00 | static_cast<unsigned char>(mListScrollOpacity * 255.0f))};
mListScrollFont->renderTextCache(cache);
delete cache;
}
@ -648,9 +651,9 @@ void Window::renderLoadingScreen(std::string text)
Renderer::swapBuffers();
}
void Window::renderListScrollOverlay(unsigned char opacity, const std::string& text)
void Window::renderListScrollOverlay(const float opacity, const std::string& text)
{
mListScrollOpacity = static_cast<unsigned char>(opacity * 0.6f);
mListScrollOpacity = opacity * 0.6f;
mListScrollText = text;
}

View file

@ -100,7 +100,7 @@ public:
void renderLoadingScreen(std::string text);
// The list scroll overlay is triggered from IList when the highest scrolling tier is reached.
void renderListScrollOverlay(unsigned char opacity, const std::string& text);
void renderListScrollOverlay(const float opacity, const std::string& text);
void renderHelpPromptsEarly(); // Used to render HelpPrompts before a fade.
void setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpStyle& style);
@ -162,7 +162,7 @@ private:
HelpComponent* mHelp;
ImageComponent* mBackgroundOverlay;
unsigned char mBackgroundOverlayOpacity;
float mBackgroundOverlayOpacity;
std::vector<GuiComponent*> mGuiStack;
std::vector<std::shared_ptr<Font>> mDefaultFonts;
std::unique_ptr<TextCache> mFrameDataText;
@ -180,7 +180,7 @@ private:
std::string mListScrollText;
std::shared_ptr<Font> mListScrollFont;
unsigned char mListScrollOpacity;
float mListScrollOpacity;
int mFrameTimeElapsed;
int mFrameCountElapsed;

View file

@ -104,7 +104,6 @@ void BadgeComponent::setBadges(const std::vector<BadgeInfo>& badges)
[badge](FlexboxComponent::FlexboxItem item) { return item.label == badge.badgeType; });
if (it != mFlexboxItems.end()) {
// Don't show the alternative emulator badge if the corresponding setting has been
// disabled.
if (badge.badgeType == "altemulator" &&
@ -172,13 +171,13 @@ void BadgeComponent::render(const glm::mat4& parentTrans)
if (!isVisible())
return;
if (mOpacity == 255) {
if (mOpacity == 1.0f) {
mFlexboxComponent.render(parentTrans);
}
else {
mFlexboxComponent.setOpacity(mOpacity);
mFlexboxComponent.render(parentTrans);
mFlexboxComponent.setOpacity(255);
mFlexboxComponent.setOpacity(1.0f);
}
}

View file

@ -291,7 +291,7 @@ void CarouselComponent::render(const glm::mat4& parentTrans)
scale = glm::clamp(scale, 1.0f / mLogoScale + 0.01f, 1.0f);
comp->setScale(scale);
comp->setOpacity(static_cast<unsigned char>(opacity));
comp->setOpacity(static_cast<float>(opacity) / 255.0f);
comp->render(logoTrans);
}
}

View file

@ -376,19 +376,17 @@ void ComponentList::render(const glm::mat4& parentTrans)
// Custom rendering.
Renderer::setMatrix(trans);
float opacity = mOpacity / 255.0f;
// Draw selector bar.
if (mFocused) {
const float selectedRowHeight = getRowHeight(mEntries.at(mCursor).data);
if (opacity == 1) {
if (mOpacity == 1.0f) {
Renderer::drawRect(0.0f, mSelectorBarOffset, std::ceil(mSize.x), selectedRowHeight,
0xFFFFFFFF, 0xFFFFFFFF, false, opacity, trans,
0xFFFFFFFF, 0xFFFFFFFF, false, mOpacity, trans,
Renderer::Blend::ONE_MINUS_DST_COLOR, Renderer::Blend::ZERO);
Renderer::drawRect(0.0f, mSelectorBarOffset, std::ceil(mSize.x), selectedRowHeight,
0x777777FF, 0x777777FF, false, opacity, trans, Renderer::Blend::ONE,
0x777777FF, 0x777777FF, false, mOpacity, trans, Renderer::Blend::ONE,
Renderer::Blend::ONE);
}
@ -404,12 +402,12 @@ void ComponentList::render(const glm::mat4& parentTrans)
float y = 0;
for (unsigned int i = 0; i < mEntries.size(); ++i) {
Renderer::drawRect(0.0f, y, std::ceil(mSize.x), 1.0f * Renderer::getScreenHeightModifier(),
0xC6C7C6FF, 0xC6C7C6FF, false, opacity, trans);
0xC6C7C6FF, 0xC6C7C6FF, false, mOpacity, trans);
y += getRowHeight(mEntries.at(i).data);
}
Renderer::drawRect(0.0f, y, std::ceil(mSize.x), 1.0f * Renderer::getScreenHeightModifier(),
0xC6C7C6FF, 0xC6C7C6FF, false, opacity, trans);
0xC6C7C6FF, 0xC6C7C6FF, false, mOpacity, trans);
Renderer::popClipRect();
}

View file

@ -193,7 +193,7 @@ void DateTimeEditComponent::render(const glm::mat4& parentTrans)
0x00000033, 0x00000033);
}
mTextCache->setColor((mColor & 0xFFFFFF00) | getOpacity());
mTextCache->setColor((mColor & 0xFFFFFF00) | static_cast<int>(getOpacity() * 255.0f));
font->renderTextCache(mTextCache.get());
if (mEditing && mTime != 0) {

View file

@ -50,7 +50,7 @@ void FlexboxComponent::render(const glm::mat4& parentTrans)
for (auto& item : mItems) {
if (!item.visible)
continue;
if (mOpacity == 255) {
if (mOpacity == 1.0f) {
item.baseImage.render(trans);
if (item.overlayImage.getTexture() != nullptr)
item.overlayImage.render(trans);
@ -58,11 +58,11 @@ void FlexboxComponent::render(const glm::mat4& parentTrans)
else {
item.baseImage.setOpacity(mOpacity);
item.baseImage.render(trans);
item.baseImage.setOpacity(255);
item.baseImage.setOpacity(1.0f);
if (item.overlayImage.getTexture() != nullptr) {
item.overlayImage.setOpacity(mOpacity);
item.overlayImage.render(trans);
item.overlayImage.setOpacity(255);
item.overlayImage.setOpacity(1.0f);
}
}
}

View file

@ -280,7 +280,7 @@ std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
return tex;
}
void HelpComponent::setOpacity(unsigned char opacity)
void HelpComponent::setOpacity(float opacity)
{
GuiComponent::setOpacity(opacity);

View file

@ -27,7 +27,7 @@ public:
void setPrompts(const std::vector<HelpPrompt>& prompts);
void render(const glm::mat4& parent) override;
void setOpacity(unsigned char opacity) override;
void setOpacity(float opacity) override;
void setStyle(const HelpStyle& style);

View file

@ -73,7 +73,7 @@ protected:
int mScrollTierAccumulator;
int mScrollCursorAccumulator;
unsigned char mTitleOverlayOpacity;
float mTitleOverlayOpacity;
unsigned int mTitleOverlayColor;
const ScrollTierList& mTierList;
@ -95,7 +95,7 @@ public:
mScrollTierAccumulator = 0;
mScrollCursorAccumulator = 0;
mTitleOverlayOpacity = 0x00;
mTitleOverlayOpacity = 0.0f;
mTitleOverlayColor = 0xFFFFFF00;
}
@ -105,7 +105,7 @@ public:
void stopScrolling()
{
mTitleOverlayOpacity = 0;
mTitleOverlayOpacity = 0.0f;
listInput(0);
if (mScrollVelocity == 0)
@ -243,15 +243,10 @@ protected:
{
// Update the title overlay opacity.
// Fade in if scroll tier is >= 1, otherwise fade out.
const int dir = (mScrollTier >= mTierList.count - 1) ? 1 : -1;
const float dir {(mScrollTier >= mTierList.count - 1) ? 1.0f : -1.0f};
// We simply translate the time directly to opacity, i.e. no scaling is performed.
int op = mTitleOverlayOpacity + deltaTime * dir;
if (op >= 255)
mTitleOverlayOpacity = 255;
else if (op <= 0)
mTitleOverlayOpacity = 0;
else
mTitleOverlayOpacity = static_cast<unsigned char>(op);
mTitleOverlayOpacity = glm::clamp(
mTitleOverlayOpacity + (static_cast<float>(deltaTime) / 255.0f) * dir, 0.0f, 1.0f);
if (mScrollVelocity == 0 || size() < 2)
return;
@ -285,8 +280,8 @@ protected:
if (!Settings::getInstance()->getBool("ListScrollOverlay"))
return;
if (size() == 0 || mTitleOverlayOpacity == 0) {
mWindow->renderListScrollOverlay(0, "");
if (size() == 0 || mTitleOverlayOpacity == 0.0f) {
mWindow->renderListScrollOverlay(0.0f, "");
return;
}

View file

@ -37,7 +37,7 @@ ImageComponent::ImageComponent(bool forceLoad, bool dynamic)
, mColorShift {0xFFFFFFFF}
, mColorShiftEnd {0xFFFFFFFF}
, mColorGradientHorizontal {true}
, mFadeOpacity {0}
, mFadeOpacity {0.0f}
, mFading {false}
, mForceLoad {forceLoad}
, mDynamic {dynamic}
@ -319,7 +319,7 @@ void ImageComponent::setColorGradientHorizontal(bool horizontal)
updateColors();
}
void ImageComponent::setOpacity(unsigned char opacity)
void ImageComponent::setOpacity(float opacity)
{
mOpacity = opacity;
updateColors();
@ -369,7 +369,7 @@ void ImageComponent::updateVertices()
void ImageComponent::updateColors()
{
const float opacity = (mOpacity * (mFading ? mFadeOpacity / 255.0f : 1.0f)) / 255.0f;
const float opacity = (mOpacity * (mFading ? mFadeOpacity : 1.0f));
const unsigned int color = Renderer::convertRGBAToABGR(
(mColorShift & 0xFFFFFF00) | static_cast<unsigned char>((mColorShift & 0xFF) * opacity));
const unsigned int colorEnd =
@ -391,7 +391,7 @@ void ImageComponent::render(const glm::mat4& parentTrans)
glm::mat4 trans {parentTrans * getTransform()};
Renderer::setMatrix(trans);
if (mTexture && mOpacity > 0) {
if (mTexture && mOpacity > 0.0f) {
if (Settings::getInstance()->getBool("DebugImage")) {
glm::vec2 targetSizePos {(mTargetSize - mSize) * mOrigin * glm::vec2 {-1.0f}};
Renderer::drawRect(targetSizePos.x, targetSizePos.y, mTargetSize.x, mTargetSize.y,
@ -447,7 +447,7 @@ void ImageComponent::fadeIn(bool textureLoaded)
// Start the fade if this is the first time we've encountered the unloaded texture.
if (!mFading) {
// Start with a zero opacity and flag it as fading.
mFadeOpacity = 0;
mFadeOpacity = 0.0f;
mFading = true;
updateColors();
}
@ -456,14 +456,14 @@ void ImageComponent::fadeIn(bool textureLoaded)
// The texture is loaded and we need to fade it in. The fade is based on the frame
// rate and is 1/4 second if running at 60 frames per second although the actual
// value is not that important.
int opacity = mFadeOpacity + 255 / 15;
float opacity {mFadeOpacity + 1.0f / 15.0f};
// See if we've finished fading.
if (opacity >= 255) {
mFadeOpacity = 255;
if (opacity >= 1.0f) {
mFadeOpacity = 1.0f;
mFading = false;
}
else {
mFadeOpacity = static_cast<unsigned char>(opacity);
mFadeOpacity = opacity;
}
updateColors();
}

View file

@ -71,7 +71,7 @@ public:
unsigned int getColorShift() const override { return mColorShift; }
void setOpacity(unsigned char opacity) override;
void setOpacity(float opacity) override;
void setSaturation(float saturation) override;
void setFlipX(bool flip); // Mirror on the X axis.
@ -124,7 +124,7 @@ private:
std::string mDefaultPath;
std::shared_ptr<TextureResource> mTexture;
unsigned char mFadeOpacity;
float mFadeOpacity;
bool mFading;
bool mForceLoad;
bool mDynamic;

View file

@ -135,9 +135,9 @@ void NinePatchComponent::render(const glm::mat4& parentTrans)
if (mTexture && mVertices != nullptr) {
Renderer::setMatrix(trans);
if (mOpacity < 255) {
if (mOpacity < 1.0f) {
mVertices[0].shaders = Renderer::SHADER_OPACITY;
mVertices[0].opacity = mOpacity / 255.0f;
mVertices[0].opacity = mOpacity;
}
else if (mVertices[0].shaders & Renderer::SHADER_OPACITY) {
// We have reached full opacity, so disable the opacity shader and set

View file

@ -500,8 +500,8 @@ private:
else {
mEnabled = true;
list->getChild(i)->setEnabled(true);
list->getChild(i)->setOpacity(255);
list->getChild(i + 1)->setOpacity(255);
list->getChild(i)->setOpacity(1.0f);
list->getChild(i + 1)->setOpacity(1.0f);
}
}
}
@ -545,8 +545,8 @@ private:
mParent->mEntries.at(i).selected = false;
checkBoxes.at(i)->setImage(UNCHECKED_PATH);
if (mParent->mMultiExclusiveSelect) {
checkBoxes.at(i)->setOpacity(255);
textEntries.at(i)->setOpacity(255);
checkBoxes.at(i)->setOpacity(1.0f);
textEntries.at(i)->setOpacity(1.0f);
textEntries.at(i)->setEnabled(true);
}
}

View file

@ -82,10 +82,10 @@ std::string RatingComponent::getRatingValue() const
return ss.str();
}
void RatingComponent::setOpacity(unsigned char opacity)
void RatingComponent::setOpacity(float opacity)
{
mOpacity = opacity;
mColorShift = (mColorShift >> 8 << 8) | mOpacity;
mColorShift = (mColorShift >> 8 << 8) | static_cast<unsigned char>(mOpacity * 255.0f);
updateColors();
}
@ -96,7 +96,7 @@ void RatingComponent::setColorShift(unsigned int color)
// Grab the opacity from the color shift because we may need
// to apply it if fading in textures.
mOpacity = color & 0xff;
mOpacity = static_cast<float>(color & 0xff) / 255.0f;
updateColors();
}
@ -155,7 +155,7 @@ void RatingComponent::render(const glm::mat4& parentTrans)
Renderer::setMatrix(trans);
if (mOpacity > 0) {
if (mOpacity > 0.0f) {
if (Settings::getInstance()->getBool("DebugImage")) {
Renderer::drawRect(0.0f, 0.0f, mSize.y * NUM_RATING_STARS, mSize.y, 0xFF000033,
0xFF000033);

View file

@ -32,7 +32,7 @@ public:
void onSizeChanged() override;
void setOpacity(unsigned char opacity) override;
void setOpacity(float opacity) override;
// Multiply all pixels in the image by this color when rendering.
void setColorShift(unsigned int color) override;

View file

@ -27,8 +27,8 @@ public:
scrollUp->setImage(":/graphics/scroll_up.svg");
scrollDown->setImage(":/graphics/scroll_down.svg");
scrollUp->setOpacity(0);
scrollDown->setOpacity(0);
scrollUp->setOpacity(0.0f);
scrollDown->setOpacity(0.0f);
if (!Settings::getInstance()->getBool("ScrollIndicators")) {
// If the scroll indicators setting is disabled, then show a permanent down arrow
@ -38,7 +38,7 @@ public:
if (state == ComponentList::SCROLL_UP ||
state == ComponentList::SCROLL_UP_DOWN ||
state == ComponentList::SCROLL_DOWN) {
scrollDown->setOpacity(255);
scrollDown->setOpacity(1.0f);
}
});
}
@ -60,7 +60,7 @@ public:
if (state == ComponentList::SCROLL_UP &&
mPreviousScrollState == ComponentList::SCROLL_NONE) {
scrollUp->setOpacity(255);
scrollUp->setOpacity(1.0f);
}
else if (state == ComponentList::SCROLL_UP &&
mPreviousScrollState == ComponentList::SCROLL_UP_DOWN) {
@ -70,12 +70,12 @@ public:
mPreviousScrollState == ComponentList::SCROLL_DOWN) {
upFadeIn = true;
fadeTime *= 2.0f;
scrollDown->setOpacity(0);
scrollDown->setOpacity(0.0f);
}
else if (state == ComponentList::SCROLL_UP_DOWN &&
mPreviousScrollState == ComponentList::SCROLL_NONE) {
scrollUp->setOpacity(255);
scrollDown->setOpacity(255);
scrollUp->setOpacity(1.0f);
scrollDown->setOpacity(1.0f);
}
else if (state == ComponentList::SCROLL_UP_DOWN &&
mPreviousScrollState == ComponentList::SCROLL_DOWN) {
@ -87,7 +87,7 @@ public:
}
else if (state == ComponentList::SCROLL_DOWN &&
mPreviousScrollState == ComponentList::SCROLL_NONE) {
scrollDown->setOpacity(255);
scrollDown->setOpacity(1.0f);
}
else if (state == ComponentList::SCROLL_DOWN &&
mPreviousScrollState == ComponentList::SCROLL_UP_DOWN) {
@ -97,7 +97,7 @@ public:
mPreviousScrollState == ComponentList::SCROLL_UP) {
downFadeIn = true;
fadeTime *= 2.0f;
scrollUp->setOpacity(0);
scrollUp->setOpacity(0.0f);
}
// If jumping more than one row using the shoulder or trigger buttons, then
@ -107,8 +107,7 @@ public:
if (upFadeIn) {
auto upFadeInFunc = [scrollUp](float t) {
scrollUp->setOpacity(
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
scrollUp->setOpacity(glm::mix(0.0f, 1.0f, t));
};
scrollUp->setAnimation(
new LambdaAnimation(upFadeInFunc, static_cast<int>(fadeTime)), 0,
@ -117,8 +116,7 @@ public:
if (upFadeOut) {
auto upFadeOutFunc = [scrollUp](float t) {
scrollUp->setOpacity(
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
scrollUp->setOpacity(glm::mix(0.0f, 1.0f, t));
};
scrollUp->setAnimation(
new LambdaAnimation(upFadeOutFunc, static_cast<int>(fadeTime)), 0,
@ -127,8 +125,7 @@ public:
if (downFadeIn) {
auto downFadeInFunc = [scrollDown](float t) {
scrollDown->setOpacity(
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
scrollDown->setOpacity(glm::mix(0.0f, 1.0f, t));
};
scrollDown->setAnimation(
new LambdaAnimation(downFadeInFunc, static_cast<int>(fadeTime)), 0,
@ -137,8 +134,7 @@ public:
if (downFadeOut) {
auto downFadeOutFunc = [scrollDown](float t) {
scrollDown->setOpacity(
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
scrollDown->setOpacity(glm::mix(0.0f, 1.0f, t));
};
scrollDown->setAnimation(
new LambdaAnimation(downFadeOutFunc, static_cast<int>(fadeTime)), 0,

View file

@ -197,9 +197,8 @@ void ScrollableContainer::update(int deltaTime)
255.0f};
auto func = [this, maxOpacity](float t) {
unsigned int color {mChildren.front()->getColor()};
unsigned int opacity {
static_cast<unsigned int>(glm::mix(0.0f, maxOpacity, t) * 255)};
color = (color & 0xFFFFFF00) + opacity;
float opacity {glm::mix(0.0f, maxOpacity, t)};
color = (color & 0xFFFFFF00) + static_cast<unsigned char>(opacity * 255.0f);
this->mChildren.front()->setColor(color);
mScrollPos = glm::vec2 {};
mAutoScrollResetAccumulator = 0;

View file

@ -32,8 +32,8 @@ public:
void setChangedColor(unsigned int color) override { mColorChangedValue = color; }
void setCallback(const std::function<void()>& callbackFunc) { mToggleCallback = callbackFunc; }
unsigned char getOpacity() const override { return mImage.getOpacity(); }
void setOpacity(unsigned char opacity) override { mImage.setOpacity(opacity); }
float getOpacity() const override { return mImage.getOpacity(); }
void setOpacity(float opacity) override { mImage.setOpacity(opacity); }
// Multiply all pixels in the image by this color when rendering.
void setColorShift(unsigned int color) override { mImage.setColorShift(color); }

View file

@ -16,8 +16,8 @@ TextComponent::TextComponent()
: mFont {Font::get(FONT_SIZE_MEDIUM)}
, mColor {0x000000FF}
, mBgColor {0x00000000}
, mColorOpacity {0x000000FF}
, mBgColorOpacity {0x00000000}
, mColorOpacity {1.0f}
, mBgColorOpacity {0.0f}
, mRenderBackground {false}
, mUppercase {false}
, mLowercase {false}
@ -41,8 +41,8 @@ TextComponent::TextComponent(const std::string& text,
: mFont {nullptr}
, mColor {0x000000FF}
, mBgColor {0x00000000}
, mColorOpacity {0x000000FF}
, mBgColorOpacity {0x00000000}
, mColorOpacity {1.0f}
, mBgColorOpacity {0.0f}
, mRenderBackground {false}
, mUppercase {false}
, mLowercase {false}
@ -81,7 +81,7 @@ void TextComponent::setFont(const std::shared_ptr<Font>& font)
void TextComponent::setColor(unsigned int color)
{
mColor = color;
mColorOpacity = mColor & 0x000000FF;
mColorOpacity = static_cast<float>(mColor & 0x000000FF) / 255.0f;
onColorChanged();
}
@ -89,22 +89,18 @@ void TextComponent::setColor(unsigned int color)
void TextComponent::setBackgroundColor(unsigned int color)
{
mBgColor = color;
mBgColorOpacity = mBgColor & 0x000000FF;
mBgColorOpacity = static_cast<float>(mBgColor & 0x000000FF) / 255.0f;
}
// Scale the opacity.
void TextComponent::setOpacity(unsigned char opacity)
void TextComponent::setOpacity(float opacity)
{
// This function is mostly called to do fade in and fade out of the text component element.
// Therefore we assume here that opacity is a fractional value (expressed as an unsigned
// char 0 - 255) of the opacity originally set with setColor() or setBackgroundColor().
unsigned char o = static_cast<unsigned char>(static_cast<float>(opacity) / 255.0f *
static_cast<float>(mColorOpacity));
mColor = (mColor & 0xFFFFFF00) | static_cast<unsigned char>(o);
float o {opacity * mColorOpacity};
mColor = (mColor & 0xFFFFFF00) | static_cast<unsigned char>(o * 255.0f);
unsigned char bgo = static_cast<unsigned char>(static_cast<float>(opacity) / 255.0f *
static_cast<float>(mBgColorOpacity));
mBgColor = (mBgColor & 0xFFFFFF00) | static_cast<unsigned char>(bgo);
float bgo {opacity * mBgColorOpacity};
mBgColor = (mBgColor & 0xFFFFFF00) | static_cast<unsigned char>(bgo * 255.0f);
onColorChanged();
GuiComponent::setOpacity(opacity);
@ -307,14 +303,15 @@ void TextComponent::onTextChanged()
text.append(abbrev);
mTextCache = std::shared_ptr<TextCache>(
f->buildTextCache(text, glm::vec2 {}, (mColor >> 8 << 8) | mOpacity, mSize.x,
mHorizontalAlignment, mLineSpacing, mNoTopMargin));
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(
text, glm::vec2 {}, (mColor >> 8 << 8) | static_cast<unsigned char>(mOpacity * 255.0f),
mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin));
}
else {
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(
f->wrapText(text, mSize.x), glm::vec2 {}, (mColor >> 8 << 8) | mOpacity, mSize.x,
mHorizontalAlignment, mLineSpacing, mNoTopMargin));
mTextCache = std::shared_ptr<TextCache>(
f->buildTextCache(f->wrapText(text, mSize.x), glm::vec2 {},
(mColor >> 8 << 8) | static_cast<unsigned char>(mOpacity * 255.0f),
mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin));
}
// This is required to set the color transparency.

View file

@ -57,8 +57,8 @@ public:
std::string getHiddenValue() const override { return mHiddenText; }
void setHiddenValue(const std::string& value) override { setHiddenText(value); }
unsigned char getOpacity() const override { return mColor & 0x000000FF; }
void setOpacity(unsigned char opacity) override;
float getOpacity() const override { return static_cast<float>((mColor & 0x000000FF) / 255.0f); }
void setOpacity(float opacity) override;
void setSelectable(bool status) { mSelectable = status; }
@ -87,8 +87,8 @@ private:
unsigned int mColor;
unsigned int mBgColor;
unsigned char mColorOpacity;
unsigned char mBgColorOpacity;
float mColorOpacity;
float mBgColorOpacity;
bool mRenderBackground;
bool mUppercase;

View file

@ -258,8 +258,8 @@ void TextEditComponent::setCursor(size_t pos)
void TextEditComponent::onTextChanged()
{
std::string wrappedText = (isMultiline() ? mFont->wrapText(mText, getTextAreaSize().x) : mText);
mTextCache = std::unique_ptr<TextCache>(
mFont->buildTextCache(wrappedText, 0.0f, 0.0f, 0x77777700 | getOpacity()));
mTextCache = std::unique_ptr<TextCache>(mFont->buildTextCache(
wrappedText, 0.0f, 0.0f, 0x77777700 | static_cast<unsigned char>(mOpacity * 255.0f)));
if (mCursor > static_cast<int>(mText.length()))
mCursor = static_cast<int>(mText.length());

View file

@ -46,7 +46,7 @@ public:
// Sets whether we're in screensaver mode.
void setScreensaverMode(bool isScreensaver) { mScreensaverMode = isScreensaver; }
// Set the opacity for the embedded static image.
void setOpacity(unsigned char opacity) override { mOpacity = opacity; }
void setOpacity(float opacity) override { mOpacity = opacity; }
bool hasStaticVideo() { return !mConfig.staticVideoPath.empty(); }
bool hasStaticImage() { return mStaticImage.getTextureSize() != glm::ivec2 {0, 0}; }

View file

@ -123,7 +123,7 @@ bool GuiDetectDevice::input(InputConfig* config, Input input)
if (input.value && mHoldingConfig == nullptr) {
// Started holding.
mHoldingConfig = config;
mHoldTime = HOLD_TIME;
mHoldTime = static_cast<int>(HOLD_TIME);
mDeviceHeld->setText(Utils::String::toUpper(config->getDeviceName()));
}
else if (!input.value && mHoldingConfig == config) {

View file

@ -17,6 +17,7 @@
GuiInfoPopup::GuiInfoPopup(std::string message, int duration)
: mMessage {message}
, mDuration {duration}
, mAlpha {1.0f}
, mRunning {true}
{
mFrame = new NinePatchComponent;
@ -102,18 +103,18 @@ bool GuiInfoPopup::updateState()
return false;
}
else if (curTime - mStartTime <= 500) {
mAlpha = ((curTime - mStartTime) * 255 / 500);
mAlpha = static_cast<float>((curTime - mStartTime) / 500.0f);
}
else if (curTime - mStartTime < mDuration - 500) {
mAlpha = 255;
mAlpha = 1.0f;
}
else {
mAlpha = ((-(curTime - mStartTime - mDuration) * 255) / 500);
mAlpha = static_cast<float>((-(curTime - mStartTime - mDuration)) / 500.0f);
}
mGrid->setOpacity(static_cast<unsigned char>(mAlpha));
mGrid->setOpacity(mAlpha);
// Apply fade-in effect to popup frame.
mFrame->setEdgeColor(0xFFFFFF00 | static_cast<unsigned char>(mAlpha));
mFrame->setCenterColor(0xFFFFFF00 | static_cast<unsigned char>(mAlpha));
mFrame->setEdgeColor(0xFFFFFF00 | static_cast<unsigned char>(mAlpha * 255.0f));
mFrame->setCenterColor(0xFFFFFF00 | static_cast<unsigned char>(mAlpha * 255.0f));
return true;
}

View file

@ -32,7 +32,7 @@ private:
std::string mMessage;
int mDuration;
int mAlpha;
float mAlpha;
int mStartTime;
bool mRunning;
};

View file

@ -71,7 +71,7 @@ GuiInputConfig::GuiInputConfig(InputConfig* target,
mSubtitle2 = std::make_shared<TextComponent>(
"HOLD ANY BUTTON 1 SECOND TO SKIP", Font::get(FONT_SIZE_SMALL), 0x999999FF, ALIGN_CENTER);
// The opacity will be set to visible for any row that is skippable.
mSubtitle2->setOpacity(0);
mSubtitle2->setOpacity(0.0f);
mGrid.setEntry(mSubtitle2, glm::ivec2 {0, 3}, false, true);
@ -157,8 +157,10 @@ GuiInputConfig::GuiInputConfig(InputConfig* target,
// Only show "HOLD TO SKIP" if this input is skippable.
mList->setCursorChangedCallback([this](CursorState) {
bool skippable = sGuiInputConfigList[mList->getCursorId()].skippable;
mSubtitle2->setOpacity(skippable * 255);
if (sGuiInputConfigList[mList->getCursorId()].skippable)
mSubtitle2->setOpacity(1.0f);
else
mSubtitle2->setOpacity(0.0f);
});
// Make the first one say "PRESS ANYTHING" if we're re-configuring everything.