Rose
Public Member Functions | List of all members
rose::gm::Surface Class Reference

A wrapper class for SDL_Surface pointers. More...

#include <Surface.h>

Inheritance diagram for rose::gm::Surface:
Inheritance graph
[legend]
Collaboration diagram for rose::gm::Surface:
Collaboration graph
[legend]

Public Member Functions

 Surface ()=default
 Create an empty Surface.
 
 Surface (SDL_Surface *surface)
 Create a Surface initialized with an SDL_Surface pointer. More...
 
 Surface (const std::filesystem::path &path)
 Create a surface from a file. More...
 
 Surface (int width, int height, int depth=32, SDL_PixelFormatEnum format=SDL_PIXELFORMAT_RGBA8888)
 Constructor. More...
 
 Surface (Size size, int depth=32, SDL_PixelFormatEnum format=SDL_PIXELFORMAT_RGBA8888)
 
 Surface (int width, int height, int depth, uint32_t rmask, uint32_t gmask, uint32_t bmask, uint32_t amask)
 
uint32_t & pixel (int x, int y) const
 Provide access to a pixel of the Surface. More...
 
color::RGBA color (int x, int y) const
 Get a pixel color of the Surface. More...
 
void setColor (int x, int y, color::RGBA color)
 Set a pixel color of the Surface. More...
 
bool createWithFormat (int width, int height, int depth=32, SDL_PixelFormatEnum format=SDL_PIXELFORMAT_RGBA8888)
 Create a surface using SDL_CreateRGBSurfaceWithFormat() More...
 
int fillRectangle (const Rectangle &rect, const color::RGBA &color)
 Fill a rectangle using SDL_FillRect() More...
 
int fillRectangle (const color::RGBA &color)
 Fill the Surface using SDL_FillRect() More...
 
bool textureFromSurface (Context &context, Texture &texture)
 Create an SDL_Texture from the Surface and set it in the Texture object. More...
 
Texture toTexture (Context &context)
 Create an SDL_Texture from the surface. More...
 
int setBlendMode (SDL_BlendMode blendMode) noexcept
 Set the Surfacle SDL_BlendMode. More...
 
int blitSurface (Surface &source)
 Blit the contents of the source Surface to this surface. More...
 

Detailed Description

A wrapper class for SDL_Surface pointers.

Provide a std::unique_ptr storage type for SDL_Surface pointers.

Constructor & Destructor Documentation

◆ Surface() [1/3]

rose::gm::Surface::Surface ( SDL_Surface *  surface)
inlineexplicit

Create a Surface initialized with an SDL_Surface pointer.

Parameters
surfaceThe SDL_Surface pointer.

◆ Surface() [2/3]

rose::gm::Surface::Surface ( const std::filesystem::path &  path)
explicit

Create a surface from a file.

Parameters
pathThe path to the file to load.

◆ Surface() [3/3]

rose::gm::Surface::Surface ( int  width,
int  height,
int  depth = 32,
SDL_PixelFormatEnum  format = SDL_PIXELFORMAT_RGBA8888 
)

Constructor.

Create a surface using SDL_CreateRGBSurfaceWithFormat()

Parameters
widthThe width of the surface.
heightThe height of the surface.
depthThe pixel depth, defaults to 32.
formatThe format, defaults to SDL_PIXELFORMAT_RGBA8888

Member Function Documentation

◆ blitSurface()

int rose::gm::Surface::blitSurface ( Surface source)

Blit the contents of the source Surface to this surface.

Parameters
sourceThe source Surface.
Returns
the SDL_Status return code.

◆ color()

color::RGBA rose::gm::Surface::color ( int  x,
int  y 
) const

Get a pixel color of the Surface.

Parameters
xThe x co-ordinate.
yThe y co-ordinate.
Returns
The color as an RGBA.

◆ createWithFormat()

bool rose::gm::Surface::createWithFormat ( int  width,
int  height,
int  depth = 32,
SDL_PixelFormatEnum  format = SDL_PIXELFORMAT_RGBA8888 
)

Create a surface using SDL_CreateRGBSurfaceWithFormat()

Parameters
widthThe width of the surface.
heightThe height of the surface.
depthThe pixel depth, defaults to 32.
formatThe format, defaults to SDL_PIXELFORMAT_RGBA8888
Returns
True if the surface was created, false otherwise.

◆ fillRectangle() [1/2]

int rose::gm::Surface::fillRectangle ( const Rectangle rect,
const color::RGBA color 
)

Fill a rectangle using SDL_FillRect()

Parameters
rectThe Rectangle to fill.
colorThe fill Color.
Returns
The return status value.

◆ fillRectangle() [2/2]

int rose::gm::Surface::fillRectangle ( const color::RGBA color)

Fill the Surface using SDL_FillRect()

Parameters
colorThe fill Color.
Returns
The return status value.

◆ pixel()

uint32_t & rose::gm::Surface::pixel ( int  x,
int  y 
) const

Provide access to a pixel of the Surface.

The co-ordinates are not checked for out of range values.

Parameters
xThe X co-ordinate.
yThe Y co-ordinate.
Returns
A reference to the pixel.

◆ setBlendMode()

int rose::gm::Surface::setBlendMode ( SDL_BlendMode  blendMode)
noexcept

Set the Surfacle SDL_BlendMode.

Parameters
blendModeThe blend mode, a value from SDL_BlendMode enum.
Returns
The return status from SDL_SetSurfaceBlendMode().

◆ setColor()

void rose::gm::Surface::setColor ( int  x,
int  y,
color::RGBA  color 
)

Set a pixel color of the Surface.

Parameters
xThe x co-ordinate.
yThe y co-ordinate.
colorthe color as an RGBA.

◆ textureFromSurface()

bool rose::gm::Surface::textureFromSurface ( Context context,
Texture texture 
)

Create an SDL_Texture from the Surface and set it in the Texture object.

Parameters
textureThe Texture object.
Returns
True if the SDL_Texture was created.

◆ toTexture()

Texture rose::gm::Surface::toTexture ( Context context)

Create an SDL_Texture from the surface.

Parameters
contextThe Renderer used.
Returns
The generatoed Texture.

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