Public Member Functions | Static Public Member Functions | Friends | List of all members
ime::Window Class Reference

Game window. More...

#include <Window.h>

Public Member Functions

 Window (const Window &)=delete
 Copy constructor. More...
 
Windowoperator= (const Window &)=delete
 Copy assignment operator. More...
 
 Window (Window &&)=delete
 Move constructor. More...
 
Windowoperator= (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 ColourgetClearColour () const
 Get the fill colour of the window when it is cleared. More...
 
std::unique_ptr< TexturetakeScreenshot ()
 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...
 

Detailed Description

Game window.

Definition at line 47 of file Window.h.

Constructor & Destructor Documentation

◆ Window() [1/2]

ime::Window::Window ( const Window )
delete

Copy constructor.

◆ Window() [2/2]

ime::Window::Window ( Window &&  )
delete

Move constructor.

Member Function Documentation

◆ close()

void ime::Window::close ( )

Close the window.

Note that closing the window will trigger an engine shutdown

See also
ime::Engine::quit

◆ getClearColour()

const Colour & ime::Window::getClearColour ( ) const

Get the fill colour of the window when it is cleared.

Returns
The colour used when clearing the window
See also
setClearColour

◆ getFrameRateLimit()

unsigned int ime::Window::getFrameRateLimit ( ) const

Get the frame rate limit of the window.

Returns
The current frame rate (0 implies no limit)

◆ getFullScreenSize()

static Vector2u ime::Window::getFullScreenSize ( )
static

Get the size of the when viewed in full screen.

Returns
The size of the window in full screen mode

◆ getIcon()

std::string ime::Window::getIcon ( ) const

Get the filename of the windows icon.

Returns
The filename of the window 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

See also
setIcon

◆ getMaxSize()

Vector2u ime::Window::getMaxSize ( ) const

Get the minimum size of the rendering region of the window.

Returns
The minimum size of the window
See also
setMaxSize

◆ getMinSize()

Vector2u ime::Window::getMinSize ( ) const

Get the minimum size of the rendering region of the window.

Returns
The minimum size of the window
See also
setMinSize

◆ getPosition()

Vector2i ime::Window::getPosition ( ) const

Get the position of the window in pixels.

Returns
The position of the window in pixels
See also
setPosition

◆ getRelativeMousePosition()

Vector2i ime::Window::getRelativeMousePosition ( ) const

Get the position of the mouse cursor relative to the window.

Returns
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

See also
setRelativeMousePosition

◆ getSize()

Vector2u ime::Window::getSize ( ) const

Get the size of the rendering region of the window.

Returns
The size of the window

The size doesn't include the titlebar and borders of the window

See also
setSize

◆ getStyle()

Uint32 ime::Window::getStyle ( ) const

Get the current window style.

Returns
The current window style
See also
setStyle

◆ getTitle()

const std::string & ime::Window::getTitle ( ) const

Get the title of the window.

Returns
The title of the window
See also
setTitle

◆ hasMaxBound()

bool ime::Window::hasMaxBound ( ) const

Check if the window has a maximum size requirement.

Returns
True if a maximum size has been set, otherwise false
See also
hasMinBound, setMaxSize

◆ hasMinBound()

bool ime::Window::hasMinBound ( ) const

Check if the window has a minimum size requirement.

Returns
True if a minimum size has been set, otherwise false
See also
hasMaxBound, setMinSize

◆ isEventListenerSuspended()

bool ime::Window::isEventListenerSuspended ( int  id) const

Check if an event listener is suspended or not.

Parameters
idThe identification number of the listener to be checked
Returns
True if suspended, otherwise false

This function also returns false if the specified event listener does not exist

See also
suspendedEventListener

◆ isFullScreen()

bool ime::Window::isFullScreen ( ) const

Check if the window is in full screen mode or not.

Returns
True if window is in full screen mode, otherwise false
See also
setFullScreen

◆ isMouseCursorGrabbed()

bool ime::Window::isMouseCursorGrabbed ( ) const

Check if the mouse cursor is grabbed or not.

Returns
True if grabbed, otherwise false
See also
setMouseCursorGrabbed

◆ isMouseCursorVisible()

bool ime::Window::isMouseCursorVisible ( ) const

Check if the mouse cursor is visible or not.

Returns
True if it is visible, otherwise false
See also
setMouseCursorVisible

◆ isOpen()

bool ime::Window::isOpen ( ) const

Check if the window is open or not.

Returns
True if the window is open, otherwise false

◆ isVerticalSyncEnabled()

bool ime::Window::isVerticalSyncEnabled ( ) const

Check if vertical synchronization is enabled or not.

Returns
True if enabled, otherwise false

◆ isVisible()

bool ime::Window::isVisible ( ) const

Check if the window is visible or not.

Returns
True if it is visible, otherwise false
See also
setVisible

◆ onClose()

int ime::Window::onClose ( const Callback<> &  callback,
bool  oneTime = false 
)

Add an event lister to a window close event.

Parameters
callbackFunction to be execute when a window close event is triggered
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

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()

See also
removeEventListener, setDefaultOnCloseHandlerEnable

◆ onFullScreenToggle()

int ime::Window::onFullScreenToggle ( const Callback< bool > &  callback,
bool  oneTime = false 
)

Add an event listener to a full screen event.

Parameters
callbackFunction to be executed when the window toggles full screen
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

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

See also
onResize, removeEventListener

◆ onGainFocus()

int ime::Window::onGainFocus ( const Callback<> &  callback,
bool  oneTime = false 
)

Add an event listener to a gain focus event.

Parameters
callbackThe function to be executed when the window gains focus
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add any number of event handlers to this event

See also
onLoseFocus, removeEventListener

◆ onLoseFocus()

int ime::Window::onLoseFocus ( const Callback<> &  callback,
bool  oneTime = false 
)

Add an event listener to an lose focus event.

Parameters
callbackThe function to be executed when the window loses focus
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add any number of event handlers to this event

See also
onGainFocus, removeEventListener

◆ onMouseEnter()

int ime::Window::onMouseEnter ( const Callback<> &  callback,
bool  oneTime = false 
)

Add an event listener to an mouse enter event.

Parameters
callbackThe function to be executed when the mouse cursor enters the window
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add any number of event handlers to this event

See also
onMouseExit, removeEventListener

◆ onMouseExit()

int ime::Window::onMouseExit ( const Callback<> &  callback,
bool  oneTime = false 
)

Add an event listener to a mouse left event.

Parameters
callbackThe function to be executed when the mouse cursor leaves the window
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add any number of event handlers to this event

See also
onMouseEnter, removeEventListener

◆ onResize()

int ime::Window::onResize ( const Callback< Vector2u > &  callback,
bool  oneTime = false 
)

Add an event listener to a window resize event.

Parameters
callbackThe function to be executed when the window is resized
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add any number of event handlers to this event

The callback is passed the new size of the window

See also
onFullScreenToggle, removeEventListener

◆ operator=() [1/2]

Window & ime::Window::operator= ( const Window )
delete

Copy assignment operator.

◆ operator=() [2/2]

Window & ime::Window::operator= ( Window &&  )
delete

Move assignment operator.

◆ removeEventListener()

bool ime::Window::removeEventListener ( int  id)

Remove an event listener from an event.

Parameters
idThe unique identification number of the event listener
Returns
True if the event listener was removed or false if no such event listener exists

◆ setClearColour()

void ime::Window::setClearColour ( const Colour colour)

Set the fill colour of the window when it is cleared.

Parameters
colourThe new fill colour

By default, the clear fill colour is black

See also
getClearColour

◆ setDefaultOnCloseHandlerEnable()

void ime::Window::setDefaultOnCloseHandlerEnable ( bool  enable)

Enable or disable the default window close handler.

Parameters
enableTrue to enable of false to disable

By default, the internal window close handler is enabled. for more info checkout onClose()

See also
onClose

◆ setFrameRateLimit()

void ime::Window::setFrameRateLimit ( unsigned int  limit)

Limit the frame rate to a maximum fixed frequency.

Parameters
limitThe new limit in frames per seconds (FPS)
Exceptions
InvalidArgumentExceptionIf limit is equal to 0
Warning
The frame rate limit must be greater than 0

BY default the frame rate limit is 60 FPS

◆ setFullScreen()

void ime::Window::setFullScreen ( bool  fullScreen)

Enable or disable full screen mode.

Parameters
fullScreenTrue enable full screen, otherwise false
Warning
This function must be called after ime::Engine::initialize is called, otherwise undefined behavior

By default, the window is not in full screen

See also
toggleFullScreen and isFullScreen

◆ setIcon()

void ime::Window::setIcon ( const std::string &  filename)

Change the window's icon.

Parameters
filenameFilename 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

See also
getIcon

◆ setMaxSize()

void ime::Window::setMaxSize ( const Vector2u size)

Set the maximum size of the rendering region of the window.

Parameters
sizeThe 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)

