-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
window.hpp
192 lines (156 loc) · 4.88 KB
/
window.hpp
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
Copyright (C) 2014 - 2017 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
/**
* @file
* Contains a wrapper class for the @ref SDL_Window class.
*/
#include <SDL_video.h>
#include <string>
class surface;
struct SDL_Renderer;
namespace sdl
{
/**
* The wrapper class for the @ref SDL_Window class.
*
* At the moment of writing it is not certain yet how many windows will be
* created. At least one as main window, but maybe the GUI dialogs will have
* their own window. Once that is known it might be a good idea to evaluate
* whether the class should become a singleton or not.
*
* The class also wraps several functions operating on @ref SDL_Window objects.
* For functions not wrapped the class offers an implicit conversion operator
* to a pointer to the @ref SDL_Window object it owns.
*/
class window
{
public:
window(const window&) = delete;
window& operator=(const window&) = delete;
/***** ***** ***** Constructor and destructor. ***** ***** *****/
/**
* Constructor.
*
* The function calls @ref SDL_CreateWindow and @ref SDL_CreateRenderer.
*
* @param title Used as title for @ref SDL_CreateWindow.
* @param x Used as x for @ref SDL_CreateWindow.
* @param y Used as y for @ref SDL_CreateWindow.
* @param w Used as w for @ref SDL_CreateWindow.
* @param h Used as x for @ref SDL_CreateWindow.
* @param window_flags Used as flags for @ref SDL_CreateWindow.
* @param render_flags Used as flags for @ref SDL_CreateRenderer.
*/
window(const std::string& title,
const int x,
const int y,
const int w,
const int h,
const Uint32 window_flags,
const Uint32 render_flags);
~window();
/***** ***** ***** Operations. ***** ***** *****/
/**
* Wrapper for @ref SDL_SetWindowSize.
*
* @param w Used as w for @ref SDL_SetWindowSize.
* @param h Used as x for @ref SDL_SetWindowSize.
*/
void set_size(const int w, const int h);
/**
* Gets the window's size, in screen coordinates.
*
* For the most part, this seems to return the same result as @ref get_output_size. However,
* SDL indicates for high DPI displays these two functions could differ. I could not observe
* any change in behavior with DPI virtualization on or off, but to be safe, I'm keeping the
* two functions seperate and using this for matters of window resolution.
*
* - vultraz, 6/27/2017
*/
SDL_Point get_size();
/** Gets the window's renderer output size, in pixels */
SDL_Point get_output_size();
/**
* Dummy function for centering the window.
*/
void center();
/**
* Dummy function for maximizing the window.
*/
void maximize();
/**
* Dummy function for restoring the window.
*/
void restore();
/**
* Dummy function for returning the window to windowed mode.
*/
void to_window();
/**
* Dummy function for setting the window to fullscreen mode.
*/
void full_screen();
/**
* Clears the contents of the window with a given color.
*
* @param r Red value of the color.
* @param g Green value of the color.
* @param b Blue value of the color.
*/
void fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 0);
/** Renders the contents of the window. */
void render();
/**
* Sets the title of the window.
*
* This is a wrapper for @ref SDL_SetWindowTitle.
*
* @param title The new title for the window.
*/
void set_title(const std::string& title);
/**
* Sets the icon of the window.
*
* This is a wrapper for @ref SDL_SetWindowIcon.
*
* @note The @p icon is a @ref SDL_Surface and not a @ref SDL_Texture, this
* is part of the SDL 2 API.
*
* @param icon The new icon for the window.
*/
void set_icon(const surface& icon);
int get_flags();
/**
* Set mimimum size of the window.
*
* This is a wrapper for @ref SDL_SetWindowMinimumWindowSize.
*/
void set_minimum_size(int min_w, int min_h);
int get_display_index();
/***** ***** ***** Conversion operators. ***** ***** *****/
/**
* Conversion operator to a SDL_Window*.
*/
operator SDL_Window*();
/**
* Conversion operator to a SDL_Renderer*.
*/
operator SDL_Renderer*();
private:
/***** ***** ***** Members. ***** ***** *****/
/** The @ref SDL_Window we own. */
SDL_Window* window_;
/** The preferred pixel format for the renderer. */
Uint32 pixel_format_;
};
} // namespace sdl