From 6a2b5008be8104680826fe40fa8e674e9357c044 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 19 Oct 2020 23:33:23 +0200 Subject: Add thumbnail loading animation Use correct ref in matrix replies, make text that contains our user id also count as a mention. --- src/QuickMedia.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index a32febb..c47147f 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -355,6 +355,12 @@ namespace QuickMedia { abort(); } + if(!loading_icon.loadFromFile(resources_root + "images/loading_icon.png")) { + fprintf(stderr, "Failed to load %s/images/loading_icon.png", resources_root.c_str()); + abort(); + } + loading_icon.setSmooth(true); + struct sigaction action; action.sa_handler = sigpipe_handler; sigemptyset(&action.sa_mask); @@ -883,7 +889,7 @@ namespace QuickMedia { } std::unique_ptr Program::create_body() { - return std::make_unique(this, font.get(), bold_font.get(), cjk_font.get()); + return std::make_unique(this, font.get(), bold_font.get(), cjk_font.get(), loading_icon); } std::unique_ptr Program::create_search_bar(const std::string &placeholder, int search_delay) { @@ -2915,7 +2921,7 @@ namespace QuickMedia { body_item->userdata = (void*)message; // Note: message has to be valid as long as body_item is used! if(message->related_event_type == RelatedEventType::REDACTION || message->related_event_type == RelatedEventType::EDIT) body_item->visible = false; - if(message->mentions_me || (me && message_contains_user_mention(message->body, me->display_name))) + if(message->mentions_me || (me && (message_contains_user_mention(message->body, me->display_name) || message_contains_user_mention(message->body, me->user_id)))) body_item->set_description_color(sf::Color(255, 100, 100)); return body_item; } @@ -2938,7 +2944,7 @@ namespace QuickMedia { ChatTab messages_tab; messages_tab.type = ChatTabType::MESSAGES; - messages_tab.body = std::make_unique(this, font.get(), bold_font.get(), cjk_font.get()); + messages_tab.body = std::make_unique(this, font.get(), bold_font.get(), cjk_font.get(), loading_icon); messages_tab.body->draw_thumbnails = true; messages_tab.body->thumbnail_resize_target_size = CHAT_MESSAGE_THUMBNAIL_MAX_SIZE; messages_tab.body->thumbnail_mask_shader = &circle_mask_shader; @@ -2948,7 +2954,7 @@ namespace QuickMedia { ChatTab rooms_tab; rooms_tab.type = ChatTabType::ROOMS; - rooms_tab.body = std::make_unique(this, font.get(), bold_font.get(), cjk_font.get()); + rooms_tab.body = std::make_unique(this, font.get(), bold_font.get(), cjk_font.get(), loading_icon); rooms_tab.body->draw_thumbnails = true; //rooms_tab.body->line_separator_color = sf::Color::Transparent; rooms_tab.body->thumbnail_mask_shader = &circle_mask_shader; @@ -3001,11 +3007,11 @@ namespace QuickMedia { // Swap room with the top one // TODO: Optimize with hash map instead of linear search? or cache the index - int room_body_index = tabs[ROOMS_TAB_INDEX].body->get_index_by_body_item(room_body_item); - if(room_body_index != -1) { - std::swap(tabs[ROOMS_TAB_INDEX].body->items[room_body_index], tabs[ROOMS_TAB_INDEX].body->items[room_swap_index]); - ++room_swap_index; - } + // int room_body_index = tabs[ROOMS_TAB_INDEX].body->get_index_by_body_item(room_body_item); + // if(room_body_index != -1) { + // std::swap(tabs[ROOMS_TAB_INDEX].body->items[room_body_index], tabs[ROOMS_TAB_INDEX].body->items[room_swap_index]); + // ++room_swap_index; + // } } else if(is_first_sync) { room_body_item->set_description(matrix->message_get_author_displayname(messages.back().get()) + ": " + extract_first_line(messages.back()->body, 150)); room->has_unread_mention = false; @@ -3313,7 +3319,7 @@ namespace QuickMedia { const float chat_input_padding_x = 15.0f; const float chat_input_padding_y = 15.0f; - Body url_selection_body(this, font.get(), bold_font.get(), cjk_font.get()); + Body url_selection_body(this, font.get(), bold_font.get(), cjk_font.get(), loading_icon); auto launch_url = [this, &video_page, &redraw](const std::string &url) mutable { if(url.empty()) -- cgit v1.2.3