FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::Surface Class Reference

Abstraction of SDL_Surface. More...

#include <C_surface.hpp>

Public Member Functions

 Surface (int width, int height, fge::Color const &color={0, 0, 0, 255})
 
 Surface (Surface const &r)
 
 Surface (Surface &&r) noexcept
 
 Surface (SDL_Surface *newSurface)
 
Surfaceoperator= (Surface const &r)
 
Surfaceoperator= (Surface &&r) noexcept
 
void clear ()
 Destroy the surface.
 
bool create (int width, int height, fge::Color const &color={0, 0, 0, 255})
 
bool loadFromFile (std::filesystem::path const &filePath)
 
bool loadFromMemory (void const *data, std::size_t size)
 
bool saveToFile (std::filesystem::path const &filePath) const
 Save the surface to a PNG format file.
 
fge::Vector2i getSize () const
 
void createMaskFromColor (fge::Color const &color, uint8_t alpha=0)
 Create a transparent mask from a color.
 
bool setPixel (int x, int y, fge::Color const &color)
 
std::optional< fge::ColorgetPixel (int x, int y) const
 
void setCircle (int x, int y, unsigned int radius, fge::Color const &color)
 
void flipHorizontally ()
 
void flipVertically ()
 
bool blitSurface (Surface const &src, std::optional< SDL_Rect > const &srcRect, std::optional< SDL_Rect > &dstRect)
 Blit a surface on this surface.
 
bool fillRect (std::optional< SDL_Rect > const &rect, fge::Color const &color)
 Fill a rectangle section of the surface with a color.
 
bool addBorder (int borderSize, fge::Color const &color)
 Add a border to the surface with a specific color.
 
void set (SDL_Surface *surface)
 Set a new surface.
 
SDL_Surface * get () const
 Get the SDL_Surface pointer.
 
fge::Vector2f normalizeTextureCoords (fge::Vector2i const &coords) const
 Convert some pixel coordinates to texture coordinates (0.0f to 1.0f)
 
fge::RectFloat normalizeTextureRect (fge::RectInt const &rect) const
 Convert a pixel rectangle to a texture rectangle (0.0f to 1.0f)
 

Detailed Description

Abstraction of SDL_Surface.

This class is an abstraction of SDL_Surface. It can be used to load image from file or memory with the help of SDL_image. The texture manager must be initialized in order to load image from file (or just init SDL_image manually).

The surface is automatically destroyed when the object is destroyed.

See also
fge::texture::Init

Member Function Documentation

◆ addBorder()

bool fge::Surface::addBorder ( int borderSize,
fge::Color const & color )

Add a border to the surface with a specific color.

An example of this function is to add a transparent border to a surface and then convert it to a texture.

Parameters
borderSizeThe size of the border
colorThe color of the border
Returns
true if the border was successfully added

◆ blitSurface()

bool fge::Surface::blitSurface ( Surface const & src,
std::optional< SDL_Rect > const & srcRect,
std::optional< SDL_Rect > & dstRect )

Blit a surface on this surface.

See also
https://wiki.libsdl.org/SDL2/SDL_BlitSurface
Parameters
srcThe source surface
srcRectThe source rectangle
dstRectThe destination rectangle
Returns
true if the blit was successful

◆ clear()

void fge::Surface::clear ( )

Destroy the surface.

◆ createMaskFromColor()

void fge::Surface::createMaskFromColor ( fge::Color const & color,
uint8_t alpha = 0 )

Create a transparent mask from a color.

Parameters
colorThe color to make transparent
alphaThe alpha value of the transparent color

◆ fillRect()

bool fge::Surface::fillRect ( std::optional< SDL_Rect > const & rect,
fge::Color const & color )

Fill a rectangle section of the surface with a color.

See also
https://wiki.libsdl.org/SDL2/SDL_FillRect
Parameters
rectThe rectangle to fill
colorThe color to fill with
Returns
true if the rectangle was successfully filled

◆ get()

SDL_Surface * fge::Surface::get ( ) const
nodiscard

Get the SDL_Surface pointer.

Returns
The SDL_Surface pointer

◆ normalizeTextureCoords()

fge::Vector2f fge::Surface::normalizeTextureCoords ( fge::Vector2i const & coords) const
nodiscard

Convert some pixel coordinates to texture coordinates (0.0f to 1.0f)

Parameters
coordsThe pixel coordinates
Returns
The texture coordinates

◆ normalizeTextureRect()

fge::RectFloat fge::Surface::normalizeTextureRect ( fge::RectInt const & rect) const
nodiscard

Convert a pixel rectangle to a texture rectangle (0.0f to 1.0f)

Parameters
rectThe pixel rectangle
Returns
The texture rectangle

◆ saveToFile()

bool fge::Surface::saveToFile ( std::filesystem::path const & filePath) const

Save the surface to a PNG format file.

Parameters
filePathThe path to the file
Returns
true if the file was successfully saved

◆ set()

void fge::Surface::set ( SDL_Surface * surface)

Set a new surface.

The newly set surface will be destroyed when the object is destroyed.

Parameters
surfaceThe new surface

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