38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <object/entity.hpp>
|
|
#include <renderer/font.hpp>
|
|
#include <renderer/texture.hpp>
|
|
#include <utility>
|
|
#include <game/input.hpp>
|
|
|
|
namespace Game::Object {
|
|
class UITextBox : public Entity {
|
|
public:
|
|
UITextBox(const std::string& name, std::shared_ptr<Renderer::Font> font, const Transform& transform, float x = 0.f, float y = 0.f);
|
|
~UITextBox() override = default;
|
|
|
|
void start() override;
|
|
void update(float deltaTime) override;
|
|
|
|
void setText(const std::string& text);
|
|
std::string getText() const;
|
|
std::string getValue() const;
|
|
bool isFocused() const;
|
|
|
|
void setPosition(float x, float y) { mX = x; mY = y; }
|
|
std::pair<float, float> getPosition() const { return {mX, mY}; }
|
|
|
|
private:
|
|
bool isMouseInsideBox() const;
|
|
void refreshVisualText();
|
|
|
|
float mX, mY;
|
|
std::string mText;
|
|
bool mIsFocused = false;
|
|
float mBoxWidth = 0.f;
|
|
float mBoxHeight = 0.f;
|
|
bool mNeedsTextRefresh = true;
|
|
};
|
|
}
|