GameKit  0.0.1a
C++ gamedev tools
TextInput.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: TextInput.hpp
5  *
6  * Description:
7  *
8  * Created: 22/01/2018 14:35:10
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_TEXTINPUT_HPP_
15 #define GK_TEXTINPUT_HPP_
16 
17 #include "gk/core/SDLHeaders.hpp"
19 #include "gk/graphics/Text.hpp"
20 
21 namespace gk {
22 
23 class TextInput : public IDrawable, public Transformable {
24  public:
25  TextInput();
26 
27  void onEvent(const SDL_Event &event);
28 
29  const std::string &content() const { return m_content; }
30 
31  Vector2f getSize() const { return m_rectText.getSize(); }
32 
33  void setPosition(float x, float y);
34  void setSize(u16 width, u16 height);
35  void setCharacterLimit(u16 characterLimit) { m_characterLimit = characterLimit; }
36  void setContent(const std::string &content) { m_content = content; m_text.setText(m_content + m_cursor); }
37  void setKeyboardSound(const std::string &keyboardSound) { m_keyboardSound = keyboardSound; }
38  void setCursor(const std::string &cursor) { m_cursor = cursor; m_text.setText(m_content + m_cursor); }
39 
40  private:
41  void draw(RenderTarget &target, RenderStates states) const override;
42 
44 
46  std::string m_content;
47 
49 
50  std::string m_keyboardSound;
51 
52  std::string m_cursor = "|";
53 };
54 
55 } // namespace gk
56 
57 #endif // GK_TEXTINPUT_HPP_
void setCharacterLimit(u16 characterLimit)
Definition: TextInput.hpp:35
RectangleShape m_rectText
Definition: TextInput.hpp:43
std::string m_content
Definition: TextInput.hpp:46
void setText(const std::string &text)
Definition: Text.hpp:40
Vector2f getSize() const
Definition: TextInput.hpp:31
unsigned short u16
Definition: IntTypes.hpp:22
void setContent(const std::string &content)
Definition: TextInput.hpp:36
void setPosition(float x, float y)
Definition: TextInput.cpp:30
Vector2f getSize() const
void draw(RenderTarget &target, RenderStates states) const override
Draw the object to a render target.
Definition: TextInput.cpp:64
const std::string & content() const
Definition: TextInput.hpp:29
std::string m_cursor
Definition: TextInput.hpp:52
void setCursor(const std::string &cursor)
Definition: TextInput.hpp:38
void setKeyboardSound(const std::string &keyboardSound)
Definition: TextInput.hpp:37
std::string m_keyboardSound
Definition: TextInput.hpp:50
Abstract base class for objects that can be drawn to a render target.
Definition: IDrawable.hpp:25
void setSize(u16 width, u16 height)
Definition: TextInput.cpp:35
u16 m_characterLimit
Definition: TextInput.hpp:48
void onEvent(const SDL_Event &event)
Definition: TextInput.cpp:39