r/o
1
#include "text.h"
2
#include "renderer.h"
3
4
unsigned short screen[80 * 25];
5
int screen_cursor_x;
6
int screen_cursor_y;
7
8
static int cursor_on = 1;
9
10
void text_refresh(void) {
11
SDL_RenderClear(renderer);
12
13
for (int y = 0; y < 25; ++y) {
14
for (int x = 0; x < 80; ++x) {
15
render_sfont(sfont, screen[y * 80 + x], x, y);
16
}
17
}
18
19
if (cursor_on) {
20
text_draw_cursor(screen_cursor_x, screen_cursor_y);
21
}
22
23
SDL_RenderPresent(renderer);
24
}
25
26
void text_refresh_at(int x, int y) {
27
render_sfont(sfont, screen[y * 80 + x], x, y);
28
}
29
30
void text_draw_cursor(int x, int y) {
31
unsigned short pair = screen[y * 80 + x];
32
int fg = cga_colors[(pair >> 8) & 0xf];
33
SDL_SetRenderDrawColor(renderer, fg >> 16, (fg >> 8) & 0xff, fg & 0xff, SDL_ALPHA_OPAQUE);
34
SDL_Rect rect = { x * FONT_WIDTH, y * FONT_HEIGHT + FONT_HEIGHT - 3, FONT_WIDTH, 2 };
35
SDL_RenderFillRect(renderer, &rect);
36
}
37
38
void text_cursor_toggle(void) {
39
cursor_on = !cursor_on;
40
}
41
42
/* vim: set sw=4 et: */
43