@@ -66,6 +66,69 @@ int CHudMenu::VidInit( void )
6666 return 1 ;
6767}
6868
69+ /*
70+ =================================
71+ ParseEscapeToken
72+
73+ Interprets the given escape token (backslash followed by a letter). The
74+ first character of the token must be a backslash. The second character
75+ specifies the operation to perform:
76+
77+ \w : White text (this is the default)
78+ \d : Dim (gray) text
79+ \y : Yellow text
80+ \r : Red text
81+ \R : Right-align (just for the remainder of the current line)
82+ =================================
83+ */
84+
85+ static int menu_r, menu_g, menu_b, menu_x, menu_ralign;
86+
87+ static inline const char * ParseEscapeToken ( const char * token )
88+ {
89+ if ( *token != ' \\ ' )
90+ return token;
91+
92+ token++;
93+
94+ switch ( *token )
95+ {
96+ case ' \0 ' :
97+ return token;
98+
99+ case ' w' :
100+ menu_r = 255 ;
101+ menu_g = 255 ;
102+ menu_b = 255 ;
103+ break ;
104+
105+ case ' d' :
106+ menu_r = 100 ;
107+ menu_g = 100 ;
108+ menu_b = 100 ;
109+ break ;
110+
111+ case ' y' :
112+ menu_r = 255 ;
113+ menu_g = 210 ;
114+ menu_b = 64 ;
115+ break ;
116+
117+ case ' r' :
118+ menu_r = 210 ;
119+ menu_g = 24 ;
120+ menu_b = 0 ;
121+ break ;
122+
123+ case ' R' :
124+ menu_x = ScreenWidth / 2 ;
125+ menu_ralign = TRUE ;
126+ break ;
127+ }
128+
129+ return ++token;
130+ }
131+
69132int CHudMenu::Draw ( float flTime )
70133{
71134 int i;
@@ -97,27 +160,45 @@ int CHudMenu::Draw( float flTime )
97160 // count the number of newlines
98161 int nlc = 0 ;
99162 for ( i = 0 ; i < MAX_MENU_STRING && g_szMenuString[i] != ' \0 ' ; i++ )
100- {
101163 if ( g_szMenuString[i] == ' \n ' )
102164 nlc++;
103- }
104165
105- int nFontHeight = Q_max (12 , screenInfo.iCharHeight );
166+ int nFontHeight = Q_max ( 12 , screenInfo.iCharHeight );
106167
107168 // center it
108- int y = ( ScreenHeight / 2 ) - ( ( nlc / 2 ) * nFontHeight ) - (3 * nFontHeight + nFontHeight / 3 ); // make sure it is above the say text
109- int x = 20 ;
169+ int y = ( ScreenHeight / 2 ) - (( nlc / 2 )* nFontHeight ) - ( 3 * nFontHeight + nFontHeight / 3 ); // make sure it is above the say text
110170
111- i = 0 ;
112- while ( i < MAX_MENU_STRING && g_szMenuString[i] != ' \0 ' )
113- {
114- gHUD . DrawHudString ( x, y, 320 , g_szMenuString + i, 255 , 255 , 255 ) ;
115- y += nFontHeight ;
171+ menu_r = 255 ;
172+ menu_g = 255 ;
173+ menu_b = 255 ;
174+ menu_x = 20 ;
175+ menu_ralign = FALSE ;
116176
117- while ( i < MAX_MENU_STRING && g_szMenuString[i] != ' \0 ' && g_szMenuString[i] != ' \n ' )
118- i++;
119- if ( g_szMenuString[i] == ' \n ' )
120- i++;
177+ const char * sptr = g_szMenuString;
178+
179+ while ( *sptr != ' \0 ' )
180+ {
181+ if ( *sptr == ' \\ ' )
182+ sptr = ParseEscapeToken ( sptr );
183+ else if ( *sptr == ' \n ' )
184+ {
185+ menu_ralign = FALSE ;
186+ menu_x = 20 ;
187+ y += nFontHeight;
188+ sptr++;
189+ }
190+ else
191+ {
192+ char menubuf[80 ] = " " ;
193+ const char *ptr = sptr;
194+ while ( *sptr != ' \0 ' && *sptr != ' \n ' && *sptr != ' \\ ' )
195+ sptr++;
196+ strlcpy ( menubuf, ptr, Q_min (( sptr - ptr + 1 ), (int )sizeof ( menubuf )));
197+ if ( menu_ralign )
198+ // IMPORTANT: Right-to-left rendered text does not parse escape tokens!
199+ menu_x = gHUD .DrawHudStringReverse ( menu_x, y, 0 , menubuf, menu_r, menu_g, menu_b );
200+ else menu_x = gHUD .DrawHudString ( menu_x, y, 320 , menubuf, menu_r, menu_g, menu_b );
201+ }
121202 }
122203
123204 return 1 ;
0 commit comments