|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
Utility bag for SDL-based applications. More...
#include <util.hpp>
Public Member Functions | |
| ~mxUtil () | |
| Destructor — closes all open joystick handles. | |
| mxUtil ()=default | |
| mxUtil (const mxUtil &)=delete | |
| mxUtil & | operator= (const mxUtil &)=delete |
| mxUtil (mxUtil &&)=delete | |
| mxUtil & | operator= (mxUtil &&)=delete |
| std::string | getFilePath (const std::string &filename) |
| Prepend the asset path to a filename. | |
| void | printText (SDL_Renderer *renderer, TTF_Font *font, int x, int y, const std::string &text, SDL_Color col) |
| Render a text string onto an SDL_Renderer. | |
| SDL_Texture * | loadTexture (SDL_Renderer *renderer, const std::string &filename) |
| Load an SDL_Texture from a file. | |
| SDL_Texture * | loadTexture (SDL_Renderer *renderer, const std::string &filename, int &w, int &h, bool color, SDL_Color key) |
| Load an SDL_Texture with colour-key transparency. | |
| SDL_Surface * | loadSurface (const std::string &name) |
| Load an image as an SDL_Surface. | |
| TTF_Font * | loadFont (const std::string &filename, int size) |
| Load a TTF font at the specified point size. | |
| void | initJoystick () |
| Initialise and open SDL joysticks. | |
| void | closeJoystick () |
| Close all open SDL joystick handles. | |
Public Attributes | |
| std::string | path = "assets" |
| Root asset directory (native). | |
| std::vector< SDL_Joystick * > | stick |
| Open joystick handles. | |
Utility bag for SDL-based applications.
Holds the asset path and provides convenience wrappers for loading textures, fonts, printing text, and managing SDL joystick handles. Non-copyable and non-movable by design — embed one instance per window.
|
inline |
Destructor — closes all open joystick handles.
Definition at line 36 of file util.hpp.
References closeJoystick().
|
default |
Referenced by mxUtil(), mxUtil(), operator=(), and operator=().
|
delete |
References mxUtil().
|
delete |
References mxUtil().
| void mx::mxUtil::closeJoystick | ( | ) |
| std::string mx::mxUtil::getFilePath | ( | const std::string & | filename | ) |
Prepend the asset path to a filename.
| filename | Relative filename. |
Definition at line 110 of file util.cpp.
References path.
Referenced by loadFont(), loadSurface(), and loadTexture().
| void mx::mxUtil::initJoystick | ( | ) |
Initialise and open SDL joysticks.
Definition at line 176 of file util.cpp.
References stick, and mx::system_out.
| TTF_Font * mx::mxUtil::loadFont | ( | const std::string & | filename, |
| int | size ) |
Load a TTF font at the specified point size.
| filename | Font file path. |
| size | Point size. |
Definition at line 162 of file util.cpp.
References getFilePath(), and mx::system_err.
| SDL_Surface * mx::mxUtil::loadSurface | ( | const std::string & | name | ) |
Load an image as an SDL_Surface.
| name | Image file path. |
Definition at line 172 of file util.cpp.
References getFilePath(), and png::LoadPNG().
| SDL_Texture * mx::mxUtil::loadTexture | ( | SDL_Renderer * | renderer, |
| const std::string & | filename ) |
Load an SDL_Texture from a file.
| renderer | Active renderer. |
| filename | Image file path (relative to asset root). |
Definition at line 134 of file util.cpp.
References loadTexture().
Referenced by loadTexture().
| SDL_Texture * mx::mxUtil::loadTexture | ( | SDL_Renderer * | renderer, |
| const std::string & | filename, | ||
| int & | w, | ||
| int & | h, | ||
| bool | color, | ||
| SDL_Color | key ) |
Load an SDL_Texture with colour-key transparency.
| renderer | Active renderer. |
| filename | Image file path. |
| w | Output: image width. |
| h | Output: image height. |
| color | Apply colour key if true. |
| key | Colour to treat as transparent. |
Definition at line 139 of file util.cpp.
References getFilePath(), png::LoadPNG(), and mx::system_err.
| void mx::mxUtil::printText | ( | SDL_Renderer * | renderer, |
| TTF_Font * | font, | ||
| int | x, | ||
| int | y, | ||
| const std::string & | text, | ||
| SDL_Color | col ) |
Render a text string onto an SDL_Renderer.
| renderer | Active renderer. |
| font | TTF font to use. |
| x | X position. |
| y | Y position. |
| text | String to draw. |
| col | Text colour. |
Definition at line 116 of file util.cpp.
References mx::system_err.
| std::string mx::mxUtil::path = "assets" |
Root asset directory (native).
Definition at line 47 of file util.hpp.
Referenced by getFilePath(), and operator=().
| std::vector<SDL_Joystick *> mx::mxUtil::stick |
Open joystick handles.
Definition at line 109 of file util.hpp.
Referenced by closeJoystick(), and initJoystick().