NAP
Typedefs | Functions
nap::SDL Namespace Reference

Typedefs

using SurfacePtr = std::unique_ptr< SDL_Surface, std::function< void(SDL_Surface *)> >
 

Functions

void NAPAPI showWindow (SDL_Window *window, bool show)
 
void NAPAPI raiseWindow (SDL_Window *window)
 
bool NAPAPI setFullscreen (SDL_Window *window, bool value)
 
bool NAPAPI getFullscreen (SDL_Window *window)
 
glm::ivec2 NAPAPI getWindowSize (SDL_Window *window)
 
uint32 NAPAPI getWindowFlags (SDL_Window *window)
 
glm::ivec2 NAPAPI getScreenSize (int screenIndex)
 
void NAPAPI setWindowSize (SDL_Window *window, const glm::ivec2 &size)
 
glm::ivec2 NAPAPI getDrawableWindowSize (SDL_Window *window)
 
glm::ivec2 NAPAPI getWindowPosition (SDL_Window *window)
 
bool NAPAPI setWindowPosition (SDL_Window *window, const glm::ivec2 &position)
 
void NAPAPI shutdownVideo ()
 
std::string NAPAPI getSDLError ()
 
uint32_t NAPAPI getWindowId (SDL_Window *window)
 
int NAPAPI getDisplayCount ()
 
NAPAPI std::vector< int > getDisplayIDs ()
 
NAPAPI std::vector< nap::DisplaygetDisplays ()
 
int NAPAPI getDisplayIndex (SDL_Window *window)
 
bool NAPAPI getDisplayName (int displayIndex, std::string &outName)
 
bool NAPAPI getDisplayBounds (int displayIndex, glm::ivec2 &outMin, glm::ivec2 &outMax)
 
bool NAPAPI getDisplayContentScale (int displayIndex, float *scale)
 
bool NAPAPI getDisplayContentScale (SDL_Window *window, float *scale)
 
Display::EOrientation NAPAPI getDisplayOrientation (int displayIndex)
 
bool NAPAPI getWindowPixelDensity (SDL_Window *window, float *density)
 
bool NAPAPI getWindowDisplayScale (SDL_Window *window, float *scale)
 
void NAPAPI hideCursor ()
 
void NAPAPI showCursor ()
 
bool NAPAPI cursorVisible ()
 
void NAPAPI toggleCursor ()
 
glm::vec2 NAPAPI getCursorPosition ()
 
glm::vec2 NAPAPI getGlobalCursorPosition ()
 
uint32 NAPAPI getMouseState (float *x, float *y)
 
uint32 NAPAPI getGlobalMouseState (float *x, float *y)
 
NAPAPI std::vector< std::string > getVideoDrivers ()
 
NAPAPI std::string getCurrentVideoDriver ()
 
bool NAPAPI initVideo (utility::ErrorState &error)
 
bool NAPAPI initVideo (EVideoDriver driver, utility::ErrorState &error)
 
bool NAPAPI videoInitialized ()
 
void NAPAPI setWindowBordered (SDL_Window *window, bool hasBorders)
 
void NAPAPI setWindowTitle (SDL_Window *window, const std::string &name)
 
void NAPAPI setWindowAlwaysOnTop (SDL_Window *window, bool enabled)
 
void NAPAPI setWindowResizable (SDL_Window *window, bool enabled)
 
NAPAPI SurfacePtr createSurface (const std::string &imagePath, utility::ErrorState &error)
 
bool NAPAPI enableTextInput (SDL_Window *window)
 
bool NAPAPI disableTextInput (SDL_Window *window)
 

Typedef Documentation

◆ SurfacePtr

using SurfacePtr = std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface*)> >

Create a 4 channel (RGBA) pixel surface from image on disk. RGB images are converted to RGBA, where the alpha channel is initialized to '255'.

Parameters
imagePathabsolute path to image on disk
errorthe error if creation fails
Returns
surface created from image, nullptr if creation failed

