#ifndef BWIDGETS_TEXTURE_HPP #define BWIDGETS_TEXTURE_HPP #include #include #include #include #include #include namespace bwidgets { class Renderer; class Texture final : public OpaqueStruct { struct Attr { uint32_t format_raw; SDL_PixelFormat* format; SDL_TextureAccess access; int w, h; } _attributes {}; public: Texture(SDL_Texture*); Texture(Renderer* r, SDL_PixelFormatEnum f, SDL_TextureAccess a, int w, int h); Texture(Renderer*, SDL_Surface*); Texture(const Texture&) = delete; ~Texture() noexcept override; auto operator=(const Texture&) = delete; [[nodiscard]] auto alpha_mode() -> uint8_t; auto alpha_mode(uint8_t) -> Texture*; [[nodiscard]] auto blend_mode() -> SDL_BlendMode; auto blend_mode(SDL_BlendMode) -> Texture*; [[nodiscard]] auto color_mode() -> Color; auto color_mode(const Color&) -> Texture*; [[nodiscard]] auto scale_mode() -> SDL_ScaleMode; auto scale_mode(SDL_ScaleMode) -> Texture*; auto update(SDL_Rect*, const void*, int) -> Texture*; [[nodiscard]] inline const auto& attributes() const { return _attributes; } inline auto update(const SDL_Rect& r, const void* pix, int pitch) { SDL_Rect rect = r; update(&rect, pix, pitch); return this; } [[nodiscard]] static inline auto attributes(SDL_Texture* t) { Attr attr {}; SDLError::success_or_throw(SDL_QueryTexture(t, &attr.format_raw, (int*)&attr.access, &attr.w, &attr.h), __FILE__, __FUNCTION__, __LINE__); attr.format = SDLError::ptr_or_throw(SDL_AllocFormat(attr.format_raw), __FILE__, __FUNCTION__, __LINE__); return attr; } }; } #endif