75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#ifndef BWIDGETS_TEXTURE_HPP
|
|
#define BWIDGETS_TEXTURE_HPP
|
|
|
|
#include <cstdint>
|
|
|
|
#include <SDL2/SDL_pixels.h>
|
|
#include <SDL2/SDL_render.h>
|
|
|
|
#include <basic_widgets/core/type/color.hpp>
|
|
#include <basic_widgets/core/type/opaque_struct.hpp>
|
|
#include <basic_widgets/core/type/sdl_error.hpp>
|
|
|
|
namespace bwidgets
|
|
{
|
|
class Renderer;
|
|
|
|
class Texture final : public OpaqueStruct<SDL_Texture>
|
|
{
|
|
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
|