15enum class WINDOW_MODE {
23 FULLSCREEN = SDL_WINDOW_FULLSCREEN,
27 FAKE_FULLSCREEN = SDL_WINDOW_FULLSCREEN_DESKTOP
36 static unsigned int cnt;
37 SDL_GLContext context;
40 unsigned int fps_time;
41 std::vector<std::string> keys_pressed;
42 EXPORT
static std::map<unsigned int, std::shared_ptr<Gamepad> > gamepad_instance_id_map;
43 EXPORT
static std::map<unsigned int, std::shared_ptr<Joystick> > joystick_instance_id_map;
79 EXPORT
Window(
const std::string& title,
int res_x,
int res_y,
int offset_x,
int offset_y,
unsigned int flags = 0);
87 EXPORT
void set_icon(
const std::string& filename);
98 EXPORT
void set_title(
const std::string& title);
197 int button,
bool pressed);
206 unsigned int axis,
int value);
215 unsigned int axis,
int value);
247 int button,
bool pressed);
256 unsigned int axis,
int value);
265 unsigned int axis,
int value);
274 unsigned int hat,
unsigned int value);
283 unsigned int hat,
unsigned int value);
337 bool down,
int clicks);
359 EXPORT
void run(
unsigned int fps = 0);
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 shoul...
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 overrid...
double delta_time
The time it took to draw the last frame.
int get_display_index()
Returns the index of the display that currently contains the window. This index corresponds to the in...
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...
void set_relative_mode(bool on)
Activates the relative mouse motion mode In the relative mouse motion mode the cursor is invisible an...
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.
void set_mouse_position(int x, int y)
Sets the mouse position inside the window.
void poll_events()
Polls all events and calls the handlers. Called by the run function.
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 over...
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 ove...
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....
void set_title(const std::string &title)
Set window title.
bool set_display_mode(const SDL_DisplayMode &mode)
Changes the window display mode when in fullscreen mode.
void stop()
Stops the main loop.
int gl_min
The minor OpenGL version number.
void set_cursor_visibility(bool show)
Sets mouse cursor visibility.
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 o...
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 overridd...
Window(const std::string &title, int res_x, int res_y, int offset_x, int offset_y, unsigned int flags=0)
int height
The height of the window surface.
int width
The width of the window surface.
virtual void handle_exit()
This function is called by run when the window is being closed. 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 overrid...
void run(unsigned int fps=0)
Starts the main loop. This function calls poll_events() and display()
bool fullscreen_mode(sgltk::WINDOW_MODE mode)
Changes the window mode.
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 ...
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....
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....
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....
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...
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.
bool get_cursor_visibility()
Returns mouse cursor visibility status.
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...
void grab_mouse(bool on)
Sets the window to grab the mouse When activate the mouse can not leave the window boundaries.
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....
int gl_maj
The manjor OpenGL version number.
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....
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 presse...
virtual void handle_keyboard(const std::string &key)
This function is called by poll_events() every frame for every key currently being pressed....
virtual void handle_resize()
This function is called by run when the window is resized. This function should be overridden.
SDL_Window * window
The window surface.
virtual void display()
This function is called by run() to draw a frame. This function should be overridden.
void set_icon(const std::string &filename)
Sets the window icon.