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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
//|_ _ _. _ ._ |_ _. _ |
//| | (/_ (_| \/ (/_ | | | | (_| (_ |<
#pragma once
#include "util.h"
#include "typedef.h"
#define clog( ... ) con_print( CONFG_WHITE, __VA_ARGS__ )
#define clogc( x, ... ) con_print( x, __VA_ARGS__ )
constexpr U8 CON_WIDTH = 52;
constexpr U8 CON_HEIGHT = 16;
constexpr U8 CON_MAX_WIDTH = CON_WIDTH - 6;
constexpr U8 CON_MAX_HEIGHT = CON_HEIGHT - 5;
constexpr U8 CON_TITLE_HEIGHT = 4;
constexpr U8 LINE_INACTIVE = 0xff;
enum ConsoleColFg_t {
CONFG_BLACK = 0,
CONFG_DARKBLUE,
CONFG_DARKGREEN,
CONFG_LIGHTBLUE,
CONFG_RED,
CONFG_PURPLE,
CONFG_GOLD,
CONFG_LIGHTGRAY,
CONFG_DARKGRAY,
CONFG_BLUE,
CONFG_LIGHTGREEN,
CONFG_CYAN,
CONFG_LIGHTRED,
CONFG_MAGENTA,
CONFG_YELLOW,
CONFG_WHITE
};
enum ConsoleColBg_t {
CONBG_BLACK = 0,
CONBG_DARKBLUE = 0x10,
CONBG_DARKGREEN = 0x20,
CONBG_LIGHTBLUE = 0x30,
CONBG_RED = 0x40,
CONBG_PURPLE = 0x50,
CONBG_GOLD = 0x60,
CONBG_LIGHTGRAY = 0x70,
CONBG_DARKGRAY = 0x80,
CONBG_BLUE = 0x90,
CONBG_LIGHTGREEN = 0xa0,
CONBG_CYAN = 0xb0,
CONBG_LIGHTRED = 0xc0,
CONBG_MAGENTA = 0xd0,
CONBG_YELLOW = 0xe0,
CONBG_WHITE = 0xf0
};
enum LineActionType_t {
LINE_ACTION_ENTER,
LINE_ACTION_LEFTARROW,
LINE_ACTION_RIGHTARROW
};
typedef void( *LINE_CALLBACK )( struct CON_LINE* self, U8 action );
struct CON_LINE {
char text[CON_MAX_WIDTH + 1];
char subtext[12];
U8 text_col = 15;
U8 subtext_col = 15;
I8 line_num;
bool active;
LINE_CALLBACK callback;
};
extern CON_LINE* con_lines;
extern U8 con_selected_line;
extern void con_print_title();
extern void con_resize( U8 w, U8 h );
extern void con_setpos( U8 x, U8 y );
extern void con_set_line_text(
U8 line,
const char* text,
bool selected = false,
U8 fg = CONFG_WHITE,
U8 bg = CONBG_BLACK
);
extern void con_set_line_subtext(
U8 line,
const char* text,
bool selected = false,
U8 fg = CONFG_WHITE,
U8 bg = CONBG_BLACK
);
extern void con_set_line(
U8 line,
const char* text,
const char* subtext,
bool selected = false,
U8 fg = CONFG_WHITE,
U8 bg = CONBG_BLACK
);
extern void con_init();
extern void con_set_line_callback( U8 line, LINE_CALLBACK cb );
extern void con_set_bottomline_text( const char* text, ... );
extern void con_set_bottomline_text( U8 color, const char* text, ... );
extern void con_clear_bottomline_text();
extern void con_clear_line( U8 line );
extern void con_clear();
extern void con_refresh();
extern void con_print( U8 color, const char* text, ... );
extern void con_print_line( U8 line );
extern void con_set_assert( const char* text, ... );
inline STR<16> con_to_setting_str( bool setting ) {
return setting ? "[ON]" : "[OFF]";
}
inline STR<16> con_to_setting_str( F32 setting ) {
char buf[16];
snprintf( buf, 16, "[%.02f]", setting );
return buf;
}
inline STR<16> con_to_setting_str( I32 setting ) {
char buf[16];
snprintf( buf, 16, "[%d]", setting );
return buf;
}
inline STR<16> con_to_setting_str( U32 setting ) {
char buf[16];
snprintf( buf, 16, "[%u]", setting );
return buf;
}
inline void con_print_colors() {
for( I16 i = 0; i <= 255; ++i )
con_print( (U8)i, "%003d", i );
}
extern STR<64> con_progressbar( F32 progress, U8 width = CON_MAX_WIDTH );
|