Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
DisplayWindow.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_DISPLAY_WINDOW_H_
34#define DVD_DISPLAY_WINDOW_H_
35
37
41
42using SDL_Window = struct SDL_Window;
43
44namespace Divide {
45
46enum class WindowType : U8 {
47 WINDOW = 0,
48 FULLSCREEN = 1,
50 COUNT
51};
52
53enum class CursorStyle : U8 {
54 NONE = 0,
55 ARROW,
57 HAND,
63 COUNT
64};
65
66enum class WindowEvent : U8 {
67 HIDDEN = 0,
68 SHOWN = 1,
69 MINIMIZED = 2,
70 MAXIMIZED = 3,
71 RESTORED = 4,
72 LOST_FOCUS = 5,
73 GAINED_FOCUS = 6,
76 RESIZED = 9,
77 SIZE_CHANGED = 10,
78 MOVED = 11,
79 APP_LOOP = 12,
80 CLOSE_REQUESTED = 13,
81 COUNT
82};
83
84enum class WindowFlags : U16 {
85 VSYNC = toBit(1),
86 HAS_FOCUS = toBit(2),
87 IS_HOVERED = toBit(3),
88 MINIMIZED = toBit(4),
89 MAXIMIZED = toBit(5),
90 HIDDEN = toBit(6),
91 DECORATED = toBit(7),
92 COUNT = 8
93};
94
95class WindowManager;
96class PlatformContext;
97
98struct WindowDescriptor;
99
100enum class ErrorCode : I8;
101
102// Platform specific window
103class DisplayWindow final : public GUIDWrapper,
105 public SDLEventListener {
106public:
107
108 struct UserData
109 {
111 bool _ownsContext{ false };
112 };
113
116 bool _flag = false;
118 const char* _text = nullptr;
120 I32 x = -1, y = -1;
121 I32 id = -1;
122 };
123
125
126 virtual ~DisplayWindow() override;
128
129public:
130 ErrorCode init(U32 windowFlags,
131 WindowType initialType,
132 const WindowDescriptor& descriptor);
133
135
136 [[nodiscard]] inline SDL_Window* getRawWindow() const noexcept;
137
138 [[nodiscard]] I32 currentDisplayIndex() const noexcept;
139
140 [[nodiscard]] inline bool isHovered() const noexcept;
141 [[nodiscard]] inline bool hasFocus() const noexcept;
142
143 [[nodiscard]] inline bool minimized() const noexcept;
144 void minimized(bool state) noexcept;
145
146 [[nodiscard]] inline bool maximized() const noexcept;
147 void maximized(bool state) noexcept;
148
149 [[nodiscard]] inline bool hidden() const noexcept;
150 void hidden(bool state) noexcept;
151
152 [[nodiscard]] inline bool decorated() const noexcept;
153 void decorated(bool state) noexcept;
154
155 [[nodiscard]] inline bool fullscreen() const noexcept;
156
157 inline void changeType(WindowType newType);
158 inline void changeToPreviousType();
159
160 void opacity(U8 opacity) noexcept;
161 [[nodiscard]] inline U8 prevOpacity() const noexcept;
162
164 [[nodiscard]] bool setDimensions(U16 width, U16 height);
165 [[nodiscard]] bool setDimensions(vec2<U16> dimensions);
166
169
170 void bringToFront() const noexcept;
171
172 [[nodiscard]] vec2<U16> getDimensions() const noexcept;
173 [[nodiscard]] vec2<U16> getPreviousDimensions() const noexcept;
174
175 [[nodiscard]] Rect<I32> getBorderSizes() const noexcept;
176 [[nodiscard]] vec2<U16> getDrawableSize() const noexcept;
177 [[nodiscard]] vec2<I32> getPosition(bool global = false, bool offset = false) const;
178
179 void setPosition(I32 x, I32 y, bool global = false, bool offset = false);
180 inline void setPosition(vec2<I32> position, bool global = false);
181
182 [[nodiscard]] inline const char* title() const noexcept;
183 template<typename... Args>
184 void title(const char* format, Args&& ...args) noexcept;
185
186 [[nodiscard]] WindowHandle handle() const noexcept;
187
188 inline void addEventListener(WindowEvent windowEvent, const EventListener& listener);
189 inline void clearEventListeners(WindowEvent windowEvent);
190
191 void notifyListeners(WindowEvent event, const WindowEventArgs& args);
192
193 inline void destroyCbk(const DELEGATE<void>& destroyCbk);
194
195 [[nodiscard]] inline Rect<I32> windowViewport() const noexcept;
196
197 [[nodiscard]] inline const Rect<I32>& renderingViewport() const noexcept;
198 void renderingViewport(const Rect<I32>& viewport) noexcept;
199
200 [[nodiscard]] bool grabState() const noexcept;
201 void grabState(bool state) const noexcept;
202
203 [[nodiscard]] bool onSDLEvent(SDL_Event event) override;
204
205
206 [[nodiscard]] GFX::CommandBufferQueue& getCurrentCommandBufferQueue();
207
209 PROPERTY_R(U32, initialDisplay, 0u);
210 PROPERTY_R(U32, flags, 0u);
213 PROPERTY_R(Uint32, windowID, 0u);
215 POINTER_R(DisplayWindow, parentWindow, nullptr);
216
217private:
218 void restore() noexcept;
221 void handleChangeWindowType(WindowType newWindowType);
222 void updateDrawableSize() noexcept;
223
224private:
230
233
236
239
240 std::array<GFX::CommandBufferQueue, Config::MAX_FRAMES_IN_FLIGHT> _commandBufferQueues;
242 bool _internalMoveEvent = false;
244
246
247}; //DisplayWindow
248
249}; //namespace Divide
250
251#include "DisplayWindow.inl"
252
253#endif //DVD_DISPLAY_WINDOW_H_
SDL_Window SDL_Window
Definition: DisplayWindow.h:42
#define PROPERTY_RW(...)
Convenience method to add a class member with public read access and write access.
#define PROPERTY_R(...)
Convenience method to add a class member with public read access but protected write access.
#define POINTER_R(...)
Convenience method to add a class member with public read access but protected write access.
bool hasFocus() const noexcept
vec2< I32 > getPosition(bool global=false, bool offset=false) const
void bringToFront() const noexcept
vec2< U16 > getDrawableSize() const noexcept
bool _internalMoveEvent
Did we generate the window move event?
void updateDrawableSize() noexcept
void handleChangeWindowType(WindowType newWindowType)
bool hidden() const noexcept
bool maximized() const noexcept
bool minimized() const noexcept
WindowHandle handle() const noexcept
virtual ~DisplayWindow() override
std::array< GFX::CommandBufferQueue, Config::MAX_FRAMES_IN_FLIGHT > _commandBufferQueues
SDL_Window * _sdlWindow
Rect< I32 > windowViewport() const noexcept
void clearEventListeners(WindowEvent windowEvent)
GFX::CommandBufferQueue & getCurrentCommandBufferQueue()
bool onSDLEvent(SDL_Event event) override
vector< DELEGATE< bool, WindowEventArgs > > EventListeners
std::array< EventListeners, to_base(WindowEvent::COUNT)> _eventListeners
const Rect< I32 > & renderingViewport() const noexcept
bool isHovered() const noexcept
bool decorated() const noexcept
void centerWindowPosition()
Centering is also easier via SDL.
Rect< I32 > _renderingViewport
vec2< U16 > _prevDimensions
void setPosition(I32 x, I32 y, bool global=false, bool offset=false)
Window positioning is handled by SDL.
void restore() noexcept
DELEGATE< void > _destroyCbk
bool setDimensions(U16 width, U16 height)
width and height get adjusted to the closest supported value
bool fullscreen() const noexcept
vec2< U16 > _drawableSize
const char * title() const noexcept
WindowManager & _parent
void destroyCbk(const DELEGATE< void > &destroyCbk)
U8 prevOpacity() const noexcept
I32 currentDisplayIndex() const noexcept
vec2< U16 > getDimensions() const noexcept
SDL_Window * getRawWindow() const noexcept
void opacity(U8 opacity) noexcept
Rect< I32 > getBorderSizes() const noexcept
void changeType(WindowType newType)
DELEGATE< bool, const WindowEventArgs & > EventListener
void notifyListeners(WindowEvent event, const WindowEventArgs &args)
bool grabState() const noexcept
void addEventListener(WindowEvent windowEvent, const EventListener &listener)
ErrorCode init(U32 windowFlags, WindowType initialType, const WindowDescriptor &descriptor)
vec2< U16 > getPreviousDimensions() const noexcept
static I64 s_cursorWindowGUID
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
PlatformContext & context() noexcept
void * SDL_GLContext
Definition: glResources.h:39
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
DELEGATE_STD< Ret, Args... > DELEGATE
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
Project & parent
Definition: DefaultScene.h:41
uint16_t U16
constexpr U8 U8_MAX
int64_t I64
uint32_t U32
constexpr T toBit(const T X)
Converts an arbitrary positive integer value to a bitwise value used for masks.
constexpr auto to_base(const Type value) -> Type