2020-09-18 16:16:12 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-09-18 16:16:12 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// TextEditComponent.h
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Component for editing text fields in menus.
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_TEXT_EDIT_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_TEXT_EDIT_COMPONENT_H
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "GuiComponent.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "components/NinePatchComponent.h"
|
|
|
|
#include "resources/Font.h"
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2013-08-19 15:36:48 +00:00
|
|
|
class Font;
|
2013-08-22 01:08:36 +00:00
|
|
|
class TextCache;
|
2013-08-19 15:36:48 +00:00
|
|
|
|
2014-01-24 22:21:10 +00:00
|
|
|
// Used to enter text.
|
2013-08-18 14:16:11 +00:00
|
|
|
class TextEditComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
TextEditComponent(Window* window);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-12-16 22:59:00 +00:00
|
|
|
void textInput(const std::string& text) override;
|
2020-06-21 12:25:28 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void onFocusGained() override;
|
|
|
|
void onFocusLost() override;
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void onSizeChanged() override;
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void setValue(const std::string& val) override;
|
2021-07-07 18:31:46 +00:00
|
|
|
std::string getValue() const override { return mText; }
|
2013-08-19 15:36:48 +00:00
|
|
|
|
2020-11-07 11:45:57 +00:00
|
|
|
void startEditing();
|
|
|
|
void stopEditing();
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
bool isEditing() const { return mEditing; }
|
|
|
|
std::shared_ptr<Font> getFont() const override { return mFont; }
|
2013-09-20 23:55:05 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void setCursor(size_t pos);
|
2014-06-15 17:55:30 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
void onTextChanged();
|
|
|
|
void onCursorChanged();
|
2013-08-21 19:49:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void updateCursorRepeat(int deltaTime);
|
|
|
|
void moveCursor(int amt);
|
2014-03-21 02:47:45 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
bool isMultiline() { return (getSize().y() > mFont->getHeight() * 1.25f); }
|
2020-06-21 12:25:28 +00:00
|
|
|
Vector2f getTextAreaPos() const;
|
|
|
|
Vector2f getTextAreaSize() const;
|
2013-09-12 21:35:44 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string mText;
|
|
|
|
std::string mTextOrig;
|
|
|
|
bool mFocused;
|
|
|
|
bool mEditing;
|
|
|
|
unsigned int mCursor; // Cursor position in characters.
|
2014-03-21 02:47:45 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
int mCursorRepeatTimer;
|
|
|
|
int mCursorRepeatDir;
|
2013-08-19 15:36:48 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Vector2f mScrollOffset;
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
NinePatchComponent mBox;
|
2021-01-15 17:53:38 +00:00
|
|
|
float mResolutionAdjustment;
|
2013-08-22 01:08:36 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
|
|
|
std::unique_ptr<TextCache> mTextCache;
|
2013-08-18 14:16:11 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_TEXT_EDIT_COMPONENT_H
|