FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objWindow.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_OBJWINDOW_HPP_INCLUDED
18#define _FGE_C_OBJWINDOW_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_scene.hpp"
22#include "FastEngine/object/C_object.hpp"
23
24#include "FastEngine/C_guiElement.hpp"
25#include "FastEngine/C_tileset.hpp"
26#include "FastEngine/object/C_objSprite.hpp"
27#include "FastEngine/object/C_objSpriteBatches.hpp"
28#include "FastEngine/object/C_objText.hpp"
29
30#define FGE_WINDOW_DEFAULT_PRIORITY (FGE_GUI_ELEMENT_PRIORITY_DEFAULT + 1)
31#define FGE_WINDOW_DEFAULT_SIZE_X 120.0f
32#define FGE_WINDOW_DEFAULT_SIZE_Y 200.0f
33#define FGE_WINDOW_PIXEL_SIZE 6
34
35#define FGE_OBJWINDOW_CLASSNAME "FGE:OBJ:WINDOW"
36#define FGE_OBJWINDOW_SCENE_PARENT_PROPERTY "_OBJWINDOW_PARENT_"
37
38namespace fge
39{
40
41class FGE_API ObjWindow : public fge::Object, public fge::Subscriber, public fge::GuiElementRecursive
42{
43public:
44 enum class ResizeModes
45 {
46 MODE_FREE,
47 MODE_FIXED
48 };
49
50 ObjWindow();
51 ObjWindow(ObjWindow const& r);
52 ~ObjWindow() override = default;
53
54 ObjWindow& operator=(ObjWindow const& r) = delete;
55
56 FGE_OBJ_DEFAULT_COPYMETHOD(fge::ObjWindow)
57
58 fge::GuiElement* getGuiElement() override { return this; }
59
60 void first(fge::Scene& scene) override;
61 void callbackRegister(fge::Event& event, fge::GuiElementHandler* guiElementHandlerPtr) override;
62 void removed(fge::Scene& scene) override;
63
64 FGE_OBJ_UPDATE_DECLARE
65 FGE_OBJ_DRAW_DECLARE
66
67 char const* getClassName() const override;
68 char const* getReadableClassName() const override;
69
72
73 void setHeight(float height);
74 void setSize(fge::Vector2f const& size);
75 fge::Vector2f const& getSize() const;
76 fge::Vector2f getDrawAreaSize() const;
77
78 void showExitButton(bool enable);
79 void makeMovable(bool enable);
80 void makeResizable(bool enable);
81
82 void setResizeMode(ObjWindow::ResizeModes modeX, ObjWindow::ResizeModes modeY);
83
84 void setViewCenterOffset(fge::Vector2f const& offset);
85 fge::Vector2f const& getViewCenterOffset() const;
86
87 static fge::ObjWindow* getWindowObjectFromScene(fge::Scene* scene);
88
89 void setTextureMinimize(fge::Texture texture);
90 void setTextureClose(fge::Texture texture);
91 void setTextureResize(fge::Texture texture);
92
93 fge::Texture const& getTextureMinimize() const;
94 fge::Texture const& getTextureClose() const;
95 fge::Texture const& getTextureResize() const;
96
97 void setTexture(fge::Texture texture);
98 void setTileSet(fge::TileSet const& tileSet);
99 void setTileSet(fge::TileSet&& tileSet);
100 fge::TileSet const& getTileSet() const;
101
102 void refreshRectBounds();
103 void refreshTextures();
104
105 fge::Scene _windowScene;
106 fge::GuiElementHandler _windowHandler;
107 mutable std::shared_ptr<fge::View> _windowView;
108
110
111private:
112 void onGuiVerify(fge::Event const& evt, SDL_EventType evtType, fge::GuiElementContext& context) override;
113
114 void
115 onGuiMouseButtonPressed(fge::Event const& evt, SDL_MouseButtonEvent const& arg, fge::GuiElementContext& context);
116 void onMouseButtonReleased(fge::Event const& evt, SDL_MouseButtonEvent const& arg);
117 void onMouseMoved(fge::Event const& evt, SDL_MouseMotionEvent const& arg);
118
119 void onPlanUpdate(fge::Scene& scene, fge::ObjectPlan plan);
120 void onObjectAdded(fge::Scene& scene, fge::ObjectDataShared const& object);
121
122 void onRefreshGlobalScale(fge::Vector2f const& scale);
123
124 bool g_movingWindowFlag{false};
125 bool g_resizeWindowFlag{false};
126 fge::Vector2f g_mouseClickLastPosition;
127 fge::Vector2f g_mouseClickLastSize;
128 fge::Vector2f g_size{FGE_WINDOW_DEFAULT_SIZE_X, FGE_WINDOW_DEFAULT_SIZE_Y};
129
130 bool g_showCloseButton{true};
131 bool g_makeMovable{true};
132 bool g_makeResizable{true};
133
134 fge::ObjWindow::ResizeModes g_resizeModeX{fge::ObjWindow::ResizeModes::MODE_FREE};
135 fge::ObjWindow::ResizeModes g_resizeModeY{fge::ObjWindow::ResizeModes::MODE_FREE};
136
137 fge::GuiElementHandler* g_guiElementHandler{nullptr};
138
139 fge::Vector2f g_viewCenterOffset;
140
141 //Textures
142 fge::Texture g_textureWindowMinimize{};
143 fge::Texture g_textureWindowClose{};
144 fge::Texture g_textureWindowResize{};
145 fge::TileSet g_tileSetWindow{{}, {FGE_WINDOW_PIXEL_SIZE, FGE_WINDOW_PIXEL_SIZE}};
146
147 fge::RectFloat g_windowMoveRect;
148 fge::RectFloat g_windowMinimizeRect;
149 fge::RectFloat g_windowCloseRect;
150 fge::RectFloat g_windowResizeRect;
151
152 mutable fge::ObjSpriteBatches g_spriteBatches;
153 mutable fge::ObjSprite g_spriteResize;
154 mutable fge::ObjSprite g_spriteMinimize;
155 mutable fge::ObjSprite g_spriteClose;
156};
157
158} // namespace fge
159
160#endif //_FGE_C_OBJWINDOW_HPP_INCLUDED
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
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
Definition C_guiElement.hpp:224
A base class for all GUI elements.
Definition C_guiElement.hpp:120
Definition C_objSpriteBatches.hpp:38
Definition C_objSprite.hpp:30
Definition C_objWindow.hpp:42
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 first(fge::Scene &scene) override
Method called when the object is added to a scene for initialization purposes.
void removed(fge::Scene &scene) override
Method called when the object is removed from a scene.
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
void callbackRegister(fge::Event &event, fge::GuiElementHandler *guiElementHandlerPtr) override
Ask the object to register all callbacks it needs to receive events.
char const * getClassName() const override
Get the unique class name of the object.
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
A class that represent a set of tiles that can be used in a TileLayer.
Definition C_tileset.hpp:68
Definition C_guiElement.hpp:45