FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objSlider.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_OBJSLIDER_HPP_INCLUDED
18#define _FGE_C_OBJSLIDER_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_object.hpp"
24
25#define FGE_OBJSLIDER_CLASSNAME "FGE:OBJ:SLIDER"
26#define FGE_OBJSLIDER_SCROLL_RATIO_DEFAULT 0.2f
27
28namespace fge
29{
30
31class FGE_API ObjSlider : public fge::Object, public fge::Subscriber, public fge::GuiElement
32{
33public:
34 ObjSlider() = default;
35 ~ObjSlider() override = default;
36
37 FGE_OBJ_DEFAULT_COPYMETHOD(fge::ObjSlider)
38
39 [[nodiscard]] fge::GuiElement* getGuiElement() override { return this; }
40
41 void first(fge::Scene& scene) override;
42 void callbackRegister(fge::Event& event, fge::GuiElementHandler* guiElementHandlerPtr) override;
43 FGE_OBJ_DRAW_DECLARE
44
45 void setSize(fge::DynamicSize const& size);
46 [[nodiscard]] fge::Vector2f getSize() const;
47
48 void allowJump(bool allow);
49 void setScrollInversion(bool inverted);
50 void setCursorPosition(float position);
51 void setCursorRatio(float ratio);
52 void scroll(float deltaRatio);
53 [[nodiscard]] float getCursorRatio() const;
54 [[nodiscard]] bool isScrollPressed() const;
55 [[nodiscard]] bool isScrollInverted() const;
56 [[nodiscard]] bool isAllowingJump() const;
57
58 void refreshSize();
59
60 void setScrollRectFillColor(fge::Color color);
61 void setScrollRectOutlineColor(fge::Color color);
62 void setScrollBaseRectFillColor(fge::Color color);
63
64 [[nodiscard]] char const* getClassName() const override;
65 [[nodiscard]] char const* getReadableClassName() const override;
66
67 [[nodiscard]] fge::RectFloat getGlobalBounds() const override;
68 [[nodiscard]] 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
76 onGuiMouseWheelScrolled(fge::Event const& evt, SDL_MouseWheelEvent const& arg, fge::GuiElementContext& context);
77 void onMouseButtonReleased(fge::Event const& evt, SDL_MouseButtonEvent const& arg);
78 void onMouseMoved(fge::Event const& evt, SDL_MouseMotionEvent const& arg);
79
80 void onGuiResized(fge::GuiElementHandler const& handler, fge::Vector2f const& size);
81
82 void onGuiVerify(fge::Event const& evt, SDL_EventType evtType, fge::GuiElementContext& context) override;
83
84 void refreshSize(fge::Vector2f const& targetSize);
85
86 mutable fge::ObjRectangleShape g_scrollRect;
87 mutable fge::ObjRectangleShape g_scrollBaseRect;
88
89 fge::GuiElementHandler* g_guiElementHandler{nullptr};
90
91 fge::DynamicSize g_size;
92
93 bool g_scrollPressed{false};
94 float g_scrollPositionY{0.0f};
95 float g_scrollLastPositionY{0.0f};
96 float g_lastMousePositionY{0.0f};
97 bool g_scrollInverted{false};
98 bool g_allowJump{true};
99};
100
101} // namespace fge
102
103#endif //_FGE_C_OBJSLIDER_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_objRectangleShape.hpp:36
Definition C_objSlider.hpp:32
void first(fge::Scene &scene) override
Method called when the object is added to a scene for initialization purposes.
fge::GuiElement * getGuiElement() override
Get the GuiElement attached to this object if there is one.
Definition C_objSlider.hpp:39
void callbackRegister(fge::Event &event, fge::GuiElementHandler *guiElementHandlerPtr) override
Ask the object to register all callbacks it needs to receive events.
fge::RectFloat getGlobalBounds() const override
Get the global bounds of the object.
char const * getClassName() const override
Get the unique class name of the object.
char const * getReadableClassName() const override
Get a readable version of the class name.
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
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_guiElement.hpp:56
Definition C_guiElement.hpp:45