R-Type
R-Type project
Inputfield.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** RType2
4 ** File description:
5 ** Inputfield
6 */
7 
8 #ifndef KAPUI_INPUTFIELD_HPP_
9 #define KAPUI_INPUTFIELD_HPP_
10 
11 #include "KapEngine.hpp"
12 
13 namespace KapEngine
14 {
15 
16  namespace UI
17  {
18 
19  class Inputfield : public Component
20  {
21  public:
22  enum InputType
23  {
24  TEXT,
25  NUMBER,
26  PASSWORD,
27  IPV4,
28  IPV6,
29  };
30 
31  Inputfield(std::shared_ptr<GameObject> go);
32  ~Inputfield();
33 
34  void onFixedUpdate() override;
35 
36  void onMouseEnter() override;
37  void onMouseStay() override;
38  void onMouseExit() override;
39 
40  void setPlaceholderText(std::string const &text);
41 
42  void setInputType(InputType type) { _type = type; }
43 
44  std::string getText() const { return _content; }
45 
46  void setBackground(std::string const &path, Tools::Rectangle const &rect);
47 
48  protected:
49  private:
50  bool __stringIsNumber(std::string const &str)
51  {
52  for (std::size_t i = 0; i < str.size(); i++)
53  {
54  if (str[i] < '0' || str[i] > '9')
55  return false;
56  }
57  return true;
58  }
59 
60  std::string __getInput();
61  void __init(std::shared_ptr<GameObject> go);
62  void __updateTexts();
63  std::string __getFormatedText() const;
64 
65  bool _hovered = false;
66  bool _clicked = false;
67 
68  InputType _type = InputType::TEXT;
69 
70  std::string _content = "";
71  };
72 
73  } // namespace UI
74 
75 } // namespace KapEngine
76 
77 #endif /* !INPUTFIELD_HPP_ */
KapEngine::UI::Inputfield::onMouseExit
void onMouseExit() override
called when mouse leave object
Definition: Inputfield.cpp:79
KapEngine::Component
Definition: Component.hpp:38
KapEngine::UI::Inputfield::onMouseEnter
void onMouseEnter() override
called when mouse enter object
Definition: Inputfield.cpp:73
KapEngine
main namespace
Definition: Component.hpp:17
KapEngine::Tools::Rectangle
Definition: Rectangle.hpp:23
KapEngine::UI::Inputfield::onFixedUpdate
void onFixedUpdate() override
call eachv x ms
Definition: Inputfield.cpp:20
KapEngine::UI::Inputfield::onMouseStay
void onMouseStay() override
called when mouse stay on object
Definition: Inputfield.cpp:77
KapEngine::UI::Inputfield
Definition: Inputfield.hpp:19