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; }; } diff --git a/examples/ttf.cc b/examples/ttf.cc index 28d02f4..43cf3c4 100644 --- a/examples/ttf.cc +++ b/examples/ttf.cc @@ -39,15 +39,19 @@ int Run() { Window window("libSDL2pp demo: font", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE); Renderer render(window, -1, SDL_RENDERER_ACCELERATED); - Font font(TESTDATA_DIR "/Vera.ttf", 20); + Font font(TESTDATA_DIR "/Vera.ttf", 30); Surface solid = font.RenderText_Solid("Hello, world! (solid mode)", SDL_Color({255, 255, 255, 255})); Surface shaded = font.RenderText_Shaded("Hello, world! (shaded mode)", SDL_Color({255, 255, 255, 255}), SDL_Color({127, 127, 127, 255})); Surface blended = font.RenderText_Blended("Hello, world! (blended mode)", SDL_Color({255, 255, 255, 255})); + font.SetOutline(1); + Surface outline = font.RenderText_Blended("Hello, world! (blended + outline)", SDL_Color({255, 255, 255, 255})); + Texture solid_tex(render, solid); Texture shaded_tex(render, shaded); Texture blended_tex(render, blended); + Texture outline_tex(render, outline); while (1) { // Process input @@ -62,13 +66,16 @@ int Run() { // Render 3 strings int h = 0; - render.Copy(solid_tex, NullOpt, Rect(0, h, solid.Get()->w, solid.Get()->h)); + render.Copy(solid_tex, NullOpt, Rect(0, h, solid.GetWidth(), solid.GetHeight())); h += solid.Get()->h; - render.Copy(shaded_tex, NullOpt, Rect(0, h, shaded.Get()->w, shaded.Get()->h)); + render.Copy(shaded_tex, NullOpt, Rect(0, h, shaded.GetWidth(), shaded.GetHeight())); h += shaded.Get()->h; - render.Copy(blended_tex, NullOpt, Rect(0, h, blended.Get()->w, blended.Get()->h)); + render.Copy(blended_tex, NullOpt, Rect(0, h, blended.GetWidth(), blended.GetHeight())); + h += blended.Get()->h; + + render.Copy(outline_tex, NullOpt, Rect(0, h, outline.GetWidth(), outline.GetHeight())); render.Present();