@@ -26,6 +26,7 @@ Variable sar_hud_x("sar_hud_x", "2", 0, "X padding of HUD.\n", FCVAR_DONTRECORD)
2626Variable sar_hud_y (" sar_hud_y" , " 2" , 0 , " Y padding of HUD.\n " , FCVAR_DONTRECORD);
2727Variable sar_hud_font_index (" sar_hud_font_index" , " 0" , 0 , " Font index of HUD.\n " , FCVAR_DONTRECORD);
2828Variable sar_hud_font_color (" sar_hud_font_color" , " 255 255 255 255" , " RGBA font color of HUD.\n " , FCVAR_DONTRECORD);
29+ Variable sar_hud_align (" sar_hud_align" , " 0" , 0 , " Alignment of HUD. (0 = left, 1 = center, 2 = right).\n " , FCVAR_DONTRECORD);
2930
3031Variable sar_hud_precision (" sar_hud_precision" , " 2" , 0 , " Precision of HUD numbers.\n " );
3132Variable sar_hud_velocity_precision (" sar_hud_velocity_precision" , " 2" , 0 , " Precision of velocity HUD numbers.\n " );
@@ -204,26 +205,15 @@ void HudContext::DrawElement(const char *fmt, ...) {
204205 if (colon) strcpy (data, colon + 2 );
205206 }
206207
207- surface->DrawTxt (font, this ->xPadding , this ->yPadding + this ->elements * (this ->fontSize + this ->spacing ), this ->textColor , data);
208-
209- ++this ->elements ;
210-
208+ int align = sar_hud_align.GetInt ();
211209 int width = surface->GetFontLength (this ->font , " %s" , data);
212- if (width > this ->maxWidth ) this ->maxWidth = width;
213- }
214- void HudContext::DrawElementOnScreen (const int groupID, const float xPos, const float yPos, const char *fmt, ...) {
215- va_list argptr;
216- va_start (argptr, fmt);
217- char data[128 ];
218- vsnprintf (data, sizeof (data), fmt, argptr);
219- va_end (argptr);
210+ int offset = !align ? 0 : align == 1 ? width / 2 : width;
220211
221- int pixLength = surface->GetFontLength (this ->font , " %s" , data);
222-
223- surface->DrawTxt (font, xPos - pixLength / 2 , yPos + this ->group [groupID] * (this ->fontSize + this ->spacing ), this ->textColor , data);
212+ surface->DrawTxt (font, this ->xPadding - offset, this ->yPadding + this ->elements * (this ->fontSize + this ->spacing ), this ->textColor , data);
224213
214+ ++this ->elements ;
225215
226- ++ this ->group [groupID] ;
216+ if (width > this ->maxWidth ) this -> maxWidth = width ;
227217}
228218
229219void HudContext::Reset (int slot) {
0 commit comments