2020-09-15 20:57:54 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-09-15 20:57:54 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// GuiComponent.cpp
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Basic GUI component handling such as placement, rotation, Z-order, rendering and animation.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
#include "GuiComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
#include "animations/Animation.h"
|
|
|
|
#include "animations/AnimationController.h"
|
2019-08-08 20:16:11 +00:00
|
|
|
#include "renderers/Renderer.h"
|
2013-06-02 16:11:29 +00:00
|
|
|
#include "Log.h"
|
2014-01-01 05:39:22 +00:00
|
|
|
#include "ThemeData.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Window.h"
|
2020-09-15 20:57:54 +00:00
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <algorithm>
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
GuiComponent::GuiComponent(Window* window)
|
2020-06-21 12:25:28 +00:00
|
|
|
: mWindow(window),
|
2020-06-23 18:07:00 +00:00
|
|
|
mParent(nullptr),
|
2020-11-08 12:03:45 +00:00
|
|
|
mColor(0),
|
|
|
|
mColorShift(0),
|
|
|
|
mColorShiftEnd(0),
|
2020-06-21 12:25:28 +00:00
|
|
|
mOpacity(255),
|
2020-08-30 20:19:37 +00:00
|
|
|
mSaturation(1.0),
|
2020-06-21 12:25:28 +00:00
|
|
|
mPosition(Vector3f::Zero()),
|
|
|
|
mOrigin(Vector2f::Zero()),
|
|
|
|
mRotationOrigin(0.5, 0.5),
|
|
|
|
mSize(Vector2f::Zero()),
|
|
|
|
mTransform(Transform4x4f::Identity()),
|
|
|
|
mIsProcessing(false),
|
2020-08-05 17:31:59 +00:00
|
|
|
mVisible(true),
|
2020-11-18 22:47:32 +00:00
|
|
|
mEnabled(true)
|
2020-05-24 08:29:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
2020-06-23 18:07:00 +00:00
|
|
|
mAnimationMap[i] = nullptr;
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent::~GuiComponent()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mWindow->removeGui(this);
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
cancelAllAnimations();
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mParent)
|
|
|
|
mParent->removeChild(this);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
2020-06-23 18:07:00 +00:00
|
|
|
getChild(i)->setParent(nullptr);
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiComponent::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++) {
|
|
|
|
if (getChild(i)->input(config, input))
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return false;
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 19:29:07 +00:00
|
|
|
void GuiComponent::updateSelf(int deltaTime)
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
|
|
|
advanceAnimation(i, deltaTime);
|
2014-06-05 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::updateChildren(int deltaTime)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->update(deltaTime);
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 19:29:07 +00:00
|
|
|
void GuiComponent::update(int deltaTime)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
updateSelf(deltaTime);
|
|
|
|
updateChildren(deltaTime);
|
2014-06-05 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
void GuiComponent::render(const Transform4x4f& parentTrans)
|
2013-06-02 19:34:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!isVisible())
|
|
|
|
return;
|
2019-07-22 03:13:48 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Transform4x4f trans = parentTrans * getTransform();
|
|
|
|
renderChildren(trans);
|
2013-06-02 19:34:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
void GuiComponent::renderChildren(const Transform4x4f& transform) const
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->render(transform);
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector3f GuiComponent::getPosition() const
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mPosition;
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 03:10:29 +00:00
|
|
|
void GuiComponent::setPosition(float x, float y, float z)
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mPosition = Vector3f(x, y, z);
|
|
|
|
onPositionChanged();
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector2f GuiComponent::getOrigin() const
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mOrigin;
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
2013-06-02 16:11:29 +00:00
|
|
|
|
2017-07-17 03:10:29 +00:00
|
|
|
void GuiComponent::setOrigin(float x, float y)
|
2013-06-02 22:33:49 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mOrigin = Vector2f(x, y);
|
|
|
|
onOriginChanged();
|
2013-06-02 22:33:49 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector2f GuiComponent::getRotationOrigin() const
|
2013-07-02 23:48:39 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mRotationOrigin;
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setRotationOrigin(float x, float y)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mRotationOrigin = Vector2f(x, y);
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector2f GuiComponent::getSize() const
|
2017-07-17 03:10:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mSize;
|
2013-07-02 23:48:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void GuiComponent::setSize(float w, float h)
|
2013-07-02 23:48:39 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mSize = Vector2f(w, h);
|
2013-07-02 23:48:39 +00:00
|
|
|
onSizeChanged();
|
|
|
|
}
|
|
|
|
|
2017-07-17 03:10:29 +00:00
|
|
|
float GuiComponent::getRotation() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mRotation;
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setRotation(float rotation)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mRotation = rotation;
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float GuiComponent::getScale() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mScale;
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setScale(float scale)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mScale = scale;
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 14:15:16 +00:00
|
|
|
float GuiComponent::getZIndex() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mZIndex;
|
2017-04-22 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setZIndex(float z)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mZIndex = z;
|
2017-04-22 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float GuiComponent::getDefaultZIndex() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mDefaultZIndex;
|
2017-04-22 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setDefaultZIndex(float z)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mDefaultZIndex = z;
|
2017-04-22 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 03:13:48 +00:00
|
|
|
bool GuiComponent::isVisible() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mVisible;
|
2019-07-22 03:13:48 +00:00
|
|
|
}
|
|
|
|
void GuiComponent::setVisible(bool visible)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mVisible = visible;
|
2019-07-22 03:13:48 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector2f GuiComponent::getCenter() const
|
2017-07-17 03:10:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return Vector2f(mPosition.x() - (getSize().x() * mOrigin.x()) + getSize().x() / 2,
|
|
|
|
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2);
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Children stuff.
|
2013-06-02 16:11:29 +00:00
|
|
|
void GuiComponent::addChild(GuiComponent* cmp)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mChildren.push_back(cmp);
|
2013-06-02 16:11:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (cmp->getParent())
|
|
|
|
cmp->getParent()->removeChild(cmp);
|
2013-06-02 16:11:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
cmp->setParent(this);
|
2013-06-02 16:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::removeChild(GuiComponent* cmp)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!cmp->getParent())
|
|
|
|
return;
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2020-06-25 17:52:38 +00:00
|
|
|
if (cmp->getParent() != this) {
|
2020-06-21 12:25:28 +00:00
|
|
|
LOG(LogError) << "Tried to remove child from incorrect parent!";
|
2020-06-25 17:52:38 +00:00
|
|
|
}
|
2013-06-02 16:11:29 +00:00
|
|
|
|
2020-06-23 18:07:00 +00:00
|
|
|
cmp->setParent(nullptr);
|
2013-06-02 16:11:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto i = mChildren.cbegin(); i != mChildren.cend(); i++) {
|
|
|
|
if (*i == cmp) {
|
|
|
|
mChildren.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-06-02 16:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::clearChildren()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mChildren.clear();
|
2013-06-02 16:11:29 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 14:15:16 +00:00
|
|
|
void GuiComponent::sortChildren()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::stable_sort(mChildren.begin(), mChildren.end(), [](GuiComponent* a, GuiComponent* b) {
|
|
|
|
return b->getZIndex() > a->getZIndex();
|
|
|
|
});
|
2017-04-22 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
unsigned int GuiComponent::getChildCount() const
|
2013-06-02 16:11:29 +00:00
|
|
|
{
|
2020-09-15 20:57:54 +00:00
|
|
|
return static_cast<int>(mChildren.size());
|
2013-06-02 16:11:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:49:43 +00:00
|
|
|
int GuiComponent::getChildIndex() const
|
|
|
|
{
|
|
|
|
std::vector<GuiComponent*>::iterator it =
|
|
|
|
std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this);
|
|
|
|
|
|
|
|
if (it != getParent()->mChildren.end())
|
2020-12-29 10:06:01 +00:00
|
|
|
return static_cast<int>(std::distance(getParent()->mChildren.begin(), it));
|
2020-12-15 17:49:43 +00:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
GuiComponent* GuiComponent::getChild(unsigned int i) const
|
2013-06-02 16:11:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mChildren.at(i);
|
2013-06-02 16:11:29 +00:00
|
|
|
}
|
2013-06-02 19:34:50 +00:00
|
|
|
|
|
|
|
void GuiComponent::setParent(GuiComponent* parent)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mParent = parent;
|
2013-06-02 19:34:50 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
GuiComponent* GuiComponent::getParent() const
|
2013-06-02 19:34:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mParent;
|
2013-06-02 19:34:50 +00:00
|
|
|
}
|
2013-07-02 14:51:33 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
unsigned char GuiComponent::getOpacity() const
|
2013-07-02 14:51:33 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mOpacity;
|
2013-07-02 14:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setOpacity(unsigned char opacity)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mOpacity = opacity;
|
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++)
|
|
|
|
(*it)->setOpacity(opacity);
|
2013-07-03 00:12:49 +00:00
|
|
|
}
|
2013-07-10 11:29:43 +00:00
|
|
|
|
2020-08-30 20:19:37 +00:00
|
|
|
unsigned int GuiComponent::getColor() const
|
|
|
|
{
|
|
|
|
return mColor;
|
|
|
|
}
|
|
|
|
|
2020-11-08 12:03:45 +00:00
|
|
|
unsigned int GuiComponent::getColorShift() const
|
|
|
|
{
|
|
|
|
return mColorShift;
|
|
|
|
}
|
|
|
|
|
2020-06-09 18:03:31 +00:00
|
|
|
void GuiComponent::setColor(unsigned int color)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mColor = color;
|
|
|
|
mColorOpacity = mColor & 0x000000FF;
|
2020-06-09 18:03:31 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 20:19:37 +00:00
|
|
|
float GuiComponent::getSaturation() const
|
2020-06-09 18:03:31 +00:00
|
|
|
{
|
2020-12-29 10:06:01 +00:00
|
|
|
return static_cast<float>(mColor);
|
2020-06-09 18:03:31 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 20:19:37 +00:00
|
|
|
void GuiComponent::setSaturation(float saturation)
|
2020-06-10 17:54:37 +00:00
|
|
|
{
|
2020-08-30 20:19:37 +00:00
|
|
|
mSaturation = saturation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setColorShift(unsigned int color)
|
|
|
|
{
|
|
|
|
mColorShift = color;
|
|
|
|
mColorShiftEnd = color;
|
2020-06-10 17:54:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
const Transform4x4f& GuiComponent::getTransform()
|
2013-07-10 11:29:43 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mTransform = Transform4x4f::Identity();
|
|
|
|
mTransform.translate(mPosition);
|
|
|
|
if (mScale != 1.0)
|
|
|
|
mTransform.scale(mScale);
|
|
|
|
if (mRotation != 0.0) {
|
2020-09-04 17:05:48 +00:00
|
|
|
// Calculate offset as difference between origin and rotation origin.
|
2020-06-21 12:25:28 +00:00
|
|
|
Vector2f rotationSize = getRotationSize();
|
|
|
|
float xOff = (mOrigin.x() - mRotationOrigin.x()) * rotationSize.x();
|
|
|
|
float yOff = (mOrigin.y() - mRotationOrigin.y()) * rotationSize.y();
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-09-04 17:05:48 +00:00
|
|
|
// Transform to offset point.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (xOff != 0.0 || yOff != 0.0)
|
|
|
|
mTransform.translate(Vector3f(xOff * -1, yOff * -1, 0.0f));
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-09-04 17:05:48 +00:00
|
|
|
// Apply rotation transform.
|
2020-06-21 12:25:28 +00:00
|
|
|
mTransform.rotateZ(mRotation);
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-09-04 17:05:48 +00:00
|
|
|
// Transform back to original point.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (xOff != 0.0 || yOff != 0.0)
|
|
|
|
mTransform.translate(Vector3f(xOff, yOff, 0.0f));
|
|
|
|
}
|
|
|
|
mTransform.translate(Vector3f(mOrigin.x() * mSize.x() * -1,
|
|
|
|
mOrigin.y() * mSize.y() * -1, 0.0f));
|
|
|
|
return mTransform;
|
2013-07-10 11:29:43 +00:00
|
|
|
}
|
2013-08-14 12:16:49 +00:00
|
|
|
|
2020-11-07 11:50:30 +00:00
|
|
|
std::string GuiComponent::getValue() const
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-11-17 14:58:52 +00:00
|
|
|
void GuiComponent::setValue(const std::string& /*value*/)
|
2013-08-14 12:16:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-07 11:50:30 +00:00
|
|
|
std::string GuiComponent::getHiddenValue() const
|
2013-08-14 12:16:49 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return "";
|
2013-08-14 12:16:49 +00:00
|
|
|
}
|
2013-08-19 15:36:48 +00:00
|
|
|
|
2020-11-07 11:50:30 +00:00
|
|
|
void GuiComponent::setHiddenValue(const std::string& /*value*/)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:59:00 +00:00
|
|
|
void GuiComponent::textInput(const std::string& text)
|
2013-08-19 15:36:48 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto iter = mChildren.cbegin(); iter != mChildren.cend(); iter++)
|
|
|
|
(*iter)->textInput(text);
|
2013-08-19 15:36:48 +00:00
|
|
|
}
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
void GuiComponent::setAnimation(Animation* anim, int delay,
|
2020-06-21 12:25:28 +00:00
|
|
|
std::function<void()> finishedCallback, bool reverse, unsigned char slot)
|
2013-12-08 17:35:43 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(slot < MAX_ANIMATIONS);
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
AnimationController* oldAnim = mAnimationMap[slot];
|
|
|
|
mAnimationMap[slot] = new AnimationController(anim, delay, finishedCallback, reverse);
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (oldAnim)
|
|
|
|
delete oldAnim;
|
2013-12-08 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 17:19:46 +00:00
|
|
|
bool GuiComponent::stopAnimation(unsigned char slot)
|
2013-12-08 17:35:43 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(slot < MAX_ANIMATIONS);
|
|
|
|
if (mAnimationMap[slot]) {
|
|
|
|
delete mAnimationMap[slot];
|
2020-06-23 18:07:00 +00:00
|
|
|
mAnimationMap[slot] = nullptr;
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-08 17:35:43 +00:00
|
|
|
}
|
2014-01-01 05:39:22 +00:00
|
|
|
|
2014-04-18 17:19:46 +00:00
|
|
|
bool GuiComponent::cancelAnimation(unsigned char slot)
|
2014-04-15 02:03:11 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(slot < MAX_ANIMATIONS);
|
|
|
|
if (mAnimationMap[slot]) {
|
|
|
|
mAnimationMap[slot]->removeFinishedCallback();
|
|
|
|
delete mAnimationMap[slot];
|
2020-06-23 18:07:00 +00:00
|
|
|
mAnimationMap[slot] = nullptr;
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-18 17:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiComponent::finishAnimation(unsigned char slot)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(slot < MAX_ANIMATIONS);
|
2020-11-16 16:44:33 +00:00
|
|
|
AnimationController* anim = mAnimationMap[slot];
|
|
|
|
if (anim) {
|
2020-09-04 17:05:48 +00:00
|
|
|
// Skip to animation's end.
|
2020-11-16 16:44:33 +00:00
|
|
|
const bool done = anim->update(anim->getAnimation()->getDuration() - anim->getTime());
|
2021-06-11 15:02:06 +00:00
|
|
|
if (done) {
|
2020-11-16 16:44:33 +00:00
|
|
|
mAnimationMap[slot] = nullptr;
|
|
|
|
delete anim; // Will also call finishedCallback.
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-15 02:03:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:58:16 +00:00
|
|
|
bool GuiComponent::advanceAnimation(unsigned char slot, unsigned int time)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(slot < MAX_ANIMATIONS);
|
|
|
|
AnimationController* anim = mAnimationMap[slot];
|
|
|
|
if (anim) {
|
|
|
|
bool done = anim->update(time);
|
|
|
|
if (done) {
|
2020-06-23 18:07:00 +00:00
|
|
|
mAnimationMap[slot] = nullptr;
|
2020-11-16 16:44:33 +00:00
|
|
|
delete anim; // Will also call finishedCallback.
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-15 01:58:16 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 02:03:11 +00:00
|
|
|
void GuiComponent::stopAllAnimations()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
|
|
|
stopAnimation(i);
|
2014-04-15 02:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::cancelAllAnimations()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
|
|
|
cancelAnimation(i);
|
2014-04-15 02:03:11 +00:00
|
|
|
}
|
|
|
|
|
2014-01-25 00:10:13 +00:00
|
|
|
bool GuiComponent::isAnimationPlaying(unsigned char slot) const
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
return mAnimationMap[slot] != nullptr;
|
2014-01-25 00:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiComponent::isAnimationReversed(unsigned char slot) const
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
assert(mAnimationMap[slot] != nullptr);
|
2020-06-21 12:25:28 +00:00
|
|
|
return mAnimationMap[slot]->isReversed();
|
2014-01-25 00:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GuiComponent::getAnimationTime(unsigned char slot) const
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
assert(mAnimationMap[slot] != nullptr);
|
2020-06-21 12:25:28 +00:00
|
|
|
return mAnimationMap[slot]->getTime();
|
2014-01-25 00:10:13 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string& view, const std::string& element, unsigned int properties)
|
2014-01-01 05:39:22 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Vector2f scale = getParent() ? getParent()->getSize()
|
2020-09-15 20:57:54 +00:00
|
|
|
: Vector2f(static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()));
|
2014-01-01 05:39:22 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "");
|
|
|
|
if (!elem)
|
|
|
|
return;
|
2014-01-01 05:39:22 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
using namespace ThemeFlags;
|
|
|
|
if (properties & POSITION && elem->has("pos")) {
|
|
|
|
Vector2f denormalized = elem->get<Vector2f>("pos") * scale;
|
|
|
|
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
|
|
|
|
}
|
2014-01-01 05:39:22 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (properties & ThemeFlags::SIZE && elem->has("size"))
|
|
|
|
setSize(elem->get<Vector2f>("size") * scale);
|
2017-04-22 14:15:16 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Position + size also implies origin
|
|
|
|
if ((properties & ORIGIN || (properties & POSITION &&
|
|
|
|
properties & ThemeFlags::SIZE)) && elem->has("origin")) {
|
|
|
|
setOrigin(elem->get<Vector2f>("origin"));
|
|
|
|
}
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (properties & ThemeFlags::ROTATION) {
|
|
|
|
if (elem->has("rotation"))
|
|
|
|
setRotationDegrees(elem->get<float>("rotation"));
|
|
|
|
if (elem->has("rotationOrigin"))
|
|
|
|
setRotationOrigin(elem->get<Vector2f>("rotationOrigin"));
|
|
|
|
}
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
|
|
|
|
setZIndex(elem->get<float>("zIndex"));
|
|
|
|
else
|
|
|
|
setZIndex(getDefaultZIndex());
|
2019-07-22 03:13:48 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (properties & ThemeFlags::VISIBLE && elem->has("visible"))
|
|
|
|
setVisible(elem->get<bool>("visible"));
|
|
|
|
else
|
|
|
|
setVisible(true);
|
2014-01-01 05:39:22 +00:00
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
|
|
|
|
void GuiComponent::updateHelpPrompts()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (getParent()) {
|
|
|
|
getParent()->updateHelpPrompts();
|
|
|
|
return;
|
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<HelpPrompt> prompts = getHelpPrompts();
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mWindow->peekGui() == this)
|
|
|
|
mWindow->setHelpPrompts(prompts, getHelpStyle());
|
2014-05-29 20:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HelpStyle GuiComponent::getHelpStyle()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return HelpStyle();
|
2014-01-25 23:34:29 +00:00
|
|
|
}
|
2016-09-12 11:31:44 +00:00
|
|
|
|
|
|
|
bool GuiComponent::isProcessing() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mIsProcessing;
|
2016-09-12 11:31:44 +00:00
|
|
|
}
|
2016-12-04 23:47:34 +00:00
|
|
|
|
|
|
|
void GuiComponent::onShow()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->onShow();
|
2016-12-04 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::onHide()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->onHide();
|
2016-12-04 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-31 19:51:24 +00:00
|
|
|
void GuiComponent::onStopVideo()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->onStopVideo();
|
|
|
|
}
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
void GuiComponent::onPauseVideo()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->onPauseVideo();
|
|
|
|
}
|
|
|
|
|
2020-09-26 20:15:36 +00:00
|
|
|
void GuiComponent::onUnpauseVideo()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->onUnpauseVideo();
|
|
|
|
}
|
|
|
|
|
2020-11-10 21:33:57 +00:00
|
|
|
void GuiComponent::onScreensaverActivate()
|
2017-01-25 15:00:56 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
2020-11-10 21:33:57 +00:00
|
|
|
getChild(i)->onScreensaverActivate();
|
2017-01-25 15:00:56 +00:00
|
|
|
}
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2020-11-10 21:33:57 +00:00
|
|
|
void GuiComponent::onScreensaverDeactivate()
|
2017-01-25 15:00:56 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
2020-11-10 21:33:57 +00:00
|
|
|
getChild(i)->onScreensaverDeactivate();
|
2017-01-25 15:00:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-18 11:21:44 +00:00
|
|
|
void GuiComponent::onGameLaunchedActivate()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->onGameLaunchedActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::onGameLaunchedDeactivate()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->onGameLaunchedDeactivate();
|
|
|
|
}
|
|
|
|
|
2017-01-25 15:00:56 +00:00
|
|
|
void GuiComponent::topWindow(bool isTop)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->topWindow(isTop);
|
2020-05-24 08:29:29 +00:00
|
|
|
}
|