Pick the largest suitable default scale. Fix #468 (#472)

This commit is contained in:
2024-11-19 18:17:15 -06:00
committed by GitHub
parent a725dc606a
commit 9d972a3961
19 changed files with 89 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ tools = Split("""
drawable_manager.cpp
keymods.cpp
replay.cpp
winutil.cpp
../alchemy.cpp
../damage.cpp
../enchant.cpp

31
src/tools/winutil.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include "winutil.hpp"
// The default scale should be the largest that the user's screen can fit all three
// BoE application windows (because they should probably default to match each other).
double fallback_scale() {
static double scale = 0;
if(scale == 0){
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
short max_width = max(boe_width, max(pc_width, scen_width));
short max_height = max(boe_height, max(pc_height, scen_height)) + getMenubarHeight();
std::vector<double> scale_options = {1.0, 1.5, 2.0, 3.0, 4.0};
for(auto it = scale_options.rbegin(); it != scale_options.rend(); ++it){
short max_scaled_width = max_width * (*it);
short max_scaled_height = max_height * (*it);
if(max_scaled_width <= desktop.width && max_scaled_height <= desktop.height){
scale = (*it);
break;
}
}
}
// Hopefully no one would ever have such a small monitor to not fit the default size.
// But just in case:
if(scale == 0){
scale = 1.0;
}
return scale;
}

View File

@@ -13,6 +13,10 @@
#include <SFML/Window.hpp>
#include <SFML/Graphics/Image.hpp>
#include <memory>
#include <vector>
#include "prefs.hpp"
#include "mathutil.hpp"
char keyToChar(sf::Keyboard::Key key, bool isShift);
@@ -51,8 +55,8 @@ void beep();
int getMenubarHeight();
// This is an additional offset between the "logical" top of the window an the UI.
// On Windows and Mac no offset is needed because the menubar is not a part of the mainPtr, but
// on Linux it is.
// On Windows and Mac no offset is needed because the menubar is not a part of the mainPtr's
// coordinate space, but on Linux it is.
inline int os_specific_y_offset() {
return
#if defined(SFML_SYSTEM_WINDOWS) || defined(SFML_SYSTEM_MAC)
@@ -62,6 +66,16 @@ inline int os_specific_y_offset() {
#endif
}
double fallback_scale();
inline double get_ui_scale() {
return get_float_pref("UIScale", fallback_scale());
}
inline double get_ui_scale_map() {
return get_float_pref("UIScaleMap", fallback_scale());
}
void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height);
class ModalSession {