Line data Source code
1 : #ifndef RENDERTEXT_H_
2 : #define RENDERTEXT_H_
3 : struct Font final
4 : {
5 : struct CharInfo final
6 : {
7 : float x, y, w, h, offsetx, offsety, advance;
8 : int tex;
9 :
10 : };
11 :
12 : std::string name;
13 : std::vector<Texture *> texs;
14 : std::vector<CharInfo> chars;
15 : int charoffset, defaultw, defaulth, scale;
16 : float bordermin, bordermax, outlinemin, outlinemax;
17 :
18 2 : Font() {}
19 : };
20 :
21 : #define FONTH (curfont->scale)
22 :
23 : extern Font *curfont;
24 :
25 0 : inline int fontwidth()
26 : {
27 0 : return FONTH/2;
28 : }
29 :
30 : extern float textscale;
31 :
32 : /**
33 : * @brief Reloads all fonts in the font map.
34 : *
35 : * If any fonts fail to reload, terminates the program with an error message.
36 : */
37 : extern void reloadfonts();
38 :
39 : /**
40 : * @brief Attempts to set the global curfont variable to the passed object.
41 : *
42 : * No effect if the pointer passed is null.
43 : *
44 : * @param f the font to attempt to set.
45 : */
46 : extern void setfont(Font *f);
47 :
48 : /**
49 : * @brief Attempts to set the global curfont variable with a named entry in fonts global
50 : *
51 : * If no font exists by the name passed, returns false and curfont remains unchanged.
52 : *
53 : * @param name the name of the font to search for
54 : *
55 : * @return true if successfully set curfont, false otherwise
56 : */
57 : extern bool setfont(const char *name);
58 :
59 : /**
60 : * @brief Push whatever font is assigned to curfont to the font stack.
61 : *
62 : * fontstack is a std::stack of font pointers. The value in curfont will be
63 : * added to fontstack even if it is null or duplicated.
64 : */
65 : extern void pushfont();
66 : extern bool popfont();
67 : extern void gettextres(int &w, int &h);
68 :
69 : extern float text_widthf(const char *str);
70 : extern void text_boundsf(const char *str, float &width, float &height, int maxwidth = -1);
71 : extern int text_visible(const char *str, float hitx, float hity, int maxwidth);
72 : extern void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth);
73 :
74 0 : inline int text_width(const char *str)
75 : {
76 0 : return static_cast<int>(std::ceil(text_widthf(str)));
77 : }
78 : #endif
|