FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objSelectBox.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_OBJSELECTBOX_HPP_INCLUDED
18#define _FGE_C_OBJSELECTBOX_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21
22#include "FastEngine/C_guiElement.hpp"
23#include "FastEngine/object/C_objRectangleShape.hpp"
24#include "FastEngine/object/C_objText.hpp"
25#include "FastEngine/object/C_object.hpp"
26#include <limits>
27
28#define FGE_OBJSELECTBOX_CLASSNAME "FGE:OBJ:SELECTBOX"
29
30namespace fge
31{
32
33class FGE_API ObjSelectBox : public fge::Object, public fge::Subscriber, public fge::GuiElement
34{
35public:
37 explicit ObjSelectBox(fge::Font font, fge::Vector2f const& pos = fge::Vector2f());
38
39 FGE_OBJ_DEFAULT_COPYMETHOD(fge::ObjSelectBox)
40
41 fge::GuiElement* getGuiElement() override { return this; }
42
43 std::size_t getItemCount() const;
44 tiny_utf8::string const* getItem(std::size_t index) const;
45 bool setItem(std::size_t index, tiny_utf8::string text);
46 void addItem(tiny_utf8::string text);
47 void clearItems();
48
49 void setSelectedText(tiny_utf8::string string);
50 tiny_utf8::string const& getSelectedText() const;
51 void clearSelectedText();
52
53 void setCharacterSize(fge::CharacterSize size);
54
55 void setActiveStat(bool active);
56 bool getActiveStat() const;
57
58 void setBoxSize(fge::Vector2f const& size);
59 void setBoxColor(fge::Color color);
60 void setBoxOutlineColor(fge::Color color);
61 void setTextColor(fge::Color color);
62
63 fge::CharacterSize getCharacterSize() const;
64
65 fge::Vector2f const& getBoxSize() const;
66 fge::Color getBoxColor() const;
67 fge::Color getBoxOutlineColor() const;
68 fge::Color getTextColor() const;
69
70 void callbackRegister(fge::Event& event, fge::GuiElementHandler* guiElementHandlerPtr) override;
71
72 FGE_OBJ_DRAW_DECLARE
73
74 void save(nlohmann::json& jsonObject, fge::Scene* scene) override;
75 void load(nlohmann::json& jsonObject, fge::Scene* scene) override;
76 void pack(fge::net::Packet& pck) override;
77 void unpack(fge::net::Packet const& pck) override;
78
79 char const* getClassName() const override;
80 char const* getReadableClassName() const override;
81
84
86
87private:
88 void
89 onGuiMouseButtonPressed(fge::Event const& evt, SDL_MouseButtonEvent const& arg, fge::GuiElementContext& context);
90 void onGuiMouseMotion(fge::Event const& evt, SDL_MouseMotionEvent const& arg, fge::GuiElementContext& context);
91
92 void onGuiVerify(fge::Event const& evt, SDL_EventType evtType, fge::GuiElementContext& context) override;
93
94 void updateBoxInstances();
95
96 fge::Color g_colorBox = fge::Color::White;
97 fge::Color g_colorBoxOutline = fge::Color::Black;
98 fge::Color g_colorText = fge::Color::Black;
99
100 mutable std::vector<fge::ObjText> g_textList;
101 mutable fge::ObjText g_textSelected;
102 mutable fge::ObjRectangleShape g_box;
103
104 std::size_t g_cursor = std::numeric_limits<std::size_t>::max();
105
106 bool g_statMouseOn = false;
107 bool g_statActive = false;
108};
109
110} // namespace fge
111
112#endif // _FGE_C_OBJSELECTBOX_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_objSelectBox.hpp:34
void load(nlohmann::json &jsonObject, fge::Scene *scene) override
Load the object from a json object.
void callbackRegister(fge::Event &event, fge::GuiElementHandler *guiElementHandlerPtr) override
Ask the object to register all callbacks it needs to receive events.
FGE_OBJ_DRAW_DECLARE void save(nlohmann::json &jsonObject, fge::Scene *scene) override
Save the object to a json object.
char const * getClassName() const override
Get the unique class name of the object.
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
void pack(fge::net::Packet &pck) override
Pack the object into a packet.
void unpack(fge::net::Packet const &pck) override
Unpack the object from a packet.
fge::RectFloat getGlobalBounds() const override
Get the global bounds of the object.
char const * getReadableClassName() const override
Get a readable version of the class name.
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