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
assets.h
Go to the documentation of this file.
1
8
9#ifndef ASW_ASSETS_H
10#define ASW_ASSETS_H
11
12#include <string>
13
14#include "./color.h"
15#include "./types.h"
16#include "./util.h"
17
18namespace asw::assets {
19
20// --- Paths ---
21
27std::string get_path(const std::string& filename);
28
37std::string get_save_path(const std::string& org, const std::string& app);
38
50std::string read_save(const std::string& org, const std::string& app, const std::string& name);
51
60bool write_save(const std::string& org, const std::string& app, const std::string& name,
61 const std::string& data);
62
63// --- Texture ---
64
73asw::Texture load_texture(const std::string& filename);
74
82asw::Texture load_texture(const std::string& filename, const std::string& key);
83
89asw::Texture get_texture(const std::string& key);
90
95void unload_texture(const std::string& key);
96
103asw::Texture create_texture(int w, int h);
104
115 int size, asw::Color inner, asw::Color outer, asw::Falloff falloff = asw::Falloff::Smooth);
116
117// --- Font ---
118
128 const std::string& filename, float size, asw::FontStyle style = asw::FontStyle::Smooth);
129
138asw::Font load_font(const std::string& filename, float size, const std::string& key,
140
146asw::Font get_font(const std::string& key);
147
152void unload_font(const std::string& key);
153
154// --- Sample ---
155
162asw::Sample load_sample(const std::string& filename);
163
170asw::Sample load_sample(const std::string& filename, const std::string& key);
171
177asw::Sample get_sample(const std::string& key);
178
183void unload_sample(const std::string& key);
184
185// --- Music ---
186
193asw::Music load_music(const std::string& filename);
194
201asw::Music load_music(const std::string& filename, const std::string& key);
202
208asw::Music get_music(const std::string& key);
209
214void unload_music(const std::string& key);
215
216// --- Global ---
217
221void clear_all();
222
223} // namespace asw::assets
224
225#endif // ASW_ASSETS_H
asw::Sample get_sample(const std::string &key)
Get a cached sample.
Definition assets.cpp:278
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.
Definition assets.cpp:405
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.
Definition assets.cpp:421
asw::Texture create_texture(int w, int h)
Create a Texture given the specified dimensions.
Definition assets.cpp:120
void unload_music(const std::string &key)
Remove a cached music.
Definition assets.cpp:326
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 ap...
Definition assets.cpp:48
asw::Texture get_texture(const std::string &key)
Get a cached texture.
Definition assets.cpp:106
void unload_sample(const std::string &key)
Remove a cached sample.
Definition assets.cpp:287
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 ...
Definition assets.cpp:144
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....
Definition assets.cpp:59
void unload_font(const std::string &key)
Remove a cached font.
Definition assets.cpp:246
asw::Music load_music(const std::string &filename)
Loads a music file from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC....
Definition assets.cpp:294
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.
Definition assets.cpp:201
void clear_all()
Clear all cached assets. This will remove all cached textures, fonts, samples, and music.
Definition assets.cpp:333
void unload_texture(const std::string &key)
Remove a cached texture.
Definition assets.cpp:115
asw::Music get_music(const std::string &key)
Get a cached music.
Definition assets.cpp:317
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 th...
Definition assets.cpp:255
asw::Font get_font(const std::string &key)
Get a cached font.
Definition assets.cpp:237
asw::Texture load_texture(const std::string &filename)
Loads a texture from a file. Formats supported are PNG, ICO, CUR, BMP, GIF, JPG, LBM,...
Definition assets.cpp:73
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Definition types.h:79
std::shared_ptr< MIX_Audio > Sample
Alias for a shared pointer to an MIX_Audio.
Definition types.h:82
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:76
std::shared_ptr< MIX_Audio > Music
Alias for a shared pointer to an MIX_Audio.
Definition types.h:85
Falloff
How a gradient or light fades from its centre to its edge.
Definition types.h:46
@ Smooth
Soft at the centre and at the edge.
FontStyle
How a font's glyphs are rendered.
Definition types.h:65
RGBA color struct with 8-bit channels.
Definition color.h:18
Types used throughout the ASW library.
General utility functions.