- rows = old_panel_size_y/old_panel_size_x;
- rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
- columns = ceil(WEP_COUNT/rows);
- weapon_size_x = old_panel_size_x / columns;
- weapon_size_y = old_panel_size_y / rows;
+ vector table_size = HUD_GetTableSize(WEP_COUNT, padded_panel_size, aspect);
+ columns = table_size.x;
+ rows = table_size.y;
+ weapon_size.x = padded_panel_size.x / columns;
+ weapon_size.y = padded_panel_size.y / rows;
+
+ // NOTE: although weapons should aways look the same even if onlyowned is enabled,
+ // we enlarge them a bit when possible to better match the desired aspect ratio
+ if(padded_panel_size.x / padded_panel_size.y < aspect)
+ {
+ // maximum number of rows that allows to display items with the desired aspect ratio
+ float max_rows = floor(padded_panel_size.y / (weapon_size.x / aspect));
+ columns = min(columns, ceil(weapon_count / max_rows));
+ rows = ceil(weapon_count / columns);
+ weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
+ weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
+ vertical_order = false;
+ }
+ else
+ {
+ float max_columns = floor(padded_panel_size.x / (weapon_size.y * aspect));
+ rows = min(rows, ceil(weapon_count / max_columns));
+ columns = ceil(weapon_count / rows);
+ weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
+ weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
+ vertical_order = true;
+ }