From 829fbb794947b843fd1b903a5ac5244e34096dc0 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Sat, 1 Mar 2025 16:49:29 +0100 Subject: [PATCH] Add double parameter scaling --- include/display_structs.hpp | 7 ++++++- source/WindowScreen_Menu.cpp | 22 +++++++++++++++------- source/cc3dsfs.cpp | 20 +++++++++++++++++--- source/frontend.cpp | 20 ++++++++++---------- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/include/display_structs.hpp b/include/display_structs.hpp index ad5208a..cb85182 100755 --- a/include/display_structs.hpp +++ b/include/display_structs.hpp @@ -11,6 +11,11 @@ #define DEFAULT_NO_ENABLED_VALUE -1 #define DEFAULT_NO_SCALING_VALUE -1 +#define DEFAULT_WINDOW_SCALING_VALUE 1.0 +#define MIN_WINDOW_SCALING_VALUE 1.0 +#define MAX_WINDOW_SCALING_VALUE 45.0 +#define WINDOW_SCALING_CHANGE 0.5 + enum ScreenType { TOP, BOTTOM, JOINT }; enum BottomRelativePosition { UNDER_TOP, LEFT_TOP, ABOVE_TOP, RIGHT_TOP, BOT_REL_POS_END }; enum NonIntegerScalingModes { SMALLER_PRIORITY, INVERSE_PROPORTIONAL_PRIORITY, EQUAL_PRIORITY, PROPORTIONAL_PRIORITY, BIGGER_PRIORITY, END_NONINT_SCALE_MODES }; @@ -22,7 +27,7 @@ struct override_win_data { int pos_x = DEFAULT_NO_POS_WINDOW_VALUE; int pos_y = DEFAULT_NO_POS_WINDOW_VALUE; int enabled = DEFAULT_NO_ENABLED_VALUE; - int scaling = DEFAULT_NO_SCALING_VALUE; + double scaling = DEFAULT_NO_SCALING_VALUE; }; struct ScreenInfo { diff --git a/source/WindowScreen_Menu.cpp b/source/WindowScreen_Menu.cpp index 12b3d7e..9e7ebf0 100755 --- a/source/WindowScreen_Menu.cpp +++ b/source/WindowScreen_Menu.cpp @@ -1,4 +1,4 @@ -#include +#include #include "frontend.hpp" #include "SFML/Audio/PlaybackDevice.hpp" @@ -345,14 +345,22 @@ void WindowScreen::window_scaling_change(bool positive) { if(this->m_info.is_fullscreen) return; double old_scaling = this->m_info.scaling; + double closest_foor_scaling = std::floor(old_scaling / WINDOW_SCALING_CHANGE) * WINDOW_SCALING_CHANGE; + double closest_ceil_scaling = std::ceil(old_scaling / WINDOW_SCALING_CHANGE) * WINDOW_SCALING_CHANGE; + double greater_scaling = old_scaling + WINDOW_SCALING_CHANGE; + double lower_scaling = old_scaling - WINDOW_SCALING_CHANGE; + if(closest_foor_scaling != closest_ceil_scaling) { + greater_scaling = closest_ceil_scaling; + lower_scaling = closest_foor_scaling; + } if(positive) - this->m_info.scaling += 0.5; + this->m_info.scaling = greater_scaling; else - this->m_info.scaling -= 0.5; - if (this->m_info.scaling < 1.25) - this->m_info.scaling = 1.0; - if (this->m_info.scaling > 44.75) - this->m_info.scaling = 45.0; + this->m_info.scaling = lower_scaling; + if (this->m_info.scaling < (MIN_WINDOW_SCALING_VALUE + (WINDOW_SCALING_CHANGE / 2))) + this->m_info.scaling = MIN_WINDOW_SCALING_VALUE; + if (this->m_info.scaling > (MAX_WINDOW_SCALING_VALUE - (WINDOW_SCALING_CHANGE / 2))) + this->m_info.scaling = MAX_WINDOW_SCALING_VALUE; if(old_scaling != this->m_info.scaling) { this->print_notification_float("Scaling", this->m_info.scaling, 1); this->future_operations.call_screen_settings_update = true; diff --git a/source/cc3dsfs.cpp b/source/cc3dsfs.cpp index c869186..effb509 100755 --- a/source/cc3dsfs.cpp +++ b/source/cc3dsfs.cpp @@ -749,6 +749,20 @@ static bool parse_int_arg(int &index, int argc, char **argv, int &target, std::s return true; } +static bool parse_double_arg(int &index, int argc, char **argv, double &target, std::string to_check) { + if(argv[index] != to_check) + return false; + if((++index) >= argc) + return true; + try { + target = std::stod(argv[index]); + } + catch(...) { + std::cerr << "Error with input for: " << to_check << std::endl; + } + return true; +} + int main(int argc, char **argv) { init_threads(); init_start_time(); @@ -768,7 +782,7 @@ int main(int argc, char **argv) { continue; if(parse_int_arg(i, argc, argv, override_data.override_top_bot_data.pos_y, "--pos_y_both")) continue; - if(parse_int_arg(i, argc, argv, override_data.override_top_bot_data.scaling, "--scaling_both")) + if(parse_double_arg(i, argc, argv, override_data.override_top_bot_data.scaling, "--scaling_both")) continue; if(parse_int_arg(i, argc, argv, override_data.override_top_bot_data.enabled, "--enabled_both")) continue; @@ -776,7 +790,7 @@ int main(int argc, char **argv) { continue; if(parse_int_arg(i, argc, argv, override_data.override_top_data.pos_y, "--pos_y_top")) continue; - if(parse_int_arg(i, argc, argv, override_data.override_top_data.scaling, "--scaling_top")) + if(parse_double_arg(i, argc, argv, override_data.override_top_data.scaling, "--scaling_top")) continue; if(parse_int_arg(i, argc, argv, override_data.override_top_data.enabled, "--enabled_top")) continue; @@ -784,7 +798,7 @@ int main(int argc, char **argv) { continue; if(parse_int_arg(i, argc, argv, override_data.override_bot_data.pos_y, "--pos_y_bot")) continue; - if(parse_int_arg(i, argc, argv, override_data.override_bot_data.scaling, "--scaling_bot")) + if(parse_double_arg(i, argc, argv, override_data.override_bot_data.scaling, "--scaling_bot")) continue; if(parse_int_arg(i, argc, argv, override_data.override_bot_data.enabled, "--enabled_bot")) continue; diff --git a/source/frontend.cpp b/source/frontend.cpp index 7bb8a13..a6243c3 100755 --- a/source/frontend.cpp +++ b/source/frontend.cpp @@ -427,7 +427,7 @@ void reset_screen_info(ScreenInfo &info) { info.crop_kind = 0; info.crop_kind_ds = 0; info.allow_games_crops = false; - info.scaling = 1.0; + info.scaling = DEFAULT_WINDOW_SCALING_VALUE; info.is_fullscreen = false; info.bottom_pos = UNDER_TOP; info.subscreen_offset = 0.5; @@ -439,10 +439,10 @@ void reset_screen_info(ScreenInfo &info) { info.show_mouse = true; info.v_sync_enabled = false; info.async = true; - info.top_scaling = -1; - info.bot_scaling = -1; - info.non_integer_top_scaling = -1.0; - info.non_integer_bot_scaling = -1.0; + info.top_scaling = DEFAULT_NO_SCALING_VALUE; + info.bot_scaling = DEFAULT_NO_SCALING_VALUE; + info.non_integer_top_scaling = DEFAULT_NO_SCALING_VALUE; + info.non_integer_bot_scaling = DEFAULT_NO_SCALING_VALUE; info.bfi = false; info.bfi_divider = 2; info.bfi_amount = 1; @@ -470,7 +470,7 @@ void override_set_data_to_screen_info(override_win_data &override_win, ScreenInf info.initial_pos_y = override_win.pos_y; if(override_win.enabled != DEFAULT_NO_ENABLED_VALUE) info.window_enabled = override_win.enabled; - if((override_win.scaling != DEFAULT_NO_SCALING_VALUE) && (override_win.scaling > 0)) + if((override_win.scaling != DEFAULT_NO_SCALING_VALUE) && (override_win.scaling >= MIN_WINDOW_SCALING_VALUE) && (override_win.scaling <= MAX_WINDOW_SCALING_VALUE)) info.scaling = override_win.scaling; } @@ -513,10 +513,10 @@ bool load_screen_info(std::string key, std::string value, std::string base, Scre } if(key == (base + "scale")) { info.scaling = std::stod(value); - if(info.scaling < 1.25) - info.scaling = 1.0; - if(info.scaling > 44.75) - info.scaling = 45.0; + if(info.scaling < MIN_WINDOW_SCALING_VALUE) + info.scaling = MIN_WINDOW_SCALING_VALUE; + if(info.scaling > MAX_WINDOW_SCALING_VALUE) + info.scaling = MAX_WINDOW_SCALING_VALUE; return true; } if(key == (base + "fullscreen")) {