ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::assets Namespace Reference

Functions

std::string get_path (const std::string &filename)
 Get the full path to an asset given its filename. The filename is relative to the base path of the application (the executable directory, or Contents/Resources in a macOS bundle).
 
std::string get_save_path (const std::string &org, const std::string &app)
 Get a writable folder for save files and settings, unique to the organisation and application. The folder is created if needed.
 
std::string read_save (const std::string &org, const std::string &app, const std::string &name)
 Read save data written by write_save, e.g. progress or settings.
 
bool write_save (const std::string &org, const std::string &app, const std::string &name, const std::string &data)
 Write save data, replacing what was saved under the name before.
 
asw::Texture load_texture (const std::string &filename)
 Loads a texture from a file. Formats supported are PNG, ICO, CUR, BMP, GIF, JPG, LBM, PCX, PNM, TIF, XCF, XPM, XV, and WEBP. This will abort if the file is not found.
 
asw::Texture load_texture (const std::string &filename, const std::string &key)
 Load a texture from a file and cache it.
 
asw::Texture get_texture (const std::string &key)
 Get a cached texture.
 
void unload_texture (const std::string &key)
 Remove a cached texture.
 
asw::Texture create_texture (int w, int h)
 Create a Texture given the specified dimensions.
 
asw::Texture create_radial_gradient (int size, asw::Color inner, asw::Color outer, asw::Falloff falloff=asw::Falloff::Smooth)
 Create a square texture with a radial gradient. The colour goes from inner at the centre to outer at the edge. Useful for lights.
 
asw::Font load_font (const std::string &filename, float size, asw::FontStyle style=asw::FontStyle::Smooth)
 Loads a TTF font from a file. This will abort if the file is not found.
 
asw::Font load_font (const std::string &filename, float size, const std::string &key, asw::FontStyle style=asw::FontStyle::Smooth)
 Load a font from a file and cache it.
 
asw::Font get_font (const std::string &key)
 Get a cached font.
 
void unload_font (const std::string &key)
 Remove a cached font.
 
asw::Sample load_sample (const std::string &filename)
 Loads a sample from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC. This will abort if the file is not found.
 
asw::Sample load_sample (const std::string &filename, const std::string &key)
 Load a sample from a file and cache it.
 
asw::Sample get_sample (const std::string &key)
 Get a cached sample.
 
void unload_sample (const std::string &key)
 Remove a cached sample.
 
asw::Music load_music (const std::string &filename)
 Loads a music file from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC. This will abort if the file is not found.
 
asw::Music load_music (const std::string &filename, const std::string &key)
 Load a music file from a file and cache it.
 
asw::Music get_music (const std::string &key)
 Get a cached music.
 
void unload_music (const std::string &key)
 Remove a cached music.
 
void clear_all ()
 Clear all cached assets. This will remove all cached textures, fonts, samples, and music.
 

Function Documentation

◆ clear_all()

void asw::assets::clear_all ( )

Clear all cached assets. This will remove all cached textures, fonts, samples, and music.

Definition at line 333 of file assets.cpp.

◆ create_radial_gradient()

asw::Texture asw::assets::create_radial_gradient ( int size,
asw::Color inner,
asw::Color outer,
asw::Falloff falloff = asw::Falloff::Smooth )

Create a square texture with a radial gradient. The colour goes from inner at the centre to outer at the edge. Useful for lights.

Parameters
sizeThe width and height of the texture.
innerThe colour at the centre.
outerThe colour at the edge and in the corners.
falloffHow the colour changes from the centre to the edge.
Returns
The created Texture object, with linear scaling and blend mode set.

Definition at line 144 of file assets.cpp.

◆ create_texture()

asw::Texture asw::assets::create_texture ( int w,
int h )

Create a Texture given the specified dimensions.

Parameters
wThe width of the texture.
hThe height of the texture.
Returns
The created Texture object.

Definition at line 120 of file assets.cpp.

◆ get_font()

asw::Font asw::assets::get_font ( const std::string & key)

Get a cached font.

Parameters
keyThe key of the cached font.
Returns
The cached Font object.

Definition at line 237 of file assets.cpp.

◆ get_music()

asw::Music asw::assets::get_music ( const std::string & key)

Get a cached music.

Parameters
keyThe key of the cached music.
Returns
The cached Music object.

Definition at line 317 of file assets.cpp.

◆ get_path()

std::string asw::assets::get_path ( const std::string & filename)

Get the full path to an asset given its filename. The filename is relative to the base path of the application (the executable directory, or Contents/Resources in a macOS bundle).

Parameters
filenameThe asset filename, relative to the base path.
Returns
The full path to the asset, or the filename unchanged if the base path can not be determined.

Definition at line 48 of file assets.cpp.

◆ get_sample()

asw::Sample asw::assets::get_sample ( const std::string & key)

Get a cached sample.

Parameters
keyThe key of the cached sample.
Returns
The cached Sample object.

Definition at line 278 of file assets.cpp.

◆ get_save_path()

std::string asw::assets::get_save_path ( const std::string & org,
const std::string & app )

Get a writable folder for save files and settings, unique to the organisation and application. The folder is created if needed.

