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.h
|
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
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_GUI_COMPONENT_H
|
|
|
|
#define ES_CORE_GUI_COMPONENT_H
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "HelpPrompt.h"
|
|
|
|
#include "HelpStyle.h"
|
2013-06-02 15:08:32 +00:00
|
|
|
#include "InputConfig.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "animations/AnimationController.h"
|
2020-09-13 17:08:17 +00:00
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
#include <functional>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <memory>
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2020-07-15 15:44:27 +00:00
|
|
|
#define DEFAULT_TEXTCOLOR 0x777777FF
|
|
|
|
#define DEFAULT_INVERTED_TEXTCOLOR 0x444444FF
|
2020-11-08 12:03:45 +00:00
|
|
|
#define DEFAULT_INVERTED_IMAGECOLOR 0x666666FF
|
2020-07-15 15:44:27 +00:00
|
|
|
#define DEFAULT_COLORSHIFT 0xFFFFFFFF
|
2020-12-17 19:36:30 +00:00
|
|
|
#define ICONCOLOR_SCRAPERMARKED 0xFF7777FF
|
|
|
|
#define ICONCOLOR_USERMARKED 0x7777FFFF
|
2020-07-15 15:44:27 +00:00
|
|
|
#define TEXTCOLOR_SCRAPERMARKED 0x992222FF
|
|
|
|
#define TEXTCOLOR_USERMARKED 0x222299FF
|
2020-08-05 17:31:59 +00:00
|
|
|
#define DISABLED_OPACITY 80
|
2020-07-15 15:44:27 +00:00
|
|
|
|
2013-12-08 17:35:43 +00:00
|
|
|
class Animation;
|
|
|
|
class AnimationController;
|
2014-05-29 20:41:47 +00:00
|
|
|
class Font;
|
2017-11-01 22:21:10 +00:00
|
|
|
class InputConfig;
|
|
|
|
class ThemeData;
|
|
|
|
class Window;
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2013-06-02 16:11:29 +00:00
|
|
|
class GuiComponent
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
GuiComponent(Window* window);
|
|
|
|
virtual ~GuiComponent();
|
|
|
|
|
2020-12-16 22:59:00 +00:00
|
|
|
virtual void textInput(const std::string& text);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Called when input is received.
|
2021-08-15 17:30:31 +00:00
|
|
|
// Return true if the input is consumed, false if it should continue to be passed
|
|
|
|
// to other children.
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual bool input(InputConfig* config, Input input);
|
|
|
|
|
|
|
|
// Called when time passes.
|
|
|
|
// Default implementation calls updateSelf(deltaTime) and updateChildren(deltaTime).
|
|
|
|
// So you should probably call GuiComponent::update(deltaTime) at some point (or at
|
|
|
|
// least updateSelf so animations work).
|
|
|
|
virtual void update(int deltaTime);
|
|
|
|
|
|
|
|
// Called when it's time to render.
|
2021-08-15 17:30:31 +00:00
|
|
|
// By default, just calls renderChildren(parentTrans * getTransform())
|
|
|
|
// Normally the following steps are required:
|
|
|
|
// 1. Calculate the new transform that your component will draw at
|
2021-08-18 19:03:25 +00:00
|
|
|
// glm::mat4 trans{parentTrans * getTransform()};
|
2020-06-21 12:25:28 +00:00
|
|
|
// 2. Set the renderer to use that new transform as the model matrix
|
2021-08-15 17:30:31 +00:00
|
|
|
// Renderer::setMatrix(trans);
|
|
|
|
// 3. Draw your component
|
|
|
|
// 4. Tell your children to render, based on your component's transform
|
|
|
|
// renderChildren(trans);
|
|
|
|
virtual void render(const glm::mat4& parentTrans);
|
|
|
|
|
|
|
|
glm::vec3 getPosition() const { return mPosition; }
|
|
|
|
void setPosition(const glm::vec3& offset) { setPosition(offset.x, offset.y, offset.z); }
|
2020-06-21 12:25:28 +00:00
|
|
|
void setPosition(float x, float y, float z = 0.0f);
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void onPositionChanged() {}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec2 getOrigin() const { return mOrigin; }
|
2020-06-21 12:25:28 +00:00
|
|
|
// Sets the origin as a percentage of this image.
|
|
|
|
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
|
|
|
|
void setOrigin(float originX, float originY);
|
2021-08-16 16:25:01 +00:00
|
|
|
void setOrigin(glm::vec2 origin) { setOrigin(origin.x, origin.y); }
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void onOriginChanged() {}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec2 getRotationOrigin() const { return mRotationOrigin; }
|
2020-06-21 12:25:28 +00:00
|
|
|
// Sets the rotation origin as a percentage of this image.
|
|
|
|
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
|
2021-07-07 18:31:46 +00:00
|
|
|
void setRotationOrigin(float originX, float originY)
|
|
|
|
{
|
2021-08-17 16:41:45 +00:00
|
|
|
mRotationOrigin = glm::vec2{originX, originY};
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
2021-08-16 16:25:01 +00:00
|
|
|
void setRotationOrigin(glm::vec2 origin) { setRotationOrigin(origin.x, origin.y); }
|
2021-07-07 18:31:46 +00:00
|
|
|
|
2021-08-16 16:25:01 +00:00
|
|
|
virtual glm::vec2 getSize() const { return mSize; }
|
|
|
|
void setSize(const glm::vec2& size) { setSize(size.x, size.y); }
|
2013-07-10 11:29:43 +00:00
|
|
|
void setSize(float w, float h);
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void setResize(float width, float height) {}
|
|
|
|
virtual void onSizeChanged() {}
|
2018-01-23 00:34:30 +00:00
|
|
|
|
2021-08-16 16:25:01 +00:00
|
|
|
virtual glm::vec2 getRotationSize() const { return getSize(); }
|
2021-07-07 18:31:46 +00:00
|
|
|
float getRotation() const { return mRotation; }
|
|
|
|
void setRotation(float rotation) { mRotation = rotation; }
|
|
|
|
void setRotationDegrees(float rotation)
|
|
|
|
{
|
2021-08-15 17:30:31 +00:00
|
|
|
setRotation(static_cast<float>(glm::radians(rotation)));
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
float getScale() const { return mScale; }
|
|
|
|
void setScale(float scale) { mScale = scale; }
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
float getZIndex() const { return mZIndex; }
|
|
|
|
void setZIndex(float zIndex) { mZIndex = zIndex; }
|
2017-04-22 14:15:16 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
float getDefaultZIndex() const { return mDefaultZIndex; }
|
|
|
|
void setDefaultZIndex(float zIndex) { mDefaultZIndex = zIndex; }
|
2017-04-22 14:15:16 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
bool isVisible() const { return mVisible; }
|
|
|
|
void setVisible(bool visible) { mVisible = visible; }
|
2019-07-22 03:13:48 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Returns the center point of the image (takes origin into account).
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec2 getCenter() const;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setParent(GuiComponent* parent) { mParent = parent; }
|
|
|
|
GuiComponent* getParent() const { return mParent; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
void addChild(GuiComponent* cmp);
|
|
|
|
void removeChild(GuiComponent* cmp);
|
2021-07-07 18:31:46 +00:00
|
|
|
void clearChildren() { mChildren.clear(); }
|
2020-06-21 12:25:28 +00:00
|
|
|
void sortChildren();
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned int getChildCount() const { return static_cast<int>(mChildren.size()); }
|
2020-12-15 17:49:43 +00:00
|
|
|
int getChildIndex() const;
|
2021-07-07 18:31:46 +00:00
|
|
|
GuiComponent* getChild(unsigned int i) const { return mChildren.at(i); }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Animation will be automatically deleted when it completes or is stopped.
|
2021-07-07 18:31:46 +00:00
|
|
|
bool isAnimationPlaying(unsigned char slot) const { return mAnimationMap[slot] != nullptr; }
|
|
|
|
bool isAnimationReversed(unsigned char slot) const
|
|
|
|
{
|
|
|
|
assert(mAnimationMap[slot] != nullptr);
|
|
|
|
return mAnimationMap[slot]->isReversed();
|
|
|
|
}
|
|
|
|
int getAnimationTime(unsigned char slot) const
|
|
|
|
{
|
|
|
|
assert(mAnimationMap[slot] != nullptr);
|
|
|
|
return mAnimationMap[slot]->getTime();
|
|
|
|
}
|
|
|
|
void setAnimation(Animation* animation,
|
|
|
|
int delay = 0,
|
|
|
|
std::function<void()> finishedCallback = nullptr,
|
|
|
|
bool reverse = false,
|
|
|
|
unsigned char slot = 0);
|
2020-06-21 12:25:28 +00:00
|
|
|
bool stopAnimation(unsigned char slot);
|
|
|
|
// Like stopAnimation, but doesn't call finishedCallback - only removes the animation, leaving
|
|
|
|
// things in their current state. Returns true if successful (an animation was in this slot).
|
|
|
|
bool cancelAnimation(unsigned char slot);
|
|
|
|
// Calls update(1.f) and finishedCallback, then deletes the animation - basically skips
|
|
|
|
// to the end. Returns true if successful (an animation was in this slot).
|
|
|
|
bool finishAnimation(unsigned char slot);
|
|
|
|
// Returns true if successful (an animation was in this slot).
|
|
|
|
bool advanceAnimation(unsigned char slot, unsigned int time);
|
|
|
|
void stopAllAnimations();
|
|
|
|
void cancelAllAnimations();
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual bool isListScrolling() { return false; }
|
|
|
|
virtual void stopListScrolling() {}
|
|
|
|
virtual unsigned char getOpacity() const { return mOpacity; }
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual void setOpacity(unsigned char opacity);
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual unsigned int getColor() const { return mColor; }
|
|
|
|
virtual unsigned int getColorShift() const { return mColorShift; }
|
2021-09-30 18:11:56 +00:00
|
|
|
virtual float getLineSpacing() { return 0.0f; }
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void setColor(unsigned int color)
|
|
|
|
{
|
|
|
|
mColor = color;
|
|
|
|
mColorOpacity = mColor & 0x000000FF;
|
|
|
|
}
|
|
|
|
virtual float getSaturation() const { return static_cast<float>(mColor); }
|
|
|
|
virtual void setSaturation(float saturation) { mSaturation = saturation; }
|
|
|
|
virtual void setColorShift(unsigned int color)
|
|
|
|
{
|
|
|
|
mColorShift = color;
|
|
|
|
mColorShiftEnd = color;
|
|
|
|
}
|
|
|
|
virtual void setOriginalColor(unsigned int color) { mColorOriginalValue = color; }
|
|
|
|
virtual void setChangedColor(unsigned int color) { mColorChangedValue = color; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-08-05 17:31:59 +00:00
|
|
|
// These functions are used to enable and disable options in menus, i.e. switches and similar.
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual bool getEnabled() { return mEnabled; }
|
|
|
|
virtual void setEnabled(bool state) { mEnabled = state; }
|
2020-08-05 17:31:59 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual std::shared_ptr<Font> getFont() const { return nullptr; }
|
2021-01-18 23:11:02 +00:00
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
const glm::mat4& getTransform();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual std::string getValue() const { return ""; }
|
|
|
|
virtual void setValue(const std::string& value) {}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual std::string getHiddenValue() const { return ""; }
|
|
|
|
virtual void setHiddenValue(const std::string& value) {}
|
2020-11-07 11:50:30 +00:00
|
|
|
|
2021-01-05 11:52:21 +00:00
|
|
|
// Used to set the parameters for ScrollableContainer.
|
2021-09-30 18:11:56 +00:00
|
|
|
virtual void setScrollParameters(float, float, float) {}
|
2021-01-05 11:52:21 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void onFocusGained() {}
|
|
|
|
virtual void onFocusLost() {}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
virtual void onShow();
|
|
|
|
virtual void onHide();
|
2021-01-31 19:51:24 +00:00
|
|
|
virtual void onStopVideo();
|
2020-09-15 20:57:54 +00:00
|
|
|
virtual void onPauseVideo();
|
2020-09-26 20:15:36 +00:00
|
|
|
virtual void onUnpauseVideo();
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual bool isVideoPaused() { return false; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-11-10 21:33:57 +00:00
|
|
|
virtual void onScreensaverActivate();
|
|
|
|
virtual void onScreensaverDeactivate();
|
2020-07-18 11:21:44 +00:00
|
|
|
virtual void onGameLaunchedActivate();
|
|
|
|
virtual void onGameLaunchedDeactivate();
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual void topWindow(bool isTop);
|
|
|
|
|
|
|
|
// Default implementation just handles <pos> and <size> tags as normalized float pairs.
|
|
|
|
// You probably want to keep this behavior for any derived classes as well as add your own.
|
|
|
|
virtual void 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);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Returns a list of help prompts.
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() { return std::vector<HelpPrompt>(); }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Called whenever help prompts change.
|
|
|
|
void updateHelpPrompts();
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual HelpStyle getHelpStyle() { return HelpStyle(); }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Returns true if the component is busy doing background processing (e.g. HTTP downloads).
|
2021-07-07 18:31:46 +00:00
|
|
|
bool isProcessing() const { return mIsProcessing; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
const static unsigned char MAX_ANIMATIONS = 4;
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
protected:
|
2021-08-15 17:30:31 +00:00
|
|
|
void renderChildren(const glm::mat4& transform) const;
|
2020-06-21 12:25:28 +00:00
|
|
|
void updateSelf(int deltaTime); // Updates animations.
|
|
|
|
void updateChildren(int deltaTime); // Updates animations.
|
2013-06-02 19:34:50 +00:00
|
|
|
|
2021-09-18 07:53:26 +00:00
|
|
|
Window* mWindow;
|
|
|
|
|
|
|
|
GuiComponent* mParent;
|
|
|
|
std::vector<GuiComponent*> mChildren;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
unsigned char mOpacity;
|
|
|
|
unsigned int mColor;
|
2020-08-30 20:19:37 +00:00
|
|
|
float mSaturation;
|
2020-06-21 12:25:28 +00:00
|
|
|
unsigned char mColorOpacity;
|
|
|
|
unsigned int mColorShift;
|
|
|
|
unsigned int mColorShiftEnd;
|
2020-07-15 15:44:27 +00:00
|
|
|
unsigned int mColorOriginalValue;
|
|
|
|
unsigned int mColorChangedValue;
|
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
glm::vec3 mPosition;
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec2 mOrigin;
|
|
|
|
glm::vec2 mRotationOrigin;
|
|
|
|
glm::vec2 mSize;
|
2013-07-10 11:29:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
float mRotation = 0.0;
|
|
|
|
float mScale = 1.0;
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
float mDefaultZIndex = 0;
|
|
|
|
float mZIndex = 0;
|
2017-04-22 14:15:16 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool mIsProcessing;
|
|
|
|
bool mVisible;
|
2020-08-05 17:31:59 +00:00
|
|
|
bool mEnabled;
|
2016-09-12 11:31:44 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
private:
|
2021-08-15 17:30:31 +00:00
|
|
|
// Don't access this directly, instead use getTransform().
|
|
|
|
glm::mat4 mTransform;
|
2020-06-21 12:25:28 +00:00
|
|
|
AnimationController* mAnimationMap[MAX_ANIMATIONS];
|
2013-06-02 15:08:32 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_GUI_COMPONENT_H
|