diff --git a/include/QF/draw.h b/include/QF/draw.h index bbbbf8e9d..aabbf7e16 100644 --- a/include/QF/draw.h +++ b/include/QF/draw.h @@ -59,7 +59,7 @@ void Draw_DestroyBuffer (draw_charbuffer_t *buffer); void Draw_ClearBuffer (draw_charbuffer_t *buffer); void Draw_ScrollBuffer (draw_charbuffer_t *buffer, int lines); void Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer); -void Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str); +int Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str); extern byte *draw_chars; diff --git a/libs/video/renderer/r_draw.c b/libs/video/renderer/r_draw.c index 3b2285ad5..5a18b99b0 100644 --- a/libs/video/renderer/r_draw.c +++ b/libs/video/renderer/r_draw.c @@ -91,12 +91,13 @@ Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer) #define TAB 8 -VISIBLE void +VISIBLE int Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str) { char *dst = buffer->chars; char c; int tab; + int lines = 0; dst += buffer->cursy * buffer->width + buffer->cursx; while ((c = *str++)) { switch (c) { @@ -109,10 +110,12 @@ Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str) buffer->cursx = 0; dst += buffer->width; buffer->cursy++; + lines++; break; case '\f': dst += buffer->width; buffer->cursy++; + lines++; break; case '\t': tab = TAB - buffer->cursx % TAB; @@ -127,12 +130,14 @@ Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str) if (buffer->cursx >= buffer->width) { buffer->cursx -= buffer->width; buffer->cursy++; + lines++; } if (buffer->cursy >= buffer->height) { - int lines = buffer->cursy - buffer->height + 1; - Draw_ScrollBuffer (buffer, lines); - dst -= lines * buffer->width; - buffer->cursy -= lines; + int excess = buffer->cursy - buffer->height + 1; + Draw_ScrollBuffer (buffer, excess); + dst -= excess * buffer->width; + buffer->cursy -= excess; } } + return lines; }