Gamedev Framework (gf)  0.8.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::Window Class Reference

An OS window. More...

#include <gf/Window.h>

Public Member Functions

 Window (StringRef title, Vector2u size, WindowFlags hints=WindowFlags(All))
 Create a new window. More...
 
 ~Window ()
 Destructor. More...
 
 Window (const Window &)=delete
 Deleted copy constructor. More...
 
Windowoperator= (const Window &)=delete
 Deleted copy assignment. More...
 
Window's lifecycle
bool isOpen ()
 Tell whether or not closing has been requested. More...
 
void close ()
 Request for closing. More...
 
Window's positon and size
void setTitle (StringRef title)
 Change the title of the window. More...
 
Vector2i getPosition () const
 Get the position of the window. More...
 
void setPosition (Vector2i position)
 Change the position of the window on screen. More...
 
Vector2u getSize () const
 Get the size of the rendering region of the window. More...
 
void setSize (Vector2u size)
 Change the size of the rendering region of the window. More...
 
Vector2u getFramebufferSize () const
 Get the size of the underlying framebuffer. More...
 
void setFullscreen (bool full=true)
 Change the window state to fullscreen or not. More...
 
void toggleFullscreen ()
 Toggle the fullscreen state. More...
 
bool isFullscreen () const
 Check if the window is fullscreen or not. More...
 
Window's state
bool isMinimized () const
 Check if the window is minimized. More...
 
void minimize ()
 Minimize the window. More...
 
void restore ()
 Restore the window. More...
 
bool isMaximized () const
 Check if the window is maximized. More...
 
void maximize ()
 Maximize the window. More...
 
bool isVisible () const
 Check if the window is visible. More...
 
void show ()
 Show a window. More...
 
void hide ()
 Hide a window. More...
 
void setVisible (bool visible=true)
 Show or hide the window. More...
 
bool isDecorated () const
 Check if the window is decorated. More...
 
void setDecorated (bool decorated=true)
 Show or hide the decoration of the window. More...
 
bool isFocused () const
 Check if the window is focused. More...
 
bool isResizable () const
 Check if the window is resizable. More...
 
void setResizable (bool resizable=true)
 Set the window resizable or not. More...
 
Event handling
bool pollEvent (Event &event)
 Pop the event on top of the event queue, if any, and return it. More...
 
bool waitEvent (Event &event)
 Wait for an event and return it. More...
 
Display
void setVerticalSyncEnabled (bool enabled)
 Enable or disable vertical synchronization. More...
 
bool isVerticalSyncEnabled () const
 Check if the vertical synchronization is enabled. More...
 
void setFramerateLimit (unsigned int limit)
 Limit the framerate to a maximum fixed frequency. More...
 
void display ()
 Display on screen what has been rendered to the window so far. More...
 
Input management
void setMouseCursorVisible (bool visible)
 Show or hide the mouse cursor. More...
 
void setMouseCursorGrabbed (bool grabbed)
 Grab or release the mouse cursor. More...
 
void setMouseCursor (const Cursor &cursor)
 Set the displayed cursor to a native system cursor. More...
 

Detailed Description

An OS window.

The gf::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.

gf::Window window("My window", { 640, 480 }, gf::WindowHints::Resizable | gf::WindowHints::Visible);
while (window.isOpen()) {
// process events
gf::Event event;
while (window.pollEvent(event)) {
if (event.type == gf::EventType::Closed) {
window.close();
}
}
// ...
}
See also
gf::RenderWindow

Constructor & Destructor Documentation

◆ Window() [1/2]

gf::Window::Window ( StringRef  title,
Vector2u  size,
WindowFlags  hints = WindowFlags(All) 
)

Create a new window.

This constructor creates the window with the size defined in size. Additional parameters can be passed with hints (resizable, visible, decorated).

Parameters
titleThe title of the window
sizeThe initial size of the window
hintsSome hints for the creation of the window
See also
gf::WindowHints

◆ ~Window()

gf::Window::~Window ( )

Destructor.

Actually destroy the window.

◆ Window() [2/2]

gf::Window::Window ( const Window )
delete

Deleted copy constructor.

Member Function Documentation

◆ close()

void gf::Window::close ( )

Request for closing.

This function does not close the window immediately. It only requests the window to close. Actual closing is done when the object is destroyed.

See also
isOpen()

◆ display()

void gf::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.

See also
RenderWindow::display()

◆ getFramebufferSize()

Vector2u gf::Window::getFramebufferSize ( ) const

Get the size of the underlying framebuffer.

This size can differ from the size returned by getSize() for high-DPI screens.

Returns
getSize(), setSize()

◆ getPosition()

Vector2i gf::Window::getPosition ( ) const

Get the position of the window.

Returns
The position of the window, in pixels
See also
setPosition()

◆ getSize()

Vector2u gf::Window::getSize ( ) const

