bwidgets/inc/basic_widgets/core/texture.hpp
Andrea Blankenstijn 7c5277dabd They say members defined in header are implicitly inline.
Also remove the static from static inline (is that C specific?)
2021-08-14 09:17:51 +02:00

80 lines
2.4 KiB
C++

#ifndef BWIDGETS_TEXTURE_HPP
#define BWIDGETS_TEXTURE_HPP
#include <cstdint>
#include <memory>
#include <SDL2/SDL_pixels.h>
#include <SDL2/SDL_render.h>
#include <basic_widgets/core/error_helper.hpp>
#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 : OpaqueStruct<SDL_Texture>::Wrapper
{
friend Renderer;
struct Attr final
{
uint32_t format_raw;
SDL_PixelFormat* format;
SDL_TextureAccess access;
int w, h;
} _attributes {};
public:
Texture(SDL_Texture*);
Texture(Renderer*, SDL_PixelFormatEnum, SDL_TextureAccess, int, int);
Texture(Renderer*, SDL_Surface*);
Texture(const Texture&) = delete;
Texture(Texture&&) = delete;
~Texture() noexcept;
auto operator=(const Texture&) = delete;
auto operator=(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]] const auto& attributes() const noexcept
{
return _attributes;
}
auto update(const SDL_Rect& r, const void* pix, int pitch)
{
SDL_Rect rect = r;
update(&rect, pix, pitch);
return this;
}
[[nodiscard]] static auto attributes(SDL_Texture* t)
{
Attr attr {};
success_or_throw<SDLError>(
SDL_QueryTexture(t, &attr.format_raw,
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
(int*)&attr.access, &attr.w, &attr.h));
attr.format = ptr_or_throw<SDLError>(SDL_AllocFormat(attr.format_raw));
return attr;
}
};
}
#endif