FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objButton.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_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 const& 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 setTextureOn(fge::Texture const& textureOn);
44 void setTextureOff(fge::Texture const& textureOff);
45
46 void setColor(fge::Color const& color);
47
48 void setActiveStat(bool active);
49 bool getActiveStat() const;
50
51 void callbackRegister(fge::Event& event, fge::GuiElementHandler* guiElementHandlerPtr) override;
52
53 FGE_OBJ_DRAW_DECLARE
54
55 void save(nlohmann::json& jsonObject, fge::Scene* scene) override;
56 void load(nlohmann::json& jsonObject, fge::Scene* scene) override;
57 void pack(fge::net::Packet& pck) override;
58 void unpack(fge::net::Packet const& pck) override;
59
60 char const* getClassName() const override;
61 char const* getReadableClassName() const override;
62
65
67
68private:
69 void
70 onGuiMouseButtonPressed(fge::Event const& evt, SDL_MouseButtonEvent const& arg, fge::GuiElementContext& context);
71 void onMouseButtonReleased(fge::Event const& evt, SDL_MouseButtonEvent const& arg);
72 void onGuiMouseMoved(fge::Event const& evt, SDL_MouseMotionEvent const& arg, fge::GuiElementContext& context);
73
74 void onGuiVerify(fge::Event const& evt, SDL_EventType evtType, fge::GuiElementContext& context) override;
75
76 mutable fge::ObjSprite g_sprite;
77
78 fge::Texture g_textureOn;
79 fge::Texture g_textureOff;
80
81 fge::Color g_color;
82
83 bool g_statMouseOn = false;
84 bool g_statActive = false;
85};
86
87} // namespace fge
88
89#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
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.
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.
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)
void save(nlohmann::json &jsonObject, fge::Scene *scene) override
Save the object to a json object.
Definition C_objSprite.hpp:30
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
This class is a wrapper for the texture manager to allow easy manipulation.
Definition C_texture.hpp:36
Definition C_packet.hpp:70
Definition C_guiElement.hpp:45