diff --git a/proj/vs2013/Common/Common.vcxproj b/proj/vs2013/Common/Common.vcxproj
index 699cc06cb..e0553f476 100644
--- a/proj/vs2013/Common/Common.vcxproj
+++ b/proj/vs2013/Common/Common.vcxproj
@@ -260,6 +260,7 @@
+
diff --git a/proj/vs2013/Common/Common.vcxproj.filters b/proj/vs2013/Common/Common.vcxproj.filters
index b70bc79d5..327b455b7 100644
--- a/proj/vs2013/Common/Common.vcxproj.filters
+++ b/proj/vs2013/Common/Common.vcxproj.filters
@@ -611,6 +611,9 @@
Tools
+
+ Tools
+
Tools
diff --git a/proj/vs2017/Common/Common.vcxproj b/proj/vs2017/Common/Common.vcxproj
index ca08294e2..738f326f0 100644
--- a/proj/vs2017/Common/Common.vcxproj
+++ b/proj/vs2017/Common/Common.vcxproj
@@ -414,6 +414,7 @@
+
diff --git a/proj/vs2017/Common/Common.vcxproj.filters b/proj/vs2017/Common/Common.vcxproj.filters
index d95655158..c77ddd6a6 100644
--- a/proj/vs2017/Common/Common.vcxproj.filters
+++ b/proj/vs2017/Common/Common.vcxproj.filters
@@ -695,6 +695,9 @@
Tools
+
+ Tools
+
Tools
diff --git a/proj/xc12/BoE.xcodeproj/project.pbxproj b/proj/xc12/BoE.xcodeproj/project.pbxproj
index 2c2ad163d..c4e8b0824 100755
--- a/proj/xc12/BoE.xcodeproj/project.pbxproj
+++ b/proj/xc12/BoE.xcodeproj/project.pbxproj
@@ -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 */; };
@@ -607,6 +608,7 @@
2BF04B080BF51924006C0831 /* boe.text.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.text.hpp; sourceTree = ""; };
2BF04B090BF51924006C0831 /* boe.town.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = boe.town.cpp; sourceTree = ""; wrapsLines = 1; };
2BF04B0A0BF51924006C0831 /* boe.town.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.town.hpp; sourceTree = ""; };
+ 413FE08E2CECFAFF000D97DC /* winutil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = winutil.cpp; sourceTree = ""; };
91034D201B225E49008F01C1 /* scen.appleevents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = scen.appleevents.mm; sourceTree = ""; };
9103DC652C6A406600849E60 /* cli.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = cli.hpp; sourceTree = ""; };
910BBA170FB8BECA001E34EA /* dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = dialog.hpp; sourceTree = ""; };
@@ -1268,6 +1270,7 @@
9185BDA11EA041570027C346 /* tools */ = {
isa = PBXGroup;
children = (
+ 413FE08E2CECFAFF000D97DC /* winutil.cpp */,
9103DC652C6A406600849E60 /* cli.hpp */,
D384F6A22C1B9D4000A806C3 /* replay.cpp */,
91C688E70FD702B9000F6D01 /* cursors.mac.mm */,
@@ -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 */,
diff --git a/proj/xc4/BoE.xcodeproj/project.pbxproj b/proj/xc4/BoE.xcodeproj/project.pbxproj
index ad461d619..f496198a3 100755
--- a/proj/xc4/BoE.xcodeproj/project.pbxproj
+++ b/proj/xc4/BoE.xcodeproj/project.pbxproj
@@ -561,6 +561,7 @@
2BF04B080BF51924006C0831 /* boe.text.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.text.hpp; sourceTree = ""; };
2BF04B090BF51924006C0831 /* boe.town.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = boe.town.cpp; sourceTree = ""; wrapsLines = 1; };
2BF04B0A0BF51924006C0831 /* boe.town.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boe.town.hpp; sourceTree = ""; };
+ 413FE08D2CECFAA4000D97DC /* winutil.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = winutil.cpp; sourceTree = ""; };
91034D201B225E49008F01C1 /* scen.appleevents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = scen.appleevents.mm; sourceTree = ""; };
910BBA170FB8BECA001E34EA /* dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = dialog.hpp; sourceTree = ""; };
910BBA180FB8BECA001E34EA /* dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dialog.cpp; sourceTree = ""; };
@@ -1215,6 +1216,7 @@
9185BDA11EA041570027C346 /* tools */ = {
isa = PBXGroup;
children = (
+ 413FE08D2CECFAA4000D97DC /* winutil.cpp */,
D384F6A12C1B9CE900A806C3 /* replay.cpp */,
91C688E70FD702B9000F6D01 /* cursors.mac.mm */,
91FE0E3523F084B70084CA6B /* drawable_manager.cpp */,
diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp
index e1f4c7b69..397dbc491 100644
--- a/src/dialogxml/dialogs/dialog.cpp
+++ b/src/dialogxml/dialogs/dialog.cpp
@@ -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;
@@ -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
@@ -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();
diff --git a/src/dialogxml/dialogs/dialog.hpp b/src/dialogxml/dialogs/dialog.hpp
index b556b682c..a93b799f8 100644
--- a/src/dialogxml/dialogs/dialog.hpp
+++ b/src/dialogxml/dialogs/dialog.hpp
@@ -261,7 +261,6 @@ public:
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);
diff --git a/src/game/boe.dlgutil.cpp b/src/game/boe.dlgutil.cpp
index 61acfb63a..1424d6736 100644
--- a/src/game/boe.dlgutil.cpp
+++ b/src/game/boe.dlgutil.cpp
@@ -1317,7 +1317,7 @@ void pick_preferences(bool record) {
}
cLedGroup& uiScale = dynamic_cast(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");
@@ -1326,7 +1326,7 @@ void pick_preferences(bool record) {
else uiScale.setSelected("other");
cLedGroup& uiMapScale = dynamic_cast(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");
@@ -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
diff --git a/src/game/boe.graphics.cpp b/src/game/boe.graphics.cpp
index f71ed899e..aec836476 100644
--- a/src/game/boe.graphics.cpp
+++ b/src/game/boe.graphics.cpp
@@ -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
diff --git a/src/game/boe.items.cpp b/src/game/boe.items.cpp
index 56a9765d3..a9f2e9eef 100644
--- a/src/game/boe.items.cpp
+++ b/src/game/boe.items.cpp
@@ -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);
diff --git a/src/game/boe.startup.cpp b/src/game/boe.startup.cpp
index 0d11fd9bd..0a68edb67 100644
--- a/src/game/boe.startup.cpp
+++ b/src/game/boe.startup.cpp
@@ -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);
@@ -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)};
diff --git a/src/global.hpp b/src/global.hpp
index f6ec25ceb..34ecaba4d 100644
--- a/src/global.hpp
+++ b/src/global.hpp
@@ -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;
diff --git a/src/pcedit/pc.graphics.cpp b/src/pcedit/pc.graphics.cpp
index 11d7f817c..d746e734c 100644
--- a/src/pcedit/pc.graphics.cpp
+++ b/src/pcedit/pc.graphics.cpp
@@ -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
diff --git a/src/pcedit/pc.main.cpp b/src/pcedit/pc.main.cpp
index a8344c68c..2d6c19c99 100644
--- a/src/pcedit/pc.main.cpp
+++ b/src/pcedit/pc.main.cpp
@@ -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();
@@ -553,7 +553,7 @@ void pick_preferences() {
prefsDlog.attachClickHandlers(&prefs_event_filter, {"okay", "cancel"});
cLedGroup& uiScale = dynamic_cast(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");
diff --git a/src/scenedit/scen.main.cpp b/src/scenedit/scen.main.cpp
index ac47ab02d..2b886e2bd 100644
--- a/src/scenedit/scen.main.cpp
+++ b/src/scenedit/scen.main.cpp
@@ -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();
@@ -716,7 +716,7 @@ void pick_preferences() {
prefsDlog.attachClickHandlers(&prefs_event_filter, {"okay", "cancel"});
cLedGroup& uiScale = dynamic_cast(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");
@@ -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
diff --git a/src/tools/SConscript b/src/tools/SConscript
index 1903adc41..c3615015d 100644
--- a/src/tools/SConscript
+++ b/src/tools/SConscript
@@ -7,6 +7,7 @@ tools = Split("""
drawable_manager.cpp
keymods.cpp
replay.cpp
+ winutil.cpp
../alchemy.cpp
../damage.cpp
../enchant.cpp
diff --git a/src/tools/winutil.cpp b/src/tools/winutil.cpp
new file mode 100644
index 000000000..0c24ab4ab
--- /dev/null
+++ b/src/tools/winutil.cpp
@@ -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 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;
+}
\ No newline at end of file
diff --git a/src/tools/winutil.hpp b/src/tools/winutil.hpp
index f6678368e..b6c3de644 100644
--- a/src/tools/winutil.hpp
+++ b/src/tools/winutil.hpp
@@ -13,6 +13,10 @@
#include
#include
#include
+#include
+
+#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 {