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
|
|
|
|
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"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "animations/Animation.h"
|
|
|
|
#include "renderers/Renderer.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
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
GuiComponent::GuiComponent()
|
|
|
|
: mWindow {Window::getInstance()}
|
2022-01-16 17:18:28 +00:00
|
|
|
, mParent {nullptr}
|
|
|
|
, mColor {0}
|
|
|
|
, mSaturation {1.0f}
|
|
|
|
, mColorShift {0}
|
|
|
|
, mColorShiftEnd {0}
|
2022-01-22 20:17:28 +00:00
|
|
|
, mColorOriginalValue {0}
|
|
|
|
, mColorChangedValue {0}
|
2022-01-30 18:30:38 +00:00
|
|
|
, mComponentThemeFlags {0}
|
2022-01-16 17:18:28 +00:00
|
|
|
, mPosition {0.0f, 0.0f, 0.0f}
|
|
|
|
, mOrigin {0.0f, 0.0f}
|
|
|
|
, mRotationOrigin {0.5f, 0.5f}
|
|
|
|
, mSize {0.0f, 0.0f}
|
2022-02-11 21:10:25 +00:00
|
|
|
, mOpacity {1.0f}
|
2022-02-12 16:38:55 +00:00
|
|
|
, mThemeOpacity {1.0f}
|
2022-01-22 20:17:28 +00:00
|
|
|
, mRotation {0.0f}
|
|
|
|
, mScale {1.0f}
|
|
|
|
, mDefaultZIndex {0.0f}
|
|
|
|
, mZIndex {0.0f}
|
2022-01-16 17:18:28 +00:00
|
|
|
, mIsProcessing {false}
|
|
|
|
, mVisible {true}
|
|
|
|
, mEnabled {true}
|
|
|
|
, mTransform {Renderer::getIdentity()}
|
2020-05-24 08:29:29 +00:00
|
|
|
{
|
2021-11-17 16:48:49 +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
|
|
|
|
2021-11-17 16:48:49 +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)
|
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); ++i) {
|
2020-06-21 12:25:28 +00:00
|
|
|
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
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned char i = 0; i < MAX_ANIMATIONS; ++i)
|
2020-06-21 12:25:28 +00:00
|
|
|
advanceAnimation(i, deltaTime);
|
2014-06-05 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::updateChildren(int deltaTime)
|
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); ++i)
|
2020-06-21 12:25:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
void GuiComponent::render(const glm::mat4& 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
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
glm::mat4 trans {parentTrans * getTransform()};
|
2020-06-21 12:25:28 +00:00
|
|
|
renderChildren(trans);
|
2013-06-02 19:34:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
void GuiComponent::renderChildren(const glm::mat4& transform) const
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); ++i)
|
2020-06-21 12:25:28 +00:00
|
|
|
getChild(i)->render(transform);
|
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
|
|
|
{
|
2021-09-28 19:46:45 +00:00
|
|
|
if (mPosition.x == x && mPosition.y == y && mPosition.z == z)
|
|
|
|
return;
|
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
mPosition = glm::vec3 {x, y, z};
|
2020-06-21 12:25:28 +00:00
|
|
|
onPositionChanged();
|
2013-06-02 15:08:32 +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
|
|
|
{
|
2021-09-28 19:46:45 +00:00
|
|
|
if (mOrigin.x == x && mOrigin.y == y)
|
|
|
|
return;
|
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
mOrigin = glm::vec2 {x, y};
|
2020-06-21 12:25:28 +00:00
|
|
|
onOriginChanged();
|
2013-06-02 22:33:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
void GuiComponent::setSize(const float w, const float h)
|
2013-07-02 23:48:39 +00:00
|
|
|
{
|
2021-09-28 19:46:45 +00:00
|
|
|
if (mSize.x == w && mSize.y == h)
|
|
|
|
return;
|
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
mSize = glm::vec2 {w, h};
|
2013-07-02 23:48:39 +00:00
|
|
|
onSizeChanged();
|
|
|
|
}
|
|
|
|
|
2022-01-22 20:17:28 +00:00
|
|
|
const glm::vec2 GuiComponent::getCenter() const
|
2017-07-17 03:10:29 +00:00
|
|
|
{
|
2022-01-16 11:09:55 +00:00
|
|
|
return glm::vec2 {mPosition.x - (getSize().x * mOrigin.x) + getSize().x / 2.0f,
|
|
|
|
mPosition.y - (getSize().y * mOrigin.y) + getSize().y / 2.0f};
|
2017-07-17 03:10:29 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-11-17 16:48:49 +00:00
|
|
|
for (auto i = mChildren.cbegin(); i != mChildren.cend(); ++i) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (*i == cmp) {
|
|
|
|
mChildren.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2022-01-22 20:17:28 +00:00
|
|
|
const int GuiComponent::getChildIndex() const
|
2020-12-15 17:49:43 +00:00
|
|
|
{
|
|
|
|
std::vector<GuiComponent*>::iterator it =
|
2021-07-07 18:31:46 +00:00
|
|
|
std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this);
|
2020-12-15 17:49:43 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-02-11 21:10:25 +00:00
|
|
|
void GuiComponent::setOpacity(float opacity)
|
2013-07-02 14:51:33 +00:00
|
|
|
{
|
2021-09-28 19:46:45 +00:00
|
|
|
if (mOpacity == opacity)
|
|
|
|
return;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mOpacity = opacity;
|
2021-11-17 16:48:49 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it)
|
2020-06-21 12:25:28 +00:00
|
|
|
(*it)->setOpacity(opacity);
|
2013-07-03 00:12:49 +00:00
|
|
|
}
|
2013-07-10 11:29:43 +00:00
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
const glm::mat4& GuiComponent::getTransform()
|
2013-07-10 11:29:43 +00:00
|
|
|
{
|
2021-08-15 17:30:31 +00:00
|
|
|
mTransform = Renderer::getIdentity();
|
|
|
|
mTransform = glm::translate(mTransform, mPosition);
|
2021-07-07 18:31:46 +00:00
|
|
|
|
|
|
|
if (mScale != 1.0f)
|
2022-01-16 11:09:55 +00:00
|
|
|
mTransform = glm::scale(mTransform, glm::vec3 {mScale});
|
2021-07-07 18:31:46 +00:00
|
|
|
|
|
|
|
if (mRotation != 0.0f) {
|
2020-09-04 17:05:48 +00:00
|
|
|
// Calculate offset as difference between origin and rotation origin.
|
2022-01-16 11:09:55 +00:00
|
|
|
glm::vec2 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.
|
2021-07-07 18:31:46 +00:00
|
|
|
if (xOff != 0.0f || yOff != 0.0f)
|
2022-01-16 11:09:55 +00:00
|
|
|
mTransform = glm::translate(mTransform, glm::vec3 {xOff * -1.0f, yOff * -1.0f, 0.0f});
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-09-04 17:05:48 +00:00
|
|
|
// Apply rotation transform.
|
2022-01-16 11:09:55 +00:00
|
|
|
mTransform = glm::rotate(mTransform, mRotation, glm::vec3 {0.0f, 0.0f, 1.0f});
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-09-04 17:05:48 +00:00
|
|
|
// Transform back to original point.
|
2021-07-07 18:31:46 +00:00
|
|
|
if (xOff != 0.0f || yOff != 0.0f)
|
2022-01-16 11:09:55 +00:00
|
|
|
mTransform = glm::translate(mTransform, glm::vec3 {xOff, yOff, 0.0f});
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2021-08-16 16:25:01 +00:00
|
|
|
mTransform = glm::translate(
|
2022-01-16 11:09:55 +00:00
|
|
|
mTransform, glm::vec3 {mOrigin.x * mSize.x * -1.0f, mOrigin.y * mSize.y * -1.0f, 0.0f});
|
2021-08-15 17:30:31 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return mTransform;
|
2013-07-10 11:29:43 +00:00
|
|
|
}
|
2013-08-14 12:16:49 +00:00
|
|
|
|
2020-12-16 22:59:00 +00:00
|
|
|
void GuiComponent::textInput(const std::string& text)
|
2013-08-19 15:36:48 +00:00
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it)
|
|
|
|
(*it)->textInput(text);
|
2013-08-19 15:36:48 +00:00
|
|
|
}
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void GuiComponent::setAnimation(Animation* anim,
|
|
|
|
int delay,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-01-22 20:17:28 +00:00
|
|
|
const 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
|
|
|
|
2022-01-22 20:17:28 +00:00
|
|
|
const 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
|
|
|
}
|
|
|
|
|
2022-01-22 20:17:28 +00:00
|
|
|
const bool GuiComponent::finishAnimation(unsigned char slot)
|
2014-04-18 17:19:46 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(slot < MAX_ANIMATIONS);
|
2022-03-06 22:31:32 +00:00
|
|
|
AnimationController* anim {mAnimationMap[slot]};
|
2020-11-16 16:44:33 +00:00
|
|
|
if (anim) {
|
2020-09-04 17:05:48 +00:00
|
|
|
// Skip to animation's end.
|
2022-03-06 22:31:32 +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
|
|
|
}
|
|
|
|
|
2022-01-22 20:17:28 +00:00
|
|
|
const bool GuiComponent::advanceAnimation(unsigned char slot, unsigned int time)
|
2014-05-15 01:58:16 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(slot < MAX_ANIMATIONS);
|
2022-03-06 22:31:32 +00:00
|
|
|
AnimationController* anim {mAnimationMap[slot]};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (anim) {
|
2022-03-06 22:31:32 +00:00
|
|
|
bool done {anim->update(time)};
|
2020-06-21 12:25:28 +00:00
|
|
|
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()
|
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned char i = 0; i < MAX_ANIMATIONS; ++i)
|
2020-06-21 12:25:28 +00:00
|
|
|
stopAnimation(i);
|
2014-04-15 02:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::cancelAllAnimations()
|
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned char i = 0; i < MAX_ANIMATIONS; ++i)
|
2020-06-21 12:25:28 +00:00
|
|
|
cancelAnimation(i);
|
2014-04-15 02:03:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties)
|
2014-01-01 05:39:22 +00:00
|
|
|
{
|
2022-02-11 22:38:23 +00:00
|
|
|
glm::vec2 scale {getParent() ?
|
|
|
|
getParent()->getSize() :
|
|
|
|
glm::vec2 {Renderer::getScreenWidth(), 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")) {
|
2022-01-16 11:09:55 +00:00
|
|
|
glm::vec2 denormalized {elem->get<glm::vec2>("pos") * scale};
|
|
|
|
setPosition(glm::vec3 {denormalized.x, denormalized.y, 0.0f});
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-01-01 05:39:22 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (properties & ThemeFlags::SIZE && elem->has("size"))
|
2021-08-16 16:25:01 +00:00
|
|
|
setSize(elem->get<glm::vec2>("size") * scale);
|
2017-04-22 14:15:16 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
// Position + size also implies origin.
|
|
|
|
if ((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) &&
|
|
|
|
elem->has("origin")) {
|
2022-02-19 19:24:25 +00:00
|
|
|
setOrigin(glm::clamp(elem->get<glm::vec2>("origin"), 0.0f, 1.0f));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
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"))
|
2021-08-16 16:25:01 +00:00
|
|
|
setRotationOrigin(elem->get<glm::vec2>("rotationOrigin"));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
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
|
|
|
|
2022-02-12 16:38:55 +00:00
|
|
|
if (properties & ThemeFlags::OPACITY && elem->has("opacity"))
|
|
|
|
mThemeOpacity = glm::clamp(elem->get<float>("opacity"), 0.0f, 1.0f);
|
|
|
|
|
|
|
|
if (properties & ThemeFlags::VISIBLE && elem->has("visible") && !elem->get<bool>("visible"))
|
|
|
|
mThemeOpacity = 0.0f;
|
2022-02-13 10:23:41 +00:00
|
|
|
else
|
|
|
|
setVisible(true);
|
2022-02-14 18:32:07 +00:00
|
|
|
|
|
|
|
if (properties && elem->has("gameselector"))
|
|
|
|
mThemeGameSelector = elem->get<std::string>("gameselector");
|
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
|
|
|
}
|
|
|
|
|
2016-12-04 23:47:34 +00:00
|
|
|
void GuiComponent::onShow()
|
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); ++i)
|
2020-06-21 12:25:28 +00:00
|
|
|
getChild(i)->onShow();
|
2016-12-04 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::onHide()
|
|
|
|
{
|
2021-11-17 16:48:49 +00:00
|
|
|
for (unsigned int i = 0; i < getChildCount(); ++i)
|
2020-06-21 12:25:28 +00:00
|
|
|
getChild(i)->onHide();
|
2016-12-04 23:47:34 +00:00
|
|
|
}
|