2021-10-10 16:15:37 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
|
|
|
// EmulationStation Desktop Edition
|
|
|
|
// ScrollIndicatorComponent.h
|
|
|
|
//
|
|
|
|
// Visually indicates whether a menu can be scrolled (up, up/down or down).
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ES_CORE_COMPONENTS_SCROLL_INDICATOR_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_SCROLL_INDICATOR_COMPONENT_H
|
|
|
|
|
|
|
|
#define FADE_IN_TIME 90.0f
|
|
|
|
|
|
|
|
#include "animations/LambdaAnimation.h"
|
|
|
|
#include "components/ComponentList.h"
|
|
|
|
|
|
|
|
class ScrollIndicatorComponent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScrollIndicatorComponent(std::shared_ptr<ComponentList> componentList,
|
|
|
|
std::shared_ptr<ImageComponent> scrollUp,
|
|
|
|
std::shared_ptr<ImageComponent> scrollDown)
|
|
|
|
: mPreviousScrollState(ComponentList::SCROLL_NONE)
|
|
|
|
{
|
|
|
|
assert(componentList != nullptr && scrollUp != nullptr && scrollDown != nullptr);
|
|
|
|
|
|
|
|
scrollUp->setImage(":/graphics/scroll_up.svg");
|
|
|
|
scrollDown->setImage(":/graphics/scroll_down.svg");
|
|
|
|
|
|
|
|
scrollUp->setOpacity(0);
|
|
|
|
scrollDown->setOpacity(0);
|
|
|
|
|
2021-10-10 18:07:44 +00:00
|
|
|
if (!Settings::getInstance()->getBool("ScrollIndicators")) {
|
|
|
|
// If the scroll indicators setting is disabled, then show a permanent down arrow
|
|
|
|
// symbol when the component list contains more entries than can fit on screen.
|
|
|
|
componentList.get()->setScrollIndicatorChangedCallback(
|
2021-10-16 11:21:52 +00:00
|
|
|
[scrollUp, scrollDown](ComponentList::ScrollIndicator state, bool singleRowScroll) {
|
2021-10-10 18:07:44 +00:00
|
|
|
if (state == ComponentList::SCROLL_UP ||
|
|
|
|
state == ComponentList::SCROLL_UP_DOWN ||
|
|
|
|
state == ComponentList::SCROLL_DOWN) {
|
|
|
|
scrollDown->setOpacity(255);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If the scroll indicator setting is enabled, then also show the up and up/down
|
|
|
|
// combination and switch between these as the list is scrolled.
|
|
|
|
componentList.get()->setScrollIndicatorChangedCallback(
|
2021-10-16 11:21:52 +00:00
|
|
|
[this, scrollUp, scrollDown](ComponentList::ScrollIndicator state,
|
|
|
|
bool singleRowScroll) {
|
|
|
|
float fadeTime{FADE_IN_TIME};
|
2021-10-10 18:07:44 +00:00
|
|
|
|
|
|
|
bool upFadeIn = false;
|
|
|
|
bool upFadeOut = false;
|
|
|
|
bool downFadeIn = false;
|
|
|
|
bool downFadeOut = false;
|
|
|
|
|
|
|
|
scrollUp->finishAnimation(0);
|
|
|
|
scrollDown->finishAnimation(0);
|
|
|
|
|
|
|
|
if (state == ComponentList::SCROLL_UP &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_NONE) {
|
|
|
|
scrollUp->setOpacity(255);
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_UP &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_UP_DOWN) {
|
|
|
|
downFadeOut = true;
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_UP &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_DOWN) {
|
|
|
|
upFadeIn = true;
|
2021-10-16 11:21:52 +00:00
|
|
|
fadeTime *= 2.0f;
|
2021-10-10 18:07:44 +00:00
|
|
|
scrollDown->setOpacity(0);
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_UP_DOWN &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_NONE) {
|
|
|
|
scrollUp->setOpacity(255);
|
|
|
|
scrollDown->setOpacity(255);
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_UP_DOWN &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_DOWN) {
|
|
|
|
upFadeIn = true;
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_UP_DOWN &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_UP) {
|
|
|
|
downFadeIn = true;
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_DOWN &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_NONE) {
|
|
|
|
scrollDown->setOpacity(255);
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_DOWN &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_UP_DOWN) {
|
|
|
|
upFadeOut = true;
|
|
|
|
}
|
|
|
|
else if (state == ComponentList::SCROLL_DOWN &&
|
|
|
|
mPreviousScrollState == ComponentList::SCROLL_UP) {
|
|
|
|
downFadeIn = true;
|
2021-10-16 11:21:52 +00:00
|
|
|
fadeTime *= 2.0f;
|
2021-10-10 18:07:44 +00:00
|
|
|
scrollUp->setOpacity(0);
|
|
|
|
}
|
|
|
|
|
2021-10-16 11:21:52 +00:00
|
|
|
// If jumping more than one row using the shoulder or trigger buttons, then
|
|
|
|
// don't fade the indicators.
|
|
|
|
if (!singleRowScroll)
|
|
|
|
fadeTime = 0.0f;
|
|
|
|
|
2021-10-10 18:07:44 +00:00
|
|
|
if (upFadeIn) {
|
|
|
|
auto upFadeInFunc = [scrollUp](float t) {
|
|
|
|
scrollUp->setOpacity(
|
|
|
|
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
|
|
|
|
};
|
|
|
|
scrollUp->setAnimation(
|
2021-10-16 11:21:52 +00:00
|
|
|
new LambdaAnimation(upFadeInFunc, static_cast<int>(fadeTime)), 0,
|
2021-10-10 18:07:44 +00:00
|
|
|
nullptr, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (upFadeOut) {
|
|
|
|
auto upFadeOutFunc = [scrollUp](float t) {
|
|
|
|
scrollUp->setOpacity(
|
|
|
|
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
|
|
|
|
};
|
|
|
|
scrollUp->setAnimation(
|
2021-10-16 11:21:52 +00:00
|
|
|
new LambdaAnimation(upFadeOutFunc, static_cast<int>(fadeTime)), 0,
|
2021-10-10 18:07:44 +00:00
|
|
|
nullptr, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (downFadeIn) {
|
|
|
|
auto downFadeInFunc = [scrollDown](float t) {
|
|
|
|
scrollDown->setOpacity(
|
|
|
|
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
|
|
|
|
};
|
|
|
|
scrollDown->setAnimation(
|
2021-10-16 11:21:52 +00:00
|
|
|
new LambdaAnimation(downFadeInFunc, static_cast<int>(fadeTime)), 0,
|
2021-10-10 18:07:44 +00:00
|
|
|
nullptr, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (downFadeOut) {
|
|
|
|
auto downFadeOutFunc = [scrollDown](float t) {
|
|
|
|
scrollDown->setOpacity(
|
|
|
|
static_cast<unsigned char>(glm::mix(0.0f, 1.0f, t) * 255));
|
|
|
|
};
|
|
|
|
scrollDown->setAnimation(
|
2021-10-16 11:21:52 +00:00
|
|
|
new LambdaAnimation(downFadeOutFunc, static_cast<int>(fadeTime)), 0,
|
2021-10-10 18:07:44 +00:00
|
|
|
nullptr, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
mPreviousScrollState = state;
|
|
|
|
});
|
|
|
|
}
|
2021-10-10 16:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ComponentList::ScrollIndicator mPreviousScrollState;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_SCROLL_INDICATOR_COMPONENT_H
|