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
util.cpp
Go to the documentation of this file.
2
3#include <SDL3/SDL.h>
4#include <SDL3_image/SDL_image.h>
5
6#include "./asw/modules/log.h"
7
8void asw::util::abortOnError(const std::string& message) {
9 asw::log::error(message);
10 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", message.c_str(),
11 nullptr);
12 exit(-1);
13}
14
17 SDL_GetTextureSize(tex.get(), &size.x, &size.y);
18 return size;
19}
20
22 const std::string& text) {
23 TTF_Text* ttf_text = TTF_CreateText(nullptr, font.get(), text.c_str(), 0);
24 asw::Vec2<int> size;
25 TTF_GetTextSize(ttf_text, &size.x, &size.y);
26 return size;
27}
A 2D vector in space.
Definition geometry.h:22
T y
The y component of the vector.
Definition geometry.h:184
T x
The x component of the vector.
Definition geometry.h:181
Structured logging system.
void error(const std::string &message)
Log an error message.
Definition log.cpp:92
asw::Vec2< float > getTextureSize(const asw::Texture &tex)
Get texture size.
Definition util.cpp:15
asw::Vec2< int > getTextSize(const asw::Font &font, const std::string &text)
Get text size.
Definition util.cpp:21
void abortOnError(const std::string &message)
Abort program and display error message.
Definition util.cpp:8
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Definition types.h:34
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:31
General utility functions.