From 4aec31515ff6f61f41dfd66551a3fce44f243535 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 20 Mar 2021 07:06:06 +0100 Subject: More work on touch (behind QM_ENABLE_TOUCH=1 environment variable), save thumbnails with their size so using a different scaling will update thumbnails to the same scale --- src/QuickMedia.cpp | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index d54229f..61b2d1b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -53,6 +53,7 @@ static const sf::Color tab_selected_color(55, 60, 68); static const float tab_margin_x = std::floor(10.0f * QuickMedia::get_ui_scale()); static int FPS_IDLE = 2; static const double IDLE_TIMEOUT_SEC = 2.0; +static const sf::Vector2i AVATAR_THUMBNAIL_SIZE(std::floor(32 * QuickMedia::get_ui_scale()), std::floor(32 * QuickMedia::get_ui_scale())); // Prevent writing to broken pipe from exiting the program static void sigpipe_handler(int) { @@ -1100,7 +1101,9 @@ namespace QuickMedia { window_size.x = window_size_u.x; window_size.y = window_size_u.y; - auto submit_handler = [this, &after_submit_handler, &json_chapters, &tabs, &tab_associated_data, &selected_tab, &loop_running, &redraw]() { + std::function submit_handler; + + submit_handler = [this, &submit_handler, &after_submit_handler, &json_chapters, &tabs, &tab_associated_data, &selected_tab, &loop_running, &redraw]() { BodyItem *selected_item = tabs[selected_tab].body->get_selected(); if(!selected_item) return; @@ -1195,6 +1198,9 @@ namespace QuickMedia { break; current_chat_room = matrix->get_room_by_id(selected_item->url); } + tabs[selected_tab].body->body_item_select_callback = [&submit_handler](BodyItem *body_item) { + submit_handler(); + }; //select_body_item_by_room(tabs[selected_tab].body.get(), current_chat_room); current_chat_room = nullptr; } else { @@ -1213,6 +1219,10 @@ namespace QuickMedia { for(size_t i = 0; i < tabs.size(); ++i) { Tab &tab = tabs[i]; + tab.body->body_item_select_callback = [&submit_handler](BodyItem *body_item) { + submit_handler(); + }; + TabAssociatedData &associated_data = tab_associated_data[i]; if(!tab.search_bar) continue; @@ -1263,6 +1273,7 @@ namespace QuickMedia { window_size.y = event.size.height; sf::FloatRect visible_area(0, 0, window_size.x, window_size.y); window.setView(sf::View(visible_area)); + idle_active_handler(); } if(tabs[selected_tab].search_bar) { @@ -2767,6 +2778,7 @@ namespace QuickMedia { window_size.y = event.size.height; sf::FloatRect visible_area(0, 0, window_size.x, window_size.y); window.setView(sf::View(visible_area)); + idle_active_handler(); } if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) @@ -3122,6 +3134,7 @@ namespace QuickMedia { sf::FloatRect visible_area(0, 0, window_size.x, window_size.y); window.setView(sf::View(visible_area)); redraw = true; + idle_active_handler(); } else if(event.type == sf::Event::GainedFocus) { redraw = true; } else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Tab) { @@ -3178,7 +3191,7 @@ namespace QuickMedia { body_item->thumbnail_url = room->get_user_avatar_url(message->user); body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE; // if construct is not configured to use ImageMagic then it wont give thumbnails of size 32x32 even when requested and the spec says that the server SHOULD do that - body_item->thumbnail_size = sf::Vector2i(32, 32); + body_item->thumbnail_size = AVATAR_THUMBNAIL_SIZE; } // TODO: Show image thumbnail inline instead of url to image and showing it as the thumbnail of the body item body_item->url = message->url; @@ -3345,7 +3358,7 @@ namespace QuickMedia { } body_item->set_description("Message deleted"); body_item->set_description_color(sf::Color::White); - body_item->thumbnail_size = sf::Vector2i(32, 32); + body_item->thumbnail_size = AVATAR_THUMBNAIL_SIZE; body_item->url.clear(); }; @@ -4170,7 +4183,7 @@ namespace QuickMedia { pinned_body_item->thumbnail_url = user_avatar_url; pinned_body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE; // if construct is not configured to use ImageMagic then it wont give thumbnails of size 32x32 even when requested and the spec says that the server SHOULD do that - pinned_body_item->thumbnail_size = sf::Vector2i(32, 32); + pinned_body_item->thumbnail_size = AVATAR_THUMBNAIL_SIZE; } } }; @@ -4190,7 +4203,7 @@ namespace QuickMedia { message_body_items->thumbnail_url = user_avatar_url; message_body_items->thumbnail_mask_type = ThumbnailMaskType::CIRCLE; // if construct is not configured to use ImageMagic then it wont give thumbnails of size 32x32 even when requested and the spec says that the server SHOULD do that - message_body_items->thumbnail_size = sf::Vector2i(32, 32); + message_body_items->thumbnail_size = AVATAR_THUMBNAIL_SIZE; } } }; @@ -4209,7 +4222,7 @@ namespace QuickMedia { pinned_body_item->thumbnail_url = current_room->get_user_avatar_url(message->user); pinned_body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE; // if construct is not configured to use ImageMagic then it wont give thumbnails of size 32x32 even when requested and the spec says that the server SHOULD do that - pinned_body_item->thumbnail_size = sf::Vector2i(32, 32); + pinned_body_item->thumbnail_size = AVATAR_THUMBNAIL_SIZE; } } }; @@ -4227,7 +4240,7 @@ namespace QuickMedia { message_body_items->thumbnail_url = current_room->get_user_avatar_url(message->user); message_body_items->thumbnail_mask_type = ThumbnailMaskType::CIRCLE; // if construct is not configured to use ImageMagic then it wont give thumbnails of size 32x32 even when requested and the spec says that the server SHOULD do that - message_body_items->thumbnail_size = sf::Vector2i(32, 32); + message_body_items->thumbnail_size = AVATAR_THUMBNAIL_SIZE; } } }; @@ -4280,9 +4293,13 @@ namespace QuickMedia { float tab_shade_height = 0.0f; bool frame_skip_text_entry = false; + room_tabs[room_selected_tab].body->body_item_select_callback = [&move_room](BodyItem *body_item) { + move_room = true; + }; + SyncData sync_data; - while (current_page == PageType::CHAT && window.isOpen()) { + while (current_page == PageType::CHAT && window.isOpen() && !move_room) { sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds(); while (window.pollEvent(event)) { if(chat_state == ChatState::URL_SELECTION) { @@ -4296,6 +4313,9 @@ namespace QuickMedia { base_event_handler(event, PageType::EXIT, tabs[selected_tab].body.get(), nullptr, false, false); event_idle_handler(event); + if(draw_room_list) + room_tabs[room_selected_tab].body->on_event(window, event); + if(event.type == sf::Event::KeyPressed && event.key.control && event.key.alt && (chat_state == ChatState::NAVIGATING || chat_state == ChatState::URL_SELECTION)) { if(event.key.code == sf::Keyboard::Up || (event.key.control && event.key.code == sf::Keyboard::K)) { room_tabs[room_selected_tab].body->select_previous_item(); @@ -4336,7 +4356,10 @@ namespace QuickMedia { redraw = true; } else if(event.type == sf::Event::LostFocus) { is_window_focused = false; - } else if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) { + } else if(event.type == sf::Event::Resized) { + redraw = true; + idle_active_handler(); + } else if(event.type == sf::Event::GainedFocus) { redraw = true; } else if(event.type == sf::Event::KeyPressed && chat_state == ChatState::NAVIGATING) { if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::PageUp || event.key.code == sf::Keyboard::Home || (event.key.control && event.key.code == sf::Keyboard::K)) { @@ -4631,7 +4654,7 @@ namespace QuickMedia { } if(current_room && current_room->body_item && room_avatar_thumbnail_data->loading_state == LoadingState::NOT_LOADED) - AsyncImageLoader::get_instance().load_thumbnail(current_room->body_item->thumbnail_url, false, sf::Vector2i(32, 32), use_tor, room_avatar_thumbnail_data); + AsyncImageLoader::get_instance().load_thumbnail(current_room->body_item->thumbnail_url, false, AVATAR_THUMBNAIL_SIZE, use_tor, room_avatar_thumbnail_data); if(room_avatar_thumbnail_data->loading_state == LoadingState::FINISHED_LOADING && room_avatar_thumbnail_data->image->getSize().x > 0 && room_avatar_thumbnail_data->image->getSize().y > 0) { if(!room_avatar_thumbnail_data->texture.loadFromImage(*room_avatar_thumbnail_data->image)) -- cgit v1.2.3