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
6void asw::util::abortOnError(const std::string& message) {
7 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", message.c_str(),
8 nullptr);
9 exit(-1);
10}
11
12asw::Color asw::util::makeColor(int r, int g, int b) {
13 asw::Color color;
14 color.r = r;
15 color.g = g;
16 color.b = b;
17 color.a = 255;
18 return color;
19}
20
21asw::Color asw::util::makeColor(int r, int g, int b, int a) {
22 asw::Color color;
23 color.r = r;
24 color.g = g;
25 color.b = b;
26 color.a = a;
27 return color;
28}
29
32 SDL_GetTextureSize(tex.get(), &size.x, &size.y);
33 return size;
34}
35
37 const std::string& text) {
38 TTF_Text* ttf_text = TTF_CreateText(nullptr, font.get(), text.c_str(), 0);
39 asw::Vec2<int> size;
40 TTF_GetTextSize(ttf_text, &size.x, &size.y);
41 return size;
42}
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
asw::Vec2< float > getTextureSize(const asw::Texture &tex)
Get texture size.
Definition util.cpp:30
asw::Color makeColor(int r, int g, int b)
Make a color from RGB values.
Definition util.cpp:12
asw::Vec2< int > getTextSize(const asw::Font &font, const std::string &text)
Get text size.
Definition util.cpp:36
void abortOnError(const std::string &message)
Abort program and display error message.
Definition util.cpp:6
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Definition types.h:23
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:20
SDL_Color Color
Alias for an SDL_Color.
Definition types.h:38
General utility functions.