2021-07-18 18:26:12 +02:00
|
|
|
#ifndef BWIDGETS_TEXTURE_HPP_
|
|
|
|
#define BWIDGETS_TEXTURE_HPP_
|
2021-07-16 17:18:13 +02:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include <SDL2/SDL_render.h>
|
|
|
|
#include <SDL2/SDL_pixels.h>
|
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
#include <basic_widgets/core/type/opaque_struct.hpp>
|
2021-07-20 15:20:46 +02:00
|
|
|
#include <basic_widgets/core/type/sdl_error.hpp>
|
2021-07-16 17:18:13 +02:00
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
namespace bwidgets::core
|
2021-07-16 17:18:13 +02:00
|
|
|
{
|
2021-07-18 18:26:12 +02:00
|
|
|
struct Renderer;
|
2021-07-16 17:18:13 +02:00
|
|
|
|
2021-07-28 15:15:32 +02:00
|
|
|
struct Texture final : OpaqueStruct<SDL_Texture>
|
2021-07-16 17:18:13 +02:00
|
|
|
{
|
|
|
|
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*);
|
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
virtual ~Texture() noexcept override;
|
2021-07-16 17:18:13 +02:00
|
|
|
|
|
|
|
uint8_t alpha_mode();
|
2021-07-18 18:26:12 +02:00
|
|
|
Texture* alpha_mode(uint8_t);
|
2021-07-16 17:18:13 +02:00
|
|
|
SDL_BlendMode blend_mode();
|
2021-07-18 18:26:12 +02:00
|
|
|
Texture* blend_mode(SDL_BlendMode);
|
2021-07-16 17:18:13 +02:00
|
|
|
SDL_Color color_mode();
|
2021-07-18 18:26:12 +02:00
|
|
|
Texture* color_mode(const SDL_Color&);
|
2021-07-16 17:18:13 +02:00
|
|
|
SDL_ScaleMode scale_mode();
|
2021-07-18 18:26:12 +02:00
|
|
|
Texture* scale_mode(SDL_ScaleMode);
|
|
|
|
Texture* update(SDL_Rect*, const void*, int);
|
2021-07-16 17:18:13 +02:00
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
inline const Attr& attributes() {
|
2021-07-16 17:18:13 +02:00
|
|
|
return _attributes;
|
|
|
|
}
|
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
inline Texture* update(const SDL_Rect& r, const void* pix, int pitch) {
|
2021-07-16 17:18:13 +02:00
|
|
|
SDL_Rect rect = r;
|
|
|
|
update(&rect, pix, pitch);
|
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
return this;
|
2021-07-16 17:18:13 +02:00
|
|
|
}
|
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
static inline const Attr attributes(SDL_Texture* t) {
|
2021-07-16 17:18:13 +02:00
|
|
|
Attr attr {};
|
2021-07-18 18:26:12 +02:00
|
|
|
SDLError::success_or_throw(
|
2021-07-16 17:18:13 +02:00
|
|
|
SDL_QueryTexture(t,
|
|
|
|
&attr.format_raw, (int*)&attr.access, &attr.w, &attr.h),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__
|
|
|
|
);
|
2021-07-18 18:26:12 +02:00
|
|
|
attr.format = SDLError::ptr_or_throw(
|
2021-07-16 17:18:13 +02:00
|
|
|
SDL_AllocFormat(attr.format_raw),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__
|
|
|
|
);
|
|
|
|
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|