sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
sgltk::Window Class Reference

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.

Detailed Description

Provides windows with OpenGL context.

Definition at line 34 of file window.h.

Constructor & Destructor Documentation

◆ Window()

Window::Window ( const std::string & title,
int res_x,
int res_y,
int offset_x,
int offset_y,
unsigned int flags = 0 )
Parameters
titleThe window tile
res_xThe x window resolution
res_yThe y window resolution
offset_xThe x position offset of the window
offset_yThe y position offset of the window
flagsAdditional 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::~Window ( )

Definition at line 66 of file window.cpp.

Member Function Documentation

◆ display()

void Window::display ( )
virtual

This function is called by run() to draw a frame. This function should be overridden.

Definition at line 426 of file window.cpp.

◆ fullscreen_mode()

bool Window::fullscreen_mode ( sgltk::WINDOW_MODE mode)

Changes the window mode.

Parameters
modeThe window mode to set
Returns
Returns true on success or false on failure

Definition at line 123 of file window.cpp.

◆ get_cursor_visibility()

bool Window::get_cursor_visibility ( )

Returns mouse cursor visibility status.

Returns
Returns true if the cursor is visible, false otherwise

Definition at line 149 of file window.cpp.

◆ get_display_index()

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.

Returns
Returns the index of the display that currently contains the window or a negative number on failure.

Definition at line 105 of file window.cpp.

◆ grab_mouse()

void Window::grab_mouse ( bool on)

Sets the window to grab the mouse When activate the mouse can not leave the window boundaries.

Parameters
onTrue to turn on, false to turn off

Definition at line 101 of file window.cpp.

◆ handle_exit()

void Window::handle_exit ( )
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.

◆ handle_gamepad_added()

void Window::handle_gamepad_added ( std::shared_ptr< sgltk::Gamepad > gamepad)
virtual

This function is called by poll_events() to handle the addition of new gamepads. This function should be overridden.

Parameters
gamepadThe gamepad that has been connected

Definition at line 356 of file window.cpp.

◆ handle_gamepad_axis()

void Window::handle_gamepad_axis ( std::shared_ptr< sgltk::Gamepad > gamepad,
unsigned int axis,
int value )
virtual

This function is called by poll_events() every frame for every axis of every gamepad. This function should be overridden.

Parameters
gamepadThe gamepad that the axis is on
axisThe id number of the axis that has a new value
valueThe new value of the axis

Definition at line 368 of file window.cpp.

◆ handle_gamepad_axis_change()

void Window::handle_gamepad_axis_change ( std::shared_ptr< sgltk::Gamepad > gamepad,
unsigned int axis,
int value )
virtual

This function is called by poll_events() for every axis value change. This function should be overridden.

Parameters
gamepadThe gamepad that the axis is on
axisThe id number of the axis that has a new value
valueThe new value of the axis

Definition at line 371 of file window.cpp.

◆ handle_gamepad_button()

void Window::handle_gamepad_button ( std::shared_ptr< sgltk::Gamepad > gamepad,
int button )
virtual

This function is called by poll_events() every frame for every gamepad button currently being pressed. This function should be overridden.

Parameters
gamepadThe gamepad that the button is on
buttonThe id number of the button pressed or released

Definition at line 362 of file window.cpp.

◆ handle_gamepad_button_press()

void Window::handle_gamepad_button_press ( std::shared_ptr< sgltk::Gamepad > gamepad,
int button,
bool pressed )
virtual

This function is called by poll_events() once for every gamepad button press or release. This function should be overridden.

Parameters
gamepadThe gamepad that the button is on
buttonThe id number of the button pressed or released
pressedIndicates whether the button was pressed (true) or released (false)

Definition at line 365 of file window.cpp.

◆ handle_gamepad_removed()

void Window::handle_gamepad_removed ( unsigned int gamepad_id)
virtual

This function is called by poll_events() to handle the removal of gamepads. This function should be overridden.

Parameters
gamepad_idThe gamepad id

Definition at line 359 of file window.cpp.

◆ handle_joystick_added()

void Window::handle_joystick_added ( std::shared_ptr< sgltk::Joystick > joystick)
virtual