Function Documentation

◆ createSurface()

NAPAPI SurfacePtr nap::SDL::createSurface ( const std::string &  imagePath,
utility::ErrorState error 
)

◆ cursorVisible()

bool NAPAPI nap::SDL::cursorVisible ( )

Returns if the cursor is visible

Returns
if the cursor is visible

◆ disableTextInput()

bool NAPAPI nap::SDL::disableTextInput ( SDL_Window *  window)

Stop accepting Unicode text input events in a window.

Parameters
windowthe window to enable text input from

◆ enableTextInput()

bool NAPAPI nap::SDL::enableTextInput ( SDL_Window *  window)

Start accepting Unicode text input events in a window.

Parameters
windowthe window to enable text input from

◆ getCurrentVideoDriver()

NAPAPI std::string nap::SDL::getCurrentVideoDriver ( )

Get the current SDL video driver. Note that the name of an SDL video driver is always lower-case, without capitals.

Returns
current SDL video driver

◆ getCursorPosition()

glm::vec2 NAPAPI nap::SDL::getCursorPosition ( )

Returns the mouse cursor position relative to the focus window.

Returns
cursor position relative to the focus window

◆ getDisplayBounds()

bool NAPAPI nap::SDL::getDisplayBounds ( int  displayIndex,
glm::ivec2 &  outMin,
glm::ivec2 &  outMax 
)

Gets desktop area represented by a display, with the primary display located at 0,0

Parameters
displayIndexindex of the display to get the bounds for
outMinmin position of desktop area represented by a display, with the primary display located at 0,0
outMaxmax position of desktop area represented by a display, with the primary display located at 0,0
Returns
true on success, false on failure

◆ getDisplayContentScale() [1/2]

bool NAPAPI nap::SDL::getDisplayContentScale ( int  displayIndex,
float *  scale 
)

Get the content scale of a display.

The content scale is the expected scale for content based on the DPI settings of the display. For example, a 4K display might have a 2.0 (200%) display scale, which means that the user expects UI elements to be twice as big on this display, to aid in readability.

SDL_GetWindowDisplayScale() should be used to query the content scale factor for individual windows, instead of querying the display for a window and calling this function, as the per-window content scale factor may differ from the base value of the display it is on, particularly on high-DPI and/or multi-monitor desktop configurations.

Parameters
displayIndexThe index of the display
scalethe returned scale, 0.0 if call fails
Returns
if the call succeeded

◆ getDisplayContentScale() [2/2]

bool NAPAPI nap::SDL::getDisplayContentScale ( SDL_Window *  window,
float *  scale 
)

Get the content scale of a display.

The content scale is the expected scale for content based on the DPI settings of the display. For example, a 4K display might have a 2.0 (200%) display scale, which means that the user expects UI elements to be twice as big on this display, to aid in readability.

SDL_GetWindowDisplayScale() should be used to query the content scale factor for individual windows, instead of querying the display for a window and calling this function, as the per-window content scale factor may differ from the base value of the display it is on, particularly on high-DPI and/or multi-monitor desktop configurations.

Parameters
windowthe window to get the content scale for
scalethe display content scaling factor, 0.0 if call fails
Returns
if the call succeeded

◆ getDisplayCount()

int NAPAPI nap::SDL::getDisplayCount ( )

Get the number of available video displays.

Returns
Number of unique displays, negative value on failure;

◆ getDisplayIDs()

NAPAPI std::vector<int> nap::SDL::getDisplayIDs ( )

Returns list of unique display ids, 0 on failure

Returns
array of unique display ids, 0 on failure

◆ getDisplayIndex()

int NAPAPI nap::SDL::getDisplayIndex ( SDL_Window *  window)

Get the unique index of the display associated with a window.

Parameters
windowthe window to get the display index for
Returns
The unique display index on success, negative on failure.

◆ getDisplayName()

bool NAPAPI nap::SDL::getDisplayName ( int  displayIndex,
std::string &  outName 
)
Parameters
displayIndexindex of display to get name for
outNamedisplay name for given display index

