-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.c
100 lines (84 loc) · 1.52 KB
/
draw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <string.h>
#include "draw.h"
#include "serial.h"
#include "term.h"
#define SPACE_CHAR ' '
static void set_term_bg(draw_bg_setting bg);
void draw_vertical(short x, short y, short h, char c)
{
term_move_cursor(x, y);
for (short i = 0; i < h; i++)
{
if (i != 0)
{
serial_write("\e[B\e[D", 6);
}
serial_tx_byte(c);
}
}
void draw_horizontal(short x, short y, short l, char c)
{
term_move_cursor(x, y);
for (short i = 0; i < l; i++)
{
serial_tx_byte(c);
}
}
void draw_border(short w, short h, short c)
{
char buf[8];
for (short i = 0; i < h; i++)
{
if (i == 0 || i == h - 1)
{
for (short j = 0; j < w; j++)
{
serial_tx_byte(c);
}
}
else
{
serial_tx_byte(c);
sprintf(buf, "\e[%uC", w - 2);
serial_write(buf, strlen(buf));
serial_tx_byte(c);
}
serial_write_newline();
}
}
void draw_vertical_bg(short x, short y, short h, draw_bg_setting bg)
{
set_term_bg(bg);
draw_vertical(x, y, h, SPACE_CHAR);
set_term_bg(DRAW_BG_RESET);
}
void draw_horizontal_bg(short x, short y, short l, draw_bg_setting bg)
{
set_term_bg(bg);
draw_horizontal(x, y, l, SPACE_CHAR);
set_term_bg(DRAW_BG_RESET);
}
static void set_term_bg(draw_bg_setting bg)
{
unsigned short bg_code;
switch (bg)
{
case DRAW_BG_RED:
bg_code = 41;
break;
case DRAW_BG_GREEN:
bg_code = 42;
break;
case DRAW_BG_BLUE:
bg_code = 44;
break;
case DRAW_BG_RESET:
default:
bg_code = 0;
break;
}
char buf[8];
sprintf(buf, "\e[%um", bg_code);
serial_write(buf, strlen(buf));
}