From f75e0a86ff65241ba072c6627a1790753700a782 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Sun, 30 Jun 2024 05:27:48 +0200 Subject: [PATCH] Add option for system-specified resolution --- include/Menus/ResolutionMenu.hpp | 2 +- source/Menus/ResolutionMenu.cpp | 8 ++++++-- source/WindowScreen_Menu.cpp | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/Menus/ResolutionMenu.hpp b/include/Menus/ResolutionMenu.hpp index b850ee3..daccfff 100755 --- a/include/Menus/ResolutionMenu.hpp +++ b/include/Menus/ResolutionMenu.hpp @@ -15,7 +15,7 @@ class ResolutionMenu : public OptionSelectionMenu { public: ResolutionMenu(bool font_load_success, sf::Font &text_font); ~ResolutionMenu(); - void prepare(float scaling_factor, int view_size_x, int view_size_y, sf::VideoMode *curr_desk_mode); + void prepare(float scaling_factor, int view_size_x, int view_size_y, int fullscreen_mode_width, int fullscreen_mode_height); void insert_data(std::vector* possible_resolutions); int selected_index = RESOLUTION_MENU_NO_ACTION; void reset_output_option(); diff --git a/source/Menus/ResolutionMenu.cpp b/source/Menus/ResolutionMenu.cpp index 9e9c991..e364fc6 100755 --- a/source/Menus/ResolutionMenu.cpp +++ b/source/Menus/ResolutionMenu.cpp @@ -49,10 +49,14 @@ sf::VideoMode ResolutionMenu::get_resolution(int index) { std::string ResolutionMenu::get_string_option(int index, int action) { sf::VideoMode mode = this->get_resolution(index); + if((mode.width == 0) && (mode.height == 0)) { + mode = sf::VideoMode::getDesktopMode(); + return "System Preference (" + std::to_string(mode.width) + " x " + std::to_string(mode.height)+")"; + } return std::to_string(mode.width) + " x " + std::to_string(mode.height); } -void ResolutionMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, sf::VideoMode *curr_desk_mode) { +void ResolutionMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, int fullscreen_mode_width, int fullscreen_mode_height) { int num_pages = this->get_num_pages(); if(this->future_data.page >= num_pages) this->future_data.page = num_pages - 1; @@ -63,7 +67,7 @@ void ResolutionMenu::prepare(float menu_scaling_factor, int view_size_x, int vie continue; int mode_index = start + i; sf::VideoMode mode = this->get_resolution(mode_index); - if((mode.width == curr_desk_mode->width) && (mode.height == curr_desk_mode->height)) + if((mode.width == fullscreen_mode_width) && (mode.height == fullscreen_mode_height)) this->labels[index]->setText("<" + this->get_string_option(mode_index, DEFAULT_ACTION) + ">"); else this->labels[index]->setText(this->get_string_option(mode_index, DEFAULT_ACTION)); diff --git a/source/WindowScreen_Menu.cpp b/source/WindowScreen_Menu.cpp index 0540e35..3850f69 100755 --- a/source/WindowScreen_Menu.cpp +++ b/source/WindowScreen_Menu.cpp @@ -777,9 +777,10 @@ void WindowScreen::setup_resolution_menu(bool reset_data) { this->possible_resolutions.clear(); std::vector modes = sf::VideoMode::getFullscreenModes(); if(modes.size() > 0) { + this->possible_resolutions.push_back(sf::VideoMode(0, 0, 0)); this->possible_resolutions.push_back(modes[0]); for(int i = 1; i < modes.size(); ++i) - if(this->possible_resolutions[0].bitsPerPixel == modes[i].bitsPerPixel) + if(modes[0].bitsPerPixel == modes[i].bitsPerPixel) this->possible_resolutions.push_back(modes[i]); } else { @@ -1958,7 +1959,7 @@ void WindowScreen::prepare_menu_draws(int view_size_x, int view_size_y) { this->relpos_menu->prepare(this->loaded_info.menu_scaling_factor, view_size_x, view_size_y, this->loaded_info.bottom_pos); break; case RESOLUTION_MENU_TYPE: - this->resolution_menu->prepare(this->loaded_info.menu_scaling_factor, view_size_x, view_size_y, &this->curr_desk_mode); + this->resolution_menu->prepare(this->loaded_info.menu_scaling_factor, view_size_x, view_size_y, this->loaded_info.fullscreen_mode_width, this->loaded_info.fullscreen_mode_height); break; case SAVE_MENU_TYPE: this->fileconfig_menu->prepare(this->loaded_info.menu_scaling_factor, view_size_x, view_size_y);