From a6208de4f8a50c32b71d03b4028d6e78ac19e632 Mon Sep 17 00:00:00 2001 From: Vraiment Date: Mon, 24 Jul 2017 23:48:14 -0700 Subject: [PATCH] Added GetDisplayDPI --- SDL2pp/Display.cc | 11 +++++++++++ SDL2pp/Display.hh | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/SDL2pp/Display.cc b/SDL2pp/Display.cc index 40733af..cecccf2 100644 --- a/SDL2pp/Display.cc +++ b/SDL2pp/Display.cc @@ -26,6 +26,17 @@ #include namespace SDL2pp { +#if SDL_VERSION_ATLEAST(2, 0, 4) +DPI GetDisplayDPI(int displayIndex) { + float diagonal = 0, horizontal = 0, vertical = 0; + if (SDL_GetDisplayDPI(displayIndex, &diagonal, &horizontal, &vertical) < 0) { + throw Exception("SDL_GetDisplayDPI"); + } + + return DPI{diagonal, horizontal, vertical}; +} +#endif + #if SDL_VERSION_ATLEAST(2, 0, 5) Rect GetDisplayUsableBounds(int displayIndex) { Rect result; diff --git a/SDL2pp/Display.hh b/SDL2pp/Display.hh index 5a1bef5..de584b7 100644 --- a/SDL2pp/Display.hh +++ b/SDL2pp/Display.hh @@ -29,6 +29,54 @@ #include namespace SDL2pp { +#if SDL_VERSION_ATLEAST(2, 0, 4) + //////////////////////////////////////////////////////////// + /// \brief Read-only struct to store DPI information of a display + /// + /// \ingroup graphics + /// + /// \headerfile SDL2pp/Display.hh + /// + //////////////////////////////////////////////////////////// + struct SDL2PP_EXPORT DPI { + //////////////////////////////////////////////////////////// + /// \brief The diagonal DPI of the display + /// + //////////////////////////////////////////////////////////// + const float Diagonal; + + //////////////////////////////////////////////////////////// + /// \brief The horizontal DPI of the display + /// + //////////////////////////////////////////////////////////// + const float Horizontal; + + //////////////////////////////////////////////////////////// + /// \brief The vertical DPI of the display + /// + //////////////////////////////////////////////////////////// + const float Vertical; + }; + + //////////////////////////////////////////////////////////// + /// \brief Gets the dots/pixels per inch of a given display + /// + /// \ingroup graphics + /// + /// \headerfile SDL2pp/Display.hh + /// + /// \param[in] displayIndex The display to retrieve the DPI + /// + /// \returns A DPI object with the dpi values for the given display + /// + /// \throws SDL2pp::Exception + /// + /// \see https://wiki.libsdl.org/SDL_GetDisplayDPI + /// + //////////////////////////////////////////////////////////// + SDL2PP_EXPORT DPI GetDisplayDPI(int displayIndex); +#endif + #if SDL_VERSION_ATLEAST(2, 0, 5) //////////////////////////////////////////////////////////// /// \brief Gets the usable desktop area of a given display