Prepare more Main Menu options data

This commit is contained in:
Lorenzooone 2024-05-13 01:47:11 +02:00
parent a4daf7186a
commit 9cba3b8895
10 changed files with 458 additions and 84 deletions

View File

@ -19,6 +19,28 @@ enum MainMenuOutAction{
MAIN_MENU_ASYNC,
MAIN_MENU_BLUR,
MAIN_MENU_PADDING,
MAIN_MENU_CROPPING,
MAIN_MENU_TOP_PAR,
MAIN_MENU_BOT_PAR,
MAIN_MENU_ONE_PAR,
MAIN_MENU_BOTTOM_SCREEN_POS,
MAIN_MENU_SMALL_SCREEN_OFFSET,
MAIN_MENU_SMALL_SCREEN_DISTANCE,
MAIN_MENU_SCREENS_X_POS,
MAIN_MENU_SCREENS_Y_POS,
MAIN_MENU_WINDOW_SCALING,
MAIN_MENU_FULLSCREEN_SCALING,
MAIN_MENU_BFI_SETTINGS,
MAIN_MENU_MENU_SCALING,
MAIN_MENU_RESOLUTION_SETTINGS,
MAIN_MENU_AUDIO_SETTINGS,
MAIN_MENU_SAVE_PROFILES,
MAIN_MENU_LOAD_PROFILES,
MAIN_MENU_STATUS,
MAIN_MENU_LICENSES,
MAIN_MENU_EXTRA_SETTINGS,
MAIN_MENU_TOP_ROTATION,
MAIN_MENU_BOTTOM_ROTATION,
};
class MainMenu : public OptionSelectionMenu {

View File

@ -31,6 +31,7 @@ protected:
int base_height_factor_menu = 1;
int base_height_divisor_menu = 1;
float min_text_size = 0.3;
float max_width_slack = 1.1;
virtual void reset_output_option();
virtual void set_output_option(int index);
virtual int get_num_options();

View File

@ -5,15 +5,13 @@
#include "hw_defs.hpp"
enum ScreenType { TOP, BOTTOM, JOINT };
enum Crop { DEFAULT_3DS, SPECIAL_DS, SCALED_DS, NATIVE_DS, SCALED_GBA, NATIVE_GBA, SCALED_GB, NATIVE_GB, SCALED_SNES, NATIVE_SNES, NATIVE_NES, CROP_END };
enum ParCorrection { PAR_NORMAL, PAR_SNES_HORIZONTAL, PAR_SNES_VERTICAL, PAR_END };
enum BottomRelativePosition { UNDER_TOP, LEFT_TOP, ABOVE_TOP, RIGHT_TOP, BOT_REL_POS_END };
enum OffsetAlgorithm { NO_DISTANCE, HALF_DISTANCE, MAX_DISTANCE, OFF_ALGO_END };
enum CurrMenuType { DEFAULT_MENU_TYPE, CONNECT_MENU_TYPE, MAIN_MENU_TYPE };
struct ScreenInfo {
bool is_blurred;
Crop crop_kind;
int crop_kind;
double scaling;
bool is_fullscreen;
BottomRelativePosition bottom_pos;
@ -27,8 +25,8 @@ struct ScreenInfo {
double bfi_divider;
double menu_scaling_factor;
bool rounded_corners_fix;
ParCorrection top_par;
ParCorrection bot_par;
int top_par;
int bot_par;
};
struct DisplayData {
@ -43,4 +41,26 @@ struct PACKED VideoOutputData {
#pragma pack(pop)
struct CropData {
int top_width;
int top_height;
int top_x;
int top_y;
int bot_width;
int bot_height;
int bot_x;
int bot_y;
bool allowed_joint;
bool allowed_top;
bool allowed_bottom;
std::string name;
};
struct PARData {
float width_multiplier;
float width_divisor;
bool is_width_main;
std::string name;
};
#endif

View File

@ -5,6 +5,7 @@
#include <mutex>
#include <queue>
#include <vector>
#include <chrono>
#include "utils.hpp"
#include "audio_data.hpp"
@ -77,6 +78,8 @@ private:
CurrMenuType loaded_menu;
ConnectionMenu *connection_menu;
MainMenu *main_menu;
std::vector<const CropData*> possible_crops;
std::vector<const PARData*> possible_pars;
sf::Texture in_tex;
@ -133,8 +136,8 @@ private:
void window_render_call();
int apply_offset_algo(int offset_contribute, OffsetAlgorithm chosen_algo);
void set_position_screens(sf::Vector2f &curr_top_screen_size, sf::Vector2f &curr_bot_screen_size, int offset_x, int offset_y, int max_x, int max_y, bool do_work = true);
int prepare_screen_ratio(sf::Vector2f &screen_size, int own_rotation, int width_limit, int height_limit, int other_rotation, ParCorrection own_par);
void calc_scaling_resize_screens(sf::Vector2f &own_screen_size, sf::Vector2f &other_screen_size, int &own_scaling, int &other_scaling, int own_rotation, int other_rotation, bool increase, bool mantain, bool set_to_zero, ParCorrection own_par, ParCorrection other_par);
int prepare_screen_ratio(sf::Vector2f &screen_size, int own_rotation, int width_limit, int height_limit, int other_rotation, const PARData *own_par);
void calc_scaling_resize_screens(sf::Vector2f &own_screen_size, sf::Vector2f &other_screen_size, int &own_scaling, int &other_scaling, int own_rotation, int other_rotation, bool increase, bool mantain, bool set_to_zero, const PARData *own_par, const PARData *other_par);
void prepare_size_ratios(bool top_increase, bool bot_increase);
int get_fullscreen_offset_x(int top_width, int top_height, int bot_width, int bot_height);
int get_fullscreen_offset_y(int top_width, int top_height, int bot_width, int bot_height);
@ -145,7 +148,7 @@ private:
void open();
void update_screen_settings();
void rotate();
sf::Vector2f getShownScreenSize(bool is_top, Crop &crop_kind);
sf::Vector2f getShownScreenSize(bool is_top, int &crop_kind);
void crop();
void setWinSize(bool is_main_thread);
void setup_main_menu();
@ -160,11 +163,14 @@ struct FrontendData {
bool reload;
};
bool is_allowed_crop(const CropData* crop_data, ScreenType s_type);
void insert_basic_crops(std::vector<const CropData*> &crop_vector);
void insert_basic_pars(std::vector<const PARData*> &par_vector);
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);
void get_par_size(float &width, float &height, float multiplier_factor, ParCorrection &correction_factor);
void get_par_size(int &width, int &height, float multiplier_factor, ParCorrection &correction_factor);
void get_par_size(float &width, float &height, float multiplier_factor, const PARData *correction_factor);
void get_par_size(int &width, int &height, float multiplier_factor, const PARData *correction_factor);
void default_sleep();
void update_output(FrontendData* frontend_data, double frame_time = 0, VideoOutputData *out_buf = NULL);
void screen_display_thread(WindowScreen *screen);

View File

@ -23,6 +23,7 @@ void ConnectionMenu::class_setup() {
this->base_height_factor_menu = 10;
this->base_height_divisor_menu = 6;
this->min_text_size = 0.3;
this->max_width_slack = 1.1;
}
void ConnectionMenu::insert_data(DevicesList *devices_list) {

View File

@ -6,6 +6,7 @@
#define OPTION_FULLSCREEN true
#define OPTION_JOIN true
#define OPTION_SPLIT true
#define OPTION_EXTRA false
struct MainMenuOptionInfo {
const std::string base_name;
@ -84,16 +85,184 @@ static const MainMenuOptionInfo quit_option = {
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_QUIT_APPLICATION};
static const MainMenuOptionInfo crop_option = {
.base_name = "Crop Settings", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_CROPPING};
static const MainMenuOptionInfo top_par_option = {
.base_name = "Top Screen PAR", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_TOP_PAR};
static const MainMenuOptionInfo bot_par_option = {
.base_name = "Bottom Screen PAR", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_BOT_PAR};
static const MainMenuOptionInfo one_par_option = {
.base_name = "Screen PAR", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = false, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_ONE_PAR};
static const MainMenuOptionInfo bottom_screen_pos_option = {
.base_name = "Bottom Screen Pos.", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_BOTTOM_SCREEN_POS};
static const MainMenuOptionInfo small_screen_offset_option = {
.base_name = "Smaller Screen Offset", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_SMALL_SCREEN_OFFSET};
static const MainMenuOptionInfo subscreen_distance_option = {
.base_name = "Sub-Screen Distance", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = false,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_SMALL_SCREEN_DISTANCE};
static const MainMenuOptionInfo canvas_x_pos_option = {
.base_name = "Canvas X Position", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = false,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_SCREENS_X_POS};
static const MainMenuOptionInfo canvas_y_pos_option = {
.base_name = "Canvas Y Position", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = false,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_SCREENS_Y_POS};
static const MainMenuOptionInfo window_scaling_option = {
.base_name = "Scaling Factor", .false_name = "",
.active_fullscreen = false, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_WINDOW_SCALING};
static const MainMenuOptionInfo fullscreen_scaling_option = {
.base_name = "Screens Scaling", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = false,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_FULLSCREEN_SCALING};
static const MainMenuOptionInfo bfi_settings_option = {
.base_name = "BFI Settings", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_BFI_SETTINGS};
static const MainMenuOptionInfo menu_scaling_option = {
.base_name = "Menu Scaling", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_MENU_SCALING};
static const MainMenuOptionInfo resolution_settings_option = {
.base_name = "Resolution Settings", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = false,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_RESOLUTION_SETTINGS};
static const MainMenuOptionInfo audio_settings_option = {
.base_name = "Audio Settings", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_AUDIO_SETTINGS};
static const MainMenuOptionInfo save_profiles_option = {
.base_name = "Save Profile", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_SAVE_PROFILES};
static const MainMenuOptionInfo load_profiles_option = {
.base_name = "Load Profile", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_LOAD_PROFILES};
static const MainMenuOptionInfo status_option = {
.base_name = "Status", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_STATUS};
static const MainMenuOptionInfo licenses_option = {
.base_name = "Licenses", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_LICENSES};
static const MainMenuOptionInfo extra_settings_option = {
.base_name = "Extra Settings", .false_name = "",
.active_fullscreen = OPTION_EXTRA, .active_windowed_screen = OPTION_EXTRA,
.active_joint_screen = OPTION_EXTRA, .active_top_screen = OPTION_EXTRA, .active_bottom_screen = OPTION_EXTRA,
.out_action = MAIN_MENU_EXTRA_SETTINGS};
static const MainMenuOptionInfo top_rotation_option = {
.base_name = "Top Screen Rot.", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_TOP_ROTATION};
static const MainMenuOptionInfo bottom_rotation_option = {
.base_name = "Bottom Screen Rot.", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_BOTTOM_ROTATION};
static const MainMenuOptionInfo top_one_rotation_option = {
.base_name = "Screen Rotation", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = false, .active_top_screen = true, .active_bottom_screen = false,
.out_action = MAIN_MENU_TOP_ROTATION};
static const MainMenuOptionInfo bottom_one_rotation_option = {
.base_name = "Screen Rotation", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = false, .active_top_screen = false, .active_bottom_screen = true,
.out_action = MAIN_MENU_BOTTOM_ROTATION};
static const MainMenuOptionInfo* pollable_options[] = {
&connect_option,
&windowed_option,
&fullscreen_option,
&join_screens_option,
&split_screens_option,
&crop_option,
&top_par_option,
&bot_par_option,
&one_par_option,
&vsync_option,
&async_option,
&blur_option,
&bottom_screen_pos_option,
&small_screen_offset_option,
&subscreen_distance_option,
&canvas_x_pos_option,
&canvas_y_pos_option,
&top_rotation_option,
&bottom_rotation_option,
&top_one_rotation_option,
&bottom_one_rotation_option,
&window_scaling_option,
&fullscreen_scaling_option,
&menu_scaling_option,
&resolution_settings_option,
&padding_option,
&bfi_settings_option,
&audio_settings_option,
&save_profiles_option,
&load_profiles_option,
&extra_settings_option,
&status_option,
&licenses_option,
&close_option,
&quit_option
};
@ -124,6 +293,7 @@ void MainMenu::class_setup() {
this->base_height_factor_menu = 12;
this->base_height_divisor_menu = 6;
this->min_text_size = 0.3;
this->max_width_slack = 1.1;
}
void MainMenu::insert_data(ScreenType s_type, bool is_fullscreen) {
@ -170,6 +340,22 @@ static std::string setTextOptionBool(int option_index, bool value) {
return pollable_options[option_index]->false_name;
}
static std::string setTextOptionFloat(int option_index, float value) {
return pollable_options[option_index]->base_name + ": " + get_float_str_decimals(value, 1);
}
static std::string setTextOptionInt(int option_index, int value) {
return pollable_options[option_index]->base_name + ": " + std::to_string(value);
}
static std::string setTextOptionDualPercentage(int option_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);
return pollable_options[option_index]->base_name + ": " + std::to_string(value_1) + " - " + std::to_string(value_2);
}
void MainMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, ScreenInfo *info, bool connected) {
int num_pages = 1 + ((this->get_num_options() - 1) / this->num_elements_per_screen);
if(this->future_data.page >= num_pages)
@ -195,6 +381,21 @@ void MainMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size
case MAIN_MENU_PADDING:
this->labels[i]->setText(setTextOptionBool(option_index, info->rounded_corners_fix));
break;
case MAIN_MENU_WINDOW_SCALING:
this->labels[i]->setText(setTextOptionFloat(option_index, info->scaling));
break;
case MAIN_MENU_MENU_SCALING:
this->labels[i]->setText(setTextOptionFloat(option_index, info->menu_scaling_factor));
break;
case MAIN_MENU_FULLSCREEN_SCALING:
this->labels[i]->setText(setTextOptionDualPercentage(option_index, info->top_scaling, info->bot_scaling));
break;
case MAIN_MENU_TOP_ROTATION:
this->labels[i]->setText(setTextOptionInt(option_index, info->top_rotation));
break;
case MAIN_MENU_BOTTOM_ROTATION:
this->labels[i]->setText(setTextOptionInt(option_index, info->bot_rotation));
break;
default:
break;
}

View File

@ -51,6 +51,7 @@ void OptionSelectionMenu::class_setup() {
this->base_height_factor_menu = 1;
this->base_height_divisor_menu = 1;
this->min_text_size = 0.3;
this->max_width_slack = 1.1;
}
bool OptionSelectionMenu::can_execute_action() {
@ -357,7 +358,10 @@ void OptionSelectionMenu::base_prepare(float menu_scaling_factor, int view_size_
const float base_height = (this->num_vertical_slices * BASE_PIXEL_FONT_HEIGHT * 10) / 9;
int max_width = (view_size_x * 9) / 10;
int max_height = (view_size_y * 9) / 10;
float max_width_corresponding_height = (max_width * this->width_divisor_menu * this->max_width_slack) / this->width_factor_menu;
float max_scaling_factor = max_height / base_height;
if(max_width_corresponding_height < max_height)
max_scaling_factor = max_width_corresponding_height / base_height;
float final_menu_scaling_factor = (menu_scaling_factor * this->base_height_factor_menu) / this->base_height_divisor_menu;
if(menu_scaling_factor > max_scaling_factor)
menu_scaling_factor = max_scaling_factor;

View File

@ -8,21 +8,9 @@
#define TOP_ROUNDED_PADDING 0
#define BOTTOM_ROUNDED_PADDING 5
static int top_screen_crop_widths[] = {TOP_WIDTH_3DS, TOP_SPECIAL_DS_WIDTH_3DS, TOP_SCALED_DS_WIDTH_3DS, WIDTH_DS, WIDTH_SCALED_GBA, WIDTH_GBA, WIDTH_SCALED_GB, WIDTH_GB, WIDTH_SCALED_SNES, WIDTH_SNES, WIDTH_NES};
static int top_screen_crop_heights[] = {HEIGHT_3DS, HEIGHT_3DS, HEIGHT_3DS, HEIGHT_DS, HEIGHT_SCALED_GBA, HEIGHT_GBA, HEIGHT_SCALED_GB, HEIGHT_GB, HEIGHT_SCALED_SNES, HEIGHT_SNES, HEIGHT_NES};
static int bot_screen_crop_widths[] = {BOT_WIDTH_3DS, BOT_WIDTH_3DS, BOT_WIDTH_3DS, WIDTH_DS, 0, 0, 0, 0, 0, 0, 0};
static int bot_screen_crop_heights[] = {HEIGHT_3DS, HEIGHT_3DS, HEIGHT_3DS, HEIGHT_DS, 0, 0, 0, 0, 0, 0, 0};
static int top_screen_crop_x[] = {0, (TOP_WIDTH_3DS - TOP_SPECIAL_DS_WIDTH_3DS) / 2, (TOP_WIDTH_3DS - TOP_SCALED_DS_WIDTH_3DS) / 2, (TOP_WIDTH_3DS - WIDTH_DS) / 2,
(TOP_WIDTH_3DS - WIDTH_SCALED_GBA) / 2, (TOP_WIDTH_3DS - WIDTH_GBA) / 2, (TOP_WIDTH_3DS - WIDTH_SCALED_GB) / 2, (TOP_WIDTH_3DS - WIDTH_GB) / 2,
(TOP_WIDTH_3DS - WIDTH_SCALED_SNES) / 2, (TOP_WIDTH_3DS - WIDTH_SNES) / 2, (TOP_WIDTH_3DS - WIDTH_NES) / 2};
static int top_screen_crop_y[] = {0, 0, 0, 0, (HEIGHT_3DS - HEIGHT_SCALED_GBA) / 2, (HEIGHT_3DS - HEIGHT_GBA) / 2, (HEIGHT_3DS - HEIGHT_SCALED_GB) / 2, (HEIGHT_3DS - HEIGHT_GB) / 2, (HEIGHT_3DS - HEIGHT_SCALED_SNES) / 2, (HEIGHT_3DS - HEIGHT_SNES) / 2, (HEIGHT_3DS - HEIGHT_NES) / 2};
static int bot_screen_crop_x[] = {0, 0, 0, (BOT_WIDTH_3DS - WIDTH_DS) / 2, 0, 0, 0, 0, 0, 0, 0};
static int bot_screen_crop_y[] = {0, 0, 0, HEIGHT_3DS - HEIGHT_DS, 0, 0, 0, 0, 0, 0, 0};
static std::string crop_names[] = {"3DS", "16:10", "Scaled DS", "Native DS", "Scaled GBA", "Native GBA", "Scaled VC GB", "VC GB", "Scaled SNES", "VC SNES", "VC NES"};
static std::string par_width_names[] = {"1:1", "SNES Horizontal", "SNES Vertical"};
WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, DisplayData* display_data, AudioData* audio_data, std::mutex* events_access) {
insert_basic_crops(this->possible_crops);
insert_basic_pars(this->possible_pars);
this->m_stype = stype;
this->events_access = events_access;
this->m_prepare_save = 0;
@ -317,20 +305,17 @@ bool WindowScreen::no_menu_poll(SFEvent &event_data) {
bool WindowScreen::main_poll(SFEvent &event_data) {
bool consumed = true;
bool done = false;
switch(event_data.type) {
case sf::Event::TextEntered:
switch(event_data.unicode) {
case 'c':
if(this->m_stype == ScreenType::BOTTOM) {
if(this->m_info.crop_kind == Crop::DEFAULT_3DS)
this->m_info.crop_kind = Crop::NATIVE_DS;
else
this->m_info.crop_kind = Crop::DEFAULT_3DS;
while(!done) {
this->m_info.crop_kind = (this->m_info.crop_kind + 1) % this->possible_crops.size();
if(is_allowed_crop(this->possible_crops[this->m_info.crop_kind], this->m_stype))
done = true;
}
else {
this->m_info.crop_kind = static_cast<Crop>((this->m_info.crop_kind + 1) % Crop::CROP_END);
}
this->print_notification("Crop: " + crop_names[this->m_info.crop_kind]);
this->print_notification("Crop: " + this->possible_crops[this->m_info.crop_kind]->name);
this->prepare_size_ratios(false, false);
this->future_operations.call_crop = true;
@ -435,20 +420,20 @@ bool WindowScreen::main_poll(SFEvent &event_data) {
case '2':
if(this->m_stype == ScreenType::BOTTOM)
break;
this->m_info.top_par = static_cast<ParCorrection>((this->m_info.top_par + 1) % (ParCorrection::PAR_END));
this->m_info.top_par = (this->m_info.top_par + 1) % this->possible_pars.size();
this->prepare_size_ratios(false, false);
this->future_operations.call_screen_settings_update = true;
this->print_notification("Top PAR: " + par_width_names[this->m_info.top_par]);
this->print_notification("Top PAR: " + this->possible_pars[this->m_info.top_par]->name);
break;
case '3':
if(this->m_stype == ScreenType::TOP)
break;
this->m_info.bot_par = static_cast<ParCorrection>((this->m_info.bot_par + 1) % (ParCorrection::PAR_END));
this->m_info.bot_par = (this->m_info.bot_par + 1) % this->possible_pars.size();
this->prepare_size_ratios(false, false);
this->future_operations.call_screen_settings_update = true;
this->print_notification("Bottom PAR: " + par_width_names[this->m_info.bot_par]);
this->print_notification("Bottom PAR: " + this->possible_pars[this->m_info.bot_par]->name);
break;
@ -1105,7 +1090,7 @@ void WindowScreen::set_position_screens(sf::Vector2f &curr_top_screen_size, sf::
this->m_height = bot_end_y;
}
int WindowScreen::prepare_screen_ratio(sf::Vector2f &screen_size, int own_rotation, int width_limit, int height_limit, int other_rotation, ParCorrection own_par) {
int WindowScreen::prepare_screen_ratio(sf::Vector2f &screen_size, int own_rotation, int width_limit, int height_limit, int other_rotation, const PARData* own_par) {
float own_width = screen_size.x;
float own_height = screen_size.y;
if((own_width < 1.0) || (own_height < 1.0))
@ -1139,7 +1124,7 @@ int WindowScreen::prepare_screen_ratio(sf::Vector2f &screen_size, int own_rotati
return height_ratio;
}
void WindowScreen::calc_scaling_resize_screens(sf::Vector2f &own_screen_size, sf::Vector2f &other_screen_size, int &own_scaling, int &other_scaling, int own_rotation, int other_rotation, bool increase, bool mantain, bool set_to_zero, ParCorrection own_par, ParCorrection other_par) {
void WindowScreen::calc_scaling_resize_screens(sf::Vector2f &own_screen_size, sf::Vector2f &other_screen_size, int &own_scaling, int &other_scaling, int own_rotation, int other_rotation, bool increase, bool mantain, bool set_to_zero, const PARData* own_par, const PARData* other_par) {
int min_other_width = other_screen_size.x;
int min_other_height = other_screen_size.y;
get_par_size(min_other_width, min_other_height, 1, other_par);
@ -1189,9 +1174,9 @@ void WindowScreen::prepare_size_ratios(bool top_increase, bool bot_increase) {
}
bool prioritize_top = (!bot_increase) && (top_increase || (this->m_info.bottom_pos == UNDER_TOP) || (this->m_info.bottom_pos == RIGHT_TOP));
if(prioritize_top)
calc_scaling_resize_screens(top_screen_size, bot_screen_size, this->m_info.top_scaling, this->m_info.bot_scaling, this->m_info.top_rotation, this->m_info.bot_rotation, top_increase, try_mantain_ratio, this->m_stype == ScreenType::BOTTOM, this->m_info.top_par, this->m_info.bot_par);
calc_scaling_resize_screens(top_screen_size, bot_screen_size, this->m_info.top_scaling, this->m_info.bot_scaling, this->m_info.top_rotation, this->m_info.bot_rotation, top_increase, try_mantain_ratio, this->m_stype == ScreenType::BOTTOM, this->possible_pars[this->m_info.top_par], this->possible_pars[this->m_info.bot_par]);
else
calc_scaling_resize_screens(bot_screen_size, top_screen_size, this->m_info.bot_scaling, this->m_info.top_scaling, this->m_info.bot_rotation, this->m_info.top_rotation, bot_increase, try_mantain_ratio, this->m_stype == ScreenType::TOP, this->m_info.bot_par, this->m_info.top_par);
calc_scaling_resize_screens(bot_screen_size, top_screen_size, this->m_info.bot_scaling, this->m_info.top_scaling, this->m_info.bot_rotation, this->m_info.top_rotation, bot_increase, try_mantain_ratio, this->m_stype == ScreenType::TOP, this->possible_pars[this->m_info.bot_par], this->possible_pars[this->m_info.top_par]);
}
int WindowScreen::get_fullscreen_offset_x(int top_width, int top_height, int bot_width, int bot_height) {
@ -1260,8 +1245,8 @@ void WindowScreen::resize_window_and_out_rects(bool do_work) {
top_scaling = this->loaded_info.top_scaling;
bot_scaling = this->loaded_info.bot_scaling;
}
get_par_size(top_width, top_height, top_scaling, this->loaded_info.top_par);
get_par_size(bot_width, bot_height, bot_scaling, this->loaded_info.bot_par);
get_par_size(top_width, top_height, top_scaling, this->possible_pars[this->loaded_info.top_par]);
get_par_size(bot_width, bot_height, bot_scaling, this->possible_pars[this->loaded_info.bot_par]);
if((!this->loaded_info.is_fullscreen) && this->loaded_info.rounded_corners_fix) {
offset_y = TOP_ROUNDED_PADDING;
@ -1328,29 +1313,31 @@ void WindowScreen::rotate() {
this->loaded_operations.call_screen_settings_update = true;
}
sf::Vector2f WindowScreen::getShownScreenSize(bool is_top, Crop &crop_kind) {
if(crop_kind >= Crop::CROP_END)
crop_kind = Crop::DEFAULT_3DS;
const int* widths = top_screen_crop_widths;
const int* heights = top_screen_crop_heights;
sf::Vector2f WindowScreen::getShownScreenSize(bool is_top, int &crop_kind) {
if(crop_kind >= this->possible_crops.size())
crop_kind = 0;
if(!is_allowed_crop(this->possible_crops[crop_kind], this->m_stype))
crop_kind = 0;
int width = this->possible_crops[crop_kind]->top_width;
int height = this->possible_crops[crop_kind]->top_height;
if(!is_top) {
widths = bot_screen_crop_widths;
heights = bot_screen_crop_heights;
width = this->possible_crops[crop_kind]->bot_width;
height = this->possible_crops[crop_kind]->bot_height;
}
int crop_arr_index = crop_kind - Crop::DEFAULT_3DS;
return sf::Vector2f(widths[crop_arr_index], heights[crop_arr_index]);
return sf::Vector2f(width, height);
}
void WindowScreen::crop() {
if(this->loaded_info.crop_kind >= Crop::CROP_END)
this->loaded_info.crop_kind = Crop::DEFAULT_3DS;
int crop_arr_index = this->loaded_info.crop_kind - Crop::DEFAULT_3DS;
if(this->loaded_info.crop_kind >= this->possible_crops.size())
this->loaded_info.crop_kind = 0;
if(!is_allowed_crop(this->possible_crops[this->loaded_info.crop_kind], this->m_stype))
this->loaded_info.crop_kind = 0;
sf::Vector2f top_screen_size = getShownScreenSize(true, this->loaded_info.crop_kind);
sf::Vector2f bot_screen_size = getShownScreenSize(false, this->loaded_info.crop_kind);
this->resize_in_rect(this->m_in_rect_top, top_screen_crop_x[crop_arr_index], top_screen_crop_y[crop_arr_index], top_screen_size.x, top_screen_size.y);
this->resize_in_rect(this->m_in_rect_bot, TOP_WIDTH_3DS + bot_screen_crop_x[crop_arr_index], bot_screen_crop_y[crop_arr_index], bot_screen_size.x, bot_screen_size.y);
this->resize_in_rect(this->m_in_rect_top, this->possible_crops[this->loaded_info.crop_kind]->top_x, this->possible_crops[this->loaded_info.crop_kind]->top_y, top_screen_size.x, top_screen_size.y);
this->resize_in_rect(this->m_in_rect_bot, TOP_WIDTH_3DS + this->possible_crops[this->loaded_info.crop_kind]->bot_x, this->possible_crops[this->loaded_info.crop_kind]->bot_y, bot_screen_size.x, bot_screen_size.y);
this->loaded_operations.call_screen_settings_update = true;
}

View File

@ -86,11 +86,8 @@ static bool load(const std::string path, const std::string name, ScreenInfo &top
if (std::getline(kvp, value)) {
if(load_screen_info(key, value, "bot_", bottom_info)) {
if(bottom_info.crop_kind != Crop::NATIVE_DS)
bottom_info.crop_kind = Crop::DEFAULT_3DS;
if(load_screen_info(key, value, "bot_", bottom_info))
continue;
}
if(load_screen_info(key, value, "joint_", joint_info))
continue;
if(load_screen_info(key, value, "top_", top_info))

View File

@ -1,13 +1,154 @@
#include "frontend.hpp"
#include <iostream>
static float par_width_multiplier[] = {1.0, 8.0, 8.0};
static float par_width_divisor[] = {1.0, 7.0, 7.0};
static bool par_width_main[] = {true, true, false};
const CropData default_3ds_crop = {
.top_width = TOP_WIDTH_3DS, .top_height = HEIGHT_3DS,
.top_x = 0, .top_y = 0,
.bot_width = BOT_WIDTH_3DS, .bot_height = HEIGHT_3DS,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = true,
.name = "3DS"};
const CropData special_ds_crop = {
.top_width = TOP_SPECIAL_DS_WIDTH_3DS, .top_height = HEIGHT_3DS,
.top_x = (TOP_WIDTH_3DS - TOP_SPECIAL_DS_WIDTH_3DS) / 2, .top_y = 0,
.bot_width = BOT_WIDTH_3DS, .bot_height = HEIGHT_3DS,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "16:10"};
const CropData scaled_ds_crop = {
.top_width = TOP_SCALED_DS_WIDTH_3DS, .top_height = HEIGHT_3DS,
.top_x = (TOP_WIDTH_3DS - TOP_SCALED_DS_WIDTH_3DS) / 2, .top_y = 0,
.bot_width = BOT_WIDTH_3DS, .bot_height = HEIGHT_3DS,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "Scaled DS"};
const CropData native_ds_crop = {
.top_width = WIDTH_DS, .top_height = HEIGHT_DS,
.top_x = (TOP_WIDTH_3DS - WIDTH_DS) / 2, .top_y = 0,
.bot_width = WIDTH_DS, .bot_height = HEIGHT_DS,
.bot_x = (BOT_WIDTH_3DS - HEIGHT_DS) / 2, .bot_y = HEIGHT_3DS - HEIGHT_DS,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = true,
.name = "Native DS"};
const CropData scaled_gba_crop = {
.top_width = WIDTH_SCALED_GBA, .top_height = HEIGHT_SCALED_GBA,
.top_x = (TOP_WIDTH_3DS - WIDTH_SCALED_GBA) / 2, .top_y = (HEIGHT_3DS - HEIGHT_SCALED_GBA) / 2,
.bot_width = 0, .bot_height = 0,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "Scaled GBA"};
const CropData native_gba_crop = {
.top_width = WIDTH_GBA, .top_height = HEIGHT_GBA,
.top_x = (TOP_WIDTH_3DS - WIDTH_GBA) / 2, .top_y = (HEIGHT_3DS - HEIGHT_GBA) / 2,
.bot_width = 0, .bot_height = 0,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "Native GBA"};
const CropData scaled_vc_gb_crop = {
.top_width = WIDTH_SCALED_GB, .top_height = HEIGHT_SCALED_GB,
.top_x = (TOP_WIDTH_3DS - WIDTH_SCALED_GB) / 2, .top_y = (HEIGHT_3DS - HEIGHT_SCALED_GB) / 2,
.bot_width = 0, .bot_height = 0,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "Scaled VC GB"};
const CropData vc_gb_crop = {
.top_width = WIDTH_GB, .top_height = HEIGHT_GB,
.top_x = (TOP_WIDTH_3DS - WIDTH_GB) / 2, .top_y = (HEIGHT_3DS - HEIGHT_GB) / 2,
.bot_width = 0, .bot_height = 0,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "VC GB"};
const CropData scaled_snes_crop = {
.top_width = WIDTH_SCALED_SNES, .top_height = HEIGHT_SCALED_SNES,
.top_x = (TOP_WIDTH_3DS - WIDTH_SCALED_SNES) / 2, .top_y = (HEIGHT_3DS - HEIGHT_SCALED_SNES) / 2,
.bot_width = 0, .bot_height = 0,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "Scaled SNES"};
const CropData vc_snes_crop = {
.top_width = WIDTH_SNES, .top_height = HEIGHT_SNES,
.top_x = (TOP_WIDTH_3DS - WIDTH_SNES) / 2, .top_y = (HEIGHT_3DS - HEIGHT_SNES) / 2,
.bot_width = 0, .bot_height = 0,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "VC SNES"};
const CropData vc_nes_crop = {
.top_width = WIDTH_NES, .top_height = HEIGHT_NES,
.top_x = (TOP_WIDTH_3DS - WIDTH_NES) / 2, .top_y = (HEIGHT_3DS - HEIGHT_NES) / 2,
.bot_width = 0, .bot_height = 0,
.bot_x = 0, .bot_y = 0,
.allowed_joint = true, .allowed_top = true, .allowed_bottom = false,
.name = "VC NES"};
static const CropData* basic_possible_crops[] = {
&default_3ds_crop,
&special_ds_crop,
&scaled_ds_crop,
&native_ds_crop,
&scaled_gba_crop,
&native_gba_crop,
&scaled_vc_gb_crop,
&vc_gb_crop,
&scaled_snes_crop,
&vc_snes_crop,
&vc_nes_crop,
};
const PARData base_par = {
.width_multiplier = 1.0, .width_divisor = 1.0,
.is_width_main = true,
.name = "1:1"};
const PARData snes_horizontal_par = {
.width_multiplier = 8.0, .width_divisor = 7.0,
.is_width_main = true,
.name = "SNES Horizontal"};
const PARData snes_vertical_par = {
.width_multiplier = 8.0, .width_divisor = 7.0,
.is_width_main = false,
.name = "SNES Vertical"};
static const PARData* basic_possible_pars[] = {
&base_par,
&snes_horizontal_par,
&snes_vertical_par,
};
bool is_allowed_crop(const CropData* crop_data, ScreenType s_type) {
if(s_type == ScreenType::JOINT && crop_data->allowed_joint)
return true;
if(s_type == ScreenType::TOP && crop_data->allowed_top)
return true;
if(s_type == ScreenType::BOTTOM && crop_data->allowed_bottom)
return true;
return false;
}
void insert_basic_crops(std::vector<const CropData*> &crop_vector) {
for(int i = 0; i < (sizeof(basic_possible_crops) / sizeof(basic_possible_crops[0])); i++) {
crop_vector.push_back(basic_possible_crops[i]);
}
}
void insert_basic_pars(std::vector<const PARData*> &par_vector) {
for(int i = 0; i < (sizeof(basic_possible_pars) / sizeof(basic_possible_pars[0])); i++) {
par_vector.push_back(basic_possible_pars[i]);
}
}
void reset_screen_info(ScreenInfo &info) {
info.is_blurred = false;
info.crop_kind = DEFAULT_3DS;
info.crop_kind = 0;
info.scaling = 1.0;
info.is_fullscreen = false;
info.bottom_pos = UNDER_TOP;
@ -30,8 +171,8 @@ void reset_screen_info(ScreenInfo &info) {
info.bfi_divider = 2.0;
info.menu_scaling_factor = 1.0;
info.rounded_corners_fix = false;
info.top_par = ParCorrection::PAR_NORMAL;
info.bot_par = ParCorrection::PAR_NORMAL;
info.top_par = 0;
info.bot_par = 0;
}
bool load_screen_info(std::string key, std::string value, std::string base, ScreenInfo &info) {
@ -40,7 +181,7 @@ bool load_screen_info(std::string key, std::string value, std::string base, Scre
return true;
}
if(key == (base + "crop")) {
info.crop_kind = static_cast<Crop>(std::stoi(value) % Crop::CROP_END);
info.crop_kind = std::stoi(value);
return true;
}
if(key == (base + "scale")) {
@ -126,11 +267,11 @@ bool load_screen_info(std::string key, std::string value, std::string base, Scre
return true;
}
if(key == (base + "top_par")) {
info.top_par = static_cast<ParCorrection>(std::stoi(value) % ParCorrection::PAR_END);
info.top_par = std::stoi(value);
return true;
}
if(key == (base + "bot_par")) {
info.bot_par = static_cast<ParCorrection>(std::stoi(value) % ParCorrection::PAR_END);
info.bot_par = std::stoi(value);
return true;
}
return false;
@ -174,29 +315,23 @@ void joystick_axis_poll(std::queue<SFEvent> &events_queue) {
}
}
void get_par_size(int &width, int &height, float multiplier_factor, ParCorrection &correction_factor) {
if(correction_factor >= ParCorrection::PAR_END)
correction_factor = ParCorrection::PAR_NORMAL;
int par_corr_index = correction_factor - ParCorrection::PAR_NORMAL;
void get_par_size(int &width, int &height, float multiplier_factor, const PARData *correction_factor) {
width *= multiplier_factor;
height *= multiplier_factor;
if(par_width_main[par_corr_index])
width = (width * par_width_multiplier[par_corr_index]) / par_width_divisor[par_corr_index];
if(correction_factor->is_width_main)
width = (width * correction_factor->width_multiplier) / correction_factor->width_divisor;
else
height = (height * par_width_divisor[par_corr_index]) / par_width_multiplier[par_corr_index];
height = (height * correction_factor->width_divisor) / correction_factor->width_multiplier;
}
void get_par_size(float &width, float &height, float multiplier_factor, ParCorrection &correction_factor) {
if(correction_factor >= ParCorrection::PAR_END)
correction_factor = ParCorrection::PAR_NORMAL;
int par_corr_index = correction_factor - ParCorrection::PAR_NORMAL;
void get_par_size(float &width, float &height, float multiplier_factor, const PARData *correction_factor) {
width *= multiplier_factor;
height *= multiplier_factor;
if(par_width_main[par_corr_index]) {
width = (width * par_width_multiplier[par_corr_index]) / par_width_divisor[par_corr_index];
if(correction_factor->is_width_main) {
width = (width * correction_factor->width_multiplier) / correction_factor->width_divisor;
}
else
height = (height * par_width_divisor[par_corr_index]) / par_width_multiplier[par_corr_index];
height = (height * correction_factor->width_divisor) / correction_factor->width_multiplier;
}
JoystickDirection get_joystick_direction(uint32_t joystickId, sf::Joystick::Axis axis, float position) {