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

Merged
NQNStudios merged 6 commits from default-scale into master 2024-11-20 00:17:15 +00:00
19 changed files with 89 additions and 25 deletions

View File

@@ -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" />

View File

@@ -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>

View File

@@ -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" />

View File

@@ -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>

View File

@@ -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 = "<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>"; };
@@ -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 */,

View File

@@ -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>"; };
@@ -1215,6 +1216,7 @@
9185BDA11EA041570027C346 /* tools */ = {
isa = PBXGroup;
children = (
413FE08D2CECFAA4000D97DC /* winutil.cpp */,
D384F6A12C1B9CE900A806C3 /* replay.cpp */,
91C688E70FD702B9000F6D01 /* cursors.mac.mm */,
91FE0E3523F084B70084CA6B /* drawable_manager.cpp */,

View File

@@ -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();

View File

@@ -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);

View File

@@ -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");
@@ -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");
@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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)};

View File

@@ -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;

View File

@@ -29,7 +29,7 @@ extern fs::path file_in_mem;
extern short store_flags[3];
CelticMinstrel commented 2024-11-19 02:58:02 +00:00 (Migrated from github.com)
Review

What do you mean, they're switched? The rectangle constructor is top, left, bottom, right.

What do you mean, they're switched? The rectangle constructor is top, left, bottom, right.
NQNStudios commented 2024-11-19 16:28:17 +00:00 (Migrated from github.com)
Review

I'm really used to the order being {x, y, width, height} in other frameworks. My bad.

I'm really used to the order being {x, y, width, height} in other frameworks. My bad.
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

View File

@@ -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<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");

View File

@@ -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<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");
@@ -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

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
CelticMinstrel commented 2024-11-19 03:00:29 +00:00 (Migrated from github.com)
Review
  1. I don't like variable names beginning with an underscore. Wouldn't just scale do just fine?
  2. This is a pretty big function, does it really need to be defined inline in the header?
1. I don't like variable names beginning with an underscore. Wouldn't just `scale` do just fine? 2. This is a pretty big function, does it really need to be defined inline in the header?
NQNStudios commented 2024-11-19 16:36:51 +00:00 (Migrated from github.com)
Review
  1. Yes
  2. Probably not. I just need to find a different header/source file that is included in the Common sources where it would make sense to be forward-declared/defined. Because if I declare it in winutil.hpp, the definition would have to be repeated in the 3 different winutil.*.cpp/mm files. Or add a winutil.all.cpp file? There have been other moments where I wished there was a winutil.all.cpp file, so maybe that's worth doing.
1. Yes 2. Probably not. I just need to find a different header/source file that is included in the Common sources where it would make sense to be forward-declared/defined. Because if I declare it in winutil.hpp, the definition would have to be repeated in the 3 different winutil.*.cpp/mm files. Or add a winutil.all.cpp file? There have been other moments where I wished there was a winutil.all.cpp file, so maybe that's worth doing.
}
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 {