@@ -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) {
@@ -414,11 +404,15 @@ HUD_ELEMENT2_NO_DISABLE(text, HudType_InGame | HudType_Paused | HudType_Menu | H
414404 for (auto &t : sar_hud_text_vals) {
415405 int x = ctx->xPadding ;
416406 int y = ctx->yPadding + ctx->elements * (ctx->fontSize + ctx->spacing );
407+ int totalPixLen = 0 ;
408+ for (auto &c : t.second .components ) totalPixLen += surface->GetFontLength (ctx->font , " %s" , c.text .c_str ());
409+ int align = sar_hud_align.GetInt ();
410+ int offset = !align ? 0 : align == 1 ? totalPixLen / 2 : totalPixLen;
417411 if (t.second .draw ) {
418412 for (auto &c : t.second .components ) {
419413 Color color = c.color ? *c.color : t.second .defaultColor ? *t.second .defaultColor : ctx->textColor ;
420414 int pixLen = surface->GetFontLength (ctx->font , " %s" , c.text .c_str ());
421- surface->DrawTxt (ctx->font , x, y, color, " %s" , c.text .c_str ());
415+ surface->DrawTxt (ctx->font , x - offset , y, color, " %s" , c.text .c_str ());
422416 x += pixLen;
423417 }
424418
0 commit comments