Resize the window to the largest box of the given aspect ratio that fits the current monitor's usable area, then center it (so it stays fully visible). Drives the normal SDL resize path → aspect re-resolves.
| 1162 | // Resize the window to the largest box of the given aspect ratio that fits |
| 1163 | // the current monitor's usable area, then center it (so it stays fully |
| 1164 | // visible). Drives the normal SDL resize path → aspect re-resolves. |
| 1165 | void ResizeWindowToRatio(float ratio) |
| 1166 | { |
| 1167 | if (!s_window || ratio <= 0.0f) |
| 1168 | return; |
| 1169 | int availW = 1920, availH = 1080; |
| 1170 | const SDL_DisplayID disp = SDL_GetDisplayForWindow(s_window); |
| 1171 | SDL_Rect ub{}; |
| 1172 | if (SDL_GetDisplayUsableBounds(disp, &ub) && ub.w > 0 && ub.h > 0) |
| 1173 | { |
| 1174 | availW = ub.w; |
| 1175 | availH = ub.h; |
| 1176 | } |
| 1177 | const float margin = 0.90f; |
| 1178 | float w = static_cast<float>(availW) * margin; |
| 1179 | float h = w / ratio; |
| 1180 | if (h > static_cast<float>(availH) * margin) |
| 1181 | { |
| 1182 | h = static_cast<float>(availH) * margin; |
| 1183 | w = h * ratio; |
| 1184 | } |
| 1185 | int iw = static_cast<int>(w + 0.5f); |
| 1186 | int ih = static_cast<int>(h + 0.5f); |
| 1187 | if (iw < 320) |
| 1188 | iw = 320; |
| 1189 | if (ih < 240) |
| 1190 | ih = 240; |
| 1191 | SDL_SetWindowSize(s_window, iw, ih); |
| 1192 | SDL_SetWindowPosition(s_window, SDL_WINDOWPOS_CENTERED_DISPLAY(disp), SDL_WINDOWPOS_CENTERED_DISPLAY(disp)); |
| 1193 | } |
| 1194 | |
| 1195 | void DrawAspectTab() |