Skip to content

Commit

Permalink
Pick the largest suitable default scale. Fix #468
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Nov 18, 2024
1 parent a725dc6 commit 32ea156
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 25 deletions.
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
3 changes: 2 additions & 1 deletion src/pcedit/pc.graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ extern fs::path file_in_mem;
extern short store_flags[3];
extern short current_active_pc;

rectangle whole_win_rect = {0,0,440,590};
// TODO why are width and height switched here?
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
46 changes: 44 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,44 @@ inline int os_specific_y_offset() {
#endif
}

// 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).
inline float fallback_scale() {
static float _fallback_scale = 0;
if(_fallback_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<float> 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){
_fallback_scale = (*it);
break;
}
}
}
// Hopefully no one would ever have such a small monitor to not fit the default size.
// But just in case:
if(_fallback_scale == 0){
_fallback_scale = 1.0;
}

return _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 32ea156

Please sign in to comment.