-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathSDLRenderingWindow.h
161 lines (123 loc) · 4.96 KB
/
SDLRenderingWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#pragma once
#include "notifications/UpdateWindowTitleNotification.h"
#include <SDL2/SDL.h>
#include <Poco/Logger.h>
#include <Poco/NObserver.h>
#include <Poco/Util/Subsystem.h>
#include <Poco/Util/AbstractConfiguration.h>
struct projectm;
class SDLRenderingWindow : public Poco::Util::Subsystem
{
public:
const char* name() const override;
void initialize(Poco::Util::Application& app) override;
void uninitialize() override;
/**
* @brief Retrieves the current drawable size of the rendering window.
*
* This is the actual canvas size for use with OpenGL. Might be less than the actual window size,
* as the OS might apply DPI scaling and subtract window decorations etc. from the window dimensions.
*
* @param width[out] A reference to a variable that will receive the canvas width.
* @param height[out] A reference to a variable that will receive the canvas height.
*/
void GetDrawableSize(int& width, int& height) const;
/**
* Swaps the OpenGL front- and back buffers.
*/
void Swap() const;
/**
* @brief Toggles the window's fullscreen mode.
*
* There is a caveat on macOS: If the user toggles fullscreen mode via the green system button in the title
* bar, SDL will not notice it and keep the last known state. Thus, the user would have to toggle it twice
* via the hotkey to see an effect.
*/
void ToggleFullscreen();
/**
* @brief Enters fullscreen mode.
*/
void Fullscreen();
/**
* @brief Leaves fullscreen mode and returns to windows mode.
*/
void Windowed();
/**
* @brief Sets the visibility of the mouse cursor
* @param visible true if the cursor should be displayed, false otherwise.
*/
void ShowCursor(bool visible);
/**
* @brief Moves the current window to the next display.
*
* Internally, this is done by finding the current display using the X/Y coords, then move it to the next
* index (or the first if the window was on the last display). If only one display is available, no changes
* are made.
*/
void NextDisplay();
/**
* @brief Returns the ID of the current display the window is shown on.
* @return
*/
int GetCurrentDisplay();
/**
* @brief Returns the dimensions of the window.
* @param [out] width The width of the window.
* @param [out] height The height of the window.
*/
void GetWindowSize(int& width, int& height);
/**
* @brief Returns the position of the window.
* @param [out] left The left position of the window.
* @param [out] top Top top position of the window.
* @param [in] relative If true, returns the position relative to the current display.
*/
void GetWindowPosition(int& left, int& top, bool relative = false);
SDL_Window* GetRenderingWindow() const;
SDL_GLContext GetGlContext() const;
protected:
/**
* Creates the SDL rendering window and an OpenGL rendering context.
*/
void CreateSDLWindow();
/**
* Closes and destroys the rendering window and the associated rendering context.
*/
void DestroySDLWindow();
/**
* Prints OpenGL debug information.
*/
void DumpOpenGLInfo();
/**
* @brief Receives notifications requesting an update of the window title.
* @param notification The update notification.
*/
void UpdateWindowTitleNotificationHandler(const Poco::AutoPtr<UpdateWindowTitleNotification>& notification);
/**
* @brief Updates the window title.
*/
void UpdateWindowTitle();
/**
* @brief Updates the swap interval from the user settings.
*/
void UpdateSwapInterval();
/**
* @brief Event callback if a configuration value has changed.
* @param property The key and value that has been changed.
*/
void OnConfigurationPropertyChanged(const Poco::Util::AbstractConfiguration::KeyValue& property);
/**
* @brief Event callback if a configuration value has been removed.
* @param key The key of the removed property.
*/
void OnConfigurationPropertyRemoved(const std::string& key);
Poco::AutoPtr<Poco::Util::AbstractConfiguration> _userConfig; //!< View of the "projectM" configuration subkey in the "user" configuration.
Poco::AutoPtr<Poco::Util::AbstractConfiguration> _config; //!< View of the "window" configuration subkey.
SDL_Window* _renderingWindow{ nullptr }; //!< Pointer to the SDL window used for rendering.
SDL_GLContext _glContext{ nullptr }; //!< Pointer to the OpenGL context associated with the window.
Poco::NObserver<SDLRenderingWindow, UpdateWindowTitleNotification> _updateWindowTitleObserver{*this, &SDLRenderingWindow::UpdateWindowTitleNotificationHandler}; //!< the observer for title update notifications
Poco::Logger& _logger{ Poco::Logger::get("SDLRenderingWindow") }; //!< The class logger.
int _lastWindowWidth{ 0 };
int _lastWindowHeight{ 0 };
bool _fullscreen{ false };
};