mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Merge pull request #5423 from hyperlogic/ajt/overlay-fade
Update ApplicationCompositor to use QPropertyAnimation for alpha fades
This commit is contained in:
commit
9727302d02
3 changed files with 36 additions and 15 deletions
|
@ -165,6 +165,8 @@ ApplicationCompositor::ApplicationCompositor() {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
_alphaPropertyAnimation = std::make_unique<QPropertyAnimation>(this, "alpha");
|
||||
}
|
||||
|
||||
ApplicationCompositor::~ApplicationCompositor() {
|
||||
|
@ -730,12 +732,28 @@ void ApplicationCompositor::updateTooltips() {
|
|||
}
|
||||
}
|
||||
|
||||
void ApplicationCompositor::update(float dt) {
|
||||
const int ALPHA_FADE_RATE = 2.0f;
|
||||
_prevAlpha = _alpha;
|
||||
if (_fadeInAlpha && _alpha < 1.0f) {
|
||||
_alpha = std::min(_alpha + ALPHA_FADE_RATE * dt, 1.0f);
|
||||
} else if (!_fadeInAlpha && _alpha > 0.0f) {
|
||||
_alpha = std::max(_alpha - ALPHA_FADE_RATE * dt, 0.0f);
|
||||
static const float FADE_DURATION = 500.0f;
|
||||
void ApplicationCompositor::fadeIn() {
|
||||
_fadeInAlpha = true;
|
||||
|
||||
_alphaPropertyAnimation->setDuration(FADE_DURATION);
|
||||
_alphaPropertyAnimation->setStartValue(_alpha);
|
||||
_alphaPropertyAnimation->setEndValue(1.0f);
|
||||
_alphaPropertyAnimation->start();
|
||||
}
|
||||
void ApplicationCompositor::fadeOut() {
|
||||
_fadeInAlpha = false;
|
||||
|
||||
_alphaPropertyAnimation->setDuration(FADE_DURATION);
|
||||
_alphaPropertyAnimation->setStartValue(_alpha);
|
||||
_alphaPropertyAnimation->setEndValue(0.0f);
|
||||
_alphaPropertyAnimation->start();
|
||||
}
|
||||
|
||||
void ApplicationCompositor::toggle() {
|
||||
if (_fadeInAlpha) {
|
||||
fadeOut();
|
||||
} else {
|
||||
fadeIn();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define hifi_ApplicationCompositor_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QPropertyAnimation>
|
||||
#include <cstdint>
|
||||
|
||||
#include <EntityItemID.h>
|
||||
|
@ -33,6 +34,8 @@ const float DEFAULT_HMD_UI_ANGULAR_SIZE = 72.0f;
|
|||
// facilities of this class
|
||||
class ApplicationCompositor : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(float alpha READ getAlpha WRITE setAlpha)
|
||||
public:
|
||||
ApplicationCompositor();
|
||||
~ApplicationCompositor();
|
||||
|
@ -70,10 +73,12 @@ public:
|
|||
void setModelTransform(const Transform& transform) { _modelTransform = transform; }
|
||||
const Transform& getModelTransform() const { return _modelTransform; }
|
||||
|
||||
void fadeIn() { _fadeInAlpha = true; }
|
||||
void fadeOut() { _fadeInAlpha = false; }
|
||||
void toggle() { _fadeInAlpha = !_fadeInAlpha; }
|
||||
void update(float dt);
|
||||
void fadeIn();
|
||||
void fadeOut();
|
||||
void toggle();
|
||||
|
||||
float getAlpha() const { return _alpha; }
|
||||
void setAlpha(float alpha) { _alpha = alpha; }
|
||||
|
||||
static glm::vec2 directionToSpherical(const glm::vec3 & direction);
|
||||
static glm::vec3 sphericalToDirection(const glm::vec2 & sphericalPos);
|
||||
|
@ -131,6 +136,8 @@ private:
|
|||
|
||||
Transform _modelTransform;
|
||||
Transform _cameraBaseTransform;
|
||||
|
||||
std::unique_ptr<QPropertyAnimation> _alphaPropertyAnimation;
|
||||
};
|
||||
|
||||
#endif // hifi_ApplicationCompositor_h
|
||||
|
|
|
@ -62,10 +62,6 @@ void OverlayConductor::update(float dt) {
|
|||
// do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// process alpha fade animations
|
||||
qApp->getApplicationCompositor().update(dt);
|
||||
}
|
||||
|
||||
void OverlayConductor::updateMode() {
|
||||
|
|
Loading…
Reference in a new issue