From 9e53670b2e948b0f2dadfdb0f37dd3507714b722 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Mon, 29 Dec 2014 21:37:44 +0300 Subject: [PATCH] Implement Width/Height/Size getters for Texture and Surface --- SDL2pp/Surface.cc | 12 ++++++++++++ SDL2pp/Surface.hh | 25 +++++++++++++++++++++++++ SDL2pp/Texture.cc | 7 +++++++ SDL2pp/Texture.hh | 12 ++++++++++++ 4 files changed, 56 insertions(+) diff --git a/SDL2pp/Surface.cc b/SDL2pp/Surface.cc index 789a0e0..4a36226 100644 --- a/SDL2pp/Surface.cc +++ b/SDL2pp/Surface.cc @@ -193,4 +193,16 @@ void Surface::FillRects(const Rect* rects, int count, Uint32 color) { throw Exception("SDL_FillRects failed"); } +int Surface::GetWidth() const { + return surface_->w; +} + +int Surface::GetHeight() const { + return surface_->h; +} + +Point Surface::GetSize() const { + return Point(surface_->w, surface_->h); +} + } diff --git a/SDL2pp/Surface.hh b/SDL2pp/Surface.hh index 5cdcb89..93d0e54 100644 --- a/SDL2pp/Surface.hh +++ b/SDL2pp/Surface.hh @@ -28,6 +28,7 @@ #include #include #include +#include struct SDL_Surface; struct SDL_PixelFormat; @@ -479,6 +480,30 @@ public: /// //////////////////////////////////////////////////////////// void FillRects(const Rect* rects, int count, Uint32 color); + + //////////////////////////////////////////////////////////// + /// \brief Get surface width + /// + /// \return Surface width in pixels + /// + //////////////////////////////////////////////////////////// + int GetWidth() const; + + //////////////////////////////////////////////////////////// + /// \brief Get surface height + /// + /// \return Surface height in pixels + /// + //////////////////////////////////////////////////////////// + int GetHeight() const; + + //////////////////////////////////////////////////////////// + /// \brief Get surface size + /// + /// \return SDL2pp::Point representing surface dimensions in pixels + /// + //////////////////////////////////////////////////////////// + Point GetSize() const; }; } diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 2a5912e..6f33f2b 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -140,4 +140,11 @@ int Texture::GetHeight() const { return h; } +Point Texture::GetSize() const { + int w, h; + if (SDL_QueryTexture(texture_, nullptr, nullptr, &w, &h) != 0) + throw Exception("SDL_QueryTexture failed"); + return Point(w, h); +} + } diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index 84b32d2..e93c6b7 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -389,6 +389,18 @@ public: /// //////////////////////////////////////////////////////////// int GetHeight() const; + + //////////////////////////////////////////////////////////// + /// \brief Get texture image size + /// + /// \return SDL2pp::Point representing texture dimensions in pixels + /// + /// \throws SDL2pp::Exception + /// + /// \see http://wiki.libsdl.org/SDL_QueryTexture + /// + //////////////////////////////////////////////////////////// + Point GetSize() const; }; }