aboutsummaryrefslogtreecommitdiffstats
path: root/src/text
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-04 10:38:40 +0200
committerBad Diode <bd@badd10de.dev>2021-06-04 10:38:40 +0200
commit0578a6db65f81f868c527aadfb57a89875d09d94 (patch)
tree2a28b0f5cc503b2a57455802d4fe5e90bba9333f /src/text
parent76343003abd8bc686e6bb5ca4bcb77cb33b76e10 (diff)
downloadstepper-0578a6db65f81f868c527aadfb57a89875d09d94.tar.gz
stepper-0578a6db65f81f868c527aadfb57a89875d09d94.zip
Add explanatory comments on text drawing functions
Diffstat (limited to 'src/text')
-rw-r--r--src/text/text.h50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/text/text.h b/src/text/text.h
index 630f04f..3b7921d 100644
--- a/src/text/text.h
+++ b/src/text/text.h
@@ -25,6 +25,7 @@ typedef struct TextEngine {
25 25
26static TextEngine text_engine = {0}; 26static TextEngine text_engine = {0};
27 27
28// Initializes the text engine.
28static inline 29static inline
29void 30void
30txt_init(u32 *font_data, u16 *font_tilemap, u16 font_offset) { 31txt_init(u32 *font_data, u16 *font_tilemap, u16 font_offset) {
@@ -43,38 +44,35 @@ txt_init(u32 *font_data, u16 *font_tilemap, u16 font_offset) {
43 text_engine.font_tilemap = font_tilemap; 44 text_engine.font_tilemap = font_tilemap;
44} 45}
45 46
47// Writes a message to the tile text background.
46static inline 48static inline
47void 49void
48txt_putc(char c) { 50txt_puts(char *msg) {
49 if (c == '\0') { 51 while (*msg) {
50 return; 52 char c = *msg++;
51 } 53 if (c == '\0') {
52 if (c == '\n') { 54 continue;
53 text_engine.cursor_x = 0; 55 }
54 text_engine.cursor_y++; 56 if (c == '\n') {
55 } else {
56 int x = text_engine.cursor_x;
57 int y = text_engine.cursor_y;
58 text_engine.font_tilemap[x + 32 * y] = text_engine.font_map[(u16)c];
59 text_engine.cursor_x += 1;
60 if (text_engine.cursor_x >= 30) {
61 text_engine.cursor_x = 0; 57 text_engine.cursor_x = 0;
62 text_engine.cursor_y++; 58 text_engine.cursor_y++;
59 } else {
60 int x = text_engine.cursor_x;
61 int y = text_engine.cursor_y;
62 text_engine.font_tilemap[x + 32 * y] = text_engine.font_map[(u16)c];
63 text_engine.cursor_x += 1;
64 if (text_engine.cursor_x >= 30) {
65 text_engine.cursor_x = 0;
66 text_engine.cursor_y++;
67 }
68 }
69 if (text_engine.cursor_y >= 20) {
70 text_engine.cursor_y = 0;
63 } 71 }
64 }
65 if (text_engine.cursor_y >= 20) {
66 text_engine.cursor_y = 0;
67 }
68}
69
70static inline
71void
72txt_puts(char *msg) {
73 while (*msg) {
74 txt_putc(*msg++);
75 } 72 }
76} 73}
77 74
75// Clears the current line on the tile text mode.
78static inline 76static inline
79void 77void
80txt_clear_line(void) { 78txt_clear_line(void) {
@@ -86,6 +84,7 @@ txt_clear_line(void) {
86 text_engine.cursor_x = 0; 84 text_engine.cursor_x = 0;
87} 85}
88 86
87// Clears the screen on the tile text mode.
89static inline 88static inline
90void 89void
91txt_clear_screen(void) { 90txt_clear_screen(void) {
@@ -97,6 +96,7 @@ txt_clear_screen(void) {
97 text_engine.cursor_y = 0; 96 text_engine.cursor_y = 0;
98} 97}
99 98
99// Moves the tile mode cursor to the specified position.
100static inline 100static inline
101void 101void
102txt_position(size_t tile_x, size_t tile_y) { 102txt_position(size_t tile_x, size_t tile_y) {
@@ -127,6 +127,8 @@ txt_draws(char *msg, size_t x, size_t y, size_t spacing) {
127 txt_puts(buf); \ 127 txt_puts(buf); \
128 } 128 }
129 129
130// Draws text to the screen with formatting starting on the x and y position and
131// with custom character spacing.
130#define txt_drawf(msg, x, y, s, ...) \ 132#define txt_drawf(msg, x, y, s, ...) \
131 { \ 133 { \
132 char buf[256] = {0}; \ 134 char buf[256] = {0}; \