6 #include <SDL_surface.h> 8 #ifdef CPP_SDL2_ENABLE_SDL_IMAGE 37 + (x *
surface_->format->BytesPerPixel),
69 other.surface_ =
nullptr;
84 :
surface_{SDL_CreateRGBSurface(flags, w, h, depth, rmask, gmask, bmask, amask)}
100 :
surface_{SDL_CreateRGBSurfaceFrom(pixels, w, h, depth, pitch, rmask, gmask, bmask, amask)}
107 :
surface_{SDL_CreateRGBSurfaceWithFormat(flags, w, h, depth, format)}
114 :
surface_{SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, depth, pitch, format)}
119 #ifdef CPP_SDL2_ENABLE_SDL_IMAGE 120 Surface(std::string
const& filename) :
surface_{IMG_Load(filename.c_str())}
131 "Tried to call sdl::Surface(std::string const& filename) ctor. " 132 "This function should call IMG_Load() from SDL_Image.\n" 133 "This program was built without SDL_Image.\n" 134 "Please Install SDL_Image and #define CPP_SDL2_USE_SDL_IMAGE " 135 "before including sdl.hpp to use this functionality");
150 auto s = SDL_ConvertSurface(
surface_, &format, 0);
151 if (!s)
throw Exception{
"SDL_ConvertSurface"};
159 auto s = SDL_ConvertSurfaceFormat(
surface_, format, 0);
160 if (!s)
throw Exception{
"SDL_ConvertSurfaceFormat"};
169 #if SDL_VERSION_ATLEAST(2, 0, 9) 177 auto dstmut =
const_cast<Rect&
>(dst);
187 auto dstmut =
const_cast<Rect&
>(dst);
221 if (SDL_SetColorKey(
surface_, SDL_FALSE, 0) != 0)
throw Exception{
"SDL_SetColorKey"};
227 if (SDL_SetColorKey(
surface_, SDL_TRUE, key) != 0)
throw Exception{
"SDL_SetColorKey"};
249 if (SDL_SetSurfaceBlendMode(
surface_, bm) != 0)
throw Exception{
"SDL_SetSurfaceBlendMode"};
254 if (SDL_GetSurfaceBlendMode(
surface_, &bm) != 0)
throw Exception{
"SDL_GetSurfaceBlendMode"};
263 if (SDL_SetSurfaceColorMod(
surface_, r, g, b))
throw Exception{
"SDL_SetSurfaceColorMod"};
270 if (SDL_GetSurfaceColorMod(
surface_, &c.r, &c.g, &c.b) != 0)
271 throw Exception{
"SDL_SetSurfaceColorMod"};
278 if (SDL_SetSurfaceAlphaMod(
surface_, alpha) != 0)
throw Exception{
"SDL_SetSurfaceAlphaMod"};
284 if (SDL_GetSurfaceAlphaMod(
surface_, &alpha) != 0)
285 throw Exception{
"SDL_GetSurfaceAlphaMod"};
void set_alphamod(Uint8 alpha) const
Set alphamod.
Surface with_format(SDL_PixelFormat const &format) const
Convert surface to given format.
Surface with_format(Uint32 format) const
convert surface from given format
void set_colormod(Color const &color) const
Set colormod.
Vec2i size() const
Get size of surface.
void disable_colorkey() const
disable colorkey
void set_colorkey(Uint32 key) const
Set colorkey.
Surface(Surface &&other) noexcept
sdl::Rect, C++ wrapping of SDL_Rect
Color colormod() const
Get colormod.
bool has_colorkey() const
Uint8 alphamod() const
Get alphamod.
Surface & operator=(Surface &&other) noexcept
Surface(SDL_Surface *surface)
Explicit converting ctor from C SDL_Surface to sdl::Surface.
Generic templated 2D vector class.
void set_colorkey(Color const &color) const
Set colorkey.
void blit_on(Surface &surf, Rect const &dst) const
Blit surface on another.
Pixel at(size_t x, size_t y) const
Get pixel at specified location inside surface.
SDL_PixelFormat const & pixelformat() const
Get surface's pixel format.
Surface(void *pixels, int w, int h, int depth, int pitch, int format)
Create surface from array of pixels.
SDL_Surface * surface_
Set surface pointer.
void set_coloralphamod(Color const &c) const
Set color and alpha mod.
Represent a lock to safely access surface content.
Pixel at(Vec2i const &pos) const
Get pixel at given coordinates inside surface.
C++ wrapping around the SDL_Color structure.
Define to deactivate exception support.
int height() const
Get height of surface.
Uint32 flags() const
Get surface flags.
void * raw_array() const
Get access to the raw array of pixels.
Represent a 4 channel pixel.
SDL_BlendMode blendmode() const
SDL_Surface * surface_
Raw pointer to the surface.
Surface(Uint32 flags, int w, int h, int depth, Uint32 rmask, Uint32 gmask, Uint32 bmask, Uint32 amask)
Create surface for given parameters.
SDL_Surface * ptr() const
Get C SDL_Surface object.
~Surface()
RAII dtor to automatically free the surface.
void set_colormod(Uint8 r, Uint8 g, Uint8 b) const
Set colormod.
Surface & convert_to(Uint32 format)
Convert this surface to specified format.
Represent an SDL_Surface.
constexpr Lock(SDL_Surface &surface_)
Private constructor for lock object.
void set_coloralphamod(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
Set color and alpha mod.
Lock lock()
Lock surface for raw access to pixel.
Color coloralphamod() const
Get color and alpha mod.
void blit_on(Rect const &src, Surface &surf, Rect const &dst) const
Blit surface on another.
Pixel operator[](Vec2i const &pos) const
Get pixel at specified location via operator[].
void set_blendmode(SDL_BlendMode const &bm) const
Set surface blend mode.
Surface & convert_to(SDL_PixelFormat const &format)
Convert this surface to specified format.
Uint32 format() const
Get surface format.
Rect cliprect() const
Get surface clip rectangle.
Color colorkey() const
Get color key.
Define to deactivate exception support.
Surface(void *pixels, int w, int h, int depth, int pitch, Uint32 rmask, Uint32 gmask, Uint32 bmask, Uint32 amask)
Create surface from array of pixels.
Surface(Uint32 flags, int w, int h, int depth, Uint32 format)
Create surface with specified format.
int width() const
Get width of surface.
Uint32 as_uint(SDL_PixelFormat const &format) const
Return the color of the current object as a 32bit number (4 bytes)