Skip to content

Commit

Permalink
Add VDP_drawTextClear (#367)
Browse files Browse the repository at this point in the history
* Improved the SYS_die function.

* Add VDP_drawTextClear function
  • Loading branch information
Lemur42332543632 authored Nov 7, 2024
1 parent e5c6c56 commit 1d99217
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
23 changes: 23 additions & 0 deletions inc/vdp_bg.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,29 @@ void VDP_clearTextLineBG(VDPPlane plane, u16 y);
* \see VDP_setTextPlane(..)
*/
void VDP_drawText(const char *str, u16 x, u16 y);

/**
* \brief
* Clears the field of characters and draws new text.<br>
* If the new line is shorter than the one previously drawn in this place, the old characters will be removed.<br>
* This function works significantly faster than calling VDP_clearText() and then VDP_drawText(). It is suitable when a lot of updating information needs to be displayed on the screen.
*
* \param str
* String to draw. For correct operation, it must not exceed 20 characters.
* \param maxLength
* Maximum string length. For correct operation, it must not exceed 20 characters.
* \param x
* X position (in tile).
* \param y
* y position (in tile).
*
* \see VDP_drawText(..)
* \see VDP_clearText(..)
* \see VDP_setTextPalette(..)
* \see VDP_setTextPriority(..)
* \see VDP_setTextPlane(..)
*/
void VDP_drawTextClear(const char* str, u8 maxLength, u16 x, u16 y);
/**
* \brief
* Clear a single line portion of text.
Expand Down
45 changes: 45 additions & 0 deletions src/vdp_bg.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,51 @@ void VDP_drawText(const char *str, u16 x, u16 y)
VDP_drawTextBG(text_plan, str, x, y);
}

void VDP_drawTextClear(const char* str, u8 maxLength, u16 x, u16 y)
{
static const char *spaceStrings[] = {
"",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};
char result[maxLength + 1];
char *spaces = spaceStrings[maxLength - strlen(str)];
char *dst = result;
const char *src;

src = str;
while (*src) {
*dst++ = *src++;
}

src = spaces;
while (*src) {
*dst++ = *src++;
}

*dst = '\0';

VDP_drawText(result, x, y);
}

void VDP_clearText(u16 x, u16 y, u16 w)
{
VDP_clearTextBG(text_plan, x, y, w);
Expand Down

0 comments on commit 1d99217

Please sign in to comment.