Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
WindowManager.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_CORE_WINDOW_MANAGER_H_
34#define DVD_CORE_WINDOW_MANAGER_H_
35
38
39namespace Divide {
40
41enum class WindowMode : U8
42{
43 WINDOWED = 0,
46};
47
48enum class RenderAPI : U8;
49class PlatformContext;
50struct WindowDescriptor;
51struct SizeChangeParams;
52
54public:
55 struct MonitorData {
58 F32 dpi{0.f};
59 };
60
61public:
62 WindowManager() noexcept;
64
65 void hideAll() noexcept;
66
67 DisplayWindow* createWindow(const WindowDescriptor& descriptor, ErrorCode& err);
68 bool destroyWindow(DisplayWindow*& window);
69
70 void drawToWindow( DisplayWindow& window );
71 void flushWindow();
72
73 void toggleFullScreen() const;
74 void increaseResolution();
75 void decreaseResolution();
76 void stepResolution( bool increment );
77
78 bool setCursorPosition(I32 x, I32 y) noexcept;
79 void snapCursorToCenter();
80
81 static bool SetGlobalCursorPosition(I32 x, I32 y) noexcept;
82 static vec2<I32> GetCursorPosition() noexcept;
83 static vec2<I32> GetGlobalCursorPosition() noexcept;
84 static U32 GetMouseState(vec2<I32>& pos, bool global) noexcept;
85 static void SetCaptureMouse(bool state) noexcept;
86
87 //Returns null if no window is currently focused
88 inline DisplayWindow* getFocusedWindow() noexcept;
89 [[nodiscard]] inline const DisplayWindow* getFocusedWindow() const noexcept;
90
91 //Returns null if no window is currently hovered
92 inline DisplayWindow* getHoveredWindow() noexcept;
93 [[nodiscard]] inline const DisplayWindow* getHoveredWindow() const noexcept;
94
95 inline DisplayWindow& getWindow(I64 guid);
96 [[nodiscard]] inline const DisplayWindow& getWindow(I64 guid) const;
97
98 inline DisplayWindow& getWindow(U32 index);
99 [[nodiscard]] inline const DisplayWindow& getWindow(U32 index) const;
100
101 inline DisplayWindow* getWindowByID(U32 ID) noexcept;
102 [[nodiscard]] inline const DisplayWindow* getWindowByID(U32 ID) const noexcept;
103
104 [[nodiscard]] inline const vector<MonitorData>& monitorData() const noexcept;
105
106 static vec2<U16> GetFullscreenResolution() noexcept;
107
108 static void CaptureMouse(bool state) noexcept;
109
110 static void SetCursorStyle(CursorStyle style);
111
112 static void ToggleRelativeMouseMode(bool state) noexcept;
113 static bool IsRelativeMouseMode() noexcept;
114
115 [[nodiscard]] DisplayWindow* activeWindow() const noexcept;
117 size_t pushActiveWindow( DisplayWindow* window );
119 size_t popActiveWindow();
120
121 POINTER_R(DisplayWindow, mainWindow, nullptr);
122
123protected:
124 friend class Application;
125
126 // Can be called at startup directly
128 RenderAPI renderingAPI,
129 vec2<I16> initialPosition,
130 vec2<U16> initialSize,
131 WindowMode windowMode,
132 I32 targetDisplayIndex);
133
134 void close();
135
136protected:
137 friend class DisplayWindow;
138 [[nodiscard]] static ErrorCode ConfigureAPISettings( const PlatformContext& context, const WindowDescriptor& descriptor );
139 [[nodiscard]] static ErrorCode ApplyAPISettings( const PlatformContext& context, RenderAPI api, DisplayWindow* targetWindow, DisplayWindow* activeWindow );
140 static void DestroyAPISettings(DisplayWindow* window) noexcept;
141
142protected:
144 std::pair<vec2<U16>, bool> _resolutionChangeQueued;
148 static SDL_DisplayMode s_mainDisplayMode;
149 static std::array<SDL_Cursor*, to_base(CursorStyle::COUNT)> s_cursors;
150 eastl::stack<DisplayWindow*> _activeWindows;
151};
152
154{
155 enum class Flags : U16
156 {
157 FULLSCREEN = toBit( 1 ),
159 DECORATED = toBit( 3 ),
160 RESIZEABLE = toBit( 4 ),
161 HIDDEN = toBit( 5 ),
162 ALLOW_HIGH_DPI = toBit( 6 ),
163 ALWAYS_ON_TOP = toBit( 7 ),
164 VSYNC = toBit( 8 ),
166 };
167
168 string title = "";
177 bool externalClose{ false };
178 bool startMaximized{ false };
179};
180
181
183{
187 U16 width{ 0u };
188 U16 height{ 0u };
190 bool isFullScreen{ false };
191 bool isMainWindow{ false };
192};
193
194} //namespace Divide
195#endif //DVD_CORE_WINDOW_MANAGER_H_
196
197#include "WindowManager.inl"
#define POINTER_R(...)
Convenience method to add a class member with public read access but protected write access.
Class that provides an interface between our framework and the OS (start/stop, display support,...
Definition: Application.h:97
void toggleFullScreen() const
static bool IsRelativeMouseMode() noexcept
static void CaptureMouse(bool state) noexcept
static vec2< U16 > GetFullscreenResolution() noexcept
DisplayWindow * activeWindow() const noexcept
static U32 GetMouseState(vec2< I32 > &pos, bool global) noexcept
DisplayWindow * getFocusedWindow() noexcept
static void DestroyAPISettings(DisplayWindow *window) noexcept
static ErrorCode ConfigureAPISettings(const PlatformContext &context, const WindowDescriptor &descriptor)
vector< std::unique_ptr< DisplayWindow > > _windows
vector< MonitorData > _monitors
static void ToggleRelativeMouseMode(bool state) noexcept
void stepResolution(bool increment)
static void SetCaptureMouse(bool state) noexcept
static vec2< I32 > GetGlobalCursorPosition() noexcept
size_t pushActiveWindow(DisplayWindow *window)
Returns the total number of active windows after the push.
static vec2< I32 > GetCursorPosition() noexcept
DisplayWindow * getWindowByID(U32 ID) noexcept
PlatformContext * _context
DisplayWindow * createWindow(const WindowDescriptor &descriptor, ErrorCode &err)
const vector< MonitorData > & monitorData() const noexcept
static ErrorCode ApplyAPISettings(const PlatformContext &context, RenderAPI api, DisplayWindow *targetWindow, DisplayWindow *activeWindow)
ErrorCode init(PlatformContext &context, RenderAPI renderingAPI, vec2< I16 > initialPosition, vec2< U16 > initialSize, WindowMode windowMode, I32 targetDisplayIndex)
static void SetCursorStyle(CursorStyle style)
eastl::stack< DisplayWindow * > _activeWindows
size_t popActiveWindow()
Returns the remaining number of windows after the pop.
bool destroyWindow(DisplayWindow *&window)
static SDL_DisplayMode s_mainDisplayMode
static bool SetGlobalCursorPosition(I32 x, I32 y) noexcept
void hideAll() noexcept
DisplayWindow * getHoveredWindow() noexcept
DisplayWindow & getWindow(I64 guid)
bool setCursorPosition(I32 x, I32 y) noexcept
void drawToWindow(DisplayWindow &window)
static std::array< SDL_Cursor *, to_base(CursorStyle::COUNT)> s_cursors
std::pair< vec2< U16 >, bool > _resolutionChangeQueued
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U16 to_U16(const T value)
int32_t I32
uint8_t U8
int16_t I16
eastl::vector< Type > vector
Definition: Vector.h:42
uint16_t U16
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
U16 width
The new width and height.
I64 winGUID
Window GUID.
bool isFullScreen
Is the window that fired the event fullscreen?
DisplayWindow * parentWindow