32 SDL_DestroyTexture(sdlTexture);
40 class Texture :
public std::unique_ptr<SDL_Texture, TextureDestroy> {
54 explicit Texture(SDL_Texture *texture) :
Texture() { reset(texture); }
64 Texture(
Renderer &renderer, SDL_PixelFormatEnum format, SDL_TextureAccess access,
int width,
int height);
75 int setBlendMOde(SDL_BlendMode blendMode) {
76 return SDL_SetTextureBlendMode(
get(), blendMode);
79 [[nodiscard]] std::tuple<int, int> getSize()
const noexcept {
81 SDL_QueryTexture(
get(),
nullptr,
nullptr, &w, &h);
82 return std::make_tuple(w, h);
109 TextureData(
Renderer &renderer, SDL_PixelFormatEnum format, SDL_TextureAccess access,
int width,
int height)
110 :
Texture(renderer, format, access, width, height) {
131 (*this) = texture.release();
175 return operator bool() && mLife < std::chrono::system_clock::now();
182 [[nodiscard]]
bool dirty() const noexcept {
return mDirty; }
200 [[nodiscard]] std::string_view
getPath()
const {
return mPath; }
207 template<
typename StringType>
208 void setPath(
const StringType path) { mPath = path; }
214 std::string_view
getURI() {
return mURI; }
220 [[nodiscard]] std::string_view
getURI()
const {
return mURI; }
227 template<
typename StringType>
228 void setURI(
const StringType URI) { mURI = URI; }
240 [[nodiscard]] std::string_view
getName()
const {
return mName; }
247 template<
typename StringType>
248 void setName(
const StringType Name) { mName = Name; }
254 void setLoadedTime(
const std::chrono::time_point<std::chrono::system_clock> loaded) { mLoaded = loaded; }
266 [[nodiscard]]
int getScale()
const {
return mScale; }
280 rect.w = mSize.width();
281 rect.h = mSize.height();
306 SDL_QueryTexture(
get(), &mFormat, &mAccess, &w, &h);
326 std::chrono::time_point<std::chrono::system_clock> mLoaded{},
346 template<
typename String>
348 auto filePath = dirPath;
349 filePath.append(fileName);
380 Orientation orientation = Orientation::Horizontal);
386 Orientation orientation = Orientation::Horizontal);
421 SDL_FreeFormat(sdlPixelFormat);
429 class PixelFormat :
public std::unique_ptr<SDL_PixelFormat, PixelFormatDestroy> {
476 color::RGBA getRGBA(SDL_PixelFormat *format, uint32_t pixel);
487 template<
typename Color>
490 static_assert(std::is_same_v<Color, ::rose::color::RGBA> ||
491 std::is_same_v<Color, ::rose::color::HSVA> ||
492 std::is_same_v<Color, SDL_Color>,
493 "Color type is not supported.");
494 if constexpr (std::is_same_v<Color, ::rose::color::RGBA>) {
495 auto fg = color.toSdlColor();
497 }
else if constexpr (std::is_same_v<Color, ::rose::color::HSVA>) {
500 }
else if constexpr (std::is_same_v<Color, SDL_Color>) {
501 sdl::Surface surface{TTF_RenderText_Blended(font.get(), text.c_str(), color)};
502 return sdl::Texture{SDL_CreateTextureFromSurface(renderer.
get(), surface.get())};
515 template<
typename Color>
518 const Color &color) {
519 static_assert(std::is_same_v<Color, ::rose::color::RGBA> ||
520 std::is_same_v<Color, ::rose::color::HSVA> ||
521 std::is_same_v<Color, SDL_Color>,
522 "Color type is not supported.");
523 if constexpr (std::is_same_v<Color, ::rose::color::RGBA>) {
524 auto fg = color.toSdlColor();
526 }
else if constexpr (std::is_same_v<Color, ::rose::color::HSVA>) {
529 }
else if constexpr (std::is_same_v<Color, SDL_Color>) {
530 sdl::Surface surface{TTF_RenderUTF8_Blended(font.get(), text.c_str(), color)};
531 return sdl::Texture{SDL_CreateTextureFromSurface(renderer.
get(), surface.get())};
True Type Fonts and supporting types and functions.
void setDirty(bool dirty)
Set the texture dirty status.
Definition: Texture.h:188
Rectangle getRectangle() const
Return a Rectangle with the size of the texture and Zero position.
Definition: Texture.h:288
void setMetaData()
Set the class meta data from the texture.
Definition: Texture.h:304
std::string_view getName()
Get the Name member.
Definition: Texture.h:234
bool expired() const noexcept
Determine if the texture has expired.
Definition: Texture.h:174
void setURI(const StringType URI)
Assign a new value to the URI member.
Definition: Texture.h:228
Red Green Blue Alpha representation of a color.
Definition: Color.h:64
A type of texture that if stretch across a destination Rectangle in rendering, will create a gradient...
Definition: Texture.h:394
void setScale(int scale)
Set the scale value associated with the texture.
Definition: Texture.h:260
std::string_view getURI() const
Get the URI member from a const TextureData object.
Definition: Texture.h:220
Size getSize() const
Get the icon size.
Definition: Texture.h:272
std::shared_ptr< TTF_Font > FontPointer
Type for TTF smart pointer.
Definition: Font.h:54
An encapsulation of the SDL_Texture structure.
Definition: Texture.h:40
Size mSize
The size of the texture.
Definition: Texture.h:311
std::string mName
A name this image may be known by.
Definition: Texture.h:323
TextureData(Renderer &renderer, SDL_PixelFormatEnum format, SDL_TextureAccess access, int width, int height)
Constructor
Definition: Texture.h:109
TextureData(Texture &&texture) noexcept
Move constructor.
Definition: Texture.h:130
std::string_view getPath() const
Get the path member from a const TextureData object.
Definition: Texture.h:200
std::string mPath
The path name to the source of the texture on the local file system.
Definition: Texture.h:316
void setName(const StringType Name)
Assign a new value to the Name member.
Definition: Texture.h:248
bool dirty() const noexcept
Determine if the texture is dirty.
Definition: Texture.h:182
constexpr int & width()
Reference access to width.
Definition: ScreenMetrics.h:332
std::string mURI
The URI of the source of the texture.
Definition: Texture.h:317
TextureData(Renderer &renderer, Size size)
Constructor.
Definition: Texture.h:121
std::string_view getName() const
Get the Name member from a const TextureData object.
Definition: Texture.h:240
Orientation
Possible values for Widget orientation.
Definition: Types.h:41
A functor to destroy an SDL_Texture in a std::unique_ptr (rose::sdl::Texture)
Definition: Texture.h:25
TextureData & operator=(SDL_Texture *texture)
Assign an SDL_Texture pointer to this object.
Definition: Texture.h:164
TextureData CreateTextureFromFile(Renderer &renderer, std::filesystem::path &filePath)
Create texture data from a file system path.
A composite of a Position and a Size.
Definition: Types.h:307
auto get() const
The the underlying SDL_Renderer* for use with the SDL2 API.
Definition: Renderer.h:163
int getScale() const
Get the scale value associate with the texture.
Definition: Texture.h:266
void setPath(const StringType path)
Assign a new value to the path member.
Definition: Texture.h:208
std::string_view getPath()
Get the path member.
Definition: Texture.h:194
int pixel(SDL_Renderer *renderer, Sint16 x, Sint16 y)
Draw pixel in currently set color.
Definition: GfxPrimitives.cpp:20
void setSize(Size size)
Set the size of the Texture.
Definition: Texture.h:298
Written as a workaround for an issue in the SDL2 Library.
Definition: Renderer.h:64
Class and functions that are used to access the SDL2 api.
Definition: Renderer.cpp:11
TextureData(SDL_Texture *texture) noexcept
Construct a new TextureData from an SDL_Texture pointer.
Definition: Texture.h:141
A size in integer dimensions.
Definition: Types.h:230
void setLoadedTime(const std::chrono::time_point< std::chrono::system_clock > loaded)
Set the time the texture was loaded.
Definition: Texture.h:254
void getRectangle(SDL_Rect &rect) const
Populate an SDL_Rect with size of the texture with a Zero position.
Definition: Texture.h:278
uint32_t mapRGBA(SDL_PixelFormatEnum pixelFormat, const color::RGBA &color)
Map a color::RGBA to a uint32_t.
Definition: Texture.cpp:95
A Texture with associated meta data.
Definition: Texture.h:90
constexpr SDL_Color toSdlColor() const noexcept
Convert this colour to an SDL_Color.
Definition: Color.h:97
sdl::Texture renderTextureBlendedUTF8(sdl::Renderer &renderer, FontPointer &font, const std::string &text, const Color &color)
Render text to a Texture.
Definition: Texture.h:517
sdl::Texture renderTextureBlended(sdl::Renderer &renderer, FontPointer &font, const std::string &text, const Color &color)
Render text to a Texture.
Definition: Texture.h:489
A gradient rendering kernel.
Definition: Texture.h:362
std::string_view getURI()
Get the URI member.
Definition: Texture.h:214
void operator()(SDL_Texture *sdlTexture)
Call the SDL API to destroy an SDL_Texture.
Definition: Texture.h:31