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