From 8aaf1815e089507b701c41b85c80c3f8a40b1e56 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Thu, 15 Jan 2015 16:51:17 +0300 Subject: [PATCH] Implement some Renderer getters --- SDL2pp/Renderer.cc | 46 +++++++++++++++++++++++ SDL2pp/Renderer.hh | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/SDL2pp/Renderer.cc b/SDL2pp/Renderer.cc index 2884c61..888c82e 100644 --- a/SDL2pp/Renderer.cc +++ b/SDL2pp/Renderer.cc @@ -227,4 +227,50 @@ bool Renderer::TargetSupported() { return SDL_RenderTargetSupported(renderer_) == SDL_TRUE; } +Rect Renderer::GetClipRect() const { + SDL_Rect rect; + SDL_RenderGetClipRect(renderer_, &rect); + return rect; +} + +Point Renderer::GetLogicalSize() const { + int w, h; + SDL_RenderGetLogicalSize(renderer_, &w, &h); + return Point(w, h); +} + +int Renderer::GetLogicalWidth() const { + int w; + SDL_RenderGetLogicalSize(renderer_, &w, nullptr); + return w; +} + +int Renderer::GetLogicalHeight() const { + int h; + SDL_RenderGetLogicalSize(renderer_, nullptr, &h); + return h; +} + +void Renderer::GetScale(float& scalex, float& scaley) const { + SDL_RenderGetScale(renderer_, &scalex, &scaley); +} + +float Renderer::GetXScale() const { + float scalex; + SDL_RenderGetScale(renderer_, &scalex, nullptr); + return scalex; +} + +float Renderer::GetYScale() const { + float scaley; + SDL_RenderGetScale(renderer_, nullptr, &scaley); + return scaley; +} + +Rect Renderer::GetViewport() const { + SDL_Rect rect; + SDL_RenderGetViewport(renderer_, &rect); + return rect; +} + } diff --git a/SDL2pp/Renderer.hh b/SDL2pp/Renderer.hh index 95bafd6..fda2111 100644 --- a/SDL2pp/Renderer.hh +++ b/SDL2pp/Renderer.hh @@ -539,6 +539,99 @@ public: /// //////////////////////////////////////////////////////////// bool TargetSupported(); + + //////////////////////////////////////////////////////////// + /// \brief Get the clip rectangle for the current target + /// + /// \returns Rect representing current clipping area + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetClipRect + /// + //////////////////////////////////////////////////////////// + Rect GetClipRect() const; + + //////////////////////////////////////////////////////////// + /// \brief Get device independent resolution for rendering + /// + /// \returns Point representing logical resolution + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetClipRect + /// + /// \note If this function is called on an Renderer who never had + /// its logical size set by SetLogicalSize(), this function + /// returns {0, 0} + /// + //////////////////////////////////////////////////////////// + Point GetLogicalSize() const; + + //////////////////////////////////////////////////////////// + /// \brief Get device independent width resolution for rendering + /// + /// \returns Logical resolution width + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetClipRect + /// + /// \note If this function is called on an Renderer who never had + /// its logical size set by SetLogicalSize(), this function + /// returns 0 + /// + //////////////////////////////////////////////////////////// + int GetLogicalWidth() const; + + //////////////////////////////////////////////////////////// + /// \brief Get device independent width resolution for rendering + /// + /// \returns Logical resolution height + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetClipRect + /// + /// \note If this function is called on an Renderer who never had + /// its logical size set by SetLogicalSize(), this function + /// returns 0 + /// + //////////////////////////////////////////////////////////// + int GetLogicalHeight() const; + + //////////////////////////////////////////////////////////// + /// \brief Get the drawing scale for the current target + /// + /// \param[out] Variable to be filled with the horizontal scaling factor + /// \param[out] Variable to be filled with the vertical scaling factor + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetScale + /// + //////////////////////////////////////////////////////////// + void GetScale(float& scalex, float& scaley) const; + + //////////////////////////////////////////////////////////// + /// \brief Get the drawing scale for the current target + /// + /// \returns Horizontal scaling factor + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetScale + /// + //////////////////////////////////////////////////////////// + float GetXScale() const; + + //////////////////////////////////////////////////////////// + /// \brief Get the drawing scale for the current target + /// + /// \returns Vertical scaling factor + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetScale + /// + //////////////////////////////////////////////////////////// + float GetYScale() const; + + //////////////////////////////////////////////////////////// + /// \brief Get the drawing area for the current target + /// + /// \returns Rect representing current drawing area + /// + /// \see http://wiki.libsdl.org/SDL_RenderGetViewport + /// + //////////////////////////////////////////////////////////// + Rect GetViewport() const; }; }