diff --git a/include/display_structs.hpp b/include/display_structs.hpp index 4e874f4..da197cc 100755 --- a/include/display_structs.hpp +++ b/include/display_structs.hpp @@ -6,7 +6,6 @@ enum ScreenType { TOP, BOTTOM, JOINT }; 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, VIDEO_MENU_TYPE, AUDIO_MENU_TYPE, CROP_MENU_TYPE, TOP_PAR_MENU_TYPE, BOTTOM_PAR_MENU_TYPE }; struct ScreenInfo { @@ -15,7 +14,7 @@ struct ScreenInfo { double scaling; bool is_fullscreen; BottomRelativePosition bottom_pos; - OffsetAlgorithm subscreen_offset_algorithm, subscreen_attached_offset_algorithm, total_offset_algorithm_x, total_offset_algorithm_y; + float subscreen_offset, subscreen_attached_offset, total_offset_x, total_offset_y; int top_rotation, bot_rotation; bool show_mouse; bool v_sync_enabled; diff --git a/include/frontend.hpp b/include/frontend.hpp index ea7dd2a..e6bcb70 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -131,6 +131,7 @@ private: void padding_change(); void crop_value_change(int new_crop_value); void par_value_change(int new_par_value, bool is_top); + void offset_change(float &value, float change); bool common_poll(SFEvent &event_data); bool main_poll(SFEvent &event_data); bool no_menu_poll(SFEvent &event_data); @@ -142,7 +143,6 @@ private: void window_bg_processing(); void display_data_to_window(bool actually_draw); 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, 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); diff --git a/source/TextRectangle.cpp b/source/TextRectangle.cpp index 6da21de..d0db9c3 100755 --- a/source/TextRectangle.cpp +++ b/source/TextRectangle.cpp @@ -251,7 +251,7 @@ void TextRectangle::updateText(int x_limit) { this->curr_color = sf::Color(160, 60, 60, 192); break; case TEXT_KIND_TITLE: - this->curr_color = sf::Color(30, 30, 60, 192); + this->curr_color = sf::Color(30, 30, 60, 0); break; default: break; diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index 002a0d0..a819e1c 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -162,6 +162,26 @@ void WindowScreen::par_value_change(int new_par_value, bool is_top) { } } +void WindowScreen::offset_change(float &value, float change) { + if(change >= 1.0) + return; + if(change <= -1.0) + return; + float absolute_change = std::abs(change); + if(absolute_change == 0.0) + return; + float close_slice = ((int)(value / absolute_change)) * absolute_change; + if((value - close_slice) > (absolute_change / 2.0)) + close_slice += absolute_change; + close_slice += change; + if(close_slice > 1.0) + close_slice = 0.0; + else if(close_slice < 0.0) + close_slice = 1.0; + value = close_slice; + this->future_operations.call_screen_settings_update = true; +} + bool WindowScreen::common_poll(SFEvent &event_data) { double old_scaling = 0.0; bool consumed = true; @@ -408,23 +428,19 @@ bool WindowScreen::main_poll(SFEvent &event_data) { break; case '6': - this->m_info.subscreen_offset_algorithm = static_cast((this->m_info.subscreen_offset_algorithm + 1) % (OffsetAlgorithm::OFF_ALGO_END)); - this->future_operations.call_screen_settings_update = true; + this->offset_change(this->m_info.subscreen_offset, 0.5); break; case '7': - this->m_info.subscreen_attached_offset_algorithm = static_cast((this->m_info.subscreen_attached_offset_algorithm + 1) % (OffsetAlgorithm::OFF_ALGO_END)); - this->future_operations.call_screen_settings_update = true; + this->offset_change(this->m_info.subscreen_attached_offset, 0.5); break; case '4': - this->m_info.total_offset_algorithm_x = static_cast((this->m_info.total_offset_algorithm_x + 1) % (OffsetAlgorithm::OFF_ALGO_END)); - this->future_operations.call_screen_settings_update = true; + this->offset_change(this->m_info.total_offset_x, 0.5); break; case '5': - this->m_info.total_offset_algorithm_y = static_cast((this->m_info.total_offset_algorithm_y + 1) % (OffsetAlgorithm::OFF_ALGO_END)); - this->future_operations.call_screen_settings_update = true; + this->offset_change(this->m_info.total_offset_y, 0.5); break; case 'y': @@ -1147,19 +1163,6 @@ void WindowScreen::window_render_call() { } } -int WindowScreen::apply_offset_algo(int offset_contribute, OffsetAlgorithm chosen_algo) { - switch(chosen_algo) { - case NO_DISTANCE: - return 0; - case HALF_DISTANCE: - return offset_contribute / 2; - case MAX_DISTANCE: - return offset_contribute; - default: - return 0; - } -} - void WindowScreen::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) { int top_screen_x = 0, top_screen_y = 0; int bot_screen_x = 0, bot_screen_y = 0; @@ -1192,32 +1195,32 @@ void WindowScreen::set_position_screens(sf::Vector2f &curr_top_screen_size, sf:: if(this->m_stype == ScreenType::JOINT) { switch(this->loaded_info.bottom_pos) { case UNDER_TOP: - bot_screen_x = apply_offset_algo(greatest_width - bot_screen_width, this->loaded_info.subscreen_offset_algorithm); - top_screen_x = apply_offset_algo(greatest_width - top_screen_width, this->loaded_info.subscreen_offset_algorithm); + bot_screen_x = (greatest_width - bot_screen_width) * this->loaded_info.subscreen_offset; + top_screen_x = (greatest_width - top_screen_width) * this->loaded_info.subscreen_offset; bot_screen_y = top_screen_height; if(max_y > 0) - bot_screen_y += apply_offset_algo(max_y - bot_screen_height - top_screen_height - offset_y, this->loaded_info.subscreen_attached_offset_algorithm); + bot_screen_y += (max_y - bot_screen_height - top_screen_height - offset_y) * this->loaded_info.subscreen_attached_offset; break; case RIGHT_TOP: - bot_screen_y = apply_offset_algo(greatest_height - bot_screen_height, this->loaded_info.subscreen_offset_algorithm); - top_screen_y = apply_offset_algo(greatest_height - top_screen_height, this->loaded_info.subscreen_offset_algorithm); + bot_screen_y = (greatest_height - bot_screen_height) * this->loaded_info.subscreen_offset; + top_screen_y = (greatest_height - top_screen_height) * this->loaded_info.subscreen_offset; bot_screen_x = top_screen_width; if(max_x > 0) - bot_screen_x += apply_offset_algo(max_x - bot_screen_width - top_screen_width - offset_x, this->loaded_info.subscreen_attached_offset_algorithm); + bot_screen_x += (max_x - bot_screen_width - top_screen_width - offset_x) * this->loaded_info.subscreen_attached_offset; break; case ABOVE_TOP: - bot_screen_x = apply_offset_algo(greatest_width - bot_screen_width, this->loaded_info.subscreen_offset_algorithm); - top_screen_x = apply_offset_algo(greatest_width - top_screen_width, this->loaded_info.subscreen_offset_algorithm); + bot_screen_x = (greatest_width - bot_screen_width) * this->loaded_info.subscreen_offset; + top_screen_x = (greatest_width - top_screen_width) * this->loaded_info.subscreen_offset; top_screen_y = bot_screen_height; if(max_y > 0) - top_screen_y += apply_offset_algo(max_y - bot_screen_height - top_screen_height - offset_y, this->loaded_info.subscreen_attached_offset_algorithm); + top_screen_y += (max_y - bot_screen_height - top_screen_height - offset_y) * this->loaded_info.subscreen_attached_offset; break; case LEFT_TOP: - bot_screen_y = apply_offset_algo(greatest_height - bot_screen_height, this->loaded_info.subscreen_offset_algorithm); - top_screen_y = apply_offset_algo(greatest_height - top_screen_height, this->loaded_info.subscreen_offset_algorithm); + bot_screen_y = (greatest_height - bot_screen_height) * this->loaded_info.subscreen_offset; + top_screen_y = (greatest_height - top_screen_height) * this->loaded_info.subscreen_offset; top_screen_x = bot_screen_width; if(max_x > 0) - top_screen_x += apply_offset_algo(max_x - bot_screen_width - top_screen_width - offset_x, this->loaded_info.subscreen_attached_offset_algorithm); + top_screen_x += (max_x - bot_screen_width - top_screen_width - offset_x) * this->loaded_info.subscreen_attached_offset; break; default: break; @@ -1350,7 +1353,7 @@ int WindowScreen::get_fullscreen_offset_x(int top_width, int top_height, int bot default: return 0; } - return apply_offset_algo(curr_desk_mode.width - offset_contribute, this->loaded_info.total_offset_algorithm_x); + return (curr_desk_mode.width - offset_contribute) * this->loaded_info.total_offset_x; } int WindowScreen::get_fullscreen_offset_y(int top_width, int top_height, int bot_width, int bot_height) { @@ -1374,7 +1377,7 @@ int WindowScreen::get_fullscreen_offset_y(int top_width, int top_height, int bot default: return 0; } - return apply_offset_algo(curr_desk_mode.height - offset_contribute, this->loaded_info.total_offset_algorithm_y); + return (curr_desk_mode.height - offset_contribute) * this->loaded_info.total_offset_y; } void WindowScreen::resize_window_and_out_rects(bool do_work) { diff --git a/source/frontend.cpp b/source/frontend.cpp index 6c005f8..704004b 100755 --- a/source/frontend.cpp +++ b/source/frontend.cpp @@ -153,10 +153,10 @@ void reset_screen_info(ScreenInfo &info) { info.scaling = 1.0; info.is_fullscreen = false; info.bottom_pos = UNDER_TOP; - info.subscreen_offset_algorithm = HALF_DISTANCE; - info.subscreen_attached_offset_algorithm = NO_DISTANCE; - info.total_offset_algorithm_x = HALF_DISTANCE; - info.total_offset_algorithm_y = HALF_DISTANCE; + info.subscreen_offset = 0.5; + info.subscreen_attached_offset = 0.0; + info.total_offset_x = 0.5; + info.total_offset_y = 0.5; info.top_rotation = 0; info.bot_rotation = 0; info.show_mouse = true; @@ -176,6 +176,14 @@ void reset_screen_info(ScreenInfo &info) { info.bot_par = 0; } +static float offset_sanitization(float value) { + if(value <= 0.0) + return 0.0; + if(value >= 1.0) + return 1.0; + return value; +} + bool load_screen_info(std::string key, std::string value, std::string base, ScreenInfo &info) { if(key == (base + "blur")) { info.is_blurred = std::stoi(value); @@ -201,20 +209,20 @@ bool load_screen_info(std::string key, std::string value, std::string base, Scre info.bottom_pos = static_cast(std::stoi(value) % BottomRelativePosition::BOT_REL_POS_END); return true; } - if(key == (base + "sub_off_algo")) { - info.subscreen_offset_algorithm = static_cast(std::stoi(value) % OffsetAlgorithm::OFF_ALGO_END); + if(key == (base + "sub_off")) { + info.subscreen_offset = offset_sanitization(std::stod(value)); return true; } - if(key == (base + "sub_att_off_algo")) { - info.subscreen_attached_offset_algorithm = static_cast(std::stoi(value) % OffsetAlgorithm::OFF_ALGO_END); + if(key == (base + "sub_att_off")) { + info.subscreen_attached_offset = offset_sanitization(std::stod(value)); return true; } - if(key == (base + "off_algo_x")) { - info.total_offset_algorithm_x = static_cast(std::stoi(value) % OffsetAlgorithm::OFF_ALGO_END); + if(key == (base + "off_x")) { + info.total_offset_x = offset_sanitization(std::stod(value)); return true; } - if(key == (base + "off_algo_y")) { - info.total_offset_algorithm_y = static_cast(std::stoi(value) % OffsetAlgorithm::OFF_ALGO_END); + if(key == (base + "off_y")) { + info.total_offset_y = offset_sanitization(std::stod(value)); return true; } if(key == (base + "top_rot")) { @@ -285,10 +293,10 @@ std::string save_screen_info(std::string base, const ScreenInfo &info) { out += base + "scale=" + std::to_string(info.scaling) + "\n"; out += base + "fullscreen=" + std::to_string(info.is_fullscreen) + "\n"; out += base + "bot_pos=" + std::to_string(info.bottom_pos) + "\n"; - out += base + "sub_off_algo=" + std::to_string(info.subscreen_offset_algorithm) + "\n"; - out += base + "sub_att_off_algo=" + std::to_string(info.subscreen_attached_offset_algorithm) + "\n"; - out += base + "off_algo_x=" + std::to_string(info.total_offset_algorithm_x) + "\n"; - out += base + "off_algo_y=" + std::to_string(info.total_offset_algorithm_y) + "\n"; + out += base + "sub_off=" + std::to_string(info.subscreen_offset) + "\n"; + out += base + "sub_att_off=" + std::to_string(info.subscreen_attached_offset) + "\n"; + out += base + "off_x=" + std::to_string(info.total_offset_x) + "\n"; + out += base + "off_y=" + std::to_string(info.total_offset_y) + "\n"; out += base + "top_rot=" + std::to_string(info.top_rotation) + "\n"; out += base + "bot_rot=" + std::to_string(info.bot_rotation) + "\n"; out += base + "vsync=" + std::to_string(info.v_sync_enabled) + "\n";