This function is called by poll_events() to handle the addition of new joysticks. This function should be overridden.

Parameters
joystickThe joystick that has been connected

Definition at line 374 of file window.cpp.

◆ handle_joystick_axis()

void Window::handle_joystick_axis ( std::shared_ptr< sgltk::Joystick > joystick,
unsigned int axis,
int value )
virtual

This function is called by poll_events() every frame for every axis of every joystick. This function should be overridden.

Parameters
joystickThe joystick that the axis is on
axisThe id number of the axis that has a new value
valueThe new value of the axis

Definition at line 386 of file window.cpp.

◆ handle_joystick_axis_change()

void Window::handle_joystick_axis_change ( std::shared_ptr< sgltk::Joystick > joystick,
unsigned int axis,
int value )
virtual

This function is called by poll_events() for every axis value change. This function should be overridden.

Parameters
joystickThe joystick that the axis is on
axisThe id number of the axis that has a new value
valueThe new value of the axis

Definition at line 389 of file window.cpp.

◆ handle_joystick_ball_motion()

void Window::handle_joystick_ball_motion ( std::shared_ptr< sgltk::Joystick > joystick,
unsigned int ball,
int xrel,
int yrel )
virtual

This function is called by poll_events() for every ball that has changed value change. This function should be overridden.

Parameters
joystickThe joystick that the ball is on
ballThe id number of the hat that has a new value
xrelThe new value of the hat
yrelThe new value of the hat

Definition at line 398 of file window.cpp.

◆ handle_joystick_button()

void Window::handle_joystick_button ( std::shared_ptr< sgltk::Joystick > joystick,
int button )
virtual

This function is called by poll_events() every frame for every joystick button currently being pressed. This function should be overridden.

Parameters
joystickThe joystick that the button is on
buttonThe id number of the button pressed or released

Definition at line 380 of file window.cpp.

◆ handle_joystick_button_press()

void Window::handle_joystick_button_press ( std::shared_ptr< sgltk::Joystick > joystick,
int button,
bool pressed )
virtual

This function is called by poll_events() once for every joystick button pressed or released. This function should be overridden.

Parameters
joystickThe joystick that the button is on
buttonThe id number of the button pressed or released
pressedIndicates whether the button was pressed (true) or released (false)

Definition at line 383 of file window.cpp.

◆ handle_joystick_hat()

void Window::handle_joystick_hat ( std::shared_ptr< sgltk::Joystick > joystick,
unsigned int hat,
unsigned int value )
virtual

This function is called by poll_events() every frame for every hat of every joystick. This function should be overridden.

Parameters
joystickThe joystick that the hat is on
hatThe id number of the hat that has a new value
valueThe new value of the hat

Definition at line 392 of file window.cpp.

◆ handle_joystick_hat_change()

void Window::handle_joystick_hat_change ( std::shared_ptr< sgltk::Joystick > joystick,
unsigned int hat,
unsigned int value )
virtual

This function is called by poll_events() for every hat value change. This function should be overridden.

Parameters
joystickThe joystick that the hat is on
hatThe id number of the hat that has a new value
valueThe new value of the hat

Definition at line 395 of file window.cpp.

◆ handle_joystick_removed()

void Window::handle_joystick_removed ( unsigned int joystick_id)
virtual

This function is called by poll_events() to handle the removal of joysticks. This function should be overridden.

Parameters
joystick_idThe joystick id

Definition at line 377 of file window.cpp.

◆ handle_key_press()

void Window::handle_key_press ( const std::string & key,
bool pressed )
virtual

This function is called by poll_events() once for every key pressed or released. This function should be overridden.

Parameters
keyThe name of the key being pressed
pressedTrue if the key has been pressed, false otherwise

Definition at line 404 of file window.cpp.

◆ handle_keyboard()

void Window::handle_keyboard ( const std::string & key)
virtual

This function is called by poll_events() every frame for every key currently being pressed. This function should be overridden.

Parameters
keyThe name of the key being pressed

Definition at line 401 of file window.cpp.

◆ handle_mouse_button()

void Window::handle_mouse_button ( int x,
int y,
int button,
bool down,
int clicks )
virtual

