2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-28 16:39:18 +00:00
|
|
|
//
|
2023-12-16 18:48:25 +00:00
|
|
|
// ES-DE
|
2020-06-28 16:39:18 +00:00
|
|
|
// TextComponent.h
|
|
|
|
//
|
|
|
|
// Displays text.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "GuiComponent.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "resources/Font.h"
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2013-11-25 20:49:02 +00:00
|
|
|
class ThemeData;
|
|
|
|
|
2022-10-08 07:33:57 +00:00
|
|
|
// TextComponent sizing works in the following ways:
|
|
|
|
// setSize(0.0f, 0.0f) - Automatically sizes single-line text by expanding horizontally.
|
|
|
|
// setSize(width, 0.0f) - Limits size horizontally and automatically expands vertically.
|
|
|
|
// setSize(width, height) - Wraps and abbreviates text inside the width and height boundaries.
|
2013-06-14 15:48:13 +00:00
|
|
|
class TextComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2022-01-19 17:01:54 +00:00
|
|
|
TextComponent();
|
|
|
|
TextComponent(const std::string& text,
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::shared_ptr<Font>& font,
|
|
|
|
unsigned int color = 0x000000FF,
|
2022-09-24 14:47:14 +00:00
|
|
|
Alignment horizontalAlignment = ALIGN_LEFT,
|
2022-09-24 19:37:00 +00:00
|
|
|
Alignment verticalAlignment = ALIGN_CENTER,
|
2022-09-23 17:40:39 +00:00
|
|
|
glm::vec3 pos = {0.0f, 0.0f, 0.0f},
|
|
|
|
glm::vec2 size = {0.0f, 0.0f},
|
2023-08-09 16:57:23 +00:00
|
|
|
unsigned int bgcolor = 0x00000000,
|
|
|
|
float lineSpacing = 1.5f,
|
|
|
|
float relativeScale = 1.0f,
|
|
|
|
bool horizontalScrolling = false,
|
|
|
|
float scrollSpeedMultiplier = 1.0f,
|
|
|
|
float scrollDelay = 1500.0f,
|
|
|
|
float scrollGap = 1.5f);
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
void setFont(const std::shared_ptr<Font>& font);
|
|
|
|
void setUppercase(bool uppercase);
|
2022-02-09 19:44:22 +00:00
|
|
|
void setLowercase(bool lowercase);
|
2022-02-09 21:06:34 +00:00
|
|
|
void setCapitalize(bool capitalize);
|
2020-06-28 16:39:18 +00:00
|
|
|
void onSizeChanged() override;
|
2021-09-28 19:46:45 +00:00
|
|
|
void setText(const std::string& text, bool update = true);
|
2021-07-07 18:31:46 +00:00
|
|
|
void setHiddenText(const std::string& text) { mHiddenText = text; }
|
2020-06-28 16:39:18 +00:00
|
|
|
void setColor(unsigned int color) override;
|
|
|
|
void setHorizontalAlignment(Alignment align);
|
2021-09-28 19:46:45 +00:00
|
|
|
void setVerticalAlignment(Alignment align) { mVerticalAlignment = align; }
|
2020-06-28 16:39:18 +00:00
|
|
|
void setLineSpacing(float spacing);
|
2021-09-30 18:11:56 +00:00
|
|
|
float getLineSpacing() override { return mLineSpacing; }
|
2021-03-13 15:52:15 +00:00
|
|
|
void setNoTopMargin(bool margin);
|
2023-01-28 13:14:30 +00:00
|
|
|
void setBackgroundColor(unsigned int color) override;
|
2021-07-07 18:31:46 +00:00
|
|
|
void setRenderBackground(bool render) { mRenderBackground = render; }
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2023-08-08 17:18:16 +00:00
|
|
|
void onFocusLost() override { resetComponent(); }
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
std::string getValue() const override { return mText; }
|
2023-01-10 21:20:00 +00:00
|
|
|
void setValue(const std::string& value) override;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
std::string getHiddenValue() const override { return mHiddenText; }
|
|
|
|
void setHiddenValue(const std::string& value) override { setHiddenText(value); }
|
2020-11-07 11:50:30 +00:00
|
|
|
|
2022-02-12 16:38:55 +00:00
|
|
|
float const getOpacity() const override
|
|
|
|
{
|
|
|
|
return static_cast<float>((mColor & 0x000000FF) / 255.0f);
|
|
|
|
}
|
2022-08-17 15:04:19 +00:00
|
|
|
float const getColorOpacity() const override { return mColorOpacity; }
|
|
|
|
|
2022-02-11 21:10:25 +00:00
|
|
|
void setOpacity(float opacity) override;
|
2023-03-03 21:37:39 +00:00
|
|
|
void setSaturation(float saturation) override;
|
2022-03-11 22:51:41 +00:00
|
|
|
void setDimming(float dimming) override;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-10-14 19:29:23 +00:00
|
|
|
void setSelectable(bool status) { mSelectable = status; }
|
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) override;
|
2014-01-01 05:39:22 +00:00
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
std::vector<HelpPrompt> getHelpPrompts() override;
|
2021-10-14 19:29:23 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned int getColor() const override { return mColor; }
|
|
|
|
std::shared_ptr<Font> getFont() const override { return mFont; }
|
2021-03-21 10:50:13 +00:00
|
|
|
Alignment getHorizontalAlignment() { return mHorizontalAlignment; }
|
|
|
|
Alignment getVerticalAlignment() { return mVerticalAlignment; }
|
2023-01-14 13:05:24 +00:00
|
|
|
const bool getSystemNameSuffix() const { return mSystemNameSuffix; }
|
|
|
|
const LetterCase getLetterCaseSystemNameSuffix() const { return mLetterCaseSystemNameSuffix; }
|
2021-01-13 18:48:31 +00:00
|
|
|
|
2022-10-24 22:39:40 +00:00
|
|
|
int getTextCacheGlyphHeight() override
|
|
|
|
{
|
|
|
|
return (mTextCache == nullptr ? 0 : mTextCache->metrics.maxGlyphHeight);
|
|
|
|
}
|
|
|
|
|
2023-08-08 17:18:16 +00:00
|
|
|
// Horizontal scrolling for single-line content that is too long to fit.
|
|
|
|
void setHorizontalScrolling(bool state) override;
|
|
|
|
void setHorizontalScrollingSpeedMultiplier(float speed) { mScrollSpeedMultiplier = speed; }
|
|
|
|
void setHorizontalScrollingDelay(float delay) { mScrollDelay = delay; }
|
2023-08-09 16:57:23 +00:00
|
|
|
void setHorizontalScrollingGap(float gap) { mScrollGap = gap; }
|
2023-08-07 20:58:35 +00:00
|
|
|
|
2023-08-08 17:43:40 +00:00
|
|
|
void resetComponent() override
|
2023-08-07 20:58:35 +00:00
|
|
|
{
|
2023-08-08 17:18:16 +00:00
|
|
|
mScrollOffset1 = 0;
|
|
|
|
mScrollOffset2 = 0;
|
|
|
|
mScrollTime = 0;
|
2023-08-07 20:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void update(int deltaTime) override;
|
|
|
|
|
2018-10-13 01:08:15 +00:00
|
|
|
protected:
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual void onTextChanged();
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
std::string mText;
|
2020-11-07 11:50:30 +00:00
|
|
|
std::string mHiddenText;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
private:
|
2020-06-28 16:39:18 +00:00
|
|
|
void onColorChanged();
|
|
|
|
|
2023-01-30 17:40:28 +00:00
|
|
|
static inline std::vector<std::string> supportedSystemdataTypes {"name",
|
|
|
|
"fullname",
|
|
|
|
"gamecount",
|
|
|
|
"gamecountGames",
|
|
|
|
"gamecountGamesNoText",
|
|
|
|
"gamecountFavorites",
|
|
|
|
"gamecountFavoritesNoText"};
|
2022-08-18 21:44:22 +00:00
|
|
|
|
2023-09-23 10:52:00 +00:00
|
|
|
static inline std::vector<std::string> supportedMetadataTypes {"name",
|
|
|
|
"description",
|
|
|
|
"rating",
|
|
|
|
"developer",
|
|
|
|
"publisher",
|
|
|
|
"genre",
|
|
|
|
"players",
|
|
|
|
"favorite",
|
|
|
|
"completed",
|
|
|
|
"kidgame",
|
|
|
|
"broken",
|
|
|
|
"playcount",
|
|
|
|
"controller",
|
|
|
|
"altemulator",
|
|
|
|
"emulator",
|
|
|
|
"manual",
|
|
|
|
"physicalName",
|
|
|
|
"physicalNameExtension",
|
|
|
|
"systemName",
|
|
|
|
"systemFullname",
|
|
|
|
"sourceSystemName",
|
|
|
|
"sourceSystemFullname"};
|
2022-08-18 21:44:22 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
Renderer* mRenderer;
|
2023-01-10 21:20:00 +00:00
|
|
|
std::string mDefaultValue;
|
2020-06-28 16:39:18 +00:00
|
|
|
unsigned int mColor;
|
|
|
|
unsigned int mBgColor;
|
2022-02-11 21:10:25 +00:00
|
|
|
float mColorOpacity;
|
|
|
|
float mBgColorOpacity;
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mRenderBackground;
|
2023-01-14 13:05:24 +00:00
|
|
|
bool mSystemNameSuffix;
|
|
|
|
LetterCase mLetterCaseSystemNameSuffix;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
bool mUppercase;
|
2022-02-09 19:44:22 +00:00
|
|
|
bool mLowercase;
|
2022-02-09 21:06:34 +00:00
|
|
|
bool mCapitalize;
|
2021-08-17 16:41:45 +00:00
|
|
|
glm::ivec2 mAutoCalcExtent;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<TextCache> mTextCache;
|
|
|
|
Alignment mHorizontalAlignment;
|
|
|
|
Alignment mVerticalAlignment;
|
|
|
|
float mLineSpacing;
|
2023-08-09 16:57:23 +00:00
|
|
|
float mRelativeScale;
|
2021-03-13 15:52:15 +00:00
|
|
|
bool mNoTopMargin;
|
2021-10-14 19:29:23 +00:00
|
|
|
bool mSelectable;
|
2022-09-23 17:40:39 +00:00
|
|
|
bool mVerticalAutoSizing;
|
2023-08-07 20:58:35 +00:00
|
|
|
|
2023-08-08 17:18:16 +00:00
|
|
|
bool mHorizontalScrolling;
|
|
|
|
float mScrollSpeed;
|
|
|
|
float mScrollSpeedMultiplier;
|
|
|
|
float mScrollDelay;
|
2023-08-09 16:57:23 +00:00
|
|
|
float mScrollGap;
|
2023-08-08 17:18:16 +00:00
|
|
|
float mScrollOffset1;
|
|
|
|
float mScrollOffset2;
|
|
|
|
float mScrollTime;
|
2013-06-14 15:48:13 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|