Implement Resolution settings

This commit is contained in:
Lorenzooone 2024-05-22 22:15:33 +02:00
parent 0819e1fad9
commit 05362f6810
8 changed files with 212 additions and 6 deletions

View File

@ -132,7 +132,7 @@ file(MAKE_DIRECTORY ${TOOLS_DATA_DIR})
set(OUTPUT_NAME cc3dsfs)
add_executable(CMakeBin2C tools/bin2c.cpp)
add_executable(${OUTPUT_NAME} source/cc3dsfs.cpp source/utils.cpp source/audio_data.cpp source/audio.cpp source/frontend.cpp source/TextRectangle.cpp source/WindowScreen.cpp source/3dscapture.cpp source/conversions.cpp source/Menus/ConnectionMenu.cpp source/Menus/OptionSelectionMenu.cpp source/Menus/MainMenu.cpp source/Menus/VideoMenu.cpp source/Menus/CropMenu.cpp source/Menus/PARMenu.cpp source/Menus/RotationMenu.cpp source/Menus/OffsetMenu.cpp source/Menus/AudioMenu.cpp source/Menus/BFIMenu.cpp source/Menus/RelativePositionMenu.cpp ${TOOLS_DATA_DIR}/font_ttf.cpp)
add_executable(${OUTPUT_NAME} source/cc3dsfs.cpp source/utils.cpp source/audio_data.cpp source/audio.cpp source/frontend.cpp source/TextRectangle.cpp source/WindowScreen.cpp source/3dscapture.cpp source/conversions.cpp source/Menus/ConnectionMenu.cpp source/Menus/OptionSelectionMenu.cpp source/Menus/MainMenu.cpp source/Menus/VideoMenu.cpp source/Menus/CropMenu.cpp source/Menus/PARMenu.cpp source/Menus/RotationMenu.cpp source/Menus/OffsetMenu.cpp source/Menus/AudioMenu.cpp source/Menus/BFIMenu.cpp source/Menus/RelativePositionMenu.cpp source/Menus/ResolutionMenu.cpp ${TOOLS_DATA_DIR}/font_ttf.cpp)
add_dependencies(${OUTPUT_NAME} FTD3XX_BUILD_PROJECT CMakeBin2C)
target_link_libraries(${OUTPUT_NAME} PRIVATE sfml-graphics sfml-audio sfml-window sfml-system ${ftd3xx_BINARY_DIR}/${FTD3XX_SUBFOLDER}/${FTD3XX_LIB})
target_link_directories(${OUTPUT_NAME} PRIVATE ${ftd3xx_BINARY_DIR}/${FTD3XX_SUBFOLDER})

View File

@ -0,0 +1,31 @@
#ifndef __RESOLUTIONMENU_HPP
#define __RESOLUTIONMENU_HPP
#include "OptionSelectionMenu.hpp"
#include <chrono>
#include "TextRectangle.hpp"
#include "sfml_gfx_structs.hpp"
#include "display_structs.hpp"
#define RESOLUTION_MENU_NO_ACTION -1
#define RESOLUTION_MENU_BACK -2
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 insert_data(std::vector<sf::VideoMode>* possible_resolutions);
int selected_index = RESOLUTION_MENU_NO_ACTION;
void reset_output_option();
protected:
void set_output_option(int index, int action);
int get_num_options();
std::string get_string_option(int index, int action);
void class_setup();
private:
std::vector<sf::VideoMode>* possible_resolutions;
sf::VideoMode get_resolution(int index);
};
#endif

View File

