mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-04 03:15:59 -04:00
Merge branch 'size-getters'
This commit is contained in:
commit
2006bcd97b
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <SDL2pp/Config.hh>
|
||||
#include <SDL2pp/Optional.hh>
|
||||
#include <SDL2pp/Rect.hh>
|
||||
#include <SDL2pp/Point.hh>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user