Implement Width/Height/Size getters for Texture and Surface

This commit is contained in:
Dmitry Marakasov 2014-12-29 21:37:44 +03:00
parent ca505369f3
commit 9e53670b2e
4 changed files with 56 additions and 0 deletions

View File

@ -193,4 +193,16 @@ void Surface::FillRects(const Rect* rects, int count, Uint32 color) {
throw Exception("SDL_FillRects failed"); 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);
}
} }

View File

@ -28,6 +28,7 @@
#include <SDL2pp/Config.hh> #include <SDL2pp/Config.hh>
#include <SDL2pp/Optional.hh> #include <SDL2pp/Optional.hh>
#include <SDL2pp/Rect.hh> #include <SDL2pp/Rect.hh>
#include <SDL2pp/Point.hh>
struct SDL_Surface; struct SDL_Surface;
struct SDL_PixelFormat; struct SDL_PixelFormat;
@ -479,6 +480,30 @@ public:
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void FillRects(const Rect* rects, int count, Uint32 color); 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;
}; };
} }

View File

@ -140,4 +140,11 @@ int Texture::GetHeight() const {
return h; 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);
}
} }

View File

@ -389,6 +389,18 @@ public:
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int GetHeight() const; 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;
}; };
} }