@ -27,6 +27,9 @@ struct ScreenInfo {
bool rounded_corners_fix;
int top_par;
int bot_par;
int fullscreen_mode_width;
int fullscreen_mode_height;
int fullscreen_mode_bpp;
};
struct DisplayData {

View File

@ -22,6 +22,7 @@
#include "AudioMenu.hpp"
#include "BFIMenu.hpp"
#include "RelativePositionMenu.hpp"
#include "ResolutionMenu.hpp"
#include "display_structs.hpp"
class WindowScreen {
@ -94,8 +95,10 @@ private:
AudioMenu *audio_menu;
BFIMenu *bfi_menu;
RelativePositionMenu *relpos_menu;
ResolutionMenu *resolution_menu;
std::vector<const CropData*> possible_crops;
std::vector<const PARData*> possible_pars;
std::vector<sf::VideoMode> possible_resolutions;
sf::Texture in_tex;
@ -204,6 +207,7 @@ struct FrontendData {
bool is_allowed_crop(const CropData* crop_data, ScreenType s_type);
void insert_basic_crops(std::vector<const CropData*> &crop_vector, ScreenType s_type);
void insert_basic_pars(std::vector<const PARData*> &par_vector);
void reset_fullscreen_info(ScreenInfo &info);
void reset_screen_info(ScreenInfo &info);
bool load_screen_info(std::string key, std::string value, std::string base, ScreenInfo &info);
std::string save_screen_info(std::string base, const ScreenInfo &info);

72
source/Menus/ResolutionMenu.cpp Executable file
View File

@ -0,0 +1,72 @@
#include "ResolutionMenu.hpp"
ResolutionMenu::ResolutionMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
this->initialize(font_load_success, text_font);
}
ResolutionMenu::~ResolutionMenu() {
}
void ResolutionMenu::class_setup() {
this->num_options_per_screen = 5;
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
this->width_factor_menu = 16;
this->width_divisor_menu = 9;
this->base_height_factor_menu = 12;
this->base_height_divisor_menu = 6;
this->min_text_size = 0.3;
this->max_width_slack = 1.1;
this->menu_color = sf::Color(30, 30, 60, 192);
this->title = "Resolution Settings";
this->show_back_x = true;
this->show_x = false;
this->show_title = true;
}
void ResolutionMenu::insert_data(std::vector<sf::VideoMode>* possible_resolutions) {
this->possible_resolutions = possible_resolutions;
this->prepare_options();
}
void ResolutionMenu::reset_output_option() {
this->selected_index = RESOLUTION_MENU_NO_ACTION;
}
void ResolutionMenu::set_output_option(int index, int action) {
if(index == BACK_X_OUTPUT_OPTION)
this->selected_index = RESOLUTION_MENU_BACK;
else
this->selected_index = index;
}
int ResolutionMenu::get_num_options() {
return (*this->possible_resolutions).size();
}
sf::VideoMode ResolutionMenu::get_resolution(int index) {
return (*this->possible_resolutions)[index];
}
std::string ResolutionMenu::get_string_option(int index, int action) {
sf::VideoMode mode = this->get_resolution(index);
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) {
int num_pages = this->get_num_pages();
if(this->future_data.page >= num_pages)
this->future_data.page = num_pages - 1;
int start = this->future_data.page * this->num_options_per_screen;
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
int index = (i * this->single_option_multiplier) + this->elements_start_id;
if(!this->future_enabled_labels[index])
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) && (mode.bitsPerPixel == curr_desk_mode->bitsPerPixel))
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));
}
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
}

View File

