diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-19 23:33:23 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-20 02:06:49 +0200 |
commit | 6a2b5008be8104680826fe40fa8e674e9357c044 (patch) | |
tree | c7d88abee4e71ebbba68384c1686829656933b1c /src/Body.cpp | |
parent | 41fe990530c546b4cac7e000b40481f87fb33305 (diff) |
Add thumbnail loading animation
Use correct ref in matrix replies,
make text that contains our user id also count as a mention.
Diffstat (limited to 'src/Body.cpp')
-rw-r--r-- | src/Body.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 0294d97..1d06559 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -25,7 +25,7 @@ namespace QuickMedia { dirty_timestamp(false), thumbnail_is_local(false), userdata(nullptr), - last_drawn_time(0), + last_drawn_time(0.0), timestamp(0), title_color(sf::Color::White), author_color(sf::Color::White), @@ -35,7 +35,7 @@ namespace QuickMedia { set_title(std::move(_title)); } - Body::Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font) : + Body::Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font, sf::Texture &loading_icon_texture) : font(font), bold_font(bold_font), cjk_font(cjk_font), @@ -52,6 +52,7 @@ namespace QuickMedia { prev_selected_item(0), page_scroll(0.0f), item_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10), + loading_icon(loading_icon_texture), num_visible_items(0), last_item_fully_visible(true), last_fully_visible_item(-1) @@ -61,6 +62,8 @@ namespace QuickMedia { thumbnail_resize_target_size.x = 120; thumbnail_resize_target_size.y = 120; item_background.setFillColor(sf::Color(55, 60, 68)); + sf::Vector2f loading_icon_size(loading_icon.getTexture()->getSize().x, loading_icon.getTexture()->getSize().y); + loading_icon.setOrigin(loading_icon_size.x * 0.5f, loading_icon_size.y * 0.5f); } // TODO: Make this work with wraparound enabled? @@ -274,7 +277,7 @@ namespace QuickMedia { sf::Vector2f scissor_size = size; const float start_y = pos.y; - const sf::Int32 elapsed_time = draw_timer.getElapsedTime().asMilliseconds(); + elapsed_time_sec = draw_timer.getElapsedTime().asSeconds(); //item_background.setFillColor(front_color); //item_background.setOutlineThickness(1.0f); @@ -354,7 +357,7 @@ namespace QuickMedia { continue; update_dirty_state(item.get(), size); - item->last_drawn_time = elapsed_time; + item->last_drawn_time = elapsed_time_sec; float item_height = get_item_height(item.get()); prev_pos.y -= (item_height + spacing_y); @@ -383,7 +386,7 @@ namespace QuickMedia { update_dirty_state(item.get(), size); float item_height = get_item_height(item.get()); - item->last_drawn_time = elapsed_time; + item->last_drawn_time = elapsed_time_sec; // This is needed here rather than above the loop, since update_dirty_text cant be called inside scissor because it corrupts the text for some reason glEnable(GL_SCISSOR_TEST); @@ -410,10 +413,9 @@ namespace QuickMedia { } // TODO: Only do this for items that are not visible, do not loop all items. - // TODO: Verify if this only runs for items that are not visible, and only once // TODO: Improve performance! right now it can use up to 5-7% cpu with a lot of items! for(auto &body_item : items) { - if(elapsed_time - body_item->last_drawn_time >= 1500) { + if(elapsed_time_sec - body_item->last_drawn_time >= 1.5) { clear_body_item_cache(body_item.get()); } } @@ -600,7 +602,8 @@ namespace QuickMedia { if(item->thumbnail_size.x > 0 && item->thumbnail_size.y > 0) content_size = sf::Vector2f(item->thumbnail_size.x, item->thumbnail_size.y); - sf::Color fallback_color(52, 58, 70, (1.0 - thumbnail_fade_progress) * 255); + sf::Uint8 fallback_fade_alpha = (1.0 - thumbnail_fade_progress) * 255; + sf::Color fallback_color(52, 58, 70, fallback_fade_alpha); if(thumbnail_mask_shader && item->thumbnail_mask_type == ThumbnailMaskType::CIRCLE) { // TODO: Use the mask shader instead, but a vertex shader is also needed for that to pass the vertex coordinates since // shapes dont have texture coordinates. @@ -616,6 +619,14 @@ namespace QuickMedia { window.draw(image_fallback); } + sf::Vector2f loading_icon_size(loading_icon.getTexture()->getSize().x, loading_icon.getTexture()->getSize().y); + auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size); + loading_icon.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y) + (content_size * 0.5f)); + loading_icon.setScale(get_ratio(loading_icon_size, new_loading_icon_size)); + loading_icon.setRotation(-elapsed_time_sec * 400.0); + loading_icon.setColor(sf::Color(255, 255, 255, fallback_fade_alpha)); + window.draw(loading_icon); + if(!has_thumbnail_texture) text_offset_x += image_padding_x + content_size.x; } |