From cb22c73dd62e6c6ae8b47518504e6ca54f7ae6d0 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Mon, 13 May 2024 01:55:52 +0200 Subject: [PATCH] Make crop checks happen only once --- include/frontend.hpp | 2 +- source/WindowScreen.cpp | 14 +++----------- source/frontend.cpp | 5 +++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/frontend.hpp b/include/frontend.hpp index 8521343..f3e8fcc 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -164,7 +164,7 @@ struct FrontendData { }; bool is_allowed_crop(const CropData* crop_data, ScreenType s_type); -void insert_basic_crops(std::vector &crop_vector); +void insert_basic_crops(std::vector &crop_vector, ScreenType s_type); void insert_basic_pars(std::vector &par_vector); void reset_screen_info(ScreenInfo &info); bool load_screen_info(std::string key, std::string value, std::string base, ScreenInfo &info); diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index 2434e38..4b3d07a 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -9,9 +9,9 @@ #define BOTTOM_ROUNDED_PADDING 5 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; + insert_basic_crops(this->possible_crops, this->m_stype); + insert_basic_pars(this->possible_pars); this->events_access = events_access; this->m_prepare_save = 0; this->m_prepare_load = 0; @@ -310,11 +310,7 @@ bool WindowScreen::main_poll(SFEvent &event_data) { case sf::Event::TextEntered: switch(event_data.unicode) { case 'c': - 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; - } + this->m_info.crop_kind = (this->m_info.crop_kind + 1) % this->possible_crops.size(); 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; @@ -1316,8 +1312,6 @@ void WindowScreen::rotate() { 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) { @@ -1330,8 +1324,6 @@ sf::Vector2f WindowScreen::getShownScreenSize(bool is_top, int &crop_kind) { void WindowScreen::crop() { 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); diff --git a/source/frontend.cpp b/source/frontend.cpp index d6d09f2..e3a9a63 100755 --- a/source/frontend.cpp +++ b/source/frontend.cpp @@ -134,9 +134,10 @@ bool is_allowed_crop(const CropData* crop_data, ScreenType s_type) { return false; } -void insert_basic_crops(std::vector &crop_vector) { +void insert_basic_crops(std::vector &crop_vector, ScreenType s_type) { for(int i = 0; i < (sizeof(basic_possible_crops) / sizeof(basic_possible_crops[0])); i++) { - crop_vector.push_back(basic_possible_crops[i]); + if(is_allowed_crop(basic_possible_crops[i], s_type)) + crop_vector.push_back(basic_possible_crops[i]); } }