The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
window.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef SDL_WINDOW_HPP_INCLUDED
16 #define SDL_WINDOW_HPP_INCLUDED
17 
18 /**
19  * @file
20  * Contains a wrapper class for the @ref SDL_Window class.
21  */
22 
23 #include <SDL_version.h>
24 
25 
26 #include "sdl/utils.hpp"
27 
28 #include <boost/noncopyable.hpp>
29 
30 #include <SDL_video.h>
31 
32 #include <string>
33 
34 struct surface;
35 struct SDL_Renderer;
36 
37 namespace sdl
38 {
39 
40 /**
41  * The wrapper class for the @ref SDL_Window class.
42  *
43  * At the moment of writing it is not certain yet how many windows will be
44  * created. At least one as main window, but maybe the GUI dialogues will have
45  * their own window. Once that is known it might be a good idea to evaluate
46  * whether the class should become a singleton or not.
47  *
48  * The class also wraps several functions operating on @ref SDL_Window objects.
49  * For functions not wrapped the class offers an implicit conversion operator
50  * to a pointer to the @ref SDL_Window object it owns.
51  */
52 class twindow : private boost::noncopyable
53 {
54 public:
55  /***** ***** ***** Constructor and destructor. ***** ***** *****/
56 
57  /**
58  * Constructor.
59  *
60  * The function calls @ref SDL_CreateWindow and @ref SDL_CreateRenderer.
61  *
62  * @param title Used as title for @ref SDL_CreateWindow.
63  * @param x Used as x for @ref SDL_CreateWindow.
64  * @param y Used as y for @ref SDL_CreateWindow.
65  * @param w Used as w for @ref SDL_CreateWindow.
66  * @param h Used as x for @ref SDL_CreateWindow.
67  * @param window_flags Used as flags for @ref SDL_CreateWindow.
68  * @param render_flags Used as flags for @ref SDL_CreateRenderer.
69  */
70  twindow(const std::string& title,
71  const int x,
72  const int y,
73  const int w,
74  const int h,
75  const Uint32 window_flags,
76  const Uint32 render_flags);
77 
78  ~twindow();
79 
80 
81  /***** ***** ***** Operations. ***** ***** *****/
82 
83  /**
84  * Wrapper for @ref SDL_SetWindowSize.
85  *
86  * @param w Used as w for @ref SDL_SetWindowSize.
87  * @param h Used as x for @ref SDL_SetWindowSize.
88  */
89  void set_size(const int w, const int h);
90 
91  /**
92  * Dummy function for centering the window.
93  */
94  void center();
95 
96  /**
97  * Dummy function for maximizing the window.
98  */
99  void maximize();
100 
101  /**
102  * Dummy function for restoring the window.
103  */
104  void restore();
105 
106  /**
107  * Dummy function for returning the window to windowed mode.
108  */
109  void to_window();
110 
111  /**
112  * Dummy function for setting the window to fullscreen mode.
113  */
114  void full_screen();
115 
116  /**
117  * Clears the contents of the window with a given color.
118  *
119  * @param r Red value of the color.
120  * @param g Green value of the color.
121  * @param b Blue value of the color.
122  */
123  void fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 0);
124 
125  /** Renders the contents of the window. */
126  void render();
127 
128  /**
129  * Sets the title of the window.
130  *
131  * This is a wrapper for @ref SDL_SetWindowTitle.
132  *
133  * @param title The new title for the window.
134  */
135  void set_title(const std::string& title);
136 
137  /**
138  * Sets the icon of the window.
139  *
140  * This is a wrapper for @ref SDL_SetWindowIcon.
141  *
142  * @note The @p icon is a @ref SDL_Surface and not a @ref SDL_Texture, this
143  * is part of the SDL 2 API.
144  *
145  * @param icon The new icon for the window.
146  */
147  void set_icon(const surface& icon);
148 
149  int get_flags();
150 
151  /**
152  * Set mimimum size of the window.
153  *
154  * This is a wrapper for @ref SDL_SetWindowMinimumWindowSize.
155  */
156  void set_minimum_size(int min_w, int min_h);
157 
158  /***** ***** ***** Conversion operators. ***** ***** *****/
159 
160  /**
161  * Conversion operator to a SDL_Window*.
162  */
163  operator SDL_Window*();
164 
165 
166 private:
167  /**
168  * Conversion operator to a SDL_Renderer*.
169  *
170  * @todo Evaluate whether the function should become public or not.
171  */
172  operator SDL_Renderer*();
173 
174  /***** ***** ***** Members. ***** ***** *****/
175 
176  /** The @ref SDL_Window we own. */
177  SDL_Window* window_;
178 
179  /** The preferred pixel format for the renderer. */
181 };
182 
183 } // namespace sdl
184 
185 
186 #endif
void restore()
Dummy function for restoring the window.
Definition: window.cpp:89
void set_size(const int w, const int h)
Wrapper for SDL_SetWindowSize.
Definition: window.cpp:69
void full_screen()
Dummy function for setting the window to fullscreen mode.
Definition: window.cpp:94
GLboolean GLboolean g
Definition: glew.h:7319
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
void render()
Renders the contents of the window.
Definition: window.cpp:108
The wrapper class for the SDL_Window class.
Definition: window.hpp:52
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
void set_icon(const surface &icon)
Sets the icon of the window.
Definition: window.cpp:118
void fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a=0)
Clears the contents of the window with a given color.
Definition: window.cpp:99
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
SDL_Window * window_
The SDL_Window we own.
Definition: window.hpp:177
void set_minimum_size(int min_w, int min_h)
Set mimimum size of the window.
Definition: window.cpp:128
void to_window()
Dummy function for returning the window to windowed mode.
Definition: window.cpp:84
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
int get_flags()
Definition: window.cpp:123
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
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)
Constructor.
Definition: window.cpp:26
void set_title(const std::string &title)
Sets the title of the window.
Definition: window.cpp:113
void maximize()
Dummy function for maximizing the window.
Definition: window.cpp:79
void center()
Dummy function for centering the window.
Definition: window.cpp:74
Uint32 pixel_format_
The preferred pixel format for the renderer.
Definition: window.hpp:180
GLsizei const GLcharARB ** string
Definition: glew.h:4503