Gamedev Framework (gf)  0.1.0
A C++11 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 (const std::string &title, Vector2u size, WindowHints hints=WindowHints())
 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 (const std::string &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...
 
Window's state
void minimize ()
 Minimize the window. More...
 
void restore ()
 Restore the window. More...
 
void maximize ()
 Maximize the window. More...
 
void show ()
 Show a window. More...
 
void hide ()
 Hide a window. More...
 
bool isFocused () const
 Check if the window is focused. More...
 
bool isMinimized () const
 Check if the window is minimized. More...
 
bool isResizable () const
 Check if the window is resizable. More...
 
bool isVisible () const
 Check if the window is visible. More...
 
bool isDecorated () const
 Check if the window is decorated. 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...
 
void display ()
 Display on screen what has been rendered to the window so far. More...
 

Detailed Description

An OS window.

Constructor & Destructor Documentation

gf::Window::Window ( const std::string &  title,
Vector2u  size,
WindowHints  hints = WindowHints() 
)

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
gf::Window::~Window ( )

Destructor.

Actually destroy the window.

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

Deleted copy constructor.

Member Function Documentation

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()
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()
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()
Vector2i gf::Window::getPosition ( ) const

Get the position of the window.

Returns
The position of the window, in pixels
See also
setPosition()
Vector2u gf::Window::getSize ( ) const

Get the size of the rendering region of the window.

Returns
The size in pixels
See also
setSize(), getFramebufferSize()
void gf::Window::hide ( )

Hide a window.

bool gf::Window::isDecorated ( ) const

Check if the window is decorated.

Returns
True if the window is decorated
bool gf::Window::isFocused ( ) const

Check if the window is focused.

Returns
True if the window is focused
bool gf::Window::isMinimized ( ) const

Check if the window is minimized.

Returns
True if the window is minimized
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()
bool gf::Window::isResizable ( ) const

Check if the window is resizable.

Returns
True if the window is resizable
bool gf::Window::isVisible ( ) const

Check if the window is visible.

Returns
True if the window is visible
void gf::Window::maximize ( )

Maximize the window.

void gf::Window::minimize ( )

Minimize the window.

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

Deleted copy assignment.

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()
void gf::Window::restore ( )

Restore the window.

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

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

Change the window state to fullscreen or not.

Parameters
fullTrue if the window must be in fullscreen
void gf::Window::setPosition ( Vector2i  position)

Change the position of the window on screen.

Parameters
positionNew position, in pixels
See also
getPosition()
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()
void gf::Window::setTitle ( const std::string &  title)

Change the title of the window.

Parameters
titleNew title
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).

Vertical synchronization is disabled by default.

Parameters
enabledTrue to enable v-sync, false to deactivate it
void gf::Window::show ( )

Show a window.

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