See also
setMinSize, getMaxSize, hasMaxBound

◆ setMinSize()

void ime::Window::setMinSize ( const Vector2u size)

Set the minimum size of the rendering region of the window.

Parameters
sizeThe 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)

See also
setMaxSize, getMaxSize

◆ setMouseCursorGrabbed()

void ime::Window::setMouseCursorGrabbed ( bool  grabbed)

Grab or release the mouse cursor.

Parameters
grabbedTrue 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

See also
isMouseCursorGrabbed

◆ setMouseCursorVisible()

void ime::Window::setMouseCursorVisible ( bool  visible)

Show or hide the mouse cursor.

Parameters
visibleTrue to show the mouse cursor, or false to hide it

By default, the mouse cursor is visible

See also
isMouseCursorVisible

◆ setPosition()

void ime::Window::setPosition ( const Vector2i position)

Set the position of thw window on the screen.

Parameters
positionThe new position in pixels
See also
getPosition

◆ setRelativeMousePosition()

void ime::Window::setRelativeMousePosition ( const Vector2i position)

Set the position of the mouse cursor relative to the window.

Parameters
positionThe new position of the cursor relative to the window

To set the position of the mouse cursor in desktop coordinates, use ime::Mouse::setPosition

See also
getRelativeMousePosition

◆ setSize()

