cpp-sdl2
C++ header-only SDL2 wrapper
|
Represent an SDL window. More...
#include <window.hpp>
Classes | |
class | GlContext |
Nested class that represent a managed OpenGL Context by the SDL. More... | |
Public Types | |
enum | gl_swap_interval { gl_swap_interval::immediate, gl_swap_interval::vsync, gl_swap_interval::adaptive_vsync } |
Define the type of window swapping strategy for opengl windows. More... | |
Public Member Functions | |
Window (std::string const &title, Vec2i const &size, Uint32 flags=SDL_WINDOW_SHOWN) | |
Construct a window. More... | |
Window ()=default | |
Construct an invalid window object. You will need to initialize it by moving in a real sdl::Window in. More... | |
Window (Window &&other) noexcept | |
Default move ctor. More... | |
Window & | operator= (Window &&other) noexcept |
Move assign operator. More... | |
Window (Window &)=delete | |
Window & | operator= (Window &)=delete |
virtual | ~Window () |
Destructor. Calls SDL_DestroyWindow() automatically for you. More... | |
SDL_Window * | ptr () const |
Getter for the raw SDL2 window pointer. More... | |
Renderer | make_renderer (Uint32 flags=SDL_RENDERER_ACCELERATED) const |
2D renderer factory. More... | |
int | display_index () const |
Get the current window display index. More... | |
void | set_display_mode (SDL_DisplayMode const &mode) const |
Set the window display mode. More... | |
SDL_DisplayMode | display_mode () const |
Get the current display mode. More... | |
Uint32 | flags () const |
Get the flags of this window. More... | |
Window & | grab (bool g=true) |
Grab window. More... | |
Window & | release (bool r=true) |
Release window. More... | |
bool | grabbed () const |
Is window grabed. More... | |
Window & | move_to (Vec2i const &v) |
Move window to specific location on screen. More... | |
Window & | move_by (Vec2i const &v) |
Translate window on screen. More... | |
Vec2i | position () const |
Get current window position. More... | |
void | resize (Vec2i const &newsize) const |
Change the size of the window the size of the window. More... | |
Vec2i | size () const |
Get current window size. More... | |
Window & | rename (std::string const &t) |
Change window name. More... | |
std::string | title () const |
the current window title More... | |
void | set_icon (Surface const &icon) const |
Set the window icon. More... | |
void | set_icon (std::string const &filename) const |
Set the window icon (may require linking and activating SDL_Image) More... | |
Window & | hide () |
Hide the window. More... | |
Window & | maximize () |
Maximize the window. More... | |
Window & | minimize () |
Minimize the window. More... | |
Window & | raise () |
Raise the window. More... | |
Window & | restore () |
Restore the window. More... | |
bool | fullscreen () const |
Returns true if window is currently fullscreen (both real and "desktop mode") More... | |
Window & | set_fullscreen (bool fs) |
Set the window fullscreen. More... | |
Window & | toggle_fullscreen () |
Toggle the window fullscreen. More... | |
SDL_SysWMinfo | wm_info () const |
Get window manager info. Exact content of this structure is fully platform dependant. More... | |
std::vector< const char * > | vk_get_instance_extensions () |
Enumerate the required extensions to create a VkSurfaceKHR on the current system. More... | |
VkSurfaceKHR | vk_create_surface (VkInstance instance) |
Create a vulkan surface for the current platform. More... | |
vk::UniqueSurfaceKHR | vk_create_unique_surface (vk::Instance instance) |
Create a vulkan surface using the C++ wrapper around UniqueHandle. More... | |
Vec2i | vk_get_drawable_size () |
Get the underlayoing drawable size of the window. More... | |
GlContext | create_context () const |
Create an OpenGL context from the current window. More... | |
void | gl_swap () const |
Swap buffers for GL when using double buffering on the current window. More... | |
Vec2i | gl_get_drawable_size () const |
Get the actual size of the OpenGL drawing area on the window. May not match window size on platform that uses display scaling. More... | |
Static Public Member Functions | |
static void | gl_set_attribute (SDL_GLattr attr, int val) |
static void | gl_set_attribute (SDL_GLattr attr, bool val) |
static int | gl_get_attribute (SDL_GLattr attr) |
Get the value of the specified OpenGL attribute. More... | |
static void | gl_reset_attribute () |
Reset all OpenGL attributes to their default values. More... | |
static bool | gl_is_extension_supported (std::string const &ext_name) |
Return true if the specified extension is supported. More... | |
static void | gl_set_swap_interval (gl_swap_interval swap_mode) |
Set the swap interval. If exception thrown while attempting to use adaptive vsync, use standard vsync. More... | |
static gl_swap_interval | gl_get_swap_interval () |
Get the current swap interval. More... | |
Private Attributes | |
SDL_Window * | window_ = nullptr |
Raw naked pointer to an SDL window. More... | |
Represent an SDL window.
Also contains accessor to any window related adjacent functionality like OpenGL/Vulkan helper functions
Definition at line 19 of file window.hpp.
|
strong |
Define the type of window swapping strategy for opengl windows.
Enumerator | |
---|---|
immediate | |
vsync | |
adaptive_vsync |
Definition at line 309 of file window.hpp.
|
inline |
Construct a window.
This safely create an SDL_Window for you
title | Name of the window |
size | Size of the window on screen when shown |
flags | Any flags needed to be passed to SDL_CreateWindow |
Definition at line 26 of file window.hpp.
|
default |
Construct an invalid window object. You will need to initialize it by moving in a real sdl::Window in.
Referenced by operator=(), and Window().
|
inlinenoexcept |
Default move ctor.
Definition at line 37 of file window.hpp.
|
delete |
|
inlinevirtual |
Destructor. Calls SDL_DestroyWindow() automatically for you.
Definition at line 58 of file window.hpp.
References window_.
|
inline |
Create an OpenGL context from the current window.
Definition at line 386 of file window.hpp.
References window_.
|
inline |
|
inline |
|
inline |
Get the flags of this window.
Definition at line 103 of file window.hpp.
References window_.
Referenced by fullscreen(), make_renderer(), and Window().
|
inline |
Returns true if window is currently fullscreen (both real and "desktop mode")
Definition at line 202 of file window.hpp.
References flags().
Referenced by toggle_fullscreen().
|
inlinestatic |
Get the value of the specified OpenGL attribute.
Definition at line 292 of file window.hpp.
|
inline |
Get the actual size of the OpenGL drawing area on the window. May not match window size on platform that uses display scaling.
Definition at line 392 of file window.hpp.
|
inlinestatic |
Get the current swap interval.
Definition at line 331 of file window.hpp.
References adaptive_vsync, immediate, and vsync.
|
inlinestatic |
Return true if the specified extension is supported.
Definition at line 303 of file window.hpp.
|
inlinestatic |
Reset all OpenGL attributes to their default values.
Definition at line 300 of file window.hpp.
|
inlinestatic |
Definition at line 284 of file window.hpp.
|
inlinestatic |
Definition at line 289 of file window.hpp.
References gl_set_attribute().
Referenced by gl_set_attribute().
|
inlinestatic |
Set the swap interval. If exception thrown while attempting to use adaptive vsync, use standard vsync.
Definition at line 317 of file window.hpp.
References adaptive_vsync, immediate, and vsync.
|
inline |
Swap buffers for GL when using double buffering on the current window.
Definition at line 389 of file window.hpp.
References window_.
|
inline |
Grab window.
Definition at line 106 of file window.hpp.
References window_.
Referenced by release().
|
inline |
|
inline |
|
inline |
2D renderer factory.
Permit to easily create a 2D renderer. Hardware acceleration enabled by default
flags | Any flags needed to be passed to SDL_CreateRenderer. |
Definition at line 66 of file window.hpp.
|
inline |
|
inline |
Translate window on screen.
v | translation vector |
Definition at line 127 of file window.hpp.
References move_to(), and position().
Move window to specific location on screen.
v | Vector pointing to the new window location |
Definition at line 120 of file window.hpp.
References window_.
Referenced by move_by().
Move assign operator.
If this object represent a valid window, it will be destroyed before acquiring the window_ pointer from other
other | Another sdl::Window object |
Definition at line 42 of file window.hpp.
References Window(), and window_.
Referenced by sdl::Window::GlContext::~GlContext().
|
inline |
Get current window position.
Definition at line 129 of file window.hpp.
References window_.
Referenced by move_by().
|
inline |
Getter for the raw SDL2 window pointer.
Definition at line 61 of file window.hpp.
References window_.
Referenced by sdl::show_message_box(), and sdl::Mouse::warp_in_window().
|
inline |
|
inline |
|
inline |
Change window name.
t | new window "title" |
Definition at line 149 of file window.hpp.
References window_.
|
inline |
Change the size of the window the size of the window.
Definition at line 138 of file window.hpp.
References window_.
|
inline |
|
inline |
Set the window display mode.
mode | Display mode to use |
Definition at line 83 of file window.hpp.
References window_.
|
inline |
Set the window fullscreen.
Definition at line 207 of file window.hpp.
References window_.
Referenced by toggle_fullscreen().
|
inline |
Set the window icon.
icon | Surface containing the icon to use |
Definition at line 159 of file window.hpp.
References sdl::Surface::ptr(), and window_.
|
inline |
Set the window icon (may require linking and activating SDL_Image)
filename | path to a file you can use to set the window icon |
Definition at line 163 of file window.hpp.
References window_.
|
inline |
Get current window size.
Definition at line 140 of file window.hpp.
References window_.
Referenced by gl_get_drawable_size(), and vk_get_drawable_size().
|
inline |
|
inline |
Toggle the window fullscreen.
Definition at line 217 of file window.hpp.
References fullscreen(), and set_fullscreen().
|
inline |
Create a vulkan surface for the current platform.
Definition at line 252 of file window.hpp.
References window_.
Referenced by vk_create_unique_surface().
|
inline |
Create a vulkan surface using the C++ wrapper around UniqueHandle.
Definition at line 262 of file window.hpp.
References vk_create_surface().
|
inline |
Get the underlayoing drawable size of the window.
Use this for vulkan viewport size, scissor rects and any place you need VkExtent
s
Definition at line 270 of file window.hpp.
|
inline |
Enumerate the required extensions to create a VkSurfaceKHR on the current system.
Definition at line 234 of file window.hpp.
Referenced by wm_info().
|
inline |
Get window manager info. Exact content of this structure is fully platform dependant.
Definition at line 220 of file window.hpp.
References vk_get_instance_extensions(), and window_.
|
private |
Raw naked pointer to an SDL window.
Definition at line 403 of file window.hpp.
Referenced by create_context(), display_index(), display_mode(), flags(), gl_get_drawable_size(), gl_swap(), grab(), grabbed(), hide(), make_renderer(), maximize(), minimize(), move_to(), operator=(), position(), ptr(), raise(), rename(), resize(), restore(), set_display_mode(), set_fullscreen(), set_icon(), size(), title(), vk_create_surface(), vk_get_drawable_size(), Window(), wm_info(), and ~Window().