Multiple text drawing per row and draw basic colors
This commit is contained in:
parent
5e464afa77
commit
54e13abc7f
43
bt.c
43
bt.c
@ -179,21 +179,24 @@ int main(void) {
|
|||||||
new_read = true;
|
new_read = true;
|
||||||
}
|
}
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
Color current_color = RAYWHITE;
|
||||||
int col_max = 200;
|
int col_max = 200;
|
||||||
char row_buf[col_max];
|
char row_buf[col_max];
|
||||||
int nrow = 0;
|
int nrow = 0;
|
||||||
int ncol = 0;
|
int ncol = 0;
|
||||||
int row_height = 18;
|
int row_height = 18;
|
||||||
|
float row_posx = 0;
|
||||||
for (int c = 0; c <= sb.length; c++) {
|
for (int c = 0; c <= sb.length; c++) {
|
||||||
if (sb.buf[c] == '\r') {
|
if (sb.buf[c] == '\r') {
|
||||||
continue;
|
continue;
|
||||||
} else if (sb.buf[c] == '\n' || sb.buf[c] == '\0' || ncol >= col_max) {
|
} else if (sb.buf[c] == '\n' || sb.buf[c] == '\0' || ncol >= col_max) {
|
||||||
row_buf[ncol] = '\0';
|
row_buf[ncol] = '\0';
|
||||||
Vector2 pos = { 0, nrow * row_height + sb.ypos };
|
Vector2 pos = { row_posx, nrow * row_height + sb.ypos };
|
||||||
DrawTextEx(*fontDefault, row_buf, pos, fontsize, 0, RAYWHITE);
|
DrawTextEx(*fontDefault, row_buf, pos, fontsize, 0, current_color);
|
||||||
nrow++;
|
nrow++;
|
||||||
ncol = 0;
|
ncol = 0;
|
||||||
} if (sb.buf[c] == '\x1b') {
|
row_posx = 0;
|
||||||
|
} else if (sb.buf[c] == '\x1b') {
|
||||||
int c2 = c + 1;
|
int c2 = c + 1;
|
||||||
// Control Sequence Introducer
|
// Control Sequence Introducer
|
||||||
int csi_args[16];
|
int csi_args[16];
|
||||||
@ -213,13 +216,41 @@ int main(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
csi_code = substr[0];
|
csi_code = substr[0];
|
||||||
|
Color new_color = current_color;
|
||||||
|
switch (csi_code) {
|
||||||
|
case 'm':
|
||||||
|
for (int i = 0; i < nargs; i++) {
|
||||||
|
if (csi_args[i] == 31) {
|
||||||
|
new_color = RED;
|
||||||
|
} else if (csi_args[i] == 32) {
|
||||||
|
new_color = GREEN;
|
||||||
|
} else if (csi_args[i] == 33) {
|
||||||
|
new_color = YELLOW;
|
||||||
|
} else if (csi_args[i] == 34) {
|
||||||
|
new_color = BLUE;
|
||||||
|
} else if (csi_args[i] == 35) {
|
||||||
|
new_color = MAGENTA;
|
||||||
|
} else if (csi_args[i] == 36) {
|
||||||
|
new_color = SKYBLUE;
|
||||||
|
} else if (csi_args[i] == 0) {
|
||||||
|
new_color = RAYWHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
row_buf[ncol] = '\0';
|
||||||
|
Vector2 pos = { row_posx, nrow * row_height + sb.ypos };
|
||||||
|
DrawTextEx(*fontDefault, row_buf, pos, fontsize, 0, current_color);
|
||||||
|
current_color = new_color;
|
||||||
|
ncol = 0;
|
||||||
|
c += (substr) - (sb.buf + c);
|
||||||
|
int width = MeasureTextEx(*fontDefault, row_buf, fontsize, 1).x;
|
||||||
|
row_posx += width + 0.85;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Found an escape sequence. Code: %c.\n", csi_code);
|
|
||||||
} else {
|
} else {
|
||||||
row_buf[ncol] = sb.buf[c];
|
row_buf[ncol++] = sb.buf[c];
|
||||||
ncol++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user