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::abort_on_error(const std::string& message)
9{
10 asw::log::error(message);
11 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", message.c_str(), nullptr);
12 exit(-1);
13}
14
16{
18 SDL_GetTextureSize(tex.get(), &size.x, &size.y);
19 return size;
20}
21
22asw::Vec2<int> asw::util::get_text_size(const asw::Font& font, const std::string& text)
23{
24 TTF_Text* ttf_text = TTF_CreateText(nullptr, font.get(), text.c_str(), 0);
25 asw::Vec2<int> size;
26 TTF_GetTextSize(ttf_text, &size.x, &size.y);
27 TTF_DestroyText(ttf_text);
28
29 return size;
30}
A 2D vector in space.
Definition geometry.h:21
T y
The y component of the vector.
Definition geometry.h:196
T x
The x component of the vector.
Definition geometry.h:193
Structured logging system.
void error(const std::string &message)
Log an error message.
Definition log.cpp:178
asw::Vec2< float > get_texture_size(const asw::Texture &tex)
Get texture size.
Definition util.cpp:15
asw::Vec2< int > get_text_size(const asw::Font &font, const std::string &text)
Get text size.
Definition util.cpp:22
void abort_on_error(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:41
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:38
General utility functions.