sgltk 0.6
Simple OpenGL Tool Kit
|
Provides windows with OpenGL context. More...
#include <window.h>
Public Member Functions | |
Window (const std::string &title, int res_x, int res_y, int offset_x, int offset_y, unsigned int flags=0) | |
void | set_icon (const std::string &filename) |
Sets the window icon. | |
void | set_icon (const sgltk::Image &icon) |
Sets the window icon. | |
void | set_title (const std::string &title) |
Set window title. | |
void | set_resizable (bool on) |
Sets or removes the ability to resize the window. | |
void | take_screenshot (sgltk::Image &image) |
Takes a screenshot of the window. | |
void | grab_mouse (bool on) |
Sets the window to grab the mouse When activate the mouse can not leave the window boundaries. | |
int | get_display_index () |
Returns the index of the display that currently contains the window. This index corresponds to the indices in the sgltk::App::sys_info.desktop_display_modes and sgltk::app::sys_info.supported_display_modes lists. | |
bool | set_display_mode (const SDL_DisplayMode &mode) |
Changes the window display mode when in fullscreen mode. | |
bool | fullscreen_mode (sgltk::WINDOW_MODE mode) |
Changes the window mode. | |
void | set_relative_mode (bool on) |
Activates the relative mouse motion mode In the relative mouse motion mode the cursor is invisible and stays in the middle of the screen. The x and y coordinates passed to the handle_mouse_motion function will be the relative horizontal and vertical distances traveled. | |
void | set_mouse_position (int x, int y) |
Sets the mouse position inside the window. | |
void | set_cursor_visibility (bool show) |
Sets mouse cursor visibility. | |
bool | get_cursor_visibility () |
Returns mouse cursor visibility status. | |
void | poll_events () |
Polls all events and calls the handlers. Called by the run function. | |
virtual void | handle_gamepad_added (std::shared_ptr< sgltk::Gamepad > gamepad) |
This function is called by poll_events() to handle the addition of new gamepads. This function should be overridden. | |
virtual void | handle_gamepad_removed (unsigned int gamepad_id) |
This function is called by poll_events() to handle the removal of gamepads. This function should be overridden. | |
virtual void | handle_gamepad_button (std::shared_ptr< sgltk::Gamepad > gamepad, int button) |
This function is called by poll_events() every frame for every gamepad button currently being pressed. This function should be overridden. | |
virtual void | handle_gamepad_button_press (std::shared_ptr< sgltk::Gamepad > gamepad, int button, bool pressed) |
This function is called by poll_events() once for every gamepad button press or release. This function should be overridden. | |
virtual void | handle_gamepad_axis (std::shared_ptr< sgltk::Gamepad > gamepad, unsigned int axis, int value) |
This function is called by poll_events() every frame for every axis of every gamepad. This function should be overridden. | |
virtual void | handle_gamepad_axis_change (std::shared_ptr< sgltk::Gamepad > gamepad, unsigned int axis, int value) |
This function is called by poll_events() for every axis value change. This function should be overridden. | |
virtual void | handle_joystick_added (std::shared_ptr< sgltk::Joystick > joystick) |
This function is called by poll_events() to handle the addition of new joysticks. This function should be overridden. | |
virtual void | handle_joystick_removed (unsigned int joystick_id) |
This function is called by poll_events() to handle the removal of joysticks. This function should be overridden. | |
virtual void | handle_joystick_button (std::shared_ptr< sgltk::Joystick > joystick, int button) |
This function is called by poll_events() every frame for every joystick button currently being pressed. This function should be overridden. | |
virtual void | handle_joystick_button_press (std::shared_ptr< sgltk::Joystick > joystick, int button, bool pressed) |
This function is called by poll_events() once for every joystick button pressed or released. This function should be overridden. | |
virtual void | handle_joystick_axis (std::shared_ptr< sgltk::Joystick > joystick, unsigned int axis, int value) |
This function is called by poll_events() every frame for every axis of every joystick. This function should be overridden. | |
virtual void | handle_joystick_axis_change (std::shared_ptr< sgltk::Joystick > joystick, unsigned int axis, int value) |
This function is called by poll_events() for every axis value change. This function should be overridden. | |
virtual void | handle_joystick_hat (std::shared_ptr< sgltk::Joystick > joystick, unsigned int hat, unsigned int value) |
This function is called by poll_events() every frame for every hat of every joystick. This function should be overridden. | |
virtual void | handle_joystick_hat_change (std::shared_ptr< sgltk::Joystick > joystick, unsigned int hat, unsigned int value) |
This function is called by poll_events() for every hat value change. This function should be overridden. | |
virtual void | handle_joystick_ball_motion (std::shared_ptr< sgltk::Joystick > joystick, unsigned int ball, int xrel, int yrel) |
This function is called by poll_events() for every ball that has changed value change. This function should be overridden. | |
virtual void | handle_keyboard (const std::string &key) |
This function is called by poll_events() every frame for every key currently being pressed. This function should be overridden. | |
virtual void | handle_key_press (const std::string &key, bool pressed) |
This function is called by poll_events() once for every key pressed or released. This function should be overridden. | |
virtual void | handle_mouse_motion (int x, int y) |
This function is called by poll_events() to handle mouse motion. This function should be overridden. | |
virtual void | handle_mouse_wheel (int x, int y) |
This function is called by poll_events() to handle mouse wheel movements. This function should be overridden. | |
virtual void | handle_mouse_button (int x, int y, int button, bool down, int clicks) |
This function is called by poll_events() to handle mouse button presses. This function should be overridden. | |
virtual void | handle_resize () |
This function is called by run when the window is resized. This function should be overridden. | |
virtual void | handle_exit () |
This function is called by run when the window is being closed. This function should be overridden. | |
virtual void | display () |
This function is called by run() to draw a frame. This function should be overridden. | |
void | run (unsigned int fps=0) |
Starts the main loop. This function calls poll_events() and display() | |
void | stop () |
Stops the main loop. |
Public Attributes | |
int | gl_maj |
The manjor OpenGL version number. | |
int | gl_min |
The minor OpenGL version number. | |
int | width |
The width of the window surface. | |
int | height |
The height of the window surface. | |
double | delta_time |
The time it took to draw the last frame. | |
SDL_Window * | window |
The window surface. |
Window::Window | ( | const std::string & | title, |
int | res_x, | ||
int | res_y, | ||
int | offset_x, | ||
int | offset_y, | ||
unsigned int | flags = 0 ) |
title | The window tile |
res_x | The x window resolution |
res_y | The y window resolution |
offset_x | The x position offset of the window |
offset_y | The y position offset of the window |
flags | Additional flags to be used by SDL_CreateWindow. The default flags are SDL_WINDOW_OPENGL and SDL_WINDOW_RESIZABLE |
Definition at line 9 of file window.cpp.
Window::~Window | ( | ) |
Definition at line 66 of file window.cpp.
|
virtual |
This function is called by run() to draw a frame. This function should be overridden.
Definition at line 426 of file window.cpp.
bool Window::fullscreen_mode | ( | sgltk::WINDOW_MODE | mode | ) |
Changes the window mode.
mode | The window mode to set |
Definition at line 123 of file window.cpp.
bool Window::get_cursor_visibility | ( | ) |
Returns mouse cursor visibility status.
Definition at line 149 of file window.cpp.
int Window::get_display_index | ( | ) |
Returns the index of the display that currently contains the window. This index corresponds to the indices in the sgltk::App::sys_info.desktop_display_modes and sgltk::app::sys_info.supported_display_modes lists.
Definition at line 105 of file window.cpp.
void Window::grab_mouse | ( | bool | on | ) |
Sets the window to grab the mouse When activate the mouse can not leave the window boundaries.
on | True to turn on, false to turn off |
Definition at line 101 of file window.cpp.
|
virtual |
This function is called by run when the window is being closed. This function should be overridden.
Definition at line 422 of file window.cpp.
|
virtual |
This function is called by poll_events() to handle the addition of new gamepads. This function should be overridden.
gamepad | The gamepad that has been connected |
Definition at line 356 of file window.cpp.
|
virtual |
This function is called by poll_events() every frame for every axis of every gamepad. This function should be overridden.
gamepad | The gamepad that the axis is on |
axis | The id number of the axis that has a new value |
value | The new value of the axis |
Definition at line 368 of file window.cpp.
|
virtual |
This function is called by poll_events() for every axis value change. This function should be overridden.
gamepad | The gamepad that the axis is on |
axis | The id number of the axis that has a new value |
value | The new value of the axis |
Definition at line 371 of file window.cpp.
|
virtual |
This function is called by poll_events() every frame for every gamepad button currently being pressed. This function should be overridden.
gamepad | The gamepad that the button is on |
button | The id number of the button pressed or released |
Definition at line 362 of file window.cpp.
|
virtual |
This function is called by poll_events() once for every gamepad button press or release. This function should be overridden.
gamepad | The gamepad that the button is on |
button | The id number of the button pressed or released |
pressed | Indicates whether the button was pressed (true) or released (false) |
Definition at line 365 of file window.cpp.
|
virtual |
This function is called by poll_events() to handle the removal of gamepads. This function should be overridden.
gamepad_id | The gamepad id |
Definition at line 359 of file window.cpp.
|
virtual |
This function is called by poll_events() to handle the addition of new joysticks. This function should be overridden.
joystick | The joystick that has been connected |
Definition at line 374 of file window.cpp.
|
virtual |
This function is called by poll_events() every frame for every axis of every joystick. This function should be overridden.
joystick | The joystick that the axis is on |
axis | The id number of the axis that has a new value |
value | The new value of the axis |
Definition at line 386 of file window.cpp.
|
virtual |
This function is called by poll_events() for every axis value change. This function should be overridden.
joystick | The joystick that the axis is on |
axis | The id number of the axis that has a new value |
value | The new value of the axis |
Definition at line 389 of file window.cpp.
|
virtual |
This function is called by poll_events() for every ball that has changed value change. This function should be overridden.
joystick | The joystick that the ball is on |
ball | The id number of the hat that has a new value |
xrel | The new value of the hat |
yrel | The new value of the hat |
Definition at line 398 of file window.cpp.
|
virtual |
This function is called by poll_events() every frame for every joystick button currently being pressed. This function should be overridden.
joystick | The joystick that the button is on |
button | The id number of the button pressed or released |
Definition at line 380 of file window.cpp.
|
virtual |
This function is called by poll_events() once for every joystick button pressed or released. This function should be overridden.
joystick | The joystick that the button is on |
button | The id number of the button pressed or released |
pressed | Indicates whether the button was pressed (true) or released (false) |
Definition at line 383 of file window.cpp.
|
virtual |
This function is called by poll_events() every frame for every hat of every joystick. This function should be overridden.
joystick | The joystick that the hat is on |
hat | The id number of the hat that has a new value |
value | The new value of the hat |
Definition at line 392 of file window.cpp.
|
virtual |
This function is called by poll_events() for every hat value change. This function should be overridden.
joystick | The joystick that the hat is on |
hat | The id number of the hat that has a new value |
value | The new value of the hat |
Definition at line 395 of file window.cpp.
|
virtual |
This function is called by poll_events() to handle the removal of joysticks. This function should be overridden.
joystick_id | The joystick id |
Definition at line 377 of file window.cpp.
|
virtual |
This function is called by poll_events() once for every key pressed or released. This function should be overridden.
key | The name of the key being pressed |
pressed | True if the key has been pressed, false otherwise |
Definition at line 404 of file window.cpp.
|
virtual |
This function is called by poll_events() every frame for every key currently being pressed. This function should be overridden.
key | The name of the key being pressed |
Definition at line 401 of file window.cpp.
|
virtual |
This function is called by poll_events() to handle mouse button presses. This function should be overridden.
x | The x coordinate where the event occurred |
y | The y coordinate where the event occurred |
button | The button that caused the event |
down | True if a button was pressed, false if it was released |
clicks | The number of clicks (e.g. 1 = single click, 2 = double click) |
Definition at line 413 of file window.cpp.
|
virtual |
This function is called by poll_events() to handle mouse motion. This function should be overridden.
x | The x coordinate where the event occurred or the relative mouse movement along the x axis (see set_relative_mode) |
y | The y coordinate where the event occurred or the relative mouse movement along the y axis (see set_relative_mode) |
Definition at line 407 of file window.cpp.
|
virtual |
This function is called by poll_events() to handle mouse wheel movements. This function should be overridden.
x | The amount scrolled horizontally |
y | The amount scrolled vertically |
Definition at line 410 of file window.cpp.
|
virtual |
This function is called by run when the window is resized. This function should be overridden.
Definition at line 419 of file window.cpp.
void Window::poll_events | ( | ) |
Polls all events and calls the handlers. Called by the run function.
Definition at line 157 of file window.cpp.
void Window::run | ( | unsigned int | fps = 0 | ) |
Starts the main loop. This function calls poll_events() and display()
fps | The frames per second limit. Any number below 1 means no limit |
Definition at line 431 of file window.cpp.
void Window::set_cursor_visibility | ( | bool | show | ) |
Sets mouse cursor visibility.
show | True to show the cursor, false otherwise |
Definition at line 141 of file window.cpp.
bool Window::set_display_mode | ( | const SDL_DisplayMode & | mode | ) |
Changes the window display mode when in fullscreen mode.
mode | The display mode to set |
Definition at line 114 of file window.cpp.
void Window::set_icon | ( | const sgltk::Image & | icon | ) |
Sets the window icon.
icon | The icon to use |
Definition at line 82 of file window.cpp.
void Window::set_icon | ( | const std::string & | filename | ) |
Sets the window icon.
filename | The icon to use |
Definition at line 77 of file window.cpp.
void Window::set_mouse_position | ( | int | x, |
int | y ) |
Sets the mouse position inside the window.
x | The x coordiante inside the window |
y | The y coordiante inside the window |
Definition at line 137 of file window.cpp.
void Window::set_relative_mode | ( | bool | on | ) |
Activates the relative mouse motion mode In the relative mouse motion mode the cursor is invisible and stays in the middle of the screen. The x and y coordinates passed to the handle_mouse_motion function will be the relative horizontal and vertical distances traveled.
on | True to turn on, false to turn off |
Definition at line 132 of file window.cpp.
void Window::set_resizable | ( | bool | on | ) |
Sets or removes the ability to resize the window.
on | If true, the window is made resizable. If false, window becomes non-resizable. |
Definition at line 90 of file window.cpp.
void Window::set_title | ( | const std::string & | title | ) |
void Window::stop | ( | ) |
Stops the main loop.
Definition at line 461 of file window.cpp.
void Window::take_screenshot | ( | sgltk::Image & | image | ) |
Takes a screenshot of the window.
image | The image to save the screenshot to |
Definition at line 94 of file window.cpp.
double sgltk::Window::delta_time |