Parameters
orgThe organisation name.
appThe application name.
Returns
The folder path ending in a path separator, or an empty string if it can not be determined.

Definition at line 59 of file assets.cpp.

◆ get_texture()

asw::Texture asw::assets::get_texture ( const std::string & key)

Get a cached texture.

Parameters
keyThe key of the cached texture.
Returns
The cached Texture object.

Definition at line 106 of file assets.cpp.

◆ load_font() [1/2]

asw::Font asw::assets::load_font ( const std::string & filename,
float size,
asw::FontStyle style = asw::FontStyle::Smooth )

Loads a TTF font from a file. This will abort if the file is not found.

Parameters
filenameThe path to the font file.
sizeThe size of the font.
styleSmooth for regular fonts, Pixel for pixel art fonts.
Returns
The loaded Font object.

Definition at line 201 of file assets.cpp.

◆ load_font() [2/2]

asw::Font asw::assets::load_font ( const std::string & filename,
float size,
const std::string & key,
asw::FontStyle style = asw::FontStyle::Smooth )

Load a font from a file and cache it.

Parameters
filenameThe path to the font file.
sizeThe size of the font.
keyThe key to associate with the loaded font for caching.
styleSmooth for regular fonts, Pixel for pixel art fonts.
Returns
The loaded Font object.

Definition at line 225 of file assets.cpp.

◆ load_music() [1/2]

asw::Music asw::assets::load_music ( const std::string & filename)

Loads a music file from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC. This will abort if the file is not found.

Parameters
filenameThe path to the music file.
Returns
The loaded Music object.

Definition at line 294 of file assets.cpp.

◆ load_music() [2/2]

asw::Music asw::assets::load_music ( const std::string & filename,
const std::string & key )

Load a music file from a file and cache it.

Parameters
filenameThe path to the music file.
keyThe key to associate with the loaded music for caching.
Returns
The loaded Music object.

Definition at line 306 of file assets.cpp.

◆ load_sample() [1/2]

asw::Sample asw::assets::load_sample ( const std::string & filename)

Loads a sample from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC. This will abort if the file is not found.

Parameters
filenameThe path to the sample file.
Returns
The loaded Sample object.

Definition at line 255 of file assets.cpp.

◆ load_sample() [2/2]

asw::Sample asw::assets::load_sample ( const std::string & filename,
const std::string & key )

Load a sample from a file and cache it.

Parameters
filenameThe path to the sample file.
keyThe key to associate with the loaded sample for caching.
Returns
The loaded Sample object.

Definition at line 267 of file assets.cpp.

◆ load_texture() [1/2]

asw::Texture asw::assets::load_texture ( const std::string & filename)

Loads a texture from a file. Formats supported are PNG, ICO, CUR, BMP, GIF, JPG, LBM, PCX, PNM, TIF, XCF, XPM, XV, and WEBP. This will abort if the file is not found.

Parameters
filenameThe path to the texture file.
Returns
A Texture object that will automatically free the underlying SDL_Texture when it goes out of scope.

Definition at line 73 of file assets.cpp.

◆ load_texture() [2/2]

asw::Texture asw::assets::load_texture ( const std::string & filename,
const std::string & key )

Load a texture from a file and cache it.

Parameters
filenameThe path to the texture file.
keyThe key to associate with the loaded texture for caching.
Returns
A Texture object that will automatically free the underlying SDL_Texture when it goes out of scope.

Definition at line 95 of file assets.cpp.

◆ read_save()

std::string asw::assets::read_save ( const std::string & org,
const std::string & app,
const std::string & name )

Read save data written by write_save, e.g. progress or settings.

Desktop builds keep it in a file in get_save_path. Web builds keep it in the browser's localStorage, since the web file system is lost when the page reloads.

Parameters
orgThe organisation name.
appThe application name.
nameThe save's name, e.g. "progress".
Returns
The saved text, or an empty string if there is none.

Definition at line 405 of file assets.cpp.

◆ unload_font()

void asw::assets::unload_font ( const std::string & key)

Remove a cached font.

Parameters
keyThe key of the cached font to remove.

Definition at line 246 of file assets.cpp.

◆ unload_music()

void asw::assets::unload_music ( const std::string & key)

Remove a cached music.

Parameters
keyThe key of the cached music to remove.

Definition at line 326 of file assets.cpp.

◆ unload_sample()

void asw::assets::unload_sample ( const std::string & key)

Remove a cached sample.

Parameters
keyThe key of the cached sample to remove.

Definition at line 287 of file assets.cpp.

◆ unload_texture()

void asw::assets::unload_texture ( const std::string & key)

Remove a cached texture.

Parameters
keyThe key of the cached texture to remove.

Definition at line 115 of file assets.cpp.

◆ write_save()

bool asw::assets::write_save ( const std::string & org,
const std::string & app,
const std::string & name,
const std::string & data )

Write save data, replacing what was saved under the name before.

Parameters
orgThe organisation name.
appThe application name.
nameThe save's name, e.g. "progress".
dataThe text to save, e.g. JSON.
Returns
true - If it was saved.

Definition at line 421 of file assets.cpp.