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-06 10:46:15 +00:00
|
|
|
#include "math/Misc.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "math/Transform4x4f.h"
|
|
|
|
#include "HelpPrompt.h"
|
|
|
|
#include "HelpStyle.h"
|
2013-06-02 15:08:32 +00:00
|
|
|
#include "InputConfig.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
|
|
|
|
#define DEFAULT_COLORSHIFT 0xFFFFFFFF
|
|
|
|
#define ICONCOLOR_SCRAPERMARKED 0xFF5555FF
|
|
|
|
#define ICONCOLOR_USERMARKED 0x5555FFFF
|
|
|
|
#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();
|
|
|
|
|
|
|
|
virtual void textInput(const char* text);
|
|
|
|
|
|
|
|
// Called when input is received.
|
|
|
|
// Return true if the input is consumed, false if
|
|
|
|
// it should continue to be passed to other children.
|
|
|
|
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.
|
|
|
|
// By default, just calls renderChildren(parentTrans * getTransform()).
|
|
|
|
// You probably want to override this like so:
|
|
|
|
// 1. Calculate the new transform that your control will draw at with
|
|
|
|
// Transform4x4f t = parentTrans * getTransform().
|
|
|
|
// 2. Set the renderer to use that new transform as the model matrix
|
|
|
|
// Renderer::setMatrix(t);
|
|
|
|
// 3. Draw your component.
|
|
|
|
// 4. Tell your children to render, based on your component's transform - renderChildren(t).
|
|
|
|
virtual void render(const Transform4x4f& parentTrans);
|
|
|
|
|
|
|
|
Vector3f getPosition() const;
|
|
|
|
inline void setPosition(const Vector3f& offset)
|
|
|
|
{ setPosition(offset.x(), offset.y(), offset.z()); }
|
|
|
|
void setPosition(float x, float y, float z = 0.0f);
|
|
|
|
virtual void onPositionChanged() {};
|
|
|
|
|
|
|
|
// Sets the origin as a percentage of this image.
|
|
|
|
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
|
|
|
|
Vector2f getOrigin() const;
|
|
|
|
void setOrigin(float originX, float originY);
|
|
|
|
inline void setOrigin(Vector2f origin) { setOrigin(origin.x(), origin.y()); }
|
|
|
|
virtual void onOriginChanged() {};
|
|
|
|
|
|
|
|
// Sets the rotation origin as a percentage of this image.
|
|
|
|
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
|
|
|
|
Vector2f getRotationOrigin() const;
|
|
|
|
void setRotationOrigin(float originX, float originY);
|
|
|
|
inline void setRotationOrigin(Vector2f origin)
|
|
|
|
{ setRotationOrigin(origin.x(), origin.y()); }
|
|
|
|
|
|
|
|
virtual Vector2f getSize() const;
|
2017-10-28 20:24:35 +00:00
|
|
|
inline void setSize(const Vector2f& size) { setSize(size.x(), size.y()); }
|
2013-07-10 11:29:43 +00:00
|
|
|
void setSize(float w, float h);
|
2013-07-02 23:48:39 +00:00
|
|
|
virtual void onSizeChanged() {};
|
2017-01-25 15:00:56 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual Vector2f getRotationSize() const { return getSize(); };
|
2018-01-23 00:34:30 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
float getRotation() const;
|
|
|
|
void setRotation(float rotation);
|
2020-09-15 20:57:54 +00:00
|
|
|
inline void setRotationDegrees(float rotation) {
|
|
|
|
setRotation(static_cast<float>(ES_DEG_TO_RAD(rotation))); }
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
float getScale() const;
|
|
|
|
void setScale(float scale);
|
2017-07-17 03:10:29 +00:00
|
|
|
|
2017-04-22 14:15:16 +00:00
|
|
|
float getZIndex() const;
|
|
|
|
void setZIndex(float zIndex);
|
|
|
|
|
|
|
|
float getDefaultZIndex() const;
|
|
|
|
void setDefaultZIndex(float zIndex);
|
|
|
|
|
2019-07-22 03:13:48 +00:00
|
|
|
bool isVisible() const;
|
|
|
|
void setVisible(bool visible);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Returns the center point of the image (takes origin into account).
|
|
|
|
Vector2f getCenter() const;
|
|
|
|
|
|
|
|
void setParent(GuiComponent* parent);
|
|
|
|
GuiComponent* getParent() const;
|
|
|
|
|
|
|
|
void addChild(GuiComponent* cmp);
|
|
|
|
void removeChild(GuiComponent* cmp);
|
|
|
|
void clearChildren();
|
|
|
|
void sortChildren();
|
|
|
|
unsigned int getChildCount() const;
|
|
|
|
GuiComponent* getChild(unsigned int i) const;
|
|
|
|
|
|
|
|
// Animation will be automatically deleted when it completes or is stopped.
|
|
|
|
bool isAnimationPlaying(unsigned char slot) const;
|
|
|
|
bool isAnimationReversed(unsigned char slot) const;
|
|
|
|
int getAnimationTime(unsigned char slot) const;
|
|
|
|
void setAnimation(Animation* animation, int delay = 0,
|
|
|
|
std::function<void()> finishedCallback = nullptr,
|
|
|
|
bool reverse = false, unsigned char slot = 0);
|
|
|
|
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();
|
|
|
|
|
2020-09-13 17:08:17 +00:00
|
|
|
virtual bool isListScrolling() { return false; };
|
|
|
|
virtual void stopListScrolling() {};
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual unsigned char getOpacity() const;
|
|
|
|
virtual void setOpacity(unsigned char opacity);
|
2020-08-30 20:19:37 +00:00
|
|
|
virtual unsigned int getColor() const;
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual void setColor(unsigned int color);
|
2020-08-30 20:19:37 +00:00
|
|
|
virtual float getSaturation() const;
|
|
|
|
virtual void setSaturation(float saturation);
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual void setColorShift(unsigned int color);
|
2020-07-15 15:44:27 +00:00
|
|
|
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.
|
|
|
|
virtual void setEnabled() { mEnabled = true; };
|
|
|
|
virtual void setDisabled() { mEnabled = false; };
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
const Transform4x4f& getTransform();
|
|
|
|
|
|
|
|
virtual std::string getValue() const;
|
|
|
|
virtual void setValue(const std::string& value);
|
|
|
|
|
|
|
|
virtual void onFocusGained() {};
|
|
|
|
virtual void onFocusLost() {};
|
|
|
|
|
|
|
|
virtual void onShow();
|
|
|
|
virtual void onHide();
|
2020-09-15 20:57:54 +00:00
|
|
|
virtual void onPauseVideo();
|
2020-09-26 20:15:36 +00:00
|
|
|
virtual void onUnpauseVideo();
|
2020-09-15 20:57:54 +00:00
|
|
|
virtual void setRenderView(bool status) { mRenderView = status; }
|
|
|
|
virtual bool getRenderView() { return mRenderView; };
|
2020-06-21 12:25:28 +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,
|
|
|
|
const std::string& view, const std::string& element, unsigned int properties);
|
|
|
|
|
|
|
|
// Returns a list of help prompts.
|
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() { return std::vector<HelpPrompt>(); };
|
|
|
|
|
|
|
|
// Called whenever help prompts change.
|
|
|
|
void updateHelpPrompts();
|
|
|
|
|
|
|
|
virtual HelpStyle getHelpStyle();
|
|
|
|
|
|
|
|
// Returns true if the component is busy doing background processing (e.g. HTTP downloads).
|
|
|
|
bool isProcessing() const;
|
|
|
|
|
|
|
|
const static unsigned char MAX_ANIMATIONS = 4;
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
protected:
|
2020-06-21 12:25:28 +00:00
|
|
|
void renderChildren(const Transform4x4f& transform) const;
|
|
|
|
void updateSelf(int deltaTime); // Updates animations.
|
|
|
|
void updateChildren(int deltaTime); // Updates animations.
|
2013-06-02 19:34:50 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Window* mWindow;
|
2013-07-10 11:29:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
GuiComponent* mParent;
|
|
|
|
std::vector<GuiComponent*> mChildren;
|
2013-07-10 11:29:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Vector3f mPosition;
|
|
|
|
Vector2f mOrigin;
|
|
|
|
Vector2f mRotationOrigin;
|
|
|
|
Vector2f 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;
|
2020-09-15 20:57:54 +00:00
|
|
|
bool mRenderView;
|
2016-09-12 11:31:44 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
// Don't access this directly! Use getTransform()!
|
|
|
|
Transform4x4f mTransform;
|
|
|
|
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
|