@ -253,9 +253,15 @@ bool VideoMenu::is_option_inc_dec(int index) {
std::string VideoMenu::setTextOptionDualPercentage(int index, int value_1, int value_2) {
int sum = value_1 + value_2;
value_1 = ((value_1 * 100) + (sum / 2)) / sum;
value_2 = ((value_2 * 100) + (sum / 2)) / sum;
value_1 += 100 - (value_1 + value_2);
if(sum > 0) {
value_1 = ((value_1 * 100) + (sum / 2)) / sum;
value_2 = ((value_2 * 100) + (sum / 2)) / sum;
value_1 += 100 - (value_1 + value_2);
}
else {
value_1 = 0;
value_2 = 0;
}
return this->get_string_option(index, DEFAULT_ACTION) + ": " + std::to_string(value_1) + " - " + std::to_string(value_2);
}

View File

@ -30,6 +30,7 @@ WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, Disp
this->audio_menu = new AudioMenu(this->font_load_success, this->text_font);
this->bfi_menu = new BFIMenu(this->font_load_success, this->text_font);
this->relpos_menu = new RelativePositionMenu(this->font_load_success, this->text_font);
this->resolution_menu = new ResolutionMenu(this->font_load_success, this->text_font);
this->in_tex.create(IN_VIDEO_WIDTH, IN_VIDEO_HEIGHT);
this->m_in_rect_top.setTexture(&this->in_tex);
this->m_in_rect_bot.setTexture(&this->in_tex);
@ -53,6 +54,7 @@ WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, Disp
}
WindowScreen::~WindowScreen() {
this->possible_resolutions.clear();
delete this->saved_buf;
delete this->notification;
delete this->connection_menu;
@ -110,6 +112,7 @@ void WindowScreen::fullscreen_change() {
if(this->curr_menu != CONNECT_MENU_TYPE)
this->curr_menu = DEFAULT_MENU_TYPE;
this->m_info.is_fullscreen = !this->m_info.is_fullscreen;
reset_fullscreen_info(this->m_info);
this->create_window(true);
}
@ -432,6 +435,22 @@ void WindowScreen::setup_save_menu() {
}
void WindowScreen::setup_resolution_menu() {
if(this->curr_menu != RESOLUTION_MENU_TYPE) {
this->possible_resolutions.clear();
std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
if(modes.size() > 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)
this->possible_resolutions.push_back(modes[i]);
if(this->possible_resolutions.size() > 0) {
this->curr_menu = RESOLUTION_MENU_TYPE;
this->resolution_menu->reset_data();
this->resolution_menu->insert_data(&this->possible_resolutions);
}
else
this->print_notification("No Resolution found", TEXT_KIND_WARNING);
}
}
void WindowScreen::setup_extra_menu() {
@ -1065,6 +1084,26 @@ void WindowScreen::poll() {
continue;
}
break;
case RESOLUTION_MENU_TYPE:
if(this->resolution_menu->poll(event_data)) {
switch(this->resolution_menu->selected_index) {
case RESOLUTION_MENU_BACK:
this->setup_video_menu();
done = true;
break;
case RESOLUTION_MENU_NO_ACTION:
break;
default:
this->m_info.fullscreen_mode_width = possible_resolutions[this->resolution_menu->selected_index].width;
this->m_info.fullscreen_mode_height = possible_resolutions[this->resolution_menu->selected_index].height;
this->m_info.fullscreen_mode_bpp = possible_resolutions[this->resolution_menu->selected_index].bitsPerPixel;
this->create_window(true);
break;
}
this->resolution_menu->reset_output_option();
continue;
}
break;
default:
break;
}
@ -1184,6 +1223,9 @@ void WindowScreen::draw(double frame_time, VideoOutputData* out_buf) {
case RELATIVE_POS_MENU_TYPE:
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);
break;
default:
break;
}
@ -1520,6 +1562,9 @@ void WindowScreen::display_data_to_window(bool actually_draw, bool is_debug) {
case RELATIVE_POS_MENU_TYPE:
this->relpos_menu->draw(this->loaded_info.menu_scaling_factor, this->m_win);
break;
case RESOLUTION_MENU_TYPE:
this->resolution_menu->draw(this->loaded_info.menu_scaling_factor, this->m_win);
break;
default:
break;
}
@ -1676,6 +1721,11 @@ void WindowScreen::calc_scaling_resize_screens(sf::Vector2f &own_screen_size, sf
int min_other_height = other_screen_size.y;
get_par_size(min_other_width, min_other_height, 1, other_par);
int chosen_ratio = prepare_screen_ratio(own_screen_size, own_rotation, min_other_width, min_other_height, other_rotation, own_par);
if(chosen_ratio <= 0) {
chosen_ratio = prepare_screen_ratio(own_screen_size, own_rotation, 0, 0, other_rotation, own_par);
if(chosen_ratio <= 0)
chosen_ratio = 0;
}
int old_scaling = own_scaling;
if(increase && (chosen_ratio > own_scaling) && (chosen_ratio > 0))
own_scaling += 1;
@ -1692,7 +1742,9 @@ void WindowScreen::calc_scaling_resize_screens(sf::Vector2f &own_screen_size, sf
other_scaling = 0;
else
other_scaling = prepare_screen_ratio(other_screen_size, other_rotation, own_width, own_height, own_rotation, other_par);
if((this->m_stype == ScreenType::JOINT) && (own_scaling > 0)) {
if(other_scaling < 0)
other_scaling = 0;
if((this->m_stype == ScreenType::JOINT) && ((own_scaling > 0) || ((other_scaling == 0) && (own_scaling == 0)))) {
// Due to size differences, it may be possible that
// the chosen screen might be able to increase its
// scaling even more without compromising the other one...
@ -1700,6 +1752,8 @@ void WindowScreen::calc_scaling_resize_screens(sf::Vector2f &own_screen_size, sf
int other_width = other_screen_size.x;
get_par_size(other_width, other_height, other_scaling, other_par);
own_scaling = prepare_screen_ratio(own_screen_size, own_rotation, other_width, other_height, other_rotation, own_par);
if(own_scaling < 0)
own_scaling = 0;
}
}
@ -1830,7 +1884,21 @@ void WindowScreen::create_window(bool re_prepare_size) {
this->m_info.show_mouse = true;
}
else {
this->curr_desk_mode = sf::VideoMode::getDesktopMode();
bool success = false;
if((this->m_info.fullscreen_mode_width > 0) && (this->m_info.fullscreen_mode_height > 0) && (this->m_info.fullscreen_mode_bpp > 0)) {
sf::VideoMode mode_created = sf::VideoMode(this->m_info.fullscreen_mode_width, this->m_info.fullscreen_mode_height, this->m_info.fullscreen_mode_bpp);
if(mode_created.isValid()) {
this->curr_desk_mode = mode_created;
success = true;
}
}
if(!success) {
std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
if(modes.size() > 0)
this->curr_desk_mode = modes[0];
else
this->curr_desk_mode = sf::VideoMode::getDesktopMode();
}
this->m_window_width = curr_desk_mode.width;
this->m_window_height = curr_desk_mode.height;
this->m_info.show_mouse = false;

View File

@ -159,6 +159,12 @@ void insert_basic_pars(std::vector<const PARData*> &par_vector) {
}
}
void reset_fullscreen_info(ScreenInfo &info) {
info.fullscreen_mode_width = 0;
info.fullscreen_mode_height = 0;
info.fullscreen_mode_bpp = 0;
}
void reset_screen_info(ScreenInfo &info) {
info.is_blurred = false;
info.crop_kind = 0;
@ -187,6 +193,7 @@ void reset_screen_info(ScreenInfo &info) {
info.rounded_corners_fix = false;
info.top_par = 0;
info.bot_par = 0;
reset_fullscreen_info(info);
}
static float offset_sanitization(float value) {
@ -308,6 +315,18 @@ bool load_screen_info(std::string key, std::string value, std::string base, Scre
info.bot_par = std::stoi(value);
return true;
}
if(key == (base + "fullscreen_mode_width")) {
info.fullscreen_mode_width = std::stoi(value);
return true;
}
if(key == (base + "fullscreen_mode_height")) {
info.fullscreen_mode_height = std::stoi(value);
return true;
}
if(key == (base + "fullscreen_mode_bpp")) {
info.fullscreen_mode_bpp = std::stoi(value);
return true;
}
return false;
}
@ -335,6 +354,9 @@ std::string save_screen_info(std::string base, const ScreenInfo &info) {
out += base + "rounded_corners_fix=" + std::to_string(info.rounded_corners_fix) + "\n";
out += base + "top_par=" + std::to_string(info.top_par) + "\n";
out += base + "bot_par=" + std::to_string(info.bot_par) + "\n";
out += base + "fullscreen_mode_width=" + std::to_string(info.fullscreen_mode_width) + "\n";
out += base + "fullscreen_mode_height=" + std::to_string(info.fullscreen_mode_height) + "\n";
out += base + "fullscreen_mode_bpp=" + std::to_string(info.fullscreen_mode_bpp) + "\n";
return out;
}