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.h
Go to the documentation of this file.
1
8
9#ifndef ASW_UTIL_H
10#define ASW_UTIL_H
11
12#include <algorithm>
13#include <string>
14#include <string_view>
15
16#include "./easing.h"
17#include "./geometry.h"
18#include "./types.h"
19
20namespace asw::util {
21
26[[noreturn]]
27void abort_on_error(const std::string& message);
28
35
42asw::Vec2<int> get_text_size(const asw::Font& font, std::string_view text);
43
49int get_font_height(const asw::Font& font);
50
57bool open_url(const std::string& url);
58
65
73template <typename T> T lerp(const T& a, const T& b, float t)
74{
75 return asw::easing::detail::mix(a, b, std::clamp(t, 0.0F, 1.0F));
76}
77
78} // namespace asw::util
79
80#endif // ASW_UTIL_H
A 2D vector in space.
Definition geometry.h:27
Easing functions for animations.
Common geometry types.
T mix(const T &a, const T &b, float f)
a + (b - a) * f. Integer types are worked in floating point, so a falling unsigned range does not wra...
Definition easing.h:33
int get_font_height(const asw::Font &font)
Get the height of a line of text in a font.
Definition util.cpp:106
void clear_text_size_cache()
Clear cached text metrics.
Definition util.cpp:115
asw::Vec2< int > get_text_size(const asw::Font &font, std::string_view text)
Get text size.
Definition util.cpp:81
asw::Vec2< float > get_texture_size(const asw::Texture &tex)
Get texture size.
Definition util.cpp:74
bool open_url(const std::string &url)
Open a web page in the player's browser, e.g. a login or store page. Web builds open it in a new tab.
Definition util.cpp:120
T lerp(const T &a, const T &b, float t)
Lerp between two values.
Definition util.h:73
void abort_on_error(const std::string &message)
Abort program and display error message.
Definition util.cpp:67
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
Definition types.h:79
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:76
Types used throughout the ASW library.