cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Surface Class Reference

Represent an SDL_Surface. More...

#include <surface.hpp>

Classes

class  Lock
 Represent a lock to safely access surface content. More...
 

Public Member Functions

 Surface (SDL_Surface *surface)
 Explicit converting ctor from C SDL_Surface to sdl::Surface. More...
 
 Surface (Surface &&other) noexcept
 
Surfaceoperator= (Surface &&other) noexcept
 
 Surface (Uint32 flags, int w, int h, int depth, Uint32 rmask, Uint32 gmask, Uint32 bmask, Uint32 amask)
 Create surface for given parameters. More...
 
 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. More...
 
 Surface (Uint32 flags, int w, int h, int depth, Uint32 format)
 Create surface with specified format. More...
 
 Surface (void *pixels, int w, int h, int depth, int pitch, int format)
 Create surface from array of pixels. More...
 
 Surface (std::string const &filename)
 Construct surface from image file, require SDL_Image. More...
 
 Surface (std::string const &filename)
 Stubbed constructor for missing SDL_Image usage. More...
 
 ~Surface ()
 RAII dtor to automatically free the surface. More...
 
SDL_Surface * ptr () const
 Get C SDL_Surface object. More...
 
Surface with_format (SDL_PixelFormat const &format) const
 Convert surface to given format. More...
 
Surface with_format (Uint32 format) const
 convert surface from given format More...
 
Surfaceconvert_to (SDL_PixelFormat const &format)
 Convert this surface to specified format. More...
 
Surfaceconvert_to (Uint32 format)
 Convert this surface to specified format. More...
 
bool has_colorkey () const
 
void blit_on (Rect const &src, Surface &surf, Rect const &dst) const
 Blit surface on another. More...
 
void blit_on (Surface &surf, Rect const &dst) const
 Blit surface on another. More...
 
int width () const
 Get width of surface. More...
 
int height () const
 Get height of surface. More...
 
Vec2i size () const
 Get size of surface. More...
 
SDL_PixelFormat const & pixelformat () const
 Get surface's pixel format. More...
 
Uint32 format () const
 Get surface format. More...
 
Uint32 flags () const
 Get surface flags. More...
 
Rect cliprect () const
 Get surface clip rectangle. More...
 
void disable_colorkey () const
 disable colorkey More...
 
void set_colorkey (Uint32 key) const
 Set colorkey. More...
 
void set_colorkey (Color const &color) const
 Set colorkey. More...
 
Color colorkey () const
 Get color key. More...
 
void set_blendmode (SDL_BlendMode const &bm) const
 Set surface blend mode. More...
 
SDL_BlendMode blendmode () const
 
void set_colormod (Color const &color) const
 Set colormod. More...
 
void set_colormod (Uint8 r, Uint8 g, Uint8 b) const
 Set colormod. More...
 
Color colormod () const
 Get colormod. More...
 
void set_alphamod (Uint8 alpha) const
 Set alphamod. More...
 
Uint8 alphamod () const
 Get alphamod. More...
 
void set_coloralphamod (Uint8 r, Uint8 g, Uint8 b, Uint8 a) const
 Set color and alpha mod. More...
 
void set_coloralphamod (Color const &c) const
 Set color and alpha mod. More...
 
Color coloralphamod () const
 Get color and alpha mod. More...
 
Lock lock ()
 Lock surface for raw access to pixel. More...
 

Private Attributes

SDL_Surface * surface_ = nullptr
 Set surface pointer. More...
 

Detailed Description

Represent an SDL_Surface.

Definition at line 21 of file surface.hpp.

Constructor & Destructor Documentation

◆ Surface() [1/8]

sdl::Surface::Surface ( SDL_Surface *  surface)
inlineexplicit

Explicit converting ctor from C SDL_Surface to sdl::Surface.

Definition at line 59 of file surface.hpp.

◆ Surface() [2/8]

