NAP
sdlhelpers.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local includes
8 #include "videodriver.h"
9 #include "display.h"
10 
11 // External Includes
12 #include <string>
13 #include <glm/glm.hpp>
14 #include <utility/dllexport.h>
15 #include <utility/errorstate.h>
16 #include <SDL_hints.h>
17 #include <SDL_surface.h>
18 
19 // SDL Forward declares
20 struct SDL_Window;
21 
22 namespace nap
23 {
24  namespace SDL
25  {
31  void NAPAPI showWindow(SDL_Window* window, bool show);
32 
37  void NAPAPI raiseWindow(SDL_Window* window);
38 
45  bool NAPAPI setFullscreen(SDL_Window* window, bool value);
46 
50  bool NAPAPI getFullscreen(SDL_Window* window);
51 
57  glm::ivec2 NAPAPI getWindowSize(SDL_Window* window);
58 
63  uint32 NAPAPI getWindowFlags(SDL_Window* window);
64 
69  glm::ivec2 NAPAPI getScreenSize(int screenIndex);
70 
76  void NAPAPI setWindowSize(SDL_Window* window, const glm::ivec2& size);
77 
83  glm::ivec2 NAPAPI getDrawableWindowSize(SDL_Window* window);
84 
90  glm::ivec2 NAPAPI getWindowPosition(SDL_Window* window);
91 
97  bool NAPAPI setWindowPosition(SDL_Window* window, const glm::ivec2& position);
98 
102  void NAPAPI shutdownVideo();
103 
107  std::string NAPAPI getSDLError();
108 
113  uint32_t NAPAPI getWindowId(SDL_Window* window);
114 
119  int NAPAPI getDisplayCount();
120 
125  NAPAPI std::vector<int> getDisplayIDs();
126 
131  NAPAPI std::vector<nap::Display> getDisplays();
132 
138  int NAPAPI getDisplayIndex(SDL_Window* window);
139 
144  bool NAPAPI getDisplayName(int displayIndex, std::string& outName);
145 
153  bool NAPAPI getDisplayBounds(int displayIndex, glm::ivec2& outMin, glm::ivec2& outMax);
154 
170  bool NAPAPI getDisplayContentScale(int displayIndex, float* scale);
171 
187  bool NAPAPI getDisplayContentScale(SDL_Window* window, float* scale);
188 
192  Display::EOrientation NAPAPI getDisplayOrientation(int displayIndex);
193 
204  bool NAPAPI getWindowPixelDensity(SDL_Window* window, float* density);
205 
220  bool NAPAPI getWindowDisplayScale(SDL_Window* window, float* scale);
221 
225  void NAPAPI hideCursor();
226 
230  void NAPAPI showCursor();
231 
236  bool NAPAPI cursorVisible();
237 
241  void NAPAPI toggleCursor();
242 
247  glm::vec2 NAPAPI getCursorPosition();
248 
254  glm::vec2 NAPAPI getGlobalCursorPosition();
255 
262  uint32 NAPAPI getMouseState(float* x, float* y);
263 
271  uint32 NAPAPI getGlobalMouseState(float* x, float* y);
272 
277  NAPAPI std::vector<std::string> getVideoDrivers();
278 
284  NAPAPI std::string getCurrentVideoDriver();
285 
291  bool NAPAPI initVideo(utility::ErrorState& error);
292 
299  bool NAPAPI initVideo(EVideoDriver driver, utility::ErrorState& error);
300 
305  bool NAPAPI videoInitialized();
306 
312  void NAPAPI setWindowBordered(SDL_Window* window, bool hasBorders);
313 
319  void NAPAPI setWindowTitle(SDL_Window* window, const std::string& name);
320 
326  void NAPAPI setWindowAlwaysOnTop(SDL_Window* window, bool enabled);
327 
333  void NAPAPI setWindowResizable(SDL_Window* window, bool enabled);
334 
342  using SurfacePtr = std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface*)>>;
343  NAPAPI SurfacePtr createSurface(const std::string& imagePath, utility::ErrorState& error);
344 
349  bool NAPAPI enableTextInput(SDL_Window* window);
350 
355  bool NAPAPI disableTextInput(SDL_Window* window);
356  }
357 }
nap::SDL::setWindowResizable
void NAPAPI setWindowResizable(SDL_Window *window, bool enabled)
nap::SDL::getDisplayIndex
int NAPAPI getDisplayIndex(SDL_Window *window)
nap::SDL::initVideo
bool NAPAPI initVideo(utility::ErrorState &error)
nap::SDL::getWindowDisplayScale
bool NAPAPI getWindowDisplayScale(SDL_Window *window, float *scale)
nap::SDL::getWindowId
uint32_t NAPAPI getWindowId(SDL_Window *window)
nap::SDL::toggleCursor
void NAPAPI toggleCursor()
nap::SDL::setWindowPosition
bool NAPAPI setWindowPosition(SDL_Window *window, const glm::ivec2 &position)
nap::SDL::hideCursor
void NAPAPI hideCursor()
nap::SDL::cursorVisible
bool NAPAPI cursorVisible()
nap::SDL::showWindow
void NAPAPI showWindow(SDL_Window *window, bool show)
nap::SDL::createSurface
NAPAPI SurfacePtr createSurface(const std::string &imagePath, utility::ErrorState &error)
nap::SDL::getGlobalMouseState
uint32 NAPAPI getGlobalMouseState(float *x, float *y)
nap::SDL::showCursor
void NAPAPI showCursor()
nap::SDL::getDisplayIDs
NAPAPI std::vector< int > getDisplayIDs()
nap::SDL::setWindowAlwaysOnTop
void NAPAPI setWindowAlwaysOnTop(SDL_Window *window, bool enabled)
nap::SDL::setFullscreen
bool NAPAPI setFullscreen(SDL_Window *window, bool value)
nap::utility::ErrorState
Definition: errorstate.h:19
nap::SDL::getMouseState
uint32 NAPAPI getMouseState(float *x, float *y)
nap::SDL::getDisplayCount
int NAPAPI getDisplayCount()
nap::SDL::videoInitialized
bool NAPAPI videoInitialized()
nap::SDL::enableTextInput
bool NAPAPI enableTextInput(SDL_Window *window)
nap::EVideoDriver
EVideoDriver
Definition: videodriver.h:20
nap::SDL::setWindowBordered
void NAPAPI setWindowBordered(SDL_Window *window, bool hasBorders)
nap::uint32
uint32_t uint32
Definition: numeric.h:20
nap::SDL::getDisplayContentScale
bool NAPAPI getDisplayContentScale(int displayIndex, float *scale)
nap::SDL::getFullscreen
bool NAPAPI getFullscreen(SDL_Window *window)
nap::SDL::getWindowSize
glm::ivec2 NAPAPI getWindowSize(SDL_Window *window)
nap::SDL::getDisplays
NAPAPI std::vector< nap::Display > getDisplays()
nap::Display::EOrientation
EOrientation
Definition: display.h:30
nap::SDL::getCurrentVideoDriver
NAPAPI std::string getCurrentVideoDriver()
nap::SDL::SurfacePtr
std::unique_ptr< SDL_Surface, std::function< void(SDL_Surface *)> > SurfacePtr
Definition: sdlhelpers.h:342
nap::SDL::getGlobalCursorPosition
glm::vec2 NAPAPI getGlobalCursorPosition()
nap::SDL::getDrawableWindowSize
glm::ivec2 NAPAPI getDrawableWindowSize(SDL_Window *window)
nap::SDL::setWindowTitle
void NAPAPI setWindowTitle(SDL_Window *window, const std::string &name)
nap::SDL::getWindowPixelDensity
bool NAPAPI getWindowPixelDensity(SDL_Window *window, float *density)
nap::SDL::disableTextInput
bool NAPAPI disableTextInput(SDL_Window *window)
nap
Definition: templateapp.h:17
nap::SDL::getWindowFlags
uint32 NAPAPI getWindowFlags(SDL_Window *window)
nap::SDL::getVideoDrivers
NAPAPI std::vector< std::string > getVideoDrivers()
nap::SDL::getWindowPosition
glm::ivec2 NAPAPI getWindowPosition(SDL_Window *window)
nap::SDL::getCursorPosition
glm::vec2 NAPAPI getCursorPosition()
nap::SDL::getDisplayName
bool NAPAPI getDisplayName(int displayIndex, std::string &outName)
nap::SDL::shutdownVideo
void NAPAPI shutdownVideo()
nap::SDL::setWindowSize
void NAPAPI setWindowSize(SDL_Window *window, const glm::ivec2 &size)
nap::SDL::getDisplayBounds
bool NAPAPI getDisplayBounds(int displayIndex, glm::ivec2 &outMin, glm::ivec2 &outMax)
nap::SDL::getScreenSize
glm::ivec2 NAPAPI getScreenSize(int screenIndex)
nap::SDL::getDisplayOrientation
Display::EOrientation NAPAPI getDisplayOrientation(int displayIndex)
nap::SDL::getSDLError
std::string NAPAPI getSDLError()
nap::SDL::raiseWindow
void NAPAPI raiseWindow(SDL_Window *window)