naev 0.11.5
font.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "nstring.h"
7#include "opengl.h"
8
9#define FONT_COLOUR_CODE '#'
10
11#define FONT_FLAG_DONTREUSE (1<<1)
16typedef struct glFont_s {
17 int id;
18 int h;
19} glFont;
20extern glFont gl_defFont;
21extern glFont gl_smallFont;
27typedef struct glFontRestore_s {
28 const glColour *col;
30
40typedef struct glPrintLineIterator_s {
41 const char *text;
42 const glFont *ft_font;
43 int width;
44 int l_width;
45 size_t l_begin, l_end;
46 size_t l_next;
47 uint8_t dead;
50
51/*
52 * glFont loading / freeing
53 *
54 * if font is NULL it uses the internal default font same with gl_print
55 */
56int gl_fontInit( glFont* font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags );
57int gl_fontAddFallback( glFont* font, const char *fname, const char *prefix );
58int gl_fontAddFallbackFont( glFont* font, const glFont *f );
59void gl_freeFont( glFont* font );
60void gl_fontExit (void);
61
62/*
63 * const char printing
64 */
65void gl_printRaw( const glFont *ft_font,
66 const double x, const double y,
67 const glColour* c, const double outlineR , const char *text);
68void gl_printRawH( const glFont *ft_font, const mat4 *H,
69 const glColour* c, const double outlineR , const char *text );
70int gl_printMaxRaw( const glFont *ft_font, const int max,
71 const double x, const double y,
72 const glColour* c, const double outlineR , const char *text);
73int gl_printMidRaw( const glFont *ft_font, const int width,
74 double x, const double y,
75 const glColour* c, const double outlineR , const char *text);
76int gl_printTextRaw( const glFont *ft_font,
77 const int width, const int height,
78 double bx, double by, int line_height,
79 const glColour* c, const double outlineR, const char *text);
80void gl_printMarkerRaw( const glFont *ft_font,
81 const double x, const double y,
82 const glColour* c, const char *text);
83
84/*
85 * printf style printing.
86 */
87/* prints text normally */
88PRINTF_FORMAT( 5, 6 ) void gl_print( const glFont *ft_font, double x, double y,
89 const glColour *c, const char *fmt, ... );
90/* prints text to a max length */
91PRINTF_FORMAT( 6, 7 ) int gl_printMax( const glFont *ft_font, const int max,
92 double x, double y,
93 const glColour *c, const char *fmt, ... );
94/* prints text centered in width at x */
95PRINTF_FORMAT( 6, 7 ) int gl_printMid( const glFont *ft_font, const int width,
96 double x, double y,
97 const glColour* c, const char *fmt, ... );
98/* respects \n -> bx,by is TOP LEFT POSITION */
99PRINTF_FORMAT( 8, 9 ) int gl_printText( const glFont *ft_font,
100 int width, int height,
101 double bx, double by, int line_height,
102 const glColour* c, const char *fmt, ... );
103
104/* Dimension stuff. */
105void gl_printLineIteratorInit( glPrintLineIterator* iter, const glFont *ft_font, const char *text, int width );
106int gl_printLineIteratorNext( glPrintLineIterator* iter );
107int gl_printWidthRaw( const glFont *ft_font, const char *text );
108PRINTF_FORMAT( 2, 3 )int gl_printWidth( const glFont *ft_font, const char *fmt, ... );
109int gl_printHeightRaw( const glFont *ft_font, int width, const char *text );
110PRINTF_FORMAT( 3, 4 )int gl_printHeight( const glFont *ft_font, int width, const char *fmt, ... );
111int gl_printLinesRaw( const glFont *ft_font, int width, const char *text );
112PRINTF_FORMAT( 3, 4 )int gl_printLines( const glFont *ft_font, int width, const char *fmt, ... );
113
114/* Restore hacks. */
115void gl_printRestoreClear (void);
116void gl_printRestoreInit( glFontRestore *restore );
117void gl_printRestoreLast (void);
118void gl_printRestore( const glFontRestore *restore );
119void gl_printStoreMax( glFontRestore *restore, const char *text, int max );
120void gl_printStore( glFontRestore *restore, const char *text );
121
122/* Misc stuff. */
123void gl_fontSetFilter( const glFont *ft_font, GLint min, GLint mag );
glFont gl_smallFont
Definition font.c:154
void gl_printRaw(const glFont *ft_font, double x, double y, const glColour *c, double outlineR, const char *text)
Prints text on screen.
Definition font.c:617
glFont gl_defFont
Definition font.c:153
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
Definition font.c:788
int gl_fontAddFallback(glFont *font, const char *fname, const char *prefix)
Adds a fallback font to a font.
Definition font.c:1618
int gl_printTextRaw(const glFont *ft_font, const int width, const int height, double bx, double by, int line_height, const glColour *c, double outlineR, const char *text)
Prints a block of text that fits in the dimensions given.
Definition font.c:870
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
Definition font.c:1723
void gl_printRawH(const glFont *ft_font, const mat4 *H, const glColour *c, const double outlineR, const char *text)
Prints text on screen using a transformation matrix.
Definition font.c:648
int gl_printMaxRaw(const glFont *ft_font, const int max, double x, double y, const glColour *c, double outlineR, const char *text)
Behaves like gl_printRaw but stops displaying text after a certain distance.
Definition font.c:721
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
Definition font.c:1517
void gl_fontExit(void)
Frees all resources associated with the font system. This also resets font ID tracking,...
Definition font.c:1771
glFont gl_defFontMono
Definition font.c:155
void gl_printMarkerRaw(const glFont *ft_font, double x, double y, const glColour *c, const char *text)
Wrapper for gl_printRaw for map overlay markers.
Definition font.c:673
static const double c[]
Definition rng.c:264
Evil hack to allow restoring, yes it makes me cry myself to sleep.
Definition font.h:27
const glColour * col
Definition font.h:28
Represents a font in memory.
Definition font.h:16
int h
Definition font.h:18
int id
Definition font.h:17
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...
Definition font.h:40
const char * text
Definition font.h:41
uint8_t no_soft_breaks
Definition font.h:48
const glFont * ft_font
Definition font.h:42
size_t l_next
Definition font.h:46
uint8_t dead
Definition font.h:47
Definition mat4.h:10