◆ getDisplayOrientation()

Display::EOrientation NAPAPI nap::SDL::getDisplayOrientation ( int  displayIndex)

@reutn the way a display is rotated.

◆ getDisplays()

NAPAPI std::vector<nap::Display> nap::SDL::getDisplays ( )

Returns a list of currently attached displays.

Returns
a list of currently attached displays

◆ getDrawableWindowSize()

glm::ivec2 NAPAPI nap::SDL::getDrawableWindowSize ( SDL_Window *  window)

Returns the actual size in pixels of a window, which can be different from the represented window size. This is the case with High DPI screens on OSX

Returns
the actual size in pixels of a window

◆ getFullscreen()

bool NAPAPI nap::SDL::getFullscreen ( SDL_Window *  window)

Returns if the window is full screen (Desktop)

◆ getGlobalCursorPosition()

glm::vec2 NAPAPI nap::SDL::getGlobalCursorPosition ( )

Get the position of the cursor, in relation to the desktop. This works just like getCursorPosition(), but the coordinates will be reported relative to the top-left of the desktop. Current position of the cursor, in relation to the desktop

◆ getGlobalMouseState()

uint32 NAPAPI nap::SDL::getGlobalMouseState ( float *  x,
float *  y 
)

Get the current state of the mouse, in relation to the desktop. This works just like getMouseState(), but the coordinates will be reported relative to the top-left of the desktop.

Parameters
xthe current x coordinate, relative to the desktop. Can be nullptr
ythe current y coordinate, relative to the desktop. Can be nullptr
Returns
The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.

◆ getMouseState()

uint32 NAPAPI nap::SDL::getMouseState ( float *  x,
float *  y 
)

Get the current state of the mouse relative to the focus window.

Parameters
xthe current x coordinate. Can be nullptr
ythe current y coordinate. Can be nullptr
Returns
The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.

◆ getScreenSize()

glm::ivec2 NAPAPI nap::SDL::getScreenSize ( int  screenIndex)
Parameters
screenIndexthe number of the display
Returns
the screen resolution in pixels, on failure return value is -1

◆ getSDLError()

std::string NAPAPI nap::SDL::getSDLError ( )

@ return the last SDL error as a string

◆ getVideoDrivers()

NAPAPI std::vector<std::string> nap::SDL::getVideoDrivers ( )

Get all available video drivers.

Returns
all available video drivers

◆ getWindowDisplayScale()

bool NAPAPI nap::SDL::getWindowDisplayScale ( SDL_Window *  window,
float *  scale 
)

Get the content display scale relative to a window's pixel size.

This is a combination of the window pixel density and the display content scale, and is the expected scale for displaying content in this window. For example, if a 3840x2160 window had a display scale of 2.0, the user expects the content to take twice as many pixels and be the same physical size as if it were being displayed in a 1920x1080 window with a display scale of 1.0.

Conceptually this value corresponds to the scale display setting, and is updated when that setting is changed, or the window moves to a display with a different scale setting.

Parameters
windowthe window to get the content scale for
scalethe window content scale, 0.0 if call fails
Returns
if call succeeded

◆ getWindowFlags()

uint32 NAPAPI nap::SDL::getWindowFlags ( SDL_Window *  window)
Parameters
windowthe window to get the flags for
Returns
flags associated with the given window

◆ getWindowId()

uint32_t NAPAPI nap::SDL::getWindowId ( SDL_Window *  window)
Returns
the id associated with a specific SDL window
Parameters
windowthe SDL window to get the id for

◆ getWindowPixelDensity()

bool NAPAPI nap::SDL::getWindowPixelDensity ( SDL_Window *  window,
float *  density 
)

Get the pixel density of a window, this is a ratio of pixel size to window size.

For example, if the window is 1920x1080 and it has a high density back buffer of 3840x2160 pixels, it would have a pixel density of 2.0.

