From a00bdf3c76cd2d813533788b83abac87d6449b18 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 26 Sep 2020 22:59:25 +0200 Subject: matrix: time based animations, dont show chat input in rooms view, improve scrolling when switching tabs --- README.md | 2 +- TODO | 5 +++- src/QuickMedia.cpp | 85 +++++++++++++++++++++++++++--------------------------- 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 4cad51b..f029f03 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Press `Middle mouse button` to "autoscroll" in scrolling image view mode.\ Press `Tab` to autocomplete a search when autocomplete is available (currently only available for youtube).\ Press `Tab` to switch between username/password field in login panel.\ Press `Ctrl + V` to paste the content of your clipboard into the search bar.\ -Press `Ctrl + I` to view image/video attached to matrix message. +Press `Ctrl + P` to view image/video attached to matrix message. ## Video controls Press `space` to pause/unpause video. `Double-click` video to fullscreen or leave fullscreen. # Mangadex diff --git a/TODO b/TODO index 0da0892..2baecfc 100644 --- a/TODO +++ b/TODO @@ -30,4 +30,7 @@ Use one special thread to load cached files. Right now if there are multiple ima Press pgup/pgdown to scroll and entire page. Press home/end to scroll to top/bottom. Scrolling past page causes the page to jump up and down very fast because the new thumbnail is loaded. Fix this somehow. In youtube this can be fixed by setting the thumbnail image fallback size to the same size and thumbnail images, but that doesn't work for matrix with different image sizes! -Find a way to decrease cpu usage when scrolling fast. Right now sf::Texture::load will use up to 10% cpu on my machine. \ No newline at end of file +Find a way to decrease cpu usage when scrolling fast. Right now sf::Texture::load will use up to 10% cpu on my machine. +Add setting to disable sending typing events to the server (matrix). +Support emoji (mainly for matrix), by readding Text code from dchat. Also do the same but for inline images, text editing and url colors and clicking (also clicking on inline images). +Also take code from dchat to support gifs (inline in text). \ No newline at end of file diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index d7a3ed7..6293e52 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3330,23 +3330,6 @@ namespace QuickMedia { return false; } return true; - } else if(tabs[selected_tab].type == ChatTabType::ROOMS) { - BodyItem *selected_item = tabs[selected_tab].body->get_selected(); - if(selected_item) { - current_room_id = selected_item->url; - selected_tab = MESSAGES_TAB_INDEX; - tabs[MESSAGES_TAB_INDEX].body->clear_items(); - - BodyItems new_items; - // TODO: Make asynchronous - if(matrix->get_all_synced_room_messages(current_room_id, new_items) == PluginResult::OK) { - tabs[MESSAGES_TAB_INDEX].body->append_items(std::move(new_items)); - } else { - std::string err_msg = "Failed to get messages in room: " + current_room_id; - show_notification("QuickMedia", err_msg, Urgency::CRITICAL); - } - return true; - } } return false; }; @@ -3375,7 +3358,7 @@ namespace QuickMedia { const float gradient_height = 5.0f; sf::Vertex gradient_points[4]; - int gradient_inc = 0; + double gradient_inc = 0; sf::Clock start_typing_timer; const double typing_timeout_seconds = 3.0; @@ -3390,7 +3373,10 @@ namespace QuickMedia { }; std::vector> typing_futures; + sf::Clock frame_timer; + while (current_page == Page::CHAT) { + sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds(); while (window.pollEvent(event)) { base_event_handler(event, Page::EXIT, false, false, false); if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) { @@ -3399,7 +3385,7 @@ namespace QuickMedia { if(event.key.code == sf::Keyboard::Up) { bool item_changed = tabs[selected_tab].body->select_previous_item(); // Top hit - if(!item_changed && !fetching_previous_messages_running) { + if(!item_changed && !fetching_previous_messages_running && tabs[selected_tab].type == ChatTabType::MESSAGES) { gradient_inc = 0; fetching_previous_messages_running = true; previous_messages_future_room_id = current_room_id; @@ -3418,22 +3404,16 @@ namespace QuickMedia { body->clear_items(); body->reset_selected(); } else if(event.key.code == sf::Keyboard::Left) { - tabs[selected_tab].body->filter_search_fuzzy(""); - tabs[selected_tab].body->clamp_selection(); tabs[selected_tab].body->clear_thumbnails(); selected_tab = std::max(0, selected_tab - 1); - //chat_input.clear(); if(typing) { fprintf(stderr, "Stopped typing\n"); typing = false; typing_futures.push_back(std::async(typing_async_func, false, current_room_id)); } } else if(event.key.code == sf::Keyboard::Right) { - tabs[selected_tab].body->filter_search_fuzzy(""); - tabs[selected_tab].body->clamp_selection(); tabs[selected_tab].body->clear_thumbnails(); selected_tab = std::min((int)tabs.size() - 1, selected_tab + 1); - //chat_input.clear(); if(typing) { fprintf(stderr, "Stopped typing\n"); typing = false; @@ -3441,7 +3421,7 @@ namespace QuickMedia { } } - if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::I) { + if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::P) { BodyItem *selected_item = tabs[selected_tab].body->get_selected(); if(!selected_item) continue; @@ -3458,19 +3438,37 @@ namespace QuickMedia { } } - if(event.type == sf::Event::TextEntered) { - chat_input.onTextEntered(event.text.unicode); - // TODO: Also show typing event when ctrl+v pasting? - if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.text.unicode != 13) { // Return key - start_typing_timer.restart(); - if(!typing) { - fprintf(stderr, "Started typing\n"); - typing_futures.push_back(std::async(typing_async_func, true, current_room_id)); + if(tabs[selected_tab].type == ChatTabType::MESSAGES) { + if(event.type == sf::Event::TextEntered) { + chat_input.onTextEntered(event.text.unicode); + // TODO: Also show typing event when ctrl+v pasting? + if(event.text.unicode != 13) { // Return key + start_typing_timer.restart(); + if(!typing) { + fprintf(stderr, "Started typing\n"); + typing_futures.push_back(std::async(typing_async_func, true, current_room_id)); + } + typing = true; + } + } + chat_input.on_event(event); + } else if(tabs[selected_tab].type == ChatTabType::ROOMS && event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Enter) { + BodyItem *selected_item = tabs[selected_tab].body->get_selected(); + if(selected_item) { + current_room_id = selected_item->url; + selected_tab = MESSAGES_TAB_INDEX; + tabs[MESSAGES_TAB_INDEX].body->clear_items(); + + BodyItems new_items; + // TODO: Make asynchronous + if(matrix->get_all_synced_room_messages(current_room_id, new_items) == PluginResult::OK) { + tabs[MESSAGES_TAB_INDEX].body->append_items(std::move(new_items)); + } else { + std::string err_msg = "Failed to get messages in room: " + current_room_id; + show_notification("QuickMedia", err_msg, Urgency::CRITICAL); } - typing = true; } } - chat_input.on_event(event); } if(typing && start_typing_timer.getElapsedTime().asSeconds() >= typing_timeout_seconds) { @@ -3508,9 +3506,11 @@ namespace QuickMedia { body_padding_vertical = 10.0f; } - float search_bottom = chat_input.getBottomWithoutShadow(); + float input_bottom = chat_input.getBottomWithoutShadow(); + if(tabs[selected_tab].type != ChatTabType::MESSAGES) + input_bottom = 0.0f; body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical + tab_height); - body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical - tab_height); + body_size = sf::Vector2f(body_width, window_size.y - input_bottom - body_padding_vertical - tab_height); //get_body_dimensions(window_size, &chat_input, body_pos, body_size, true); } @@ -3547,7 +3547,7 @@ namespace QuickMedia { sync_running = false; } - if(previous_messages_future.valid() && previous_messages_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { + if(fetching_previous_messages_running && previous_messages_future.valid() && previous_messages_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { BodyItems new_body_items = previous_messages_future.get(); fprintf(stderr, "Finished fetching older messages, num new messages: %zu\n", new_body_items.size()); // Ignore finished fetch of messages if it happened in another room. When we navigate back to the room we will get the messages again @@ -3564,7 +3564,8 @@ namespace QuickMedia { window.clear(back_color); - chat_input.draw(window, false); + if(tabs[selected_tab].type == ChatTabType::MESSAGES) + chat_input.draw(window, false); 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)); @@ -3603,8 +3604,8 @@ namespace QuickMedia { // TODO: Stop showing this when switching rooms, or have one for each room. Also add bottom one? for fetching new messages if(fetching_previous_messages_running) { - double progress = 0.5 + std::sin((double)(gradient_inc % 360) * 0.017453292519943295 - 1.5707963267948966*0.5) * 0.5; - gradient_inc += 2; + double progress = 0.5 + std::sin(std::fmod(gradient_inc, 360.0) * 0.017453292519943295 - 1.5707963267948966*0.5) * 0.5; + gradient_inc += (frame_time_ms * 0.5); sf::Color top_color = interpolate_colors(back_color, sf::Color(175, 180, 188), progress); gradient_points[0].color = top_color; -- cgit v1.2.3