Game window. More...
#include <Window.h>
Public Member Functions | |
Window (const Window &)=delete | |
Copy constructor. More... | |
Window & | operator= (const Window &)=delete |
Copy assignment operator. More... | |
Window (Window &&)=delete | |
Move constructor. More... | |
Window & | operator= (Window &&)=delete |
Move assignment operator. More... | |
void | setStyle (Uint32 windowStyle) |
Set the window style. More... | |
Uint32 | getStyle () const |
Get the current window style. More... | |
void | setTitle (const std::string &title) |
Set the title of the window. More... | |
const std::string & | getTitle () const |
Get the title of the window. More... | |
void | setIcon (const std::string &filename) |
Change the window's icon. More... | |
std::string | getIcon () const |
Get the filename of the windows icon. More... | |
void | setPosition (const Vector2i &position) |
Set the position of thw window on the screen. More... | |
Vector2i | getPosition () const |
Get the position of the window in pixels. More... | |
void | setRelativeMousePosition (const Vector2i &position) |
Set the position of the mouse cursor relative to the window. More... | |
Vector2i | getRelativeMousePosition () const |
Get the position of the mouse cursor relative to the window. More... | |
void | setSize (const Vector2u &size) |
Set the size of the rendering region of the window. More... | |
Vector2u | getSize () const |
Get the size of the rendering region of the window. More... | |
void | setMinSize (const Vector2u &size) |
Set the minimum size of the rendering region of the window. More... | |
Vector2u | getMinSize () const |
Get the minimum size of the rendering region of the window. More... | |
void | setMaxSize (const Vector2u &size) |
Set the maximum size of the rendering region of the window. More... | |
Vector2u | getMaxSize () const |
Get the minimum size of the rendering region of the window. More... | |
bool | hasMinBound () const |
Check if the window has a minimum size requirement. More... | |
bool | hasMaxBound () const |
Check if the window has a maximum size requirement. More... | |
void | setFullScreen (bool fullScreen) |
Enable or disable full screen mode. More... | |
bool | isFullScreen () const |
Check if the window is in full screen mode or not. More... | |
void | toggleFullScreen () |
Switch between full screen and non full screen mode. More... | |
void | setVisible (bool visible) |
Show or hide the window. More... | |
bool | isVisible () const |
Check if the window is visible or not. More... | |
void | setMouseCursorVisible (bool visible) |
Show or hide the mouse cursor. More... | |
bool | isMouseCursorVisible () const |
Check if the mouse cursor is visible or not. More... | |
void | setMouseCursorGrabbed (bool grabbed) |
Grab or release the mouse cursor. More... | |
bool | isMouseCursorGrabbed () const |
Check if the mouse cursor is grabbed or not. More... | |
void | setFrameRateLimit (unsigned int limit) |
Limit the frame rate to a maximum fixed frequency. More... | |
unsigned int | getFrameRateLimit () const |
Get the frame rate limit of the window. More... | |
void | setVerticalSyncEnable (bool vSyncEnable) |
Enable or disable vertical synchronization. More... | |
bool | isVerticalSyncEnabled () const |
Check if vertical synchronization is enabled or not. More... | |
void | setClearColour (const Colour &colour) |
Set the fill colour of the window when it is cleared. More... | |
const Colour & | getClearColour () const |
Get the fill colour of the window when it is cleared. More... | |
std::unique_ptr< Texture > | takeScreenshot () |
Take a screenshot of the window. More... | |
void | takeScreenshot (const std::string &filename) |
Take a screenshot of the window and immediately save it to a file. More... | |
void | close () |
Close the window. More... | |
bool | isOpen () const |
Check if the window is open or not. More... | |
void | suspendedEventListener (int id, bool suspend) |
Pause or resume execution of an event listener. More... | |
bool | isEventListenerSuspended (int id) const |
Check if an event listener is suspended or not. More... | |
void | setDefaultOnCloseHandlerEnable (bool enable) |
Enable or disable the default window close handler. More... | |
int | onClose (const Callback<> &callback, bool oneTime=false) |
Add an event lister to a window close event. More... | |
int | onLoseFocus (const Callback<> &callback, bool oneTime=false) |
Add an event listener to an lose focus event. More... | |
int | onGainFocus (const Callback<> &callback, bool oneTime=false) |
Add an event listener to a gain focus event. More... | |
int | onMouseEnter (const Callback<> &callback, bool oneTime=false) |
Add an event listener to an mouse enter event. More... | |
int | onMouseExit (const Callback<> &callback, bool oneTime=false) |
Add an event listener to a mouse left event. More... | |
int | onFullScreenToggle (const Callback< bool > &callback, bool oneTime=false) |
Add an event listener to a full screen event. More... | |
int | onResize (const Callback< Vector2u > &callback, bool oneTime=false) |
Add an event listener to a window resize event. More... | |
bool | removeEventListener (int id) |
Remove an event listener from an event. More... | |
Static Public Member Functions | |
static Vector2u | getFullScreenSize () |
Get the size of the when viewed in full screen. More... | |
Friends | |
class | Engine |
Needs access to constructor. More... | |
|
delete |
Copy constructor.
|
delete |
Move constructor.
void ime::Window::close | ( | ) |
Close the window.
Note that closing the window will trigger an engine shutdown
const Colour & ime::Window::getClearColour | ( | ) | const |
Get the fill colour of the window when it is cleared.
unsigned int ime::Window::getFrameRateLimit | ( | ) | const |
Get the frame rate limit of the window.
|
static |
Get the size of the when viewed in full screen.
std::string ime::Window::getIcon | ( | ) | const |
Get the filename of the windows icon.
This function will return an empty string if the windows icon is not user specified. That is, when the window uses the operating systems default icon
Vector2u ime::Window::getMaxSize | ( | ) | const |
Get the minimum size of the rendering region of the window.
Vector2u ime::Window::getMinSize | ( | ) | const |
Get the minimum size of the rendering region of the window.
Vector2i ime::Window::getPosition | ( | ) | const |
Get the position of the window in pixels.
Vector2i ime::Window::getRelativeMousePosition | ( | ) | const |
Get the position of the mouse cursor relative to the window.
To get the position of the mouse cursor in desktop coordinates, use ime::Mouse::getPosition
Vector2u ime::Window::getSize | ( | ) | const |
Get the size of the rendering region of the window.
The size doesn't include the titlebar and borders of the window
Uint32 ime::Window::getStyle | ( | ) | const |
const std::string & ime::Window::getTitle | ( | ) | const |
bool ime::Window::hasMaxBound | ( | ) | const |
Check if the window has a maximum size requirement.
bool ime::Window::hasMinBound | ( | ) | const |
Check if the window has a minimum size requirement.
bool ime::Window::isEventListenerSuspended | ( | int | id | ) | const |
Check if an event listener is suspended or not.
id | The identification number of the listener to be checked |
This function also returns false if the specified event listener does not exist
bool ime::Window::isFullScreen | ( | ) | const |
Check if the window is in full screen mode or not.
bool ime::Window::isMouseCursorGrabbed | ( | ) | const |
Check if the mouse cursor is grabbed or not.
bool ime::Window::isMouseCursorVisible | ( | ) | const |
Check if the mouse cursor is visible or not.
bool ime::Window::isOpen | ( | ) | const |
Check if the window is open or not.
bool ime::Window::isVerticalSyncEnabled | ( | ) | const |
Check if vertical synchronization is enabled or not.
bool ime::Window::isVisible | ( | ) | const |
Check if the window is visible or not.
int ime::Window::onClose | ( | const Callback<> & | callback, |
bool | oneTime = false |
||
) |
Add an event lister to a window close event.
callback | Function to be execute when a window close event is triggered |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
The window close event is triggered when close() is called, when the close window (x) button is clicked or when alt + F4 is pressed
By default, this event has an internal event listener which closes the window and shuts down the engine. To disable it call setDefaultOnCloseHandlerEnable()
int ime::Window::onFullScreenToggle | ( | const Callback< bool > & | callback, |
bool | oneTime = false |
||
) |
Add an event listener to a full screen event.
callback | Function to be executed when the window toggles full screen |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add any number of event handlers to this event
The callback is passed a boolean flag indicating whether or not the window is full screen
int ime::Window::onGainFocus | ( | const Callback<> & | callback, |
bool | oneTime = false |
||
) |
Add an event listener to a gain focus event.
callback | The function to be executed when the window gains focus |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add any number of event handlers to this event
int ime::Window::onLoseFocus | ( | const Callback<> & | callback, |
bool | oneTime = false |
||
) |
Add an event listener to an lose focus event.
callback | The function to be executed when the window loses focus |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add any number of event handlers to this event
int ime::Window::onMouseEnter | ( | const Callback<> & | callback, |
bool | oneTime = false |
||
) |
Add an event listener to an mouse enter event.
callback | The function to be executed when the mouse cursor enters the window |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add any number of event handlers to this event
int ime::Window::onMouseExit | ( | const Callback<> & | callback, |
bool | oneTime = false |
||
) |
Add an event listener to a mouse left event.
callback | The function to be executed when the mouse cursor leaves the window |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add any number of event handlers to this event
Add an event listener to a window resize event.
callback | The function to be executed when the window is resized |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add any number of event handlers to this event
The callback is passed the new size of the window
bool ime::Window::removeEventListener | ( | int | id | ) |
Remove an event listener from an event.
id | The unique identification number of the event listener |
void ime::Window::setClearColour | ( | const Colour & | colour | ) |
Set the fill colour of the window when it is cleared.
colour | The new fill colour |
By default, the clear fill colour is black
void ime::Window::setDefaultOnCloseHandlerEnable | ( | bool | enable | ) |
void ime::Window::setFrameRateLimit | ( | unsigned int | limit | ) |
Limit the frame rate to a maximum fixed frequency.
limit | The new limit in frames per seconds (FPS) |
InvalidArgumentException | If limit is equal to 0 |
BY default the frame rate limit is 60 FPS
void ime::Window::setFullScreen | ( | bool | fullScreen | ) |
Enable or disable full screen mode.
fullScreen | True enable full screen, otherwise false |
By default, the window is not in full screen
void ime::Window::setIcon | ( | const std::string & | filename | ) |
Change the window's icon.
filename | Filename of the window icon to set |
Note that if the specified icon cannot be found, the current icon will remain set. If the current icon is not a user specified icon, then the Operating System (OS) icon will be used. In addition, the icon must be in 32-bits RGBA format
By default, the OS icon is used
void ime::Window::setMaxSize | ( | const Vector2u & | size | ) |
Set the maximum size of the rendering region of the window.
size | The new maximum size |
Set size to Vector2u{0, 0} to remove the max size restriction
By default the maximum size is Vector2u{0, 0} (unrestricted)
void ime::Window::setMinSize | ( | const Vector2u & | size | ) |
Set the minimum size of the rendering region of the window.
size | The new minimum size |
Set size to Vector2u{0, 0} to remove the min size restriction
By default the minimum size is Vector2u{0, 0} (unrestricted)
void ime::Window::setMouseCursorGrabbed | ( | bool | grabbed | ) |
Grab or release the mouse cursor.
grabbed | True to grab the mouse or false to release it |
If grabbed is set to true, then the mouse cursor will no longer be able to leave the bounds of the window. Note that the mouse can only be grabbed if the window has focus
void ime::Window::setMouseCursorVisible | ( | bool | visible | ) |
Show or hide the mouse cursor.
visible | True to show the mouse cursor, or false to hide it |
By default, the mouse cursor is visible
void ime::Window::setPosition | ( | const Vector2i & | position | ) |
Set the position of thw window on the screen.
position | The new position in pixels |
void ime::Window::setRelativeMousePosition | ( | const Vector2i & | position | ) |
Set the position of the mouse cursor relative to the window.
position | The new position of the cursor relative to the window |
To set the position of the mouse cursor in desktop coordinates, use ime::Mouse::setPosition
void ime::Window::setSize | ( | const Vector2u & | size | ) |
Set the size of the rendering region of the window.
size | The new size in pixels |
If the specified size is less than the minimum required size, it will be capped to the minimum size and if it is greater than the maximum size it will be capped to the maximum size
void ime::Window::setStyle | ( | Uint32 | windowStyle | ) |
Set the window style.
windowStyle | New window style (ime::WindowStyle enumeration) |
Note that window styles can be combined using bitwise OR combination of ime::WindowStyle enumerations. For example, to create a window that is closable and resizable, you do as follows:
By default, the window style is ime::WindowStyle::Default
void ime::Window::setTitle | ( | const std::string & | title | ) |
void ime::Window::setVerticalSyncEnable | ( | bool | vSyncEnable | ) |
Enable or disable vertical synchronization.
vSyncEnable | True to enable Vsync or false to disable it |
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).
By default, vertical synchronization is disabled
void ime::Window::setVisible | ( | bool | visible | ) |
Show or hide the window.
visible | True to show the window or false to hide it |
By default, the window is shown
void ime::Window::suspendedEventListener | ( | int | id, |
bool | suspend | ||
) |
Pause or resume execution of an event listener.
id | The event listeners unique identification number |
suspend | True to suspend/pause or false to unsuspend/resume |
std::unique_ptr< Texture > ime::Window::takeScreenshot | ( | ) |
Take a screenshot of the window.
The returned texture has the same size as the window
Calling this function when the window is not created leads to undefined behavior
void ime::Window::takeScreenshot | ( | const std::string & | filename | ) |
Take a screenshot of the window and immediately save it to a file.
filename | Name of the file to save the screenshot to |
The format of the image is automatically deduced from the file extension. The supported image formats are bmp, png, tga and jpg. The destination file is overwritten if it already exists
Note that calling this function before the window is created leads to undefined behavior
void ime::Window::toggleFullScreen | ( | ) |
Switch between full screen and non full screen mode.
By default, the window is not in full screen