diff --git a/CMakeLists.txt b/CMakeLists.txt index c240250..03aac61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/ConnectionMenu.cpp source/OptionSelectionMenu.cpp source/MainMenu.cpp source/VideoMenu.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/ConnectionMenu.cpp source/OptionSelectionMenu.cpp source/MainMenu.cpp source/VideoMenu.cpp source/CropMenu.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}) diff --git a/include/CropMenu.hpp b/include/CropMenu.hpp new file mode 100755 index 0000000..a5126ff --- /dev/null +++ b/include/CropMenu.hpp @@ -0,0 +1,30 @@ +#ifndef __CROPMENU_HPP +#define __CROPMENU_HPP + +#include "OptionSelectionMenu.hpp" +#include + +#include "TextRectangle.hpp" +#include "sfml_gfx_structs.hpp" +#include "display_structs.hpp" + +#define CROP_MENU_NO_ACTION -1 +#define CROP_MENU_BACK -2 + +class CropMenu : public OptionSelectionMenu { +public: + CropMenu(bool font_load_success, sf::Font &text_font); + ~CropMenu(); + void prepare(float scaling_factor, int view_size_x, int view_size_y, int current_crop); + void insert_data(std::vector* possible_crops); + int selected_index = CROP_MENU_NO_ACTION; +protected: + void reset_output_option(); + void set_output_option(int index); + int get_num_options(); + std::string get_string_option(int index); + void class_setup(); +private: + std::vector* possible_crops; +}; +#endif diff --git a/include/display_structs.hpp b/include/display_structs.hpp index 05effe0..15c86f9 100755 --- a/include/display_structs.hpp +++ b/include/display_structs.hpp @@ -7,7 +7,7 @@ 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 }; +enum CurrMenuType { DEFAULT_MENU_TYPE, CONNECT_MENU_TYPE, MAIN_MENU_TYPE, VIDEO_MENU_TYPE, AUDIO_MENU_TYPE, CROP_MENU_TYPE }; struct ScreenInfo { bool is_blurred; diff --git a/include/frontend.hpp b/include/frontend.hpp index 9615753..0f1c280 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -15,6 +15,7 @@ #include "ConnectionMenu.hpp" #include "MainMenu.hpp" #include "VideoMenu.hpp" +#include "CropMenu.hpp" #include "display_structs.hpp" class WindowScreen { @@ -80,6 +81,7 @@ private: ConnectionMenu *connection_menu; MainMenu *main_menu; VideoMenu *video_menu; + CropMenu *crop_menu; std::vector possible_crops; std::vector possible_pars; @@ -125,6 +127,7 @@ private: void blur_change(); void poll_window(); void padding_change(); + void crop_value_change(int new_crop_value); bool common_poll(SFEvent &event_data); bool main_poll(SFEvent &event_data); bool no_menu_poll(SFEvent &event_data); @@ -155,6 +158,7 @@ private: void setWinSize(bool is_main_thread); void setup_main_menu(); void setup_video_menu(); + void setup_crop_menu(); void update_connection(); }; diff --git a/source/CropMenu.cpp b/source/CropMenu.cpp new file mode 100755 index 0000000..9186deb --- /dev/null +++ b/source/CropMenu.cpp @@ -0,0 +1,66 @@ +#include "CropMenu.hpp" + +CropMenu::CropMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){ + this->initialize(font_load_success, text_font); +} + +CropMenu::~CropMenu() { +} + +void CropMenu::class_setup() { + this->num_elements_per_screen = 5; + this->min_elements_text_scaling_factor = num_elements_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 = "Crop Settings"; + this->show_back_x = true; + this->show_x = false; + this->show_title = true; +} + +void CropMenu::insert_data(std::vector* possible_crops) { + this->possible_crops = possible_crops; + this->prepare_options(); +} + +void CropMenu::reset_output_option() { + this->selected_index = CROP_MENU_NO_ACTION; +} + +void CropMenu::set_output_option(int index) { + if(index == -1) + this->selected_index = CROP_MENU_BACK; + else + this->selected_index = index; +} + +int CropMenu::get_num_options() { + return (*this->possible_crops).size(); +} + +std::string CropMenu::get_string_option(int index) { + return (*this->possible_crops)[index]->name; +} + +void CropMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, int current_crop) { + 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_elements_per_screen; + for(int i = 0; i < this->num_elements_per_screen; i++) { + int index = i + this->elements_start_id; + if(!this->future_enabled_labels[index]) + continue; + int crop_index = start + i; + if(crop_index == current_crop) + this->labels[index]->setText("<" + (*this->possible_crops)[crop_index]->name + ">"); + else + this->labels[index]->setText((*this->possible_crops)[crop_index]->name); + } + this->base_prepare(menu_scaling_factor, view_size_x, view_size_y); +} diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index c7a8f98..a6feca0 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -23,6 +23,7 @@ WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, Disp this->connection_menu = new ConnectionMenu(this->font_load_success, this->text_font); this->main_menu = new MainMenu(this->font_load_success, this->text_font); this->video_menu = new VideoMenu(this->font_load_success, this->text_font); + this->crop_menu = new CropMenu(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); @@ -51,6 +52,7 @@ WindowScreen::~WindowScreen() { delete this->connection_menu; delete this->main_menu; delete this->video_menu; + delete this->crop_menu; } void WindowScreen::build() { @@ -122,6 +124,13 @@ void WindowScreen::padding_change() { this->print_notification_on_off("Extra Padding", this->m_info.rounded_corners_fix); } +void WindowScreen::crop_value_change(int new_crop_value) { + this->m_info.crop_kind = new_crop_value % 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; +} + bool WindowScreen::common_poll(SFEvent &event_data) { double old_scaling = 0.0; bool consumed = true; @@ -262,6 +271,14 @@ void WindowScreen::setup_video_menu() { } } +void WindowScreen::setup_crop_menu() { + if(this->curr_menu != CROP_MENU_TYPE) { + this->curr_menu = CROP_MENU_TYPE; + this->crop_menu->reset_data(); + this->crop_menu->insert_data(&this->possible_crops); + } +} + bool WindowScreen::no_menu_poll(SFEvent &event_data) { bool consumed = true; switch(event_data.type) { @@ -320,11 +337,7 @@ bool WindowScreen::main_poll(SFEvent &event_data) { case sf::Event::TextEntered: switch(event_data.unicode) { case 'c': - 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; - + this->crop_value_change(this->m_info.crop_kind + 1); break; case 'b': @@ -553,20 +566,16 @@ void WindowScreen::poll() { case MAIN_MENU_CLOSE_MENU: this->curr_menu = DEFAULT_MENU_TYPE; return; - break; case MAIN_MENU_QUIT_APPLICATION: this->m_prepare_quit = true; this->curr_menu = DEFAULT_MENU_TYPE; return; - break; case MAIN_MENU_FULLSCREEN: this->fullscreen_change(); return; - break; case MAIN_MENU_SPLIT: this->split_change(); return; - break; case MAIN_MENU_VIDEO_SETTINGS: this->setup_video_menu(); return; @@ -583,7 +592,6 @@ void WindowScreen::poll() { case VIDEO_MENU_BACK: this->setup_main_menu(); return; - break; case VIDEO_MENU_VSYNC: this->vsync_change(); break; @@ -596,12 +604,30 @@ void WindowScreen::poll() { case VIDEO_MENU_PADDING: this->padding_change(); break; + case VIDEO_MENU_CROPPING: + this->setup_crop_menu(); + return; default: break; } this->video_menu->selected_index = VIDEO_MENU_NO_ACTION; continue; } + case CROP_MENU_TYPE: + if(this->crop_menu->poll(event_data)) { + switch(this->crop_menu->selected_index) { + case CROP_MENU_BACK: + this->setup_video_menu(); + return; + case CROP_MENU_NO_ACTION: + break; + default: + this->crop_value_change(this->crop_menu->selected_index); + break; + } + this->crop_menu->selected_index = CROP_MENU_NO_ACTION; + continue; + } break; default: break; @@ -698,6 +724,9 @@ void WindowScreen::draw(double frame_time, VideoOutputData* out_buf) { case VIDEO_MENU_TYPE: this->video_menu->prepare(this->loaded_info.menu_scaling_factor, view_size_x, view_size_y, &this->loaded_info); break; + case CROP_MENU_TYPE: + this->crop_menu->prepare(this->loaded_info.menu_scaling_factor, view_size_x, view_size_y, this->loaded_info.crop_kind); + break; default: break; } @@ -999,6 +1028,9 @@ void WindowScreen::display_data_to_window(bool actually_draw) { case VIDEO_MENU_TYPE: this->video_menu->draw(this->loaded_info.menu_scaling_factor, this->m_win); break; + case CROP_MENU_TYPE: + this->crop_menu->draw(this->loaded_info.menu_scaling_factor, this->m_win); + break; default: break; }