Continued improving it.

This commit is contained in:
mibi88 2023-07-11 13:29:48 +02:00
parent 813c23ad00
commit dc2a0b1473

View file

@ -12,8 +12,8 @@ void showtext(Game *game, bopti_image_t *face, char *text) {
dfont(&FONT_USED); dfont(&FONT_USED);
unsigned int i, n, y = 1, l = 0; unsigned int i, n, y = 1, l = 0;
int line_max_chars; int line_max_chars;
unsigned int max_lines_amount = BOX_HEIGHT/(FONT_USED.line_height + unsigned int max_lines_amount = BOX_HEIGHT/FONT_USED.line_height;
FONT_USED.char_spacing); const char *c;
/* Run a little fancy animation. */ /* Run a little fancy animation. */
for(i=0;i<BOX_HEIGHT;i++){ for(i=0;i<BOX_HEIGHT;i++){
draw(game); draw(game);
@ -31,19 +31,20 @@ void showtext(Game *game, bopti_image_t *face, char *text) {
* yet. */ * yet. */
for(i=0;i<strlen(text);i++){ for(i=0;i<strlen(text);i++){
/* Get how many chars we can draw on screen with a padding on the left /* Get how many chars we can draw on screen with a padding on the left
* and on the right of 1 px. */ * of BOX_HEIGHT px and on the right of 1 px. */
drsize(text+i, &FONT_USED, DWIDTH-2, &line_max_chars); c = drsize(text+i, &FONT_USED, DWIDTH-(BOX_HEIGHT*PXSIZE+PXSIZE), NULL);
/* c is a pointer to the last char that can be drawn. So: */
line_max_chars = c-(text+i);
/* TODO: Handle lines that are longer than what I can draw. */ /* TODO: Handle lines that are longer than what I can draw. */
/* Loop from the end to the start for word wrap. */ /* Loop from the end to the start for word wrap. */
for(n=line_max_chars; n>0; n--) { for(n=line_max_chars; n>0; n--) {
/* If we found a space, we can draw this line and do the same for /* If we found a space, we can draw this line and do the same for
* the next line. */ * the next line. */
if(text[i+n] == ' '){ if(text[i+n] == ' '){
dtext_opt(1, y, C_BLACK, C_NONE, DTEXT_TOP, DTEXT_LEFT, text+i, dtext_opt(BOX_HEIGHT, y, C_BLACK, C_NONE, DTEXT_TOP, DTEXT_LEFT,
n); /* Draw everything. */ text+i, n); /* Draw everything. */
/* Increment y by the line height plus the space between them. /* Increment y by the line height. */
*/ y += FONT_USED.line_height;
y += FONT_USED.line_height+FONT_USED.char_spacing;
i += n; /* We drew everything to i+n */ i += n; /* We drew everything to i+n */
l++; /* We drew one more line. */ l++; /* We drew one more line. */
break; break;
@ -57,17 +58,17 @@ void showtext(Game *game, bopti_image_t *face, char *text) {
while(game->frame_duration < 20) sleep(); while(game->frame_duration < 20) sleep();
game->frame_duration = 0; game->frame_duration = 0;
/* Ask the user to press EXE to continue. */ /* Ask the user to press EXE to continue. */
dtext(1, y, C_BLACK, "[EXE] To continue ..."); dtext(BOX_HEIGHT, y, C_BLACK, "[EXE] to continue ...");
/* Reset y and l. */
y = 1;
l = 0;
/* Clear the screen. */ /* Clear the screen. */
drect(0, i*PXSIZE, DWIDTH, (i+1)*PXSIZE, C_BLACK); drect(0, 0, DWIDTH, BOX_HEIGHT*PXSIZE, C_WHITE);
} }
/* Make a little animation :). */ /* Make a little animation :). */
dupdate(); dupdate();
if(l>=max_lines_amount-1){ if(l>=max_lines_amount-1){
while(getkey().key != KEY_EXE) sleep(); while(getkey().key != KEY_EXE) sleep();
/* Reset y and l. */
y = 1;
l = 0;
} }
else{ else{
while(game->frame_duration < 20) sleep(); while(game->frame_duration < 20) sleep();