sdl::Surface::Surface ( Surface &&  other)
inlinenoexcept

Definition at line 61 of file surface.hpp.

◆ Surface() [3/8]

sdl::Surface::Surface ( Uint32  flags,
int  w,
int  h,
int  depth,
Uint32  rmask,
Uint32  gmask,
Uint32  bmask,
Uint32  amask 
)
inline

Create surface for given parameters.

Definition at line 75 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ Surface() [4/8]

sdl::Surface::Surface ( void *  pixels,
int  w,
int  h,
int  depth,
int  pitch,
Uint32  rmask,
Uint32  gmask,
Uint32  bmask,
Uint32  amask 
)
inline

Create surface from array of pixels.

Definition at line 90 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ Surface() [5/8]

sdl::Surface::Surface ( Uint32  flags,
int  w,
int  h,
int  depth,
Uint32  format 
)
inline

Create surface with specified format.

Definition at line 106 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ Surface() [6/8]

sdl::Surface::Surface ( void *  pixels,
int  w,
int  h,
int  depth,
int  pitch,
int  format 
)
inline

Create surface from array of pixels.

Definition at line 113 of file surface.hpp.

References sdl::Surface::Lock::Surface, and sdl::Surface::Lock::surface_.

◆ Surface() [7/8]

sdl::Surface::Surface ( std::string const &  filename)
inline

Construct surface from image file, require SDL_Image.

Definition at line 121 of file surface.hpp.

◆ Surface() [8/8]

sdl::Surface::Surface ( std::string const &  filename)
inline

Stubbed constructor for missing SDL_Image usage.

Definition at line 128 of file surface.hpp.

◆ ~Surface()

sdl::Surface::~Surface ( )
inline

RAII dtor to automatically free the surface.

Definition at line 141 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Member Function Documentation

◆ alphamod()

Uint8 sdl::Surface::alphamod ( ) const
inline

Get alphamod.

Definition at line 281 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by coloralphamod().

◆ blendmode()

SDL_BlendMode sdl::Surface::blendmode ( ) const
inline

Definition at line 251 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ blit_on() [1/2]

void sdl::Surface::blit_on ( Rect const &  src,
Surface surf,
Rect const &  dst 
) const
inline

Blit surface on another.

Definition at line 174 of file surface.hpp.

References sdl::Surface::Lock::surface_, and surface_.

◆ blit_on() [2/2]

void sdl::Surface::blit_on ( Surface surf,
Rect const &  dst 
) const
inline

Blit surface on another.

Definition at line 185 of file surface.hpp.

References sdl::Surface::Lock::surface_, and surface_.

◆ cliprect()

Rect sdl::Surface::cliprect ( ) const
inline

Get surface clip rectangle.

Definition at line 211 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ coloralphamod()

Color sdl::Surface::coloralphamod ( ) const
inline

Get color and alpha mod.

Definition at line 302 of file surface.hpp.

References alphamod(), and colormod().

◆ colorkey()

Color sdl::Surface::colorkey ( ) const
inline

Get color key.

Definition at line 239 of file surface.hpp.

References pixelformat(), and sdl::Surface::Lock::surface_.

◆ colormod()

Color sdl::Surface::colormod ( ) const
inline

Get colormod.

Definition at line 267 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by coloralphamod().

◆ convert_to() [1/2]

Surface& sdl::Surface::convert_to ( SDL_PixelFormat const &  format)
inline

Convert this surface to specified format.

Definition at line 165 of file surface.hpp.

References with_format().

◆ convert_to() [2/2]

Surface& sdl::Surface::convert_to ( Uint32  format)
inline

Convert this surface to specified format.

Definition at line 167 of file surface.hpp.

References with_format().

◆ disable_colorkey()

void sdl::Surface::disable_colorkey ( ) const
inline

disable colorkey

Definition at line 219 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ flags()

Uint32 sdl::Surface::flags ( ) const
inline

