diff options
author | Ben Millwood <thebenmachine@gmail.com> | 2009-10-03 11:55:35 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:15:31 +0000 |
commit | a30e294034cfda3ce2a6b77158e7017d6a0d804f (patch) | |
tree | 25112c57c1b6635bddc0cd3dbe3ac1a04918394f | |
parent | 231f5f84c6ba1d9c27f9594ba6531a30c9681f44 (diff) |
* Some SnapVector nonsense
* A (perhaps) finally fixed Item_Text_Wrap
-rw-r--r-- | src/qcommon/q_shared.h | 4 | ||||
-rw-r--r-- | src/ui/ui_shared.c | 30 |
2 files changed, 19 insertions, 15 deletions
diff --git a/src/qcommon/q_shared.h b/src/qcommon/q_shared.h index b325b49a..82b4f87e 100644 --- a/src/qcommon/q_shared.h +++ b/src/qcommon/q_shared.h @@ -468,8 +468,8 @@ typedef struct { // Snaps the vector to the floor value always, ignoring any weirdness from // snapping negative versus positive numbers -#define Floor(f) ( (f) >= 0.f ? (int)(f) : -(int)(-(f)) ) -#define SnapVector(v) {(v)[0]=Floor((v)[0]);(v)[1]=Floor((v)[1]);(v)[2]=Floor((v)[2]);} +#define Floor(f) ((f) >= 0.f ? (int)(f) : -(int)(-(f))) +#define SnapVector(v) ((v)[0]=Floor((v)[0]),(v)[1]=Floor((v)[1]),(v)[2]=Floor((v)[2])) // just in case you do't want to use the macros vec_t _DotProduct( const vec3_t v1, const vec3_t v2 ); diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index c6a5ba46..18a80ae7 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -4543,7 +4543,7 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) char c[ 2 ] = { 0 }; const char *thisline = text; size_t outlen = 0, testlen; - int eol = -1; + int eol; if( strlen( text ) >= sizeof( out ) ) return NULL; @@ -4551,7 +4551,7 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) while( *thisline ) { // strip leading space and collapse colours - while( 1 ) + while( *thisline ) { while( isspace( *thisline ) && *thisline != '\n' ) thisline++; @@ -4574,8 +4574,8 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) outlen += 2; } - for( testlen = 1; thisline[ testlen ] && - outlen + testlen + 1 < sizeof( out ) && + for( testlen = 1, eol = 0; thisline[ testlen ] && + outlen + testlen + 2 < sizeof( out ) && UI_Text_Width( thisline, scale, testlen ) < width; testlen++ ) { // set an eol marker in the last whitespace @@ -4583,9 +4583,6 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) { if( thisline[ eol = testlen ] == '\n' ) break; - // place the eol at the first whitespace, not spaces that follow - while( isspace( thisline[ testlen ] ) && thisline[ testlen ] != '\n' ) - testlen++; } // save colour codes for restoration next line @@ -4598,9 +4595,13 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) } // if we couldn't place a whitespace eol then just put it at the end - if( !thisline[ testlen ] || outlen + testlen + 1 == sizeof( out ) ) + if( eol == 0 ) eol = testlen; + // place a space at the beginning of wrapped lines to prevent silly things + if( thisline[ eol ] != '\n' ) + out[ outlen++ ] = ' '; + // copy up the the line break Com_Memcpy( &out[ outlen ], thisline, eol ); outlen += eol; @@ -4608,12 +4609,15 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) if( outlen + 1 < sizeof( out ) ) out[ outlen++ ] = '\n'; - // continue colour codes on the next line if there is one - if( c[ 0 ] && thisline[ eol ] && thisline[ eol + 1 ] && - outlen + 3 < sizeof( out ) ) + // if there is another line, continue colour codes on it (else die) + if( thisline[ eol ] && thisline[ eol + 1 ] && + outlen + 1 < sizeof( out ) ) { - Com_Memcpy( &out[ outlen ], c, 2 ); - outlen += 2; + if( c[ 0 ] && outlen + 3 < sizeof( out ) ) + { + Com_Memcpy( &out[ outlen ], c, 2 ); + outlen += 2; + } } else break; |