This function is called by poll_events() to handle mouse button presses. This function should be overridden.

Parameters
xThe x coordinate where the event occurred
yThe y coordinate where the event occurred
buttonThe button that caused the event
downTrue if a button was pressed, false if it was released
clicksThe number of clicks (e.g. 1 = single click, 2 = double click)

Definition at line 413 of file window.cpp.

◆ handle_mouse_motion()

void Window::handle_mouse_motion ( int x,
int y )
virtual

This function is called by poll_events() to handle mouse motion. This function should be overridden.

Parameters
xThe x coordinate where the event occurred or the relative mouse movement along the x axis (see set_relative_mode)
yThe 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.

◆ handle_mouse_wheel()

void Window::handle_mouse_wheel ( int x,
int y )
virtual

This function is called by poll_events() to handle mouse wheel movements. This function should be overridden.

Parameters
xThe amount scrolled horizontally
yThe amount scrolled vertically

Definition at line 410 of file window.cpp.

◆ handle_resize()

void Window::handle_resize ( )
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.

◆ poll_events()

void Window::poll_events ( )

Polls all events and calls the handlers. Called by the run function.

Definition at line 157 of file window.cpp.

◆ run()

void Window::run ( unsigned int fps = 0)

Starts the main loop. This function calls poll_events() and display()

Parameters
fpsThe frames per second limit. Any number below 1 means no limit

Definition at line 431 of file window.cpp.

◆ set_cursor_visibility()

void Window::set_cursor_visibility ( bool show)

Sets mouse cursor visibility.

Parameters
showTrue to show the cursor, false otherwise

Definition at line 141 of file window.cpp.

◆ set_display_mode()

bool Window::set_display_mode ( const SDL_DisplayMode & mode)

Changes the window display mode when in fullscreen mode.

Parameters
modeThe display mode to set
Returns
Returns true on success, false otherwise

Definition at line 114 of file window.cpp.

◆ set_icon() [1/2]

void Window::set_icon ( const sgltk::Image & icon)

Sets the window icon.

Parameters
iconThe icon to use
Note
The image size should not exceed 356x356 pixel.

Definition at line 82 of file window.cpp.

◆ set_icon() [2/2]

void Window::set_icon ( const std::string & filename)

Sets the window icon.

Parameters
filenameThe icon to use
Note
The image size should not exceed 356x356 pixel.

Definition at line 77 of file window.cpp.

◆ set_mouse_position()

void Window::set_mouse_position ( int x,
int y )

Sets the mouse position inside the window.

Parameters
xThe x coordiante inside the window
yThe y coordiante inside the window

Definition at line 137 of file window.cpp.

◆ set_relative_mode()

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.

Parameters
onTrue to turn on, false to turn off

Definition at line 132 of file window.cpp.

◆ set_resizable()

void Window::set_resizable ( bool on)

Sets or removes the ability to resize the window.

Parameters
onIf true, the window is made resizable. If false, window becomes non-resizable.

Definition at line 90 of file window.cpp.

◆ set_title()

void Window::set_title ( const std::string & title)

Set window title.

Parameters
titleThe new window title

Definition at line 86 of file window.cpp.

◆ stop()

void Window::stop ( )

Stops the main loop.

Definition at line 461 of file window.cpp.

◆ take_screenshot()

void Window::take_screenshot ( sgltk::Image & image)

Takes a screenshot of the window.

Parameters
imageThe image to save the screenshot to

Definition at line 94 of file window.cpp.

Member Data Documentation

◆ delta_time

double sgltk::Window::delta_time

The time it took to draw the last frame.

Definition at line 64 of file window.h.

◆ gl_maj

int sgltk::Window::gl_maj

The manjor OpenGL version number.

Definition at line 48 of file window.h.

◆ gl_min

int sgltk::Window::gl_min

The minor OpenGL version number.

Definition at line 52 of file window.h.

◆ height

int sgltk::Window::height

The height of the window surface.

Definition at line 60 of file window.h.

◆ width

int sgltk::Window::width

The width of the window surface.

Definition at line 56 of file window.h.

◆ window

SDL_Window* sgltk::Window::window

The window surface.

Definition at line 68 of file window.h.


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