Skip to content

Commit

Permalink
Pick the largest suitable default scale. Fix #468 (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios authored Nov 20, 2024
1 parent a725dc6 commit 9d972a3
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 25 deletions.
1 change: 1 addition & 0 deletions proj/vs2013/Common/Common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
<ClCompile Include="..\..\..\src\tools\replay.cpp" />
<ClCompile Include="..\..\..\src\tools\undo.cpp" />
<ClCompile Include="..\..\..\src\tools\keymods.cpp" />
<ClCompile Include="..\..\..\src\tools\winutil.cpp" />
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp" />
<ClCompile Include="..\..\..\src\tools\framerate_limiter.cpp" />
<ClCompile Include="..\..\..\src\universe\creature.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions proj/vs2013/Common/Common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@
<ClCompile Include="..\..\..\src\tools\keymods.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\winutil.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp">
<Filter>Tools</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions proj/vs2017/Common/Common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@
<ClCompile Include="..\..\..\src\tools\replay.cpp" />
<ClCompile Include="..\..\..\src\tools\undo.cpp" />
<ClCompile Include="..\..\..\src\tools\keymods.cpp" />
<ClCompile Include="..\..\..\src\tools\winutil.cpp" />
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp" />
<ClCompile Include="..\..\..\src\universe\creature.cpp" />
<ClCompile Include="..\..\..\src\universe\living.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions proj/vs2017/Common/Common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@
<ClCompile Include="..\..\..\src\tools\keymods.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\winutil.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp">
<Filter>Tools</Filter>
</ClCompile>
Expand Down
4 changes: 4 additions & 0 deletions proj/xc12/BoE.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
2BF04B2C0BF51924006C0831 /* boe.startup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BF04B050BF51924006C0831 /* boe.startup.cpp */; };
2BF04B2D0BF51924006C0831 /* boe.text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BF04B070BF51924006C0831 /* boe.text.cpp */; };
2BF04B2E0BF51924006C0831 /* boe.town.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BF04B090BF51924006C0831 /* boe.town.cpp */; };
413FE08F2CECFAFF000D97DC /* winutil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413FE08E2CECFAFF000D97DC /* winutil.cpp */; };
91034D211B225E4A008F01C1 /* scen.appleevents.mm in Sources */ = {isa = PBXBuildFile; fileRef = 91034D201B225E49008F01C1 /* scen.appleevents.mm */; };
911A14031B8FAFC600900FD9 /* town_read.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91C2A6EC1B8FA91400346948 /* town_read.cpp */; };
911A14041B8FB00300900FD9 /* talk_read.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91C2A6EE1B8FAA8E00346948 /* talk_read.cpp */; };
Expand Down Expand Up @@ -607,6 +608,7 @@
2BF04B080BF51924006C0831 /* boe.text.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.text.hpp; sourceTree = "<group>"; };
2BF04B090BF51924006C0831 /* boe.town.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = boe.town.cpp; sourceTree = "<group>"; wrapsLines = 1; };
2BF04B0A0BF51924006C0831 /* boe.town.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.town.hpp; sourceTree = "<group>"; };
413FE08E2CECFAFF000D97DC /* winutil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = winutil.cpp; sourceTree = "<group>"; };
91034D201B225E49008F01C1 /* scen.appleevents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = scen.appleevents.mm; sourceTree = "<group>"; };
9103DC652C6A406600849E60 /* cli.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = cli.hpp; sourceTree = "<group>"; };
910BBA170FB8BECA001E34EA /* dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = dialog.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1268,6 +1270,7 @@
9185BDA11EA041570027C346 /* tools */ = {
isa = PBXGroup;
children = (
413FE08E2CECFAFF000D97DC /* winutil.cpp */,
9103DC652C6A406600849E60 /* cli.hpp */,
D384F6A22C1B9D4000A806C3 /* replay.cpp */,
91C688E70FD702B9000F6D01 /* cursors.mac.mm */,
Expand Down Expand Up @@ -2073,6 +2076,7 @@
919CC2641B37739300273FDA /* tinyxml.cpp in Sources */,
919CC2651B37739800273FDA /* tinyxmlerror.cpp in Sources */,
919CC2661B37739E00273FDA /* tinyxmlparser.cpp in Sources */,
413FE08F2CECFAFF000D97DC /* winutil.cpp in Sources */,
919CC2671B3773BA00273FDA /* tinyprint.cpp in Sources */,
919CC2681B3773C200273FDA /* control.cpp in Sources */,
919CC2691B3773C700273FDA /* button.cpp in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions proj/xc4/BoE.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@
2BF04B080BF51924006C0831 /* boe.text.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.text.hpp; sourceTree = "<group>"; };
2BF04B090BF51924006C0831 /* boe.town.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = boe.town.cpp; sourceTree = "<group>"; wrapsLines = 1; };
2BF04B0A0BF51924006C0831 /* boe.town.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.town.hpp; sourceTree = "<group>"; };
413FE08D2CECFAA4000D97DC /* winutil.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = winutil.cpp; sourceTree = "<group>"; };
91034D201B225E49008F01C1 /* scen.appleevents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = scen.appleevents.mm; sourceTree = "<group>"; };
910BBA170FB8BECA001E34EA /* dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = dialog.hpp; sourceTree = "<group>"; };
910BBA180FB8BECA001E34EA /* dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dialog.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1215,6 +1216,7 @@
9185BDA11EA041570027C346 /* tools */ = {
isa = PBXGroup;
children = (
413FE08D2CECFAA4000D97DC /* winutil.cpp */,
D384F6A12C1B9CE900A806C3 /* replay.cpp */,
91C688E70FD702B9000F6D01 /* cursors.mac.mm */,
91FE0E3523F084B70084CA6B /* drawable_manager.cpp */,
Expand Down
8 changes: 4 additions & 4 deletions src/dialogxml/dialogs/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ void cDialog::recalcRect(){
}
}

winRect.right *= ui_scale();
winRect.bottom *= ui_scale();
winRect.right *= get_ui_scale();
winRect.bottom *= get_ui_scale();
}

bool cDialog::initCalled = false;
Expand Down Expand Up @@ -719,7 +719,7 @@ void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter&
break;
case sf::Event::MouseButtonPressed:
key.mod = current_key_mod();
where = {(int)(currentEvent.mouseButton.x / ui_scale()), (int)(currentEvent.mouseButton.y / ui_scale())};
where = {(int)(currentEvent.mouseButton.x / get_ui_scale()), (int)(currentEvent.mouseButton.y / get_ui_scale())};
process_click(where, key.mod, fps_limiter);
break;
default: // To silence warning of unhandled enum values
Expand Down Expand Up @@ -1076,7 +1076,7 @@ void cDialog::draw(){

// Scale dialogs:
sf::View view = win.getDefaultView();
view.setViewport(sf::FloatRect(0, 0, ui_scale(), ui_scale()));
view.setViewport(sf::FloatRect(0, 0, get_ui_scale(), get_ui_scale()));
win.setView(view);

ctrlIter iter = controls.begin();
Expand Down
1 change: 0 additions & 1 deletion src/dialogxml/dialogs/dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class cDialog {
cDialog& operator=(cDialog& other) = delete;
cDialog(cDialog& other) = delete;
private:
inline double ui_scale() { return get_float_pref("UIScale", 1.0); };
void draw();
void handle_events();
void handle_one_event(const sf::Event&, cFramerateLimiter& fps_limiter);
Expand Down
6 changes: 3 additions & 3 deletions src/game/boe.dlgutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ void pick_preferences(bool record) {
}

cLedGroup& uiScale = dynamic_cast<cLedGroup&>(prefsDlog["scaleui"]);
double ui_scale = get_float_pref("UIScale", 1.0);
double ui_scale = get_ui_scale();
if (ui_scale>0.95 && ui_scale<1.05) uiScale.setSelected("1");
else if (ui_scale>1.45 && ui_scale<1.55) uiScale.setSelected("1_5");
else if (ui_scale>1.95 && ui_scale<2.05) uiScale.setSelected("2");
Expand All @@ -1326,7 +1326,7 @@ void pick_preferences(bool record) {
else uiScale.setSelected("other");

cLedGroup& uiMapScale = dynamic_cast<cLedGroup&>(prefsDlog["scalemap"]);
double ui_map_scale = get_float_pref("UIScaleMap", 1.0);
double ui_map_scale = get_ui_scale_map();
if (ui_map_scale>0.95 && ui_map_scale<1.05) uiMapScale.setSelected("1");
else if (ui_map_scale>1.45 && ui_map_scale<1.55) uiMapScale.setSelected("1_5");
else if (ui_map_scale>1.95 && ui_map_scale<2.05) uiMapScale.setSelected("2");
Expand Down Expand Up @@ -1370,7 +1370,7 @@ void pick_preferences(bool record) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if(get_int_pref("DisplayMode") != store_display_mode || get_float_pref("UIScale") != ui_scale || get_float_pref("UIScaleMap") != ui_map_scale)
if(get_int_pref("DisplayMode") != store_display_mode || get_ui_scale() != ui_scale || get_ui_scale_map() != ui_map_scale)
changed_display_mode = true;
#ifdef __GNUC__
#pragma GCC diagnostic pop
Expand Down
4 changes: 2 additions & 2 deletions src/game/boe.graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ void adjust_window_mode() {
winSettings.stencilBits = 1;
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
hideMenuBar();
double ui_scale = get_float_pref("UIScale", 1.0);
double ui_scale = get_ui_scale();
if(ui_scale < 0.1) ui_scale = 1.0;
float width = 605 * ui_scale, height = 430 * ui_scale;
float width = boe_width * ui_scale, height = boe_height * ui_scale;

// TODO: Make display_mode an enum
// 0 - center 1- ul 2 - ur 3 - dl 4 - dr 5 - small win
Expand Down
2 changes: 1 addition & 1 deletion src/game/boe.items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ short get_num_of_items(short max_num) {
}

void init_mini_map() {
double ui_scale = get_float_pref("UIScaleMap", 1.0);
double ui_scale = get_ui_scale();
if (ui_scale < 0.1) ui_scale = 1.0;
if (mini_map.isOpen()) mini_map.close();
mini_map.create(sf::VideoMode(ui_scale*296,ui_scale*277), "Map", sf::Style::Titlebar | sf::Style::Close);
Expand Down
4 changes: 2 additions & 2 deletions src/game/boe.startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void show_logo(cFramerateLimiter& fps_limiter) {
if(get_int_pref("DisplayMode") != 5)
hideMenuBar();

double ui_scale = get_float_pref("UIScale", 1.0);
double ui_scale = get_ui_scale();
if(ui_scale < 1) ui_scale = 1;
rectangle logo_from = {0, 0, int(ui_scale *350), int(ui_scale * 350)};
logo_from.offset((whole_window.right - logo_from.right) / 2,(whole_window.bottom - logo_from.bottom) / 2);
Expand All @@ -163,7 +163,7 @@ void show_logo(cFramerateLimiter& fps_limiter) {
void plop_fancy_startup(cFramerateLimiter& fps_limiter) {
rectangle whole_window = view_rect();

float ui_scale = get_float_pref("UIScale", 1.0);
float ui_scale = get_ui_scale();
if (ui_scale<1) ui_scale=1;
rectangle from_rect;
rectangle intro_from = {0, 0, int(ui_scale * 480), int(ui_scale * 640)};
Expand Down
5 changes: 5 additions & 0 deletions src/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ typedef signed int snd_num_t;
const unsigned long long OBOE_CURRENT_VERSION = 0x020000; // MMmmff; M - major, m - minor, f - bugfix
const char* oboeVersionString();

// Window Resolutions
const short boe_width = 605, boe_height = 430;
const short pc_width = 590, pc_height = 440;
const short scen_width = 584, scen_height = 420;

// A convenient alias
namespace boost { namespace filesystem {}}
namespace fs = boost::filesystem;
Expand Down
2 changes: 1 addition & 1 deletion src/pcedit/pc.graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern fs::path file_in_mem;
extern short store_flags[3];
extern short current_active_pc;

rectangle whole_win_rect = {0,0,440,590};
rectangle whole_win_rect = {0,0,pc_height,pc_width};
extern rectangle pc_area_buttons[6][4] ; // 0 - whole 1 - pic 2 - name 3 - stat strs 4,5 - later
extern rectangle item_string_rects[24][4]; // 0 - name 1 - drop 2 - id 3 -
extern rectangle pc_info_rect; // Frame that holds a pc's basic info and items
Expand Down
8 changes: 4 additions & 4 deletions src/pcedit/pc.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ sf::FloatRect compute_viewport(const sf::RenderWindow& mainPtr, float ui_scale)

void adjust_window (sf::RenderWindow& mainPtr, sf::View& mainView) {

double ui_scale = get_float_pref("UIScale", 1.0);
double ui_scale = get_ui_scale();

int const width = ui_scale * 590;
int const height = ui_scale * 440 + os_specific_y_offset();
int const width = ui_scale * pc_width;
int const height = ui_scale * pc_height + os_specific_y_offset();

mainPtr.create(sf::VideoMode(width, height), "Blades of Exile Character Editor", sf::Style::Titlebar | sf::Style::Close);
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
Expand Down Expand Up @@ -553,7 +553,7 @@ void pick_preferences() {
prefsDlog.attachClickHandlers(&prefs_event_filter, {"okay", "cancel"});

cLedGroup& uiScale = dynamic_cast<cLedGroup&>(prefsDlog["scaleui"]);
double ui_scale = get_float_pref("UIScale", 1.0);
double ui_scale = get_ui_scale();
if (ui_scale>0.95 && ui_scale<1.05) uiScale.setSelected("1");
else if (ui_scale>1.45 && ui_scale<1.55) uiScale.setSelected("1_5");
else if (ui_scale>1.95 && ui_scale<2.05) uiScale.setSelected("2");
Expand Down
10 changes: 5 additions & 5 deletions src/scenedit/scen.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ void adjust_windows (sf::RenderWindow & mainPtr, sf::View & mainView) {
// TODO: things might still be broken when upscaled.
// translate_mouse_coordinates has been applied in some places but more work might be needed.
// In particular, the white area on the right side of the main menu needs fixing.
double ui_scale = get_float_pref("UIScale", 1.0);
double ui_scale = get_ui_scale();

const int width = ui_scale * 584;
const int height = ui_scale * 420 + os_specific_y_offset();
const int width = ui_scale * scen_width;
const int height = ui_scale * scen_height + os_specific_y_offset();

mainPtr.create(sf::VideoMode(width, height), "Blades of Exile Scenario Editor", sf::Style::Titlebar | sf::Style::Close);
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
Expand Down Expand Up @@ -716,7 +716,7 @@ void pick_preferences() {
prefsDlog.attachClickHandlers(&prefs_event_filter, {"okay", "cancel"});

cLedGroup& uiScale = dynamic_cast<cLedGroup&>(prefsDlog["scaleui"]);
double ui_scale = get_float_pref("UIScale", 1.0);
double ui_scale = get_ui_scale();
if (ui_scale>0.95 && ui_scale<1.05) uiScale.setSelected("1");
else if (ui_scale>1.45 && ui_scale<1.55) uiScale.setSelected("1_5");
else if (ui_scale>1.95 && ui_scale<2.05) uiScale.setSelected("2");
Expand Down Expand Up @@ -747,7 +747,7 @@ void pick_preferences() {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if(get_float_pref("UIScale") != ui_scale)
if(get_ui_scale() != ui_scale)
changed_display_mode = true;
#ifdef __GNUC__
#pragma GCC diagnostic pop
Expand Down
1 change: 1 addition & 0 deletions src/tools/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tools = Split("""
drawable_manager.cpp
keymods.cpp
replay.cpp
winutil.cpp
../alchemy.cpp
../damage.cpp
../enchant.cpp
Expand Down
31 changes: 31 additions & 0 deletions src/tools/winutil.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 16 additions & 2 deletions src/tools/winutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 9d972a3

Please sign in to comment.