|
|
|||
File indexing completed on 2026-06-02 08:58:15
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_WINDOW_HPP 0026 #define SFML_WINDOW_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Window/ContextSettings.hpp> 0032 #include <SFML/Window/GlResource.hpp> 0033 #include <SFML/Window/WindowBase.hpp> 0034 0035 0036 namespace sf 0037 { 0038 namespace priv 0039 { 0040 class GlContext; 0041 } 0042 0043 class Event; 0044 0045 //////////////////////////////////////////////////////////// 0046 /// \brief Window that serves as a target for OpenGL rendering 0047 /// 0048 //////////////////////////////////////////////////////////// 0049 class SFML_WINDOW_API Window : public WindowBase, GlResource 0050 { 0051 public: 0052 0053 //////////////////////////////////////////////////////////// 0054 /// \brief Default constructor 0055 /// 0056 /// This constructor doesn't actually create the window, 0057 /// use the other constructors or call create() to do so. 0058 /// 0059 //////////////////////////////////////////////////////////// 0060 Window(); 0061 0062 //////////////////////////////////////////////////////////// 0063 /// \brief Construct a new window 0064 /// 0065 /// This constructor creates the window with the size and pixel 0066 /// depth defined in \a mode. An optional style can be passed to 0067 /// customize the look and behavior of the window (borders, 0068 /// title bar, resizable, closable, ...). If \a style contains 0069 /// Style::Fullscreen, then \a mode must be a valid video mode. 0070 /// 0071 /// The fourth parameter is an optional structure specifying 0072 /// advanced OpenGL context settings such as antialiasing, 0073 /// depth-buffer bits, etc. 0074 /// 0075 /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) 0076 /// \param title Title of the window 0077 /// \param style %Window style, a bitwise OR combination of sf::Style enumerators 0078 /// \param settings Additional settings for the underlying OpenGL context 0079 /// 0080 //////////////////////////////////////////////////////////// 0081 Window(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); 0082 0083 //////////////////////////////////////////////////////////// 0084 /// \brief Construct the window from an existing control 0085 /// 0086 /// Use this constructor if you want to create an OpenGL 0087 /// rendering area into an already existing control. 0088 /// 0089 /// The second parameter is an optional structure specifying 0090 /// advanced OpenGL context settings such as antialiasing, 0091 /// depth-buffer bits, etc. 0092 /// 0093 /// \param handle Platform-specific handle of the control 0094 /// \param settings Additional settings for the underlying OpenGL context 0095 /// 0096 //////////////////////////////////////////////////////////// 0097 explicit Window(WindowHandle handle, const ContextSettings& settings = ContextSettings()); 0098 0099 //////////////////////////////////////////////////////////// 0100 /// \brief Destructor 0101 /// 0102 /// Closes the window and frees all the resources attached to it. 0103 /// 0104 //////////////////////////////////////////////////////////// 0105 virtual ~Window(); 0106 0107 //////////////////////////////////////////////////////////// 0108 /// \brief Create (or recreate) the window 0109 /// 0110 /// If the window was already created, it closes it first. 0111 /// If \a style contains Style::Fullscreen, then \a mode 0112 /// must be a valid video mode. 0113 /// 0114 /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) 0115 /// \param title Title of the window 0116 /// \param style %Window style, a bitwise OR combination of sf::Style enumerators 0117 /// 0118 //////////////////////////////////////////////////////////// 0119 virtual void create(VideoMode mode, const String& title, Uint32 style = Style::Default); 0120 0121 //////////////////////////////////////////////////////////// 0122 /// \brief Create (or recreate) the window 0123 /// 0124 /// If the window was already created, it closes it first. 0125 /// If \a style contains Style::Fullscreen, then \a mode 0126 /// must be a valid video mode. 0127 /// 0128 /// The fourth parameter is an optional structure specifying 0129 /// advanced OpenGL context settings such as antialiasing, 0130 /// depth-buffer bits, etc. 0131 /// 0132 /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) 0133 /// \param title Title of the window 0134 /// \param style %Window style, a bitwise OR combination of sf::Style enumerators 0135 /// \param settings Additional settings for the underlying OpenGL context 0136 /// 0137 //////////////////////////////////////////////////////////// 0138 virtual void create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings); 0139 0140 //////////////////////////////////////////////////////////// 0141 /// \brief Create (or recreate) the window from an existing control 0142 /// 0143 /// Use this function if you want to create an OpenGL 0144 /// rendering area into an already existing control. 0145 /// If the window was already created, it closes it first. 0146 /// 0147 /// \param handle Platform-specific handle of the control 0148 /// 0149 //////////////////////////////////////////////////////////// 0150 virtual void create(WindowHandle handle); 0151 0152 //////////////////////////////////////////////////////////// 0153 /// \brief Create (or recreate) the window from an existing control 0154 /// 0155 /// Use this function if you want to create an OpenGL 0156 /// rendering area into an already existing control. 0157 /// If the window was already created, it closes it first. 0158 /// 0159 /// The second parameter is an optional structure specifying 0160 /// advanced OpenGL context settings such as antialiasing, 0161 /// depth-buffer bits, etc. 0162 /// 0163 /// \param handle Platform-specific handle of the control 0164 /// \param settings Additional settings for the underlying OpenGL context 0165 /// 0166 //////////////////////////////////////////////////////////// 0167 virtual void create(WindowHandle handle, const ContextSettings& settings); 0168 0169 //////////////////////////////////////////////////////////// 0170 /// \brief Close the window and destroy all the attached resources 0171 /// 0172 /// After calling this function, the sf::Window instance remains 0173 /// valid and you can call create() to recreate the window. 0174 /// All other functions such as pollEvent() or display() will 0175 /// still work (i.e. you don't have to test isOpen() every time), 0176 /// and will have no effect on closed windows. 0177 /// 0178 //////////////////////////////////////////////////////////// 0179 virtual void close(); 0180 0181 //////////////////////////////////////////////////////////// 0182 /// \brief Get the settings of the OpenGL context of the window 0183 /// 0184 /// Note that these settings may be different from what was 0185 /// passed to the constructor or the create() function, 0186 /// if one or more settings were not supported. In this case, 0187 /// SFML chose the closest match. 0188 /// 0189 /// \return Structure containing the OpenGL context settings 0190 /// 0191 //////////////////////////////////////////////////////////// 0192 const ContextSettings& getSettings() const; 0193 0194 //////////////////////////////////////////////////////////// 0195 /// \brief Enable or disable vertical synchronization 0196 /// 0197 /// Activating vertical synchronization will limit the number 0198 /// of frames displayed to the refresh rate of the monitor. 0199 /// This can avoid some visual artifacts, and limit the framerate 0200 /// to a good value (but not constant across different computers). 0201 /// 0202 /// Vertical synchronization is disabled by default. 0203 /// 0204 /// \param enabled True to enable v-sync, false to deactivate it 0205 /// 0206 //////////////////////////////////////////////////////////// 0207 void setVerticalSyncEnabled(bool enabled); 0208 0209 //////////////////////////////////////////////////////////// 0210 /// \brief Limit the framerate to a maximum fixed frequency 0211 /// 0212 /// If a limit is set, the window will use a small delay after 0213 /// each call to display() to ensure that the current frame 0214 /// lasted long enough to match the framerate limit. 0215 /// SFML will try to match the given limit as much as it can, 0216 /// but since it internally uses sf::sleep, whose precision 0217 /// depends on the underlying OS, the results may be a little 0218 /// unprecise as well (for example, you can get 65 FPS when 0219 /// requesting 60). 0220 /// 0221 /// \param limit Framerate limit, in frames per seconds (use 0 to disable limit) 0222 /// 0223 //////////////////////////////////////////////////////////// 0224 void setFramerateLimit(unsigned int limit); 0225 0226 //////////////////////////////////////////////////////////// 0227 /// \brief Activate or deactivate the window as the current target 0228 /// for OpenGL rendering 0229 /// 0230 /// A window is active only on the current thread, if you want to 0231 /// make it active on another thread you have to deactivate it 0232 /// on the previous thread first if it was active. 0233 /// Only one window can be active on a thread at a time, thus 0234 /// the window previously active (if any) automatically gets deactivated. 0235 /// This is not to be confused with requestFocus(). 0236 /// 0237 /// \param active True to activate, false to deactivate 0238 /// 0239 /// \return True if operation was successful, false otherwise 0240 /// 0241 //////////////////////////////////////////////////////////// 0242 bool setActive(bool active = true) const; 0243 0244 //////////////////////////////////////////////////////////// 0245 /// \brief Display on screen what has been rendered to the window so far 0246 /// 0247 /// This function is typically called after all OpenGL rendering 0248 /// has been done for the current frame, in order to show 0249 /// it on screen. 0250 /// 0251 //////////////////////////////////////////////////////////// 0252 void display(); 0253 0254 private: 0255 0256 //////////////////////////////////////////////////////////// 0257 /// \brief Processes an event before it is sent to the user 0258 /// 0259 /// This function is called every time an event is received 0260 /// from the internal window (through pollEvent or waitEvent). 0261 /// It filters out unwanted events, and performs whatever internal 0262 /// stuff the window needs before the event is returned to the 0263 /// user. 0264 /// 0265 /// \param event Event to filter 0266 /// 0267 //////////////////////////////////////////////////////////// 0268 bool filterEvent(const Event& event); 0269 0270 //////////////////////////////////////////////////////////// 0271 /// \brief Perform some common internal initializations 0272 /// 0273 //////////////////////////////////////////////////////////// 0274 void initialize(); 0275 0276 //////////////////////////////////////////////////////////// 0277 // Member data 0278 //////////////////////////////////////////////////////////// 0279 priv::GlContext* m_context; //!< Platform-specific implementation of the OpenGL context 0280 Clock m_clock; //!< Clock for measuring the elapsed time between frames 0281 Time m_frameTimeLimit; //!< Current framerate limit 0282 }; 0283 0284 } // namespace sf 0285 0286 0287 #endif // SFML_WINDOW_HPP 0288 0289 0290 //////////////////////////////////////////////////////////// 0291 /// \class sf::Window 0292 /// \ingroup window 0293 /// 0294 /// sf::Window is the main class of the Window module. It defines 0295 /// an OS window that is able to receive an OpenGL rendering. 0296 /// 0297 /// A sf::Window can create its own new window, or be embedded into 0298 /// an already existing control using the create(handle) function. 0299 /// This can be useful for embedding an OpenGL rendering area into 0300 /// a view which is part of a bigger GUI with existing windows, 0301 /// controls, etc. It can also serve as embedding an OpenGL rendering 0302 /// area into a window created by another (probably richer) GUI library 0303 /// like Qt or wxWidgets. 0304 /// 0305 /// The sf::Window class provides a simple interface for manipulating 0306 /// the window: move, resize, show/hide, control mouse cursor, etc. 0307 /// It also provides event handling through its pollEvent() and waitEvent() 0308 /// functions. 0309 /// 0310 /// Note that OpenGL experts can pass their own parameters (antialiasing 0311 /// level, bits for the depth and stencil buffers, etc.) to the 0312 /// OpenGL context attached to the window, with the sf::ContextSettings 0313 /// structure which is passed as an optional argument when creating the 0314 /// window. 0315 /// 0316 /// On dual-graphics systems consisting of a low-power integrated GPU 0317 /// and a powerful discrete GPU, the driver picks which GPU will run an 0318 /// SFML application. In order to inform the driver that an SFML application 0319 /// can benefit from being run on the more powerful discrete GPU, 0320 /// #SFML_DEFINE_DISCRETE_GPU_PREFERENCE can be placed in a source file 0321 /// that is compiled and linked into the final application. The macro 0322 /// should be placed outside of any scopes in the global namespace. 0323 /// 0324 /// Usage example: 0325 /// \code 0326 /// // Declare and create a new window 0327 /// sf::Window window(sf::VideoMode(800, 600), "SFML window"); 0328 /// 0329 /// // Limit the framerate to 60 frames per second (this step is optional) 0330 /// window.setFramerateLimit(60); 0331 /// 0332 /// // The main loop - ends as soon as the window is closed 0333 /// while (window.isOpen()) 0334 /// { 0335 /// // Event processing 0336 /// sf::Event event; 0337 /// while (window.pollEvent(event)) 0338 /// { 0339 /// // Request for closing the window 0340 /// if (event.type == sf::Event::Closed) 0341 /// window.close(); 0342 /// } 0343 /// 0344 /// // Activate the window for OpenGL rendering 0345 /// window.setActive(); 0346 /// 0347 /// // OpenGL drawing commands go here... 0348 /// 0349 /// // End the current frame and display its contents on screen 0350 /// window.display(); 0351 /// } 0352 /// \endcode 0353 /// 0354 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|