Get the size of the rendering region of the window.

Returns
The size in pixels
See also
setSize(), getFramebufferSize()

◆ hide()

void gf::Window::hide ( )

Hide a window.

See also
show()

◆ isDecorated()

bool gf::Window::isDecorated ( ) const

Check if the window is decorated.

Returns
True if the window is decorated

◆ isFocused()

bool gf::Window::isFocused ( ) const

Check if the window is focused.

Returns
True if the window is focused

◆ isFullscreen()

bool gf::Window::isFullscreen ( ) const
inline

Check if the window is fullscreen or not.

Returns
True if the window is fullscreen

◆ isMaximized()

bool gf::Window::isMaximized ( ) const

Check if the window is maximized.

Returns
True if the window is maximized

◆ isMinimized()

bool gf::Window::isMinimized ( ) const

Check if the window is minimized.

Returns
True if the window is minimized

◆ isOpen()

bool gf::Window::isOpen ( )

Tell whether or not closing has been requested.

Returns
True if the window is open, false if closing has been requested
See also
close()

◆ isResizable()

bool gf::Window::isResizable ( ) const

Check if the window is resizable.

Returns
True if the window is resizable

◆ isVerticalSyncEnabled()

bool gf::Window::isVerticalSyncEnabled ( ) const

Check if the vertical synchronization is enabled.

Returns
True if the v-sync is enabled
See also
setVerticalSyncEnabled()

◆ isVisible()

bool gf::Window::isVisible ( ) const

Check if the window is visible.

Returns
True if the window is visible

◆ maximize()

void gf::Window::maximize ( )

Maximize the window.

◆ minimize()

void gf::Window::minimize ( )

Minimize the window.

◆ operator=()

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

Deleted copy assignment.

◆ pollEvent()

bool gf::Window::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.

gf::Event event;
while (window.pollEvent(event)) {
// process event...
}
Parameters
eventEvent to be returned
Returns
True if an event was returned, or false if the event queue was empty
See also
waitEvent()

◆ restore()

void gf::Window::restore ( )

Restore the window.

Restore the size and position of a minimized or maximized window.

◆ setDecorated()

void gf::Window::setDecorated ( bool  decorated = true)

Show or hide the decoration of the window.

Parameters
decoratedTrue to show decoration
See also
isDecorated()

◆ setFramerateLimit()

void gf::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.

Parameters
limitFramerate limit, in frames per seconds (use 0 to disable limit)

◆ setFullscreen()

void gf::Window::setFullscreen ( bool  full = true)

Change the window state to fullscreen or not.

Parameters
fullTrue if the window must be in fullscreen

◆ setMouseCursor()

void gf::Window::setMouseCursor ( const Cursor cursor)

Set the displayed cursor to a native system cursor.

Upon window creation, the arrow cursor is used by default.

Warning
The cursor must not be destroyed while in use by the window.
Parameters
cursorNative system cursor type to display

◆ setMouseCursorGrabbed()

void gf::Window::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 and calling this function for fullscreen windows won't have any effect (fullscreen windows always grab the cursor).

Parameters
grabbedTrue to enable, false to disable

◆ setMouseCursorVisible()

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

Show or hide the mouse cursor.

The mouse cursor is visible by default.

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

◆ setPosition()

void gf::Window::setPosition ( Vector2i  position)

Change the position of the window on screen.

Parameters
positionNew position, in pixels
See also
getPosition()

◆ setResizable()

void gf::Window::setResizable ( bool  resizable = true)

Set the window resizable or not.

Warning
This function is only available if you have built gf with SDL 2.0.5 (event the latest Debian stable has it, but not Travis-CI...)
Parameters
resizableTrue to make the window resizable, false otherwise

◆ setSize()

void gf::Window::setSize ( Vector2u  size)

Change the size of the rendering region of the window.

Parameters
sizeNew size, in pixels
See also
getSize(), getFramebufferSize()

◆ setTitle()

void gf::Window::setTitle ( StringRef  title)

Change the title of the window.

Parameters
titleNew title

◆ setVerticalSyncEnabled()

void gf::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).

Parameters
enabledTrue to enable v-sync, false to deactivate it
See also
isVerticalSyncEnabled()

◆ setVisible()

void gf::Window::setVisible ( bool  visible = true)

Show or hide the window.

The window is shown by default.

Parameters
visibleTrue to show the window, false to hide it
See also
show(), hide(), isVisible()

◆ show()

void gf::Window::show ( )

Show a window.

See also
hide()

◆ toggleFullscreen()

void gf::Window::toggleFullscreen ( )

Toggle the fullscreen state.

◆ waitEvent()

bool gf::Window::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.

gf::Event event;
if (window.waitEvent(event))
{
// process event...
}
Parameters
eventEvent to be returned
Returns
False if any error occurred
See also
pollEvent()