From c207201a4a5a47e4ad286ba7371e4176c8ed5056 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 19 Mar 2021 12:22:25 +0100 Subject: Start on touch support, add support for ui scaling, revert back to old get_message_by_id method for matrix to support loading user display names in replies --- src/QuickMedia.cpp | 103 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 39 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index e515c7a..e080cbc 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -25,6 +25,7 @@ #include "../include/SfmlFixes.hpp" #include "../include/ResourceLoader.hpp" #include "../include/AsyncTask.hpp" +#include "../include/Utils.hpp" #include "../external/hash-library/sha256.h" #include @@ -46,10 +47,10 @@ static const sf::Color back_color(21, 25, 30); static const std::string fourchan_google_captcha_api_key = "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc"; -static const float tab_text_size = 16.0f; -static const float tab_height = tab_text_size + 10.0f; +static const float tab_text_size = 16.0f * QuickMedia::get_ui_scale(); +static const float tab_height = tab_text_size + 10.0f * QuickMedia::get_ui_scale(); static const sf::Color tab_selected_color(55, 60, 68); -static const float tab_margin_x = 10.0f; +static const float tab_margin_x = 10.0f * QuickMedia::get_ui_scale(); static int FPS_IDLE = 2; static const double IDLE_TIMEOUT_SEC = 2.0; @@ -747,12 +748,15 @@ namespace QuickMedia { } void Program::event_idle_handler(const sf::Event &event) { - if(event.type == sf::Event::KeyPressed || event.type == sf::Event::TextEntered) { - if(idle) - window.setFramerateLimit(monitor_hz); - idle = false; - idle_timer.restart(); - } + if(event.type == sf::Event::KeyPressed || event.type == sf::Event::TextEntered) + idle_active_handler(); + } + + void Program::idle_active_handler() { + if(idle) + window.setFramerateLimit(monitor_hz); + idle = false; + idle_timer.restart(); } void Program::update_idle_state() { @@ -925,12 +929,12 @@ namespace QuickMedia { static void get_body_dimensions(const sf::Vector2f &window_size, SearchBar *search_bar, sf::Vector2f &body_pos, sf::Vector2f &body_size, bool has_tabs = false) { float body_padding_horizontal = 25.0f; - float body_padding_vertical = 25.0f; + float body_padding_vertical = 25.0f * get_ui_scale(); float body_width = window_size.x - body_padding_horizontal * 2.0f; if(body_width <= 480.0f) { body_width = window_size.x; body_padding_horizontal = 0.0f; - body_padding_vertical = 10.0f; + body_padding_vertical = 10.0f * get_ui_scale(); } float tab_h = tab_height; @@ -997,17 +1001,17 @@ namespace QuickMedia { { float shade_extra_height = 0.0f; if(!tabs[selected_tab].search_bar) - shade_extra_height = 10.0f; + shade_extra_height = 10.0f * get_ui_scale(); const float width_per_tab = window_size.x / tabs.size(); tab_background.setSize(sf::Vector2f(std::floor(width_per_tab - tab_margin_x * 2.0f), tab_height)); float tab_vertical_offset = tabs[selected_tab].search_bar ? tabs[selected_tab].search_bar->getBottomWithoutShadow() : 0.0f; tabs[selected_tab].body->draw(window, body_pos, body_size, *json_chapters); - const float tab_y = std::floor(tab_vertical_offset + tab_height * 0.5f - (tab_text_size + 5.0f) * 0.5f) + shade_extra_height; + const float tab_y = std::floor(tab_vertical_offset + tab_height * 0.5f - (tab_text_size + 5.0f * get_ui_scale()) * 0.5f) + shade_extra_height; tab_shade.setPosition(0.0f, std::floor(tab_vertical_offset)); - tab_shade.setSize(sf::Vector2f(window_size.x, shade_extra_height + tab_height + 10.0f)); + tab_shade.setSize(sf::Vector2f(window_size.x, shade_extra_height + tab_height + 10.0f * get_ui_scale())); window.draw(tab_shade); int i = 0; @@ -1076,7 +1080,7 @@ namespace QuickMedia { std::vector tab_associated_data; for(size_t i = 0; i < tabs.size(); ++i) { TabAssociatedData data; - data.search_result_text = sf::Text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 30); + data.search_result_text = sf::Text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 30 * get_ui_scale()); tab_associated_data.push_back(std::move(data)); } @@ -1247,7 +1251,11 @@ namespace QuickMedia { while (window.isOpen() && loop_running) { sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds(); while (window.pollEvent(event)) { - event_idle_handler(event); + if(tabs[selected_tab].body->on_event(window, event)) + idle_active_handler(); + else + event_idle_handler(event); + if (event.type == sf::Event::Closed) { window.close(); } else if(event.type == sf::Event::Resized) { @@ -2258,7 +2266,7 @@ namespace QuickMedia { sf::Texture image_texture; sf::Sprite image; - sf::Text error_message("", *FontLoader::get_font(FontLoader::FontType::LATIN), 30); + sf::Text error_message("", *FontLoader::get_font(FontLoader::FontType::LATIN), 30 * get_ui_scale()); error_message.setFillColor(sf::Color::White); bool download_in_progress = false; @@ -2322,7 +2330,7 @@ namespace QuickMedia { bool error = !error_message.getString().isEmpty(); bool redraw = true; - sf::Text chapter_text(images_page->manga_name + " | " + images_page->get_chapter_name() + " | Page " + std::to_string(image_index + 1) + "/" + std::to_string(num_images), *FontLoader::get_font(FontLoader::FontType::LATIN), 14); + sf::Text chapter_text(images_page->manga_name + " | " + images_page->get_chapter_name() + " | Page " + std::to_string(image_index + 1) + "/" + std::to_string(num_images), *FontLoader::get_font(FontLoader::FontType::LATIN), 14 * get_ui_scale()); if(image_index == num_images) chapter_text.setString(images_page->manga_name + " | " + images_page->get_chapter_name() + " | End"); chapter_text.setFillColor(sf::Color::White); @@ -2591,7 +2599,7 @@ namespace QuickMedia { sf::Sprite attached_image_sprite; GoogleCaptchaChallengeInfo challenge_info; - sf::Text challenge_description_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 24); + sf::Text challenge_description_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 24 * get_ui_scale()); challenge_description_text.setFillColor(sf::Color::White); const size_t captcha_num_columns = 3; const size_t captcha_num_rows = 3; @@ -2713,14 +2721,14 @@ namespace QuickMedia { comment_input_shade.setFillColor(sf::Color(31, 35, 41)); sf::Sprite logo_sprite(plugin_logo); - logo_sprite.setScale(0.8f, 0.8f); + logo_sprite.setScale(0.8f * get_ui_scale(), 0.8f * get_ui_scale()); sf::Vector2f logo_size(plugin_logo.getSize().x * logo_sprite.getScale().x, plugin_logo.getSize().y * logo_sprite.getScale().y); float prev_chat_height = comment_input.get_height(); float chat_input_height_full = 0.0f; - const float logo_padding_x = 15.0f; - const float chat_input_padding_x = 10.0f; - const float chat_input_padding_y = 10.0f; + const float logo_padding_x = 15.0f * get_ui_scale(); + const float chat_input_padding_x = 10.0f * get_ui_scale(); + const float chat_input_padding_y = 10.0f * get_ui_scale(); sf::Vector2f body_pos; sf::Vector2f body_size; @@ -2733,6 +2741,11 @@ namespace QuickMedia { while (current_page == PageType::IMAGE_BOARD_THREAD && window.isOpen()) { while (window.pollEvent(event)) { + if(navigation_stage == NavigationStage::REPLYING || navigation_stage == NavigationStage::VIEWING_COMMENTS) { + if(thread_body->on_event(window, event)) + idle_active_handler(); + } + event_idle_handler(event); if(navigation_stage == NavigationStage::REPLYING && !frame_skip_text_entry) { comment_input.process_event(event); @@ -2927,7 +2940,7 @@ namespace QuickMedia { comment_input.set_position(sf::Vector2f(std::floor(logo_padding_x + logo_size.x + chat_input_padding_x), chat_input_padding_y)); float body_padding_horizontal = 25.0f; - float body_padding_vertical = 5.0f; + float body_padding_vertical = 5.0f * get_ui_scale(); float body_width = window_size.x - body_padding_horizontal * 2.0f; if(body_width <= 480.0f) { body_width = window_size.x; @@ -3056,7 +3069,7 @@ namespace QuickMedia { SearchBar password_input(nullptr, "Password", true); SearchBar homeserver_input(nullptr, "Homeserver"); - sf::Text status_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 18); + sf::Text status_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 18 * get_ui_scale()); const int num_inputs = 3; SearchBar *inputs[num_inputs] = { &login_input, &password_input, &homeserver_input }; @@ -3095,7 +3108,11 @@ namespace QuickMedia { while (current_page == PageType::CHAT_LOGIN && window.isOpen()) { while (window.pollEvent(event)) { - event_idle_handler(event); + if(body->on_event(window, event)) + idle_active_handler(); + else + event_idle_handler(event); + if (event.type == sf::Event::Closed) { current_page = PageType::EXIT; window.close(); @@ -3270,15 +3287,15 @@ namespace QuickMedia { ChatState chat_state = ChatState::NAVIGATING; std::shared_ptr currently_operating_on_item; - sf::Text replying_to_text("Replying to:", *FontLoader::get_font(FontLoader::FontType::LATIN), 18); + sf::Text replying_to_text("Replying to:", *FontLoader::get_font(FontLoader::FontType::LATIN), 18 * get_ui_scale()); sf::Sprite logo_sprite(plugin_logo); - logo_sprite.setScale(0.8f, 0.8f); + logo_sprite.setScale(0.8f * get_ui_scale(), 0.8f * get_ui_scale()); sf::Vector2f logo_size(plugin_logo.getSize().x * logo_sprite.getScale().x, plugin_logo.getSize().y * logo_sprite.getScale().y); - sf::Text room_name_text("", *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), 18); - const float room_name_text_height = 20.0f; - const float room_name_text_padding_y = 10.0f; + sf::Text room_name_text("", *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), 18 * get_ui_scale()); + const float room_name_text_height = 18.0f * get_ui_scale(); + const float room_name_text_padding_y = 10.0f * get_ui_scale(); const float room_name_total_height = room_name_text_height + room_name_text_padding_y * 2.0f; const float room_avatar_height = 32.0f; @@ -4015,9 +4032,9 @@ namespace QuickMedia { float prev_chat_height = chat_input.get_height(); float chat_input_height_full = 0.0f; - const float logo_padding_x = 15.0f; - const float chat_input_padding_x = 10.0f; - const float chat_input_padding_y = 10.0f; + const float logo_padding_x = 15.0f * get_ui_scale(); + const float chat_input_padding_x = 10.0f * get_ui_scale(); + const float chat_input_padding_y = 10.0f * get_ui_scale(); auto launch_url = [this, &video_page, &redraw](const std::string &url) mutable { if(url.empty()) @@ -4268,6 +4285,14 @@ namespace QuickMedia { while (current_page == PageType::CHAT && window.isOpen()) { sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds(); while (window.pollEvent(event)) { + if(chat_state == ChatState::URL_SELECTION) { + if(url_selection_body.on_event(window, event)) + idle_active_handler(); + } else { + if(tabs[selected_tab].body->on_event(window, event)) + idle_active_handler(); + } + base_event_handler(event, PageType::EXIT, tabs[selected_tab].body.get(), nullptr, false, false); event_idle_handler(event); @@ -4622,7 +4647,7 @@ namespace QuickMedia { float width_ratio = (float)texture_size.x / (float)texture_size.y; float height_scale = room_avatar_height / (float)texture_size.y; float width_scale = height_scale * width_ratio; - room_avatar_sprite.setScale(width_scale, height_scale); + room_avatar_sprite.setScale(width_scale * get_ui_scale(), height_scale * get_ui_scale()); } } @@ -4647,13 +4672,13 @@ namespace QuickMedia { float padding_bottom = 0.0f; if(selected_tab == MESSAGES_TAB_INDEX || selected_tab == PINNED_TAB_INDEX) { room_name_padding_y = 10.0f + room_name_total_height; - tab_vertical_offset = 10.0f; + tab_vertical_offset = 10.0f * get_ui_scale(); } tab_shade_height = tab_spacer_height + std::floor(tab_vertical_offset) + tab_height + room_name_padding_y + padding_bottom; float body_padding_horizontal = 25.0f; - float body_padding_vertical = 5.0f; + float body_padding_vertical = 5.0f * get_ui_scale(); float body_width = window_size.x - body_padding_horizontal * 2.0f; if(body_width <= 480.0f) { body_width = window_size.x; @@ -4661,8 +4686,8 @@ namespace QuickMedia { } this->body_pos = sf::Vector2f(0.0f, tab_shade_height); - if(body_width > 640.0f && show_room_side_panel) { - this->body_size = sf::Vector2f(300.0f, window_size.y - tab_shade_height); + if(window_size.x > 900.0f && show_room_side_panel) { + this->body_size = sf::Vector2f(300.0f * get_ui_scale(), window_size.y - tab_shade_height); draw_room_list = true; } else { this->body_size = sf::Vector2f(0.0f, 0.0f); -- cgit v1.2.3