-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
window.hpp
207 lines (166 loc) · 5.41 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright (C) 2014 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.
*/
#ifndef SDL_WINDOW_HPP_INCLUDED
#define SDL_WINDOW_HPP_INCLUDED
/**
* @file
* Contains a wrapper class for the @ref SDL_Window class.
*/
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST(2, 0, 0)
#include "sdl_utils.hpp"
#include <boost/noncopyable.hpp>
#include <SDL_video.h>
#include <string>
struct surface;
struct SDL_Renderer;
namespace sdl
{
class ttexture;
/**
* 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 dialogues 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 twindow : private boost::noncopyable
{
public:
/***** ***** ***** 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.
*/
twindow(const std::string& title,
const int x,
const int y,
const int w,
const int h,
const Uint32 window_flags,
const Uint32 render_flags);
~twindow();
/***** ***** ***** 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);
/**
* Dummy function for setting the screen to full screen mode.
*
* @todo Implement this function properly.
*/
void full_screen();
/** Clears the contents of the window. */
void clear();
/** 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);
/**
* Creates a texture for the renderer of this object.
*
* @param access Used as access for @ref SDL_CreateTexture.
* @param w Used as w for @ref SDL_CreateTexture.
* @param h Used as x for @ref SDL_CreateTexture.
*/
ttexture create_texture(const int access, const int w, const int h);
/**
* Creates a texture for the renderer.
*
* This is a helper function forwarded to the constructor of the
* @ref ttexture class.
*
* See @ref texture::ttexture.
*
* @param access Forwarded to @ref texture::ttexture.
* @param source_surface__ Forwarded to @ref texture::ttexture.
*/
ttexture create_texture(const int access, SDL_Surface* source_surface__);
/**
* Creates a texture for the renderer.
*
* This is a helper function forwarded to the constructor of the
* @ref ttexture class.
*
* See @ref texture::ttexture.
*
* @param access Forwarded to @ref texture::ttexture.
* @param surface Forwarded to @ref texture::ttexture.
*/
ttexture create_texture(const int access, const surface& surface);
/***** ***** ***** Draw function overloads. ***** ***** *****/
/**
* Draw a texture on the window's renderer.
*
* The function is forwareded to @ref ttexture::draw.
*
* @param texture The texture whose draw function to call.
* @param x Forwarded to @ref ttexture::draw.
* @param y Forwarded to @ref ttexture::draw.
*/
void draw(ttexture& texture, const int x, const int y);
/***** ***** ***** Conversion operators. ***** ***** *****/
/**
* Conversion operator to a SDL_Window*.
*/
operator SDL_Window*();
private:
/**
* Conversion operator to a SDL_Renderer*.
*
* @todo Evaluate whether the function should become public or not.
*/
operator SDL_Renderer*();
/***** ***** ***** Members. ***** ***** *****/
/** The @ref SDL_Window we own. */
SDL_Window* window_;
/** The preferred pixel format for the renderer. */
Uint32 pixel_format_;
};
} // namespace sdl
#endif
#endif