Add newlines to draw text
This commit is contained in:
@ -18,11 +18,27 @@ void drawText(
|
||||
) {
|
||||
if(len == 0) return;
|
||||
size_t rLen = mathMin(len, strlen(text));
|
||||
if(rLen == 0) return;
|
||||
|
||||
assertTrue(x + rLen <= FRAME_WIDTH, "Text is too long.");
|
||||
assertTrue(x < FRAME_WIDTH, "Text is too far right.");
|
||||
assertTrue(y < FRAME_HEIGHT, "Text is too low.");
|
||||
|
||||
uint16_t i = y * FRAME_WIDTH + x;
|
||||
memcpy(&FRAME_BUFFER[i], text, rLen);
|
||||
memset(&FRAME_COLOR[i], color, rLen);
|
||||
char_t c;
|
||||
uint16_t xPos = x;
|
||||
uint16_t yPos = y * FRAME_WIDTH;
|
||||
size_t i = 0;
|
||||
do {
|
||||
c = text[i++];
|
||||
if(c == '\n') {
|
||||
yPos += FRAME_WIDTH;
|
||||
xPos = x;
|
||||
continue;
|
||||
}
|
||||
|
||||
assertTrue(xPos < FRAME_WIDTH, "Text overflows right.");
|
||||
|
||||
FRAME_BUFFER[yPos + xPos] = c;
|
||||
FRAME_COLOR[yPos + xPos] = color;
|
||||
xPos++;
|
||||
} while(i < rLen);
|
||||
}
|
@ -89,7 +89,7 @@ void drawUITextbox() {
|
||||
memset(&FRAME_COLOR[DRAW_UI_TEXTBOX_CURSOR_POS], COLOR_WHITE, 3);
|
||||
if(TEXTBOX.textIndex < TEXTBOX.textLength) return;
|
||||
|
||||
int32_t blink = (int32_t)(TIME.time * TEXTBOX_BLINKS_PER_SECOND) % 2;
|
||||
int32_t blink = (int32_t)(TIME.time * DRAW_UI_TEXTBOX_BLINKS_PER_SECOND) % 2;
|
||||
FRAME_BUFFER[DRAW_UI_TEXTBOX_CURSOR_POS + 1] = blink ? '>' : ' ';
|
||||
FRAME_BUFFER[DRAW_UI_TEXTBOX_CURSOR_POS + 2] = blink ? ' ' : '>';
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
#define DRAW_UI_TEXTBOX_WIDTH FRAME_WIDTH
|
||||
#define DRAW_UI_TEXTBOX_HEIGHT 8
|
||||
#define DRAW_UI_TEXTBOX_CURSOR_POS ((FRAME_HEIGHT * FRAME_WIDTH) - 4)
|
||||
#define DRAW_UI_TEXTBOX_BLINKS_PER_SECOND 2
|
||||
|
||||
/**
|
||||
* Draws a UI box to the frame buffer.
|
||||
|
Reference in New Issue
Block a user