FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objButton.hpp
1/*
2 * Copyright 2025 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_OBJBUTTON_HPP_INCLUDED
18#define _FGE_C_OBJBUTTON_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "C_objSprite.hpp"
22#include "C_object.hpp"
23#include "FastEngine/C_guiElement.hpp"
24
25#define FGE_OBJBUTTON_CLASSNAME "FGE:OBJ:BUTTON"
26
27namespace fge
28{
29
30class FGE_API ObjButton : public fge::Object, public fge::Subscriber, public fge::GuiElement
31{
32public:
33 ObjButton();
34 ObjButton(fge::Texture textureOn, fge::Texture textureOff, fge::Vector2f const& pos = fge::Vector2f());
35 explicit ObjButton(fge::Texture texture, fge::Vector2f const& pos = fge::Vector2f());
36
37 FGE_OBJ_DEFAULT_COPYMETHOD(fge::ObjButton)
38
39 fge::GuiElement* getGuiElement() override { return this; }
40
41 fge::Texture const& getTextureOn() const;
42 fge::Texture const& getTextureOff() const;
43 void setTexture(fge::Texture const& texture, bool resetRect = false);
44 void setTextureOn(fge::Texture const& textureOn, bool resetRect = false);
45 void setTextureOff(fge::Texture const& textureOff, bool resetRect = false);
46 void setTextureRect(fge::RectInt const& rectangle);
47 void setTextureOnRect(fge::RectInt const& rectangle);
48 void setTextureOffRect(fge::RectInt const& rectangle);
49
50 void setColor(fge::Color const& color);
51
52 void setActiveStat(bool active);
53 bool getActiveStat() const;
54
55 void callbackRegister(fge::Event& event, fge::GuiElementHandler* guiElementHandlerPtr) override;
56
57 FGE_OBJ_DRAW_DECLARE
58
59 void save(nlohmann::json& jsonObject) override;
60 void load(nlohmann::json& jsonObject, std::filesystem::path const& filePath) override;
61 void pack(fge::net::Packet& pck) override;
62 void unpack(fge::net::Packet const& pck) override;
63
64 char const* getClassName() const override;
65 char const* getReadableClassName() const override;
66
67 fge::RectFloat getGlobalBounds() const override;
68 fge::RectFloat getLocalBounds() const override;
69
71
72private:
73 void
74 onGuiMouseButtonPressed(fge::Event const& evt, SDL_MouseButtonEvent const& arg, fge::GuiElementContext& context);
75 void onMouseButtonReleased(fge::Event const& evt, SDL_MouseButtonEvent const& arg);
76 void onGuiMouseMoved(fge::Event const& evt, SDL_MouseMotionEvent const& arg, fge::GuiElementContext& context);
77
78 void onGuiVerify(fge::Event const& evt, SDL_EventType evtType, fge::GuiElementContext& context) override;
79
80 mutable fge::ObjSprite g_sprite;
81
82 fge::Texture g_textureOn;
83 fge::Texture g_textureOff;
84 fge::RectInt g_textureRectOn;
85 fge::RectInt g_textureRectOff;
86
87 fge::Color g_color;
88
89 bool g_statMouseOn = false;
90 bool g_statActive = false;
91};
92
93} // namespace fge
94
95#endif // _FGE_C_OBJBUTTON_HPP_INCLUDED
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
Definition C_color.hpp:35
This class is a wrapper for SDL events.
Definition C_event.hpp:59
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_objButton.hpp:31
fge::GuiElement * getGuiElement() override
Get the GuiElement attached to this object if there is one.
Definition C_objButton.hpp:39
void callbackRegister(fge::Event &event, fge::GuiElementHandler *guiElementHandlerPtr) override
Ask the object to register all callbacks it needs to receive events.
void save(nlohmann::json &jsonObject) override
Save the object to 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.
void unpack(fge::net::Packet const &pck) override
Unpack the object from a packet.
void load(nlohmann::json &jsonObject, std::filesystem::path const &filePath) override
Load the object from a json object.
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.
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
Definition C_objSprite.hpp:30
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
This class is a useful utility to "link" multiple objects around.
Definition C_subscription.hpp:150
This class is a wrapper for the texture manager to allow easy manipulation.
Definition C_texture.hpp:36
Definition C_packet.hpp:52
Definition C_guiElement.hpp:45