Onlyowned layout: instead of keeping original table proportions as much as possible...
authorterencehill <piuntn@gmail.com>
Sun, 15 Feb 2015 00:14:46 +0000 (01:14 +0100)
committerterencehill <piuntn@gmail.com>
Sun, 15 Feb 2015 00:14:46 +0000 (01:14 +0100)
qcsrc/client/hud.qc

index 8463117..54c23ef 100644 (file)
@@ -591,29 +591,24 @@ void HUD_Weapons(void)
                rows = table_size.y;
                weapon_size.x = padded_panel_size.x / columns;
                weapon_size.y = padded_panel_size.y / rows;
                rows = table_size.y;
                weapon_size.x = padded_panel_size.x / columns;
                weapon_size.y = padded_panel_size.y / rows;
-
-               // reduce table trying to keep the original table proportions as much as possible
                vertical_order = (columns >= rows);
                vertical_order = (columns >= rows);
-               if(vertical_order)
-               {
-                       rows = ceil(sqrt(weapon_count / (columns / rows)));
-                       columns = ceil(weapon_count / rows);
-               }
-               else
-               {
-                       columns = ceil(sqrt(weapon_count / (rows / columns)));
-                       rows = ceil(weapon_count / columns);
-               }
 
                // 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
 
                // 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.y > padded_panel_size.x)
+               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);
                }
                else
                {
                        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);
                }
                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);
                }
                        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);
                }