Line data Source code
1 : #ifndef RENDERTEXT_H_
2 : #define RENDERTEXT_H_
3 : struct font
4 : {
5 : struct charinfo
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 : constexpr int minreswidth = 640,
30 : minresheight = 480;
31 :
32 : extern float textscale;
33 :
34 : extern void reloadfonts();
35 :
36 0 : inline void setfont(font *f)
37 : {
38 0 : if(f)
39 : {
40 0 : curfont = f;
41 : }
42 0 : }
43 :
44 : extern bool setfont(const char *name);
45 : extern void pushfont();
46 : extern bool popfont();
47 : extern void gettextres(int &w, int &h);
48 :
49 : extern float text_widthf(const char *str);
50 : extern void text_boundsf(const char *str, float &width, float &height, int maxwidth = -1);
51 : extern int text_visible(const char *str, float hitx, float hity, int maxwidth);
52 : extern void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth);
53 :
54 0 : inline int text_width(const char *str)
55 : {
56 0 : return static_cast<int>(std::ceil(text_widthf(str)));
57 : }
58 : #endif
|