Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
An OS window. More...
#include <gf/Window.h>
Public Member Functions | |
Window (const std::string &title, Vector2u size, WindowFlags hints=WindowFlags(All)) | |
Create a new window. More... | |
~Window () | |
Destructor. More... | |
Window (const Window &)=delete | |
Deleted copy constructor. More... | |
Window & | operator= (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... | |
void | toggleFullscreen () |
Toggle the fullscreen state. More... | |
bool | isFullscreen () const |
Check if the window is 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... | |
Input management | |
void | setMouseCursorVisible (bool visible) |
Show or hide the mouse cursor. More... | |
void | setMouseCursorGrabbed (bool grabbed) |
Grab or release the mouse cursor. More... | |
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 | ( | const std::string & | 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).
title | The title of the window |
size | The initial size of the window |
hints | Some hints for the creation of the window |
gf::Window::~Window | ( | ) |
Destructor.
Actually destroy the window.
|
delete |
Deleted copy constructor.
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.
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.
Vector2u gf::Window::getFramebufferSize | ( | ) | const |
Vector2i gf::Window::getPosition | ( | ) | const |
Vector2u gf::Window::getSize | ( | ) | const |
Get the size of the rendering region of the window.
void gf::Window::hide | ( | ) |
Hide a window.
bool gf::Window::isDecorated | ( | ) | const |
Check if the window is decorated.
bool gf::Window::isFocused | ( | ) | const |
Check if the window is focused.
|
inline |
Check if the window is fullscreen or not.
bool gf::Window::isMinimized | ( | ) | const |
Check if the window is minimized.
bool gf::Window::isOpen | ( | ) |
Tell whether or not closing has been requested.
bool gf::Window::isResizable | ( | ) | const |
Check if the window is resizable.
bool gf::Window::isVisible | ( | ) | const |
Check if the window is visible.
void gf::Window::maximize | ( | ) |
Maximize the window.
void gf::Window::minimize | ( | ) |
Minimize the window.
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.
event | Event to be returned |
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.
full | True if the window must be in fullscreen |
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).
grabbed | True to enable, false to disable |
void gf::Window::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 gf::Window::setPosition | ( | Vector2i | position | ) |
Change the position of the window on screen.
position | New position, in pixels |
void gf::Window::setSize | ( | Vector2u | size | ) |
Change the size of the rendering region of the window.
size | New size, in pixels |
void gf::Window::setTitle | ( | const std::string & | title | ) |
Change the title of the window.
title | New 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.
enabled | True to enable v-sync, false to deactivate it |
void gf::Window::show | ( | ) |
Show a window.
void gf::Window::toggleFullscreen | ( | ) |
Toggle the fullscreen state.
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.
event | Event to be returned |