1 #ifndef _TEXT_RENDER_H
2 #define _TEXT_RENDER_H
3 
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include "video/color.h"
7 #include "resources/fonts.h"
8 
9 typedef enum {
10     TEXT_TOP = 0,
11     TEXT_MIDDLE,
12     TEXT_BOTTOM
13 } text_valign;
14 
15 typedef enum {
16     TEXT_LEFT = 0,
17     TEXT_CENTER,
18     TEXT_RIGHT
19 } text_halign;
20 
21 typedef struct {
22     uint8_t left;
23     uint8_t right;
24     uint8_t top;
25     uint8_t bottom;
26 } text_padding;
27 
28 typedef enum {
29     TEXT_HORIZONTAL = 0,
30     TEXT_VERTICAL,
31 } text_direction;
32 
33 enum {
34     TEXT_SHADOW_NONE = 0,
35     TEXT_SHADOW_TOP = 0x1,
36     TEXT_SHADOW_BOTTOM = 0x2,
37     TEXT_SHADOW_LEFT = 0x4,
38     TEXT_SHADOW_RIGHT = 0x8,
39     TEXT_SHADOW_HORIZONTAL = 0xC,
40     TEXT_SHADOW_VERTICAL = 0x3,
41     TEXT_SHADOW_ALL = 0xF
42 };
43 
44 typedef struct {
45     color cforeground;
46     text_valign valign;
47     text_halign halign;
48     text_padding padding;
49     text_direction direction;
50     font_size font;
51     uint8_t shadow;
52     uint8_t cspacing;
53     uint8_t lspacing;
54     uint8_t opacity;
55     bool wrap;
56 } text_settings;
57 
58 // New text rendering functions
59 void text_defaults(text_settings *settings);
60 int text_find_max_strlen(int maxchars, const char *ptr);
61 int text_find_line_count(text_direction dir, int cols, int rows, int len, const char *text);
62 void text_render_char(const text_settings *settings, int x, int y, char ch);
63 void text_render(const text_settings *settings, int x, int y, int w, int h, const char *text);
64 int text_char_width(const text_settings *settings);
65 
66 // Old functions
67 void font_get_wrapped_size(const font *font, const char *text, int max_w, int *out_w, int *out_h);
68 void font_get_wrapped_size_shadowed(const font *font, const char *text, int max_w, int shadow_flag, int *out_w, int *out_h);
69 void font_render_char(const font *font, char ch, int x, int y, color c);
70 void font_render_char_shadowed(const font *font, char ch, int x, int y, color c, int shadow_flags);
71 void font_render_len(const font *font, const char *text, int len, int x, int y, color c);
72 void font_render_len_shadowed(const font *font, const char *text, int len, int x, int y, color c, int shadow_flags);
73 void font_render(const font *font, const char *text, int x, int y, color c);
74 void font_render_shadowed(const font *font, const char *text, int x, int y, color c, int shadow_flags);
75 void font_render_wrapped(const font *font, const char *text, int x, int y, int w, color c);
76 void font_render_wrapped_shadowed(const font *font, const char *text, int x, int y, int w, color c, int shadow_flags);
77 
78 #endif // _TEXT_RENDER_H
79