b06934755739102fc540ac462bf1d344f9b6e466
[TDDC76_proj.git] /
1 ////////////////////////////////////////////////////////////
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
23 ////////////////////////////////////////////////////////////
24
25 #ifndef SFML_RENDERWINDOW_HPP
26 #define SFML_RENDERWINDOW_HPP
27
28 ////////////////////////////////////////////////////////////
29 // Headers
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Graphics/Export.hpp>
32 #include <SFML/Graphics/RenderTarget.hpp>
33 #include <SFML/Graphics/Image.hpp>
34 #include <SFML/Window/Window.hpp>
35 #include <string>
36
37
38 namespace sf
39 {
40 ////////////////////////////////////////////////////////////
41 /// \brief Window that can serve as a target for 2D drawing
42 ///
43 ////////////////////////////////////////////////////////////
44 class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
45 {
46 public :
47
48 ////////////////////////////////////////////////////////////
49 /// \brief Default constructor
50 ///
51 /// This constructor doesn't actually create the window,
52 /// use the other constructors or call "create" to do so.
53 ///
54 ////////////////////////////////////////////////////////////
55 RenderWindow();
56
57 ////////////////////////////////////////////////////////////
58 /// \brief Construct a new window
59 ///
60 /// This constructor creates the window with the size and pixel
61 /// depth defined in \a mode. An optional style can be passed to
62 /// customize the look and behaviour of the window (borders,
63 /// title bar, resizable, closable, ...).
64 ///
65 /// The fourth parameter is an optional structure specifying
66 /// advanced OpenGL context settings such as antialiasing,
67 /// depth-buffer bits, etc. You shouldn't care about these
68 /// parameters for a regular usage of the graphics module.
69 ///
70 /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
71 /// \param title Title of the window
72 /// \param style Window style
73 /// \param settings Additional settings for the underlying OpenGL context
74 ///
75 ////////////////////////////////////////////////////////////
76 RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
77
78 ////////////////////////////////////////////////////////////
79 /// \brief Construct the window from an existing control
80 ///
81 /// Use this constructor if you want to create an SFML
82 /// rendering area into an already existing control.
83 ///
84 /// The fourth parameter is an optional structure specifying
85 /// advanced OpenGL context settings such as antialiasing,
86 /// depth-buffer bits, etc. You shouldn't care about these
87 /// parameters for a regular usage of the graphics module.
88 ///
89 /// \param handle Platform-specific handle of the control
90 /// \param settings Additional settings for the underlying OpenGL context
91 ///
92 ////////////////////////////////////////////////////////////
93 explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings());
94
95 ////////////////////////////////////////////////////////////
96 /// \brief Destructor
97 ///
98 /// Closes the window and free all the resources attached to it.
99 ///
100 ////////////////////////////////////////////////////////////
101 virtual ~RenderWindow();
102
103 ////////////////////////////////////////////////////////////
104 /// \brief Get the size of the rendering region of the window
105 ///
106 /// The size doesn't include the titlebar and borders
107 /// of the window.
108 ///
109 /// \return Size in pixels
110 ///
111 ////////////////////////////////////////////////////////////
112 virtual Vector2u getSize() const;
113
114 ////////////////////////////////////////////////////////////
115 /// \brief Copy the current contents of the window to an image
116 ///
117 /// This is a slow operation, whose main purpose is to make
118 /// screenshots of the application. If you want to update an
119 /// image with the contents of the window and then use it for
120 /// drawing, you should rather use a sf::Texture and its
121 /// update(Window&) function.
122 /// You can also draw things directly to a texture with the
123 /// sf::RenderTexture class.
124 ///
125 /// \return Image containing the captured contents
126 ///
127 ////////////////////////////////////////////////////////////
128 Image capture() const;
129
130 protected:
131
132 ////////////////////////////////////////////////////////////
133 /// \brief Function called after the window has been created
134 ///
135 /// This function is called so that derived classes can
136 /// perform their own specific initialization as soon as
137 /// the window is created.
138 ///
139 ////////////////////////////////////////////////////////////
140 virtual void onCreate();
141
142 ////////////////////////////////////////////////////////////
143 /// \brief Function called after the window has been resized
144 ///
145 /// This function is called so that derived classes can
146 /// perform custom actions when the size of the window changes.
147 ///
148 ////////////////////////////////////////////////////////////
149 virtual void onResize();
150
151 private :
152
153 ////////////////////////////////////////////////////////////
154 /// \brief Activate the target for rendering
155 ///
156 /// \param active True to make the target active, false to deactivate it
157 ///
158 /// \return True if the function succeeded
159 ///
160 ////////////////////////////////////////////////////////////
161 virtual bool activate(bool active);
162 };
163
164 } // namespace sf
165
166
167 #endif // SFML_RENDERWINDOW_HPP
168
169
170 ////////////////////////////////////////////////////////////
171 /// \class sf::RenderWindow
172 /// \ingroup graphics
173 ///
174 /// sf::RenderWindow is the main class of the Graphics module.
175 /// It defines an OS window that can be painted using the other
176 /// classes of the graphics module.
177 ///
178 /// sf::RenderWindow is derived from sf::Window, thus it inherits
179 /// all its features: events, window management, OpenGL rendering,
180 /// etc. See the documentation of sf::Window for a more complete
181 /// description of all these features, as well as code examples.
182 ///
183 /// On top of that, sf::RenderWindow adds more features related to
184 /// 2D drawing with the graphics module (see its base class
185 /// sf::RenderTarget for more details).
186 /// Here is a typical rendering and event loop with a sf::RenderWindow:
187 ///
188 /// \code
189 /// // Declare and create a new render-window
190 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
191 ///
192 /// // Limit the framerate to 60 frames per second (this step is optional)
193 /// window.setFramerateLimit(60);
194 ///
195 /// // The main loop - ends as soon as the window is closed
196 /// while (window.isOpen())
197 /// {
198 /// // Event processing
199 /// sf::Event event;
200 /// while (window.pollEvent(event))
201 /// {
202 /// // Request for closing the window
203 /// if (event.type == sf::Event::Closed)
204 /// window.close();
205 /// }
206 ///
207 /// // Clear the whole window before rendering a new frame
208 /// window.clear();
209 ///
210 /// // Draw some graphical entities
211 /// window.draw(sprite);
212 /// window.draw(circle);
213 /// window.draw(text);
214 ///
215 /// // End the current frame and display its contents on screen
216 /// window.display();
217 /// }
218 /// \endcode
219 ///
220 /// Like sf::Window, sf::RenderWindow is still able to render direct
221 /// OpenGL stuff. It is even possible to mix together OpenGL calls
222 /// and regular SFML drawing commands.
223 ///
224 /// \code
225 /// // Create the render window
226 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
227 ///
228 /// // Create a sprite and a text to display
229 /// sf::Sprite sprite;
230 /// sf::Text text;
231 /// ...
232 ///
233 /// // Perform OpenGL initializations
234 /// glMatrixMode(GL_PROJECTION);
235 /// ...
236 ///
237 /// // Start the rendering loop
238 /// while (window.isOpen())
239 /// {
240 /// // Process events
241 /// ...
242 ///
243 /// // Draw a background sprite
244 /// window.pushGLStates();
245 /// window.draw(sprite);
246 /// window.popGLStates();
247 ///
248 /// // Draw a 3D object using OpenGL
249 /// glBegin(GL_QUADS);
250 /// glVertex3f(...);
251 /// ...
252 /// glEnd();
253 ///
254 /// // Draw text on top of the 3D object
255 /// window.pushGLStates();
256 /// window.draw(text);
257 /// window.popGLStates();
258 ///
259 /// // Finally, display the rendered frame on screen
260 /// window.display();
261 /// }
262 /// \endcode
263 ///
264 /// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View
265 ///
266 ////////////////////////////////////////////////////////////