|
SFML
Simple and Fast Multimedia Library
|
Window that serves as a target for OpenGL rendering. More...
#include <Window.hpp>
Public Member Functions | |
| Window () | |
| Default constructor. | |
| Window (VideoMode mode, const String &title, std::uint32_t style=Style::Default, State state=State::Windowed, const ContextSettings &settings={}) | |
| Construct a new window. | |
| Window (VideoMode mode, const String &title, State state, const ContextSettings &settings={}) | |
| Construct a new window. | |
| Window (WindowHandle handle, const ContextSettings &settings={}) | |
| Construct the window from an existing control. | |
| ~Window () override | |
| Destructor. | |
| Window (const Window &)=delete | |
| Deleted copy constructor. | |
| Window & | operator= (const Window &)=delete |
| Deleted copy assignment. | |
| Window (Window &&) noexcept | |
| Move constructor. | |
| Window & | operator= (Window &&) noexcept |
| Move assignment. | |
| void | create (VideoMode mode, const String &title, std::uint32_t style=Style::Default, State state=State::Windowed) override |
| Create (or recreate) the window. | |
| virtual void | create (VideoMode mode, const String &title, std::uint32_t style, State state, const ContextSettings &settings) |
| Create (or recreate) the window. | |
| void | create (WindowHandle handle) override |
| Create (or recreate) the window from an existing control. | |
| virtual void | create (WindowHandle handle, const ContextSettings &settings) |
| Create (or recreate) the window from an existing control. | |
| void | close () override |
| Close the window and destroy all the attached resources. | |
| const ContextSettings & | getSettings () const |
| Get the settings of the OpenGL context of the window. | |
| void | setVerticalSyncEnabled (bool enabled) |
| Enable or disable vertical synchronization. | |
| void | setFramerateLimit (unsigned int limit) |
| Limit the framerate to a maximum fixed frequency. | |
| bool | setActive (bool active=true) const |
| Activate or deactivate the window as the current target for OpenGL rendering. | |
| void | display () |
| Display on screen what has been rendered to the window so far. | |
| Public Member Functions inherited from sf::WindowBase | |
| WindowBase () | |
| Default constructor. | |
| WindowBase (VideoMode mode, const String &title, std::uint32_t style=Style::Default, State state=State::Windowed) | |
| Construct a new window. | |
| WindowBase (VideoMode mode, const String &title, State state) | |
| Construct a new window. | |
| WindowBase (WindowHandle handle) | |
| Construct the window from an existing control. | |
| virtual | ~WindowBase () |
| Destructor. | |
| WindowBase (const WindowBase &)=delete | |
| Deleted copy constructor. | |
| WindowBase & | operator= (const WindowBase &)=delete |
| Deleted copy assignment. | |
| WindowBase (WindowBase &&) noexcept | |
| Move constructor. | |
| WindowBase & | operator= (WindowBase &&) noexcept |
| Move assignment. | |
| bool | isOpen () const |
| Tell whether or not the window is open. | |
| std::optional< Event > | pollEvent () |
| Pop the next event from the front of the FIFO event queue, if any, and return it. | |
| std::optional< Event > | waitEvent (Time timeout=Time::Zero) |
| Wait for an event and return it. | |
| template<typename... Ts> | |
| void | handleEvents (Ts &&... handlers) |
| Handle all pending events. | |
| Vector2i | getPosition () const |
| Get the position of the window. | |
| void | setPosition (Vector2i position) |
| Change the position of the window on screen. | |
| Vector2u | getSize () const |
| Get the size of the rendering region of the window. | |
| void | setSize (Vector2u size) |
| Change the size of the rendering region of the window. | |
| void | setMinimumSize (const std::optional< Vector2u > &minimumSize) |
| Set the minimum window rendering region size. | |
| void | setMaximumSize (const std::optional< Vector2u > &maximumSize) |
| Set the maximum window rendering region size. | |
| void | setTitle (const String &title) |
| Change the title of the window. | |
| void | setIcon (Vector2u size, const std::uint8_t *pixels) |
| Change the window's icon. | |
| void | setVisible (bool visible) |
| Show or hide the window. | |
| void | setMouseCursorVisible (bool visible) |
| Show or hide the mouse cursor. | |
| void | setMouseCursorGrabbed (bool grabbed) |
| Grab or release the mouse cursor. | |
| void | setMouseCursor (const Cursor &cursor) |
| Set the displayed cursor to a native system cursor. | |
| void | setKeyRepeatEnabled (bool enabled) |
| Enable or disable automatic key-repeat. | |
| void | setJoystickThreshold (float threshold) |
| Change the joystick threshold. | |
| void | requestFocus () |
| Request the current window to be made the active foreground window. | |
| bool | hasFocus () const |
| Check whether the window has the input focus. | |
| WindowHandle | getNativeHandle () const |
| Get the OS-specific handle of the window. | |
| bool | createVulkanSurface (const VkInstance &instance, VkSurfaceKHR &surface, const VkAllocationCallbacks *allocator=nullptr) |
| Create a Vulkan rendering surface. | |
Additional Inherited Members | |
| Protected Member Functions inherited from sf::WindowBase | |
| virtual void | onCreate () |
| Function called after the window has been created. | |
| virtual void | onResize () |
| Function called after the window has been resized. | |
Window that serves as a target for OpenGL rendering.
sf::Window is the main class of the Window module. It defines an OS window that is able to receive an OpenGL rendering.
A sf::Window can create its own new window, or be embedded into an already existing control using the create(handle) function. This can be useful for embedding an OpenGL rendering area into a view which is part of a bigger GUI with existing windows, controls, etc. It can also serve as embedding an OpenGL rendering area into a window created by another (probably richer) GUI library like Qt or wxWidgets.
The sf::Window class provides a simple interface for manipulating the window: move, resize, show/hide, control mouse cursor, etc. It also provides event handling through its pollEvent() and waitEvent() functions.
Note that OpenGL experts can pass their own parameters (antialiasing level, bits for the depth and stencil buffers, etc.) to the OpenGL context attached to the window, with the sf::ContextSettings structure which is passed as an optional argument when creating the window.
On dual-graphics systems consisting of a low-power integrated GPU and a powerful discrete GPU, the driver picks which GPU will run an SFML application. In order to inform the driver that an SFML application can benefit from being run on the more powerful discrete GPU, #SFML_DEFINE_DISCRETE_GPU_PREFERENCE can be placed in a source file that is compiled and linked into the final application. The macro should be placed outside of any scopes in the global namespace.
Usage example:
| sf::Window::Window | ( | ) |
Default constructor.
This constructor doesn't actually create the window, use the other constructors or call create() to do so.
| sf::Window::Window | ( | VideoMode | mode, |
| const String & | title, | ||
| std::uint32_t | style = Style::Default, | ||
| State | state = State::Windowed, | ||
| const ContextSettings & | settings = {} ) |
Construct a new window.
This constructor creates the window with the size and pixel depth defined in mode. An optional style can be passed to customize the look and behavior of the window (borders, title bar, resizable, closable, ...). An optional state can be provided. If state is State::Fullscreen, then mode must be a valid video mode.
The last parameter is an optional structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.
| mode | Video mode to use (defines the width, height and depth of the rendering area of the window) |
| title | Title of the window |
| style | Window style, a bitwise OR combination of sf::Style enumerators |
| state | Window state |
| settings | Additional settings for the underlying OpenGL context |
| sf::Window::Window | ( | VideoMode | mode, |
| const String & | title, | ||
| State | state, | ||
| const ContextSettings & | settings = {} ) |
Construct a new window.
This constructor creates the window with the size and pixel depth defined in mode. If state is State::Fullscreen, then mode must be a valid video mode.
The last parameter is an optional structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.
| mode | Video mode to use (defines the width, height and depth of the rendering area of the window) |
| title | Title of the window |
| state | Window state |
| settings | Additional settings for the underlying OpenGL context |
|
explicit |
Construct the window from an existing control.
Use this constructor if you want to create an OpenGL rendering area into an already existing control.
The second parameter is an optional structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.
| handle | Platform-specific handle of the control |
| settings | Additional settings for the underlying OpenGL context |
|
override |
Destructor.
Closes the window and frees all the resources attached to it.
|
delete |
Deleted copy constructor.
|
noexcept |
Move constructor.
|
overridevirtual |
Close the window and destroy all the attached resources.
After calling this function, the sf::Window instance remains valid and you can call create() to recreate the window. All other functions such as pollEvent() or display() will still work (i.e. you don't have to test isOpen() every time), and will have no effect on closed windows.
Reimplemented from sf::WindowBase.
|
virtual |
Create (or recreate) the window.
If the window was already created, it closes it first. If state is State::Fullscreen, then mode must be a valid video mode.
The last parameter is an optional structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.
| mode | Video mode to use (defines the width, height and depth of the rendering area of the window) |
| title | Title of the window |
| style | Window style, a bitwise OR combination of sf::Style enumerators |
| state | Window state |
| settings | Additional settings for the underlying OpenGL context |
|
overridevirtual |
Create (or recreate) the window.
If the window was already created, it closes it first. If state is State::Fullscreen, then mode must be a valid video mode.
| mode | Video mode to use (defines the width, height and depth of the rendering area of the window) |
| title | Title of the window |
| style | Window style, a bitwise OR combination of sf::Style enumerators |
| state | Window state |
Reimplemented from sf::WindowBase.
|
overridevirtual |
Create (or recreate) the window from an existing control.
Use this function if you want to create an OpenGL rendering area into an already existing control. If the window was already created, it closes it first.
| handle | Platform-specific handle of the control |
Reimplemented from sf::WindowBase.
|
virtual |
Create (or recreate) the window from an existing control.
Use this function if you want to create an OpenGL rendering area into an already existing control. If the window was already created, it closes it first.
The second parameter is an optional structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.
| handle | Platform-specific handle of the control |
| settings | Additional settings for the underlying OpenGL context |
| void sf::Window::display | ( | ) |
Display on screen what has been rendered to the window so far.
This function is typically called after all OpenGL rendering has been done for the current frame, in order to show it on screen.
|
nodiscard |
Get the settings of the OpenGL context of the window.
Note that these settings may be different from what was passed to the constructor or the create() function, if one or more settings were not supported. In this case, SFML chose the closest match.
|
nodiscard |
Activate or deactivate the window as the current target for OpenGL rendering.
A window is active only on the current thread, if you want to make it active on another thread you have to deactivate it on the previous thread first if it was active. Only one window can be active on a thread at a time, thus the window previously active (if any) automatically gets deactivated. This is not to be confused with requestFocus().
| active | True to activate, false to deactivate |
| void sf::Window::setFramerateLimit | ( | unsigned int | limit | ) |
Limit the framerate to a maximum fixed frequency.
If a limit is set, the window will use a small delay after each call to display() to ensure that the current frame lasted long enough to match the framerate limit. SFML will try to match the given limit as much as it can, but since it internally uses sf::sleep, whose precision depends on the underlying OS, the results may be a little imprecise as well (for example, you can get 65 FPS when requesting 60).
| limit | Framerate limit, in frames per seconds (use 0 to disable limit) |
| void sf::Window::setVerticalSyncEnabled | ( | bool | enabled | ) |
Enable or disable vertical synchronization.
Activating vertical synchronization will limit the number of frames displayed to the refresh rate of the monitor. This can avoid some visual artifacts, and limit the framerate to a good value (but not constant across different computers).
Vertical synchronization is disabled by default.
| enabled | True to enable v-sync, false to deactivate it |