summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author/dev/humancontroller <devhc@example.com>2014-07-13 19:54:54 +0200
committer/dev/humancontroller <devhc@example.com>2017-03-09 13:51:14 +0100
commite9231cb1f09f479ae59ebf5a217b73634b65fc64 (patch)
tree47a16de77239f4b80bc9c512e8be1c503af87141
parenta9b6624cdb68e50df0034f0ade1eef99fc0dd3b6 (diff)
prefer drawing the bottom lines of overly long texts
-rw-r--r--src/ui/ui_shared.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c
index aadad31e..7c9e4452 100644
--- a/src/ui/ui_shared.c
+++ b/src/ui/ui_shared.c
@@ -4565,7 +4565,7 @@ void Item_Text_Wrapped_Paint( itemDef_t *item )
float lineHeight = fontHeight + lineSpacing;
float textHeight;
int textLength;
- int paintLines, totalLines, lineNum = 0;
+ int firstLine, paintLines, totalLines, lineNum;
float paintY;
int i;
@@ -4588,11 +4588,21 @@ void Item_Text_Wrapped_Paint( itemDef_t *item )
if( textPtr[ i ] == '\n' )
totalLines++;
}
+ if( textLength && textPtr[ textLength - 1 ] != '\n' )
+ {
+ totalLines++; // count the last, non-newline-terminated line
+ textLength++; // a '\0' will mark the end of the last line
+ }
paintLines = ( int )floor( ( h + lineSpacing ) / lineHeight );
- if( paintLines > totalLines )
+ if( totalLines > paintLines )
+ firstLine = totalLines - paintLines;
+ else
+ {
+ firstLine = 0;
paintLines = totalLines;
+ }
textHeight = ( paintLines * lineHeight ) - lineSpacing;
@@ -4615,11 +4625,15 @@ void Item_Text_Wrapped_Paint( itemDef_t *item )
p = textPtr;
- for( i = 0, lineNum = 0; i < textLength && lineNum < paintLines; i++ )
+ // skip the first few lines
+ for( lineNum = 0; lineNum < firstLine; lineNum++ )
+ p = strchr( p, '\n' ) + 1;
+
+ for( i = p - textPtr; i < textLength && lineNum < firstLine + paintLines; i++ )
{
int lineLength = &textPtr[ i ] - p;
- if( lineLength >= sizeof( buff ) - 1 )
+ if( lineLength >= sizeof( buff ) )
break;
if( textPtr[ i ] == '\n' || textPtr[ i ] == '\0' )
@@ -4643,7 +4657,7 @@ void Item_Text_Wrapped_Paint( itemDef_t *item )
lineItem.textRect.w = 0.0f;
lineItem.textRect.h = 0.0f;
lineItem.window.rect.x = x;
- lineItem.window.rect.y = paintY + ( lineNum * lineHeight );
+ lineItem.window.rect.y = paintY + ( ( lineNum - firstLine ) * lineHeight );
lineItem.window.rect.w = w;
lineItem.window.rect.h = lineHeight;
lineItem.window.border = item->window.border;