FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objTextinputbox.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_OBJTEXTINPUTBOX_HPP_INCLUDED
18#define _FGE_C_OBJTEXTINPUTBOX_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_guiElement.hpp"
22#include "FastEngine/object/C_objRectangleShape.hpp"
23#include "FastEngine/object/C_objText.hpp"
24#include "FastEngine/object/C_object.hpp"
25
26#define FGE_OBJTEXTINBOX_CLASSNAME "FGE:OBJ:TEXTINBOX"
27
28namespace fge
29{
30
31class FGE_API ObjTextInputBox : public fge::Object, public fge::Subscriber, public fge::GuiElement
32{
33public:
35 explicit ObjTextInputBox(fge::Font const& font,
36 uint16_t maxLength = 10,
37 fge::Vector2f const& pos = fge::Vector2f());
38
39 FGE_OBJ_DEFAULT_COPYMETHOD(fge::ObjTextInputBox)
40
41 fge::GuiElement* getGuiElement() override { return this; }
42
43 void setString(tiny_utf8::string string);
44 void setFont(fge::Font font);
45 void setCharacterSize(fge::CharacterSize size);
46 void setHideTextFlag(bool flag);
47 void setMaxLength(uint16_t length);
48
49 void setActiveStat(bool active);
50
51 void setBoxSize(fge::Vector2f const& size);
52 void setBoxSize(float w, float h);
53
54 void setBoxColor(fge::Color const& color);
55 void setBoxOutlineColor(fge::Color const& color);
56 void setTextColor(fge::Color const& color);
57
58 tiny_utf8::string const& getString() const;
59 fge::CharacterSize getCharacterSize() const;
60 bool isTextHide() const;
61 uint16_t getMaxLength() const;
62
63 bool getActiveStat() const;
64
65 fge::Vector2f const& getBoxSize() const;
66
67 fge::Color const& getBoxColor() const;
68 fge::Color const& getBoxOutlineColor() const;
69 fge::Color const& getTextColor() const;
70
71 void callbackRegister(fge::Event& event, fge::GuiElementHandler* guiElementHandlerPtr) override;
72
73 FGE_OBJ_UPDATE_DECLARE
74 FGE_OBJ_DRAW_DECLARE
75
76 void save(nlohmann::json& jsonObject, fge::Scene* scene) override;
77 void load(nlohmann::json& jsonObject, fge::Scene* scene) override;
78 void pack(fge::net::Packet& pck) override;
79 void unpack(fge::net::Packet const& pck) override;
80
81 char const* getClassName() const override;
82 char const* getReadableClassName() const override;
83
86
89
90private:
91 void
92 onGuiMouseButtonPressed(fge::Event const& evt, SDL_MouseButtonEvent const& arg, fge::GuiElementContext& context);
93 void onTextInput(fge::Event const& evt, SDL_TextInputEvent const& arg);
94 void onKeyDown(fge::Event const& evt, SDL_KeyboardEvent const& arg);
95
96 void onGuiVerify(fge::Event const& evt, SDL_EventType evtType, fge::GuiElementContext& context) override;
97
98 std::chrono::milliseconds g_cursorBlinkTime{0};
99 uint16_t g_cursor{0};
100 uint16_t g_maxLength{10};
101 bool g_hide{false};
102
103 fge::Color g_colorBox{fge::Color::White};
104 fge::Color g_colorBoxOutline{fge::Color::Black};
105
106 tiny_utf8::string g_string;
107 mutable fge::ObjText g_text;
108 mutable fge::ObjRectangleShape g_box;
109 mutable fge::ObjRectangleShape g_cursorLine;
110
111 fge::Vector2f g_boxSize{120.0f, 18.0f};
112
113 bool g_statActive{false};
114};
115
116} // namespace fge
117
118#endif // _FGE_C_OBJTEXTINPUTBOX_HPP_INCLUDED
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
Definition C_color.hpp:35
static Color const Black
Black predefined color.
Definition C_color.hpp:140
static Color const White
White predefined color.
Definition C_color.hpp:141
This class is a wrapper for SDL events.
Definition C_event.hpp:59
This class is a wrapper for the font manager to allow easy manipulation.
Definition C_font.hpp:35
A class to handle highest priority selection of GUI elements.
Definition C_guiElement.hpp:235
A base class for all GUI elements.
Definition C_guiElement.hpp:120
Definition C_objRectangleShape.hpp:36
Definition C_objTextinputbox.hpp:32
char const * getReadableClassName() const override
Get a readable version of the class name.
fge::RectFloat getGlobalBounds() const override
Get the global bounds of the object.
void callbackRegister(fge::Event &event, fge::GuiElementHandler *guiElementHandlerPtr) override
Ask the object to register all callbacks it needs to receive events.
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
void load(nlohmann::json &jsonObject, fge::Scene *scene) override
Load the object from a json object.
void pack(fge::net::Packet &pck) override
Pack the object into a packet.
char const * getClassName() const override
Get the unique class name of the object.
FGE_OBJ_UPDATE_DECLARE FGE_OBJ_DRAW_DECLARE void save(nlohmann::json &jsonObject, fge::Scene *scene) override
Save the object to a json object.
void unpack(fge::net::Packet const &pck) override
Unpack the object from a packet.
Definition C_objText.hpp:90
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
This class is a useful utility to "link" multiple objects around.
Definition C_subscription.hpp:150
Definition C_packet.hpp:70
Definition C_guiElement.hpp:45