Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rendertext.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <math.h> // for ceil
4 
5 #include "inexor/shared/cube_formatting.hpp" // for PRINTFARGS
6 #include "inexor/shared/cube_tools.hpp" // for DELETEA
7 // Simplistic bitmap text rendering
8 #include "inexor/shared/cube_vector.hpp" // for vector
9 
10 struct Texture;
11 struct matrix4x3;
12 
13 struct font
14 {
15  struct charinfo
16  {
17  short x, y, w, h, offsetx, offsety, advance, tex;
18  };
19 
20  char *name;
24 
25  font() : name(nullptr) {}
26  ~font() { delete name; name = nullptr; }
27 };
28 
29 #define FONTH (curfont->scale)
30 #define FONTW (FONTH/2)
31 #define MINRESW 640
32 #define MINRESH 480
33 
34 extern font *curfont;
35 extern const matrix4x3 *textmatrix;
36 extern bool setfont(const char *name);
37 extern void pushfont();
38 extern bool popfont();
39 extern void gettextres(int &w, int &h);
40 extern void draw_text(const char *str, int left, int top, int r = 255, int g = 255, int b = 255, int a = 255, int cursor = -1, int maxwidth = -1);
41 extern void draw_textf(const char *fstr, int left, int top, ...) PRINTFARGS(1, 4);
42 extern float text_widthf(const char *str);
43 extern void text_boundsf(const char *str, float &width, float &height, int maxwidth = -1);
44 extern int text_visible(const char *str, float hitx, float hity, int maxwidth);
45 extern void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth);
46 
47 static inline int text_width(const char *str)
48 {
49  return int(ceil(text_widthf(str)));
50 }
51 
52 static inline void text_bounds(const char *str, int &width, int &height, int maxwidth = -1)
53 {
54  float widthf, heightf;
55  text_boundsf(str, widthf, heightf, maxwidth);
56  width = int(ceil(widthf));
57  height = int(ceil(heightf));
58 }
59 
60 static inline void text_pos(const char *str, int cursor, int &cx, int &cy, int maxwidth)
61 {
62  float cxf, cyf;
63  text_posf(str, cursor, cxf, cyf, maxwidth);
64  cx = int(cxf);
65  cy = int(cyf);
66 }
Definition: geom.hpp:902
int defaultw
Definition: rendertext.hpp:23
int charoffset
Definition: rendertext.hpp:23
static int text_width(const char *str)
Definition: rendertext.hpp:47
GLenum GLsizei GLsizei height
Definition: glexts.hpp:291
short x
Definition: rendertext.hpp:17
void draw_text(const char *str, int left, int top, int r=255, int g=255, int b=255, int a=255, int cursor=-1, int maxwidth=-1)
Definition: rendertext.cpp:361
vector< Texture * > texs
Definition: rendertext.hpp:21
GLenum GLsizei width
Definition: glexts.hpp:291
short h
Definition: rendertext.hpp:17
#define PRINTFARGS(fmt, args)
Definition: cube_formatting.hpp:11
static void text_pos(const char *str, int cursor, int &cx, int &cy, int maxwidth)
Definition: rendertext.hpp:60
Definition: rendertext.hpp:13
short advance
Definition: rendertext.hpp:17
void gettextres(int &w, int &h)
Definition: rendertext.cpp:151
Definition: rendertext.hpp:15
void text_boundsf(const char *str, float &width, float &height, int maxwidth=-1)
Definition: rendertext.cpp:341
bool popfont()
Definition: rendertext.cpp:144
short tex
Definition: rendertext.hpp:17
vector< charinfo > chars
Definition: rendertext.hpp:22
void draw_textf(const char *fstr, int left, int top,...) PRINTFARGS(1
font()
Definition: rendertext.hpp:25
char * name
Definition: rendertext.hpp:20
font * curfont
Definition: rendertext.cpp:26
int text_visible(const char *str, float hitx, float hity, int maxwidth)
Definition: rendertext.cpp:303
short y
Definition: rendertext.hpp:17
short w
Definition: rendertext.hpp:17
int scale
Definition: rendertext.hpp:23
short offsety
Definition: rendertext.hpp:17
void pushfont()
Definition: rendertext.cpp:139
int defaulth
Definition: rendertext.hpp:23
bool setfont(const char *name)
Definition: rendertext.cpp:129
void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth)
Definition: rendertext.cpp:322
static void text_bounds(const char *str, int &width, int &height, int maxwidth=-1)
Definition: rendertext.hpp:52
void float text_widthf(const char *str)
Definition: rendertext.cpp:168
~font()
Definition: rendertext.hpp:26
const matrix4x3 * textmatrix
Definition: rendertext.cpp:198
short offsetx
Definition: rendertext.hpp:17
A Texture entry, holding info about a texture on the GPU.
Definition: texture.hpp:27