Get surface flags.

Definition at line 208 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ format()

Uint32 sdl::Surface::format ( ) const
inline

Get surface format.

Definition at line 205 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ has_colorkey()

bool sdl::Surface::has_colorkey ( ) const
inline

Definition at line 170 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ height()

int sdl::Surface::height ( ) const
inline

Get height of surface.

Definition at line 197 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by size().

◆ lock()

Lock sdl::Surface::lock ( )
inline

Lock surface for raw access to pixel.

Return a lock object that permit to access the pixels. When lock goes out of scope, resources goes unlocked automatically

Definition at line 312 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ operator=()

Surface& sdl::Surface::operator= ( Surface &&  other)
inlinenoexcept

Definition at line 63 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ pixelformat()

SDL_PixelFormat const& sdl::Surface::pixelformat ( ) const
inline

Get surface's pixel format.

Definition at line 202 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by colorkey(), and set_colorkey().

◆ ptr()

SDL_Surface* sdl::Surface::ptr ( ) const
inline

Get C SDL_Surface object.

Definition at line 144 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by sdl::Window::set_icon(), and sdl::Texture::Texture().

◆ set_alphamod()

void sdl::Surface::set_alphamod ( Uint8  alpha) const
inline

Set alphamod.

Definition at line 276 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by set_coloralphamod().

◆ set_blendmode()

void sdl::Surface::set_blendmode ( SDL_BlendMode const &  bm) const
inline

Set surface blend mode.

Definition at line 247 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ set_coloralphamod() [1/2]

void sdl::Surface::set_coloralphamod ( Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
) const
inline

Set color and alpha mod.

Definition at line 290 of file surface.hpp.

References set_alphamod(), and set_colormod().

◆ set_coloralphamod() [2/2]

void sdl::Surface::set_coloralphamod ( Color const &  c) const
inline

Set color and alpha mod.

Definition at line 296 of file surface.hpp.

References set_alphamod(), and set_colormod().

◆ set_colorkey() [1/2]

void sdl::Surface::set_colorkey ( Uint32  key) const
inline

Set colorkey.

Definition at line 225 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ set_colorkey() [2/2]

void sdl::Surface::set_colorkey ( Color const &  color) const
inline

Set colorkey.

Definition at line 230 of file surface.hpp.

References sdl::Color::as_uint(), pixelformat(), and sdl::Surface::Lock::surface_.

◆ set_colormod() [1/2]

void sdl::Surface::set_colormod ( Color const &  color) const
inline

Set colormod.

Definition at line 259 of file surface.hpp.

References set_colormod().

Referenced by set_coloralphamod(), and set_colormod().

◆ set_colormod() [2/2]

void sdl::Surface::set_colormod ( Uint8  r,
Uint8  g,
Uint8  b 
) const
inline

Set colormod.

Definition at line 261 of file surface.hpp.

References sdl::Surface::Lock::surface_.

◆ size()

Vec2i sdl::Surface::size ( ) const
inline

Get size of surface.

Definition at line 199 of file surface.hpp.

References height(), and width().

◆ width()

int sdl::Surface::width ( ) const
inline

Get width of surface.

Definition at line 195 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by size().

◆ with_format() [1/2]

Surface sdl::Surface::with_format ( SDL_PixelFormat const &  format) const
inline

Convert surface to given format.

Parameters
formatWhat pixel format to use

Definition at line 148 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Referenced by convert_to().

◆ with_format() [2/2]

Surface sdl::Surface::with_format ( Uint32  format) const
inline

convert surface from given format

Parameters
formatwhat format to use

Definition at line 157 of file surface.hpp.

References sdl::Surface::Lock::surface_.

Member Data Documentation

◆ surface_

SDL_Surface* sdl::Surface::surface_ = nullptr
private

Set surface pointer.

Definition at line 320 of file surface.hpp.

Referenced by blit_on().


The documentation for this class was generated from the following file: