Window that serves as a base for other windows. More...
#include <SFML/Window/WindowBase.hpp>
Public Member Functions | |
WindowBase () | |
Default constructor. | |
WindowBase (VideoMode mode, const String &title, Uint32 style=Style::Default) | |
Construct a new window. | |
WindowBase (WindowHandle handle) | |
Construct the window from an existing control. | |
virtual | ~WindowBase () |
Destructor. | |
virtual void | create (VideoMode mode, const String &title, Uint32 style=Style::Default) |
Create (or recreate) the window. | |
virtual void | create (WindowHandle handle) |
Create (or recreate) the window from an existing control. | |
virtual void | close () |
Close the window and destroy all the attached resources. | |
bool | isOpen () const |
Tell whether or not the window is open. | |
bool | pollEvent (Event &event) |
Pop the event on top of the event queue, if any, and return it. | |
bool | waitEvent (Event &event) |
Wait for an event and return it. | |
Vector2i | getPosition () const |
Get the position of the window. | |
void | setPosition (const 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 (const Vector2u &size) |
Change the size of the rendering region of the window. | |
void | setTitle (const String &title) |
Change the title of the window. | |
void | setIcon (unsigned int width, unsigned int height, const Uint8 *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 | getSystemHandle () const |
Get the OS-specific handle of the window. | |
bool | createVulkanSurface (const VkInstance &instance, VkSurfaceKHR &surface, const VkAllocationCallbacks *allocator=0) |
Create a Vulkan rendering surface. | |
Protected Member Functions | |
virtual void | onCreate () |
Function called after the window has been created. | |
virtual void | onResize () |
Function called after the window has been resized. | |
Friends | |
class | Window |
Window that serves as a base for other windows.
sf::WindowBase serves as the base class for all Windows.
A sf::WindowBase can create its own new window, or be embedded into an already existing control using the create(handle) function.
The sf::WindowBase 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.
Usage example:
Definition at line 56 of file WindowBase.hpp.
sf::WindowBase::WindowBase | ( | ) |
Default constructor.
This constructor doesn't actually create the window, use the other constructors or call create() to do so.
sf::WindowBase::WindowBase | ( | VideoMode | mode, |
const String & | title, | ||
Uint32 | style = Style::Default ) |
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, ...). If style contains Style::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 |
|
explicit |
Construct the window from an existing control.
handle | Platform-specific handle of the control |
|
virtual |
Destructor.
Closes the window and frees all the resources attached to it.
|
virtual |
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 in sf::Window.
|
virtual |
Create (or recreate) the window.
If the window was already created, it closes it first. If style contains Style::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 |
Reimplemented in sf::Window.
|
virtual |
Create (or recreate) the window from an existing control.
handle | Platform-specific handle of the control |
Reimplemented in sf::Window.
bool sf::WindowBase::createVulkanSurface | ( | const VkInstance & | instance, |
VkSurfaceKHR & | surface, | ||
const VkAllocationCallbacks * | allocator = 0 ) |
Vector2i sf::WindowBase::getPosition | ( | ) | const |
Vector2u sf::WindowBase::getSize | ( | ) | const |
Get the size of the rendering region of the window.
The size doesn't include the titlebar and borders of the window.
WindowHandle sf::WindowBase::getSystemHandle | ( | ) | const |
Get the OS-specific handle of the window.
The type of the returned handle is sf::WindowHandle, which is a typedef to the handle type defined by the OS. You shouldn't need to use this function, unless you have very specific stuff to implement that SFML doesn't support, or implement a temporary workaround until a bug is fixed.
bool sf::WindowBase::hasFocus | ( | ) | const |
Check whether the window has the input focus.
At any given time, only one window may have the input focus to receive input events such as keystrokes or most mouse events.
bool sf::WindowBase::isOpen | ( | ) | const |
Tell whether or not the window is open.
This function returns whether or not the window exists. Note that a hidden window (setVisible(false)) is open (therefore this function would return true).
|
protectedvirtual |
Function called after the window has been created.
This function is called so that derived classes can perform their own specific initialization as soon as the window is created.
Reimplemented in sf::RenderWindow.
|
protectedvirtual |
Function called after the window has been resized.
This function is called so that derived classes can perform custom actions when the size of the window changes.
Reimplemented in sf::RenderWindow.
bool sf::WindowBase::pollEvent | ( | Event & | event | ) |
Pop the event on top of the event queue, if any, and return it.
This function is not blocking: if there's no pending event then it will return false and leave event unmodified. Note that more than one event may be present in the event queue, thus you should always call this function in a loop to make sure that you process every pending event.
event | Event to be returned |
void sf::WindowBase::requestFocus | ( | ) |
Request the current window to be made the active foreground window.
At any given time, only one window may have the input focus to receive input events such as keystrokes or mouse events. If a window requests focus, it only hints to the operating system, that it would like to be focused. The operating system is free to deny the request. This is not to be confused with setActive().
void sf::WindowBase::setIcon | ( | unsigned int | width, |
unsigned int | height, | ||
const Uint8 * | pixels ) |
Change the window's icon.
pixels must be an array of width x height pixels in 32-bits RGBA format.
The OS default icon is used by default.
width | Icon's width, in pixels |
height | Icon's height, in pixels |
pixels | Pointer to the array of pixels in memory. The pixels are copied, so you need not keep the source alive after calling this function. |
void sf::WindowBase::setJoystickThreshold | ( | float | threshold | ) |
Change the joystick threshold.
The joystick threshold is the value below which no JoystickMoved event will be generated.
The threshold value is 0.1 by default.
threshold | New threshold, in the range [0, 100] |
void sf::WindowBase::setKeyRepeatEnabled | ( | bool | enabled | ) |
Enable or disable automatic key-repeat.
If key repeat is enabled, you will receive repeated KeyPressed events while keeping a key pressed. If it is disabled, you will only get a single event when the key is pressed.
Key repeat is enabled by default.
enabled | True to enable, false to disable |
void sf::WindowBase::setMouseCursor | ( | const Cursor & | cursor | ) |
Set the displayed cursor to a native system cursor.
Upon window creation, the arrow cursor is used by default.
cursor | Native system cursor type to display |
void sf::WindowBase::setMouseCursorGrabbed | ( | bool | grabbed | ) |
Grab or release the mouse cursor.
If set, grabs the mouse cursor inside this window's client area so it may no longer be moved outside its bounds. Note that grabbing is only active while the window has focus.
grabbed | True to enable, false to disable |
void sf::WindowBase::setMouseCursorVisible | ( | bool | visible | ) |
Show or hide the mouse cursor.
The mouse cursor is visible by default.
visible | True to show the mouse cursor, false to hide it |
void sf::WindowBase::setPosition | ( | const Vector2i & | position | ) |
Change the position of the window on screen.
This function only works for top-level windows (i.e. it will be ignored for windows created from the handle of a child window/control).
position | New position, in pixels |
void sf::WindowBase::setSize | ( | const Vector2u & | size | ) |
Change the size of the rendering region of the window.
size | New size, in pixels |
void sf::WindowBase::setTitle | ( | const String & | title | ) |
void sf::WindowBase::setVisible | ( | bool | visible | ) |
Show or hide the window.
The window is shown by default.
visible | True to show the window, false to hide it |
bool sf::WindowBase::waitEvent | ( | Event & | event | ) |
Wait for an event and return it.
This function is blocking: if there's no pending event then it will wait until an event is received. After this function returns (and no error occurred), the event object is always valid and filled properly. This function is typically used when you have a thread that is dedicated to events handling: you want to make this thread sleep as long as no new event is received.
event | Event to be returned |
|
friend |
Definition at line 432 of file WindowBase.hpp.