void ime::Window::setSize ( const Vector2u size)

Set the size of the rendering region of the window.

Parameters
sizeThe 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

See also
setMinSize and setMaxSize

◆ setStyle()

void ime::Window::setStyle ( Uint32  windowStyle)

Set the window style.

Parameters
windowStyleNew 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:

window.setStyle(ime::WindowStyle::Close | ime::WindowStyle::Resize);
Note
Changing the window style will recreate the game window

By default, the window style is ime::WindowStyle::Default

See also
getStyle

◆ setTitle()

void ime::Window::setTitle ( const std::string &  title)

Set the title of the window.

Parameters
titleThe new title of the window
See also
getTitle

◆ setVerticalSyncEnable()

void ime::Window::setVerticalSyncEnable ( bool  vSyncEnable)

Enable or disable vertical synchronization.

Parameters
vSyncEnableTrue 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

◆ setVisible()

void ime::Window::setVisible ( bool  visible)

Show or hide the window.

Parameters
visibleTrue to show the window or false to hide it

By default, the window is shown

◆ suspendedEventListener()

void ime::Window::suspendedEventListener ( int  id,
bool  suspend 
)

Pause or resume execution of an event listener.

Parameters
idThe event listeners unique identification number
suspendTrue to suspend/pause or false to unsuspend/resume
See also
isEventListenerSuspended

◆ takeScreenshot() [1/2]

std::unique_ptr< Texture > ime::Window::takeScreenshot ( )

Take a screenshot of the window.

Returns
A texture updated with the current content 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

See also
ime::Engine::initialize

◆ takeScreenshot() [2/2]

void ime::Window::takeScreenshot ( const std::string &  filename)

Take a screenshot of the window and immediately save it to a file.

Parameters
filenameName 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

window.takeScreenshot("images/screenshot.png");

Note that calling this function before the window is created leads to undefined behavior

Note
This function performs a slow operation

◆ toggleFullScreen()

void ime::Window::toggleFullScreen ( )

Switch between full screen and non full screen mode.

Warning
This function must be called after ime::Engine::initialize is called, otherwise undefined behavior

By default, the window is not in full screen

See also
setFullScreen

Friends And Related Function Documentation

◆ Engine

friend class Engine
friend

Needs access to constructor.

Definition at line 651 of file Window.h.


The documentation for this class was generated from the following file: