Skip to content

Commit

Permalink
Minor optimizations to checking widths of text in console
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Aug 8, 2015
1 parent 85ce027 commit 1bd8d23
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/c_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,11 @@ static struct
static int C_TextWidth(char *text)
{
size_t i;
size_t len = strlen(text);
char prevletter = '\0';
int w = 0;

for (i = 0; i < strlen(text); ++i)
for (i = 0; i < len; ++i)
{
char letter = text[i];
int c = letter - CONSOLEFONTSTART;
Expand Down Expand Up @@ -581,14 +582,15 @@ static void C_DrawConsoleText(int x, int y, char *text, int color1, int color2,
size_t len = strlen(text);
char prevletter = '\0';

while (C_TextWidth(text) > SCREENWIDTH - CONSOLETEXTX * 3 - CONSOLESCROLLBARWIDTH + 2)
{
text[len - 1] = '.';
text[len] = '.';
text[len + 1] = '.';
text[len + 2] = '\0';
--len;
}
if (len > 80)
while (C_TextWidth(text) > SCREENWIDTH - CONSOLETEXTX * 3 - CONSOLESCROLLBARWIDTH + 2)
{
text[len - 1] = '.';
text[len] = '.';
text[len + 1] = '.';
text[len + 2] = '\0';
--len;
}

for (i = 0; i < len; ++i)
{
Expand Down

0 comments on commit 1bd8d23

Please sign in to comment.