Parameters
windowthe window to get the pixel density for
densitythe window pixel density, 0.0 if call fails
Returns
if call succeeded

◆ getWindowPosition()

glm::ivec2 NAPAPI nap::SDL::getWindowPosition ( SDL_Window *  window)

returns the window position as pixel coordinates

Parameters
windowthe window to get the position for
Returns
the window position in pixels

◆ getWindowSize()

glm::ivec2 NAPAPI nap::SDL::getWindowSize ( SDL_Window *  window)

Returns the size of an SDL window

Parameters
windowthe window to retrieve the size for
Returns
the window size

◆ hideCursor()

void NAPAPI nap::SDL::hideCursor ( )

Hides the mouse cursor

◆ initVideo() [1/2]

bool NAPAPI nap::SDL::initVideo ( EVideoDriver  driver,
utility::ErrorState error 
)

Initializes the SDL video system using the given driver. Call this before creating any windows or render contexts!

Parameters
drivervideo back-end driver, call fails if driver is not available.
Returns
if the system initialized using the selected driver.

◆ initVideo() [2/2]

bool NAPAPI nap::SDL::initVideo ( utility::ErrorState error)

Initializes SDL video system. Call this before creating any windows or render contexts!

Returns
if the system initialized correctly or not

◆ raiseWindow()

void NAPAPI nap::SDL::raiseWindow ( SDL_Window *  window)

Makes sure the window is on top and receives input focus.

Parameters
windowthe window to raise

◆ setFullscreen()

bool NAPAPI nap::SDL::setFullscreen ( SDL_Window *  window,
bool  value 
)

Sets the window to be full screen in desktop mode

Parameters
windowthe window to enable / disable
valueif the window is full screen
Returns
if full screen operation succeeded

◆ setWindowAlwaysOnTop()

void NAPAPI nap::SDL::setWindowAlwaysOnTop ( SDL_Window *  window,
bool  enabled 
)

Brings the window to the front and keeps it there

Parameters
windowthe window to move to the front and keep on top
enabledif always on top should be enabled

◆ setWindowBordered()

void NAPAPI nap::SDL::setWindowBordered ( SDL_Window *  window,
bool  hasBorders 
)

Controls if the window has any borders.

Parameters
windowthe window to set
hasBordersif the window should have borders

◆ setWindowPosition()

bool NAPAPI nap::SDL::setWindowPosition ( SDL_Window *  window,
const glm::ivec2 &  position 
)

Set the position of a window on screen.

Parameters
windowthe window to set the position for
positionthe window location in pixels

◆ setWindowResizable()

void NAPAPI nap::SDL::setWindowResizable ( SDL_Window *  window,
bool  enabled 
)

Turn resizing of a window by a user on or off.

Parameters
windowthe resize window
enabledresize flag

◆ setWindowSize()

void NAPAPI nap::SDL::setWindowSize ( SDL_Window *  window,
const glm::ivec2 &  size 
)

resizes an SDL window

Parameters
windowthe window to resize
sizethe new window size

◆ setWindowTitle()

void NAPAPI nap::SDL::setWindowTitle ( SDL_Window *  window,
const std::string &  name 
)

Sets the window title.

Parameters
windowthe window to set the title for
namethe new window name

◆ showCursor()

void NAPAPI nap::SDL::showCursor ( )

Shows the mouse cursor

◆ showWindow()

void NAPAPI nap::SDL::showWindow ( SDL_Window *  window,
bool  show 
)

Makes a window visible.

Parameters
windowpointer to the window to make visible.
showif the window is shown or hidden

◆ shutdownVideo()

void NAPAPI nap::SDL::shutdownVideo ( )

Shutdown SDL

◆ toggleCursor()

void NAPAPI nap::SDL::toggleCursor ( )

Toggles cursor visibility on / off

◆ videoInitialized()

bool NAPAPI nap::SDL::videoInitialized ( )

Returns if the video subsystem has been initialized

Returns
if the SDL video subsystem has been initialized