aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp55
1 files changed, 36 insertions, 19 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index a58b3d8..903c966 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1547,7 +1547,6 @@ namespace QuickMedia {
if(tabs[selected_tab].page->is_single_page()) {
if(tabs[selected_tab].search_bar) tabs[selected_tab].search_bar->clear();
if(new_tabs.size() == 1 && !new_tabs[0].page) {
- tabs[selected_tab].body->clear_thumbnails();
tabs[selected_tab].body = std::move(new_tabs[0].body);
tabs[selected_tab].page->submit_body_item = prev_selected_item;
return;
@@ -1871,7 +1870,6 @@ namespace QuickMedia {
if(associated_data.fetch_status == FetchStatus::LOADING && associated_data.fetch_type == FetchType::SEARCH && associated_data.fetch_future.ready()) {
if(!associated_data.search_text_updated) {
FetchResult fetch_result = associated_data.fetch_future.get();
- tabs[i].body->clear_thumbnails();
tabs[i].body->items = std::move(fetch_result.body_items);
tabs[i].body->select_first_item();
associated_data.fetched_page = 0;
@@ -1924,6 +1922,7 @@ namespace QuickMedia {
window.clear(back_color);
page_loop_render(window, tabs, selected_tab, tab_associated_data[selected_tab], json_chapters, ui_tabs);
+ AsyncImageLoader::get_instance().update();
window.display();
if(!tabs[selected_tab].body->items.empty() && tabs[selected_tab].body->is_last_item_fully_visible())
@@ -2442,6 +2441,8 @@ namespace QuickMedia {
break;
}
+ AsyncImageLoader::get_instance().update();
+
if(!video_loaded) {
window.clear(back_color);
load_sprite.setPosition(window_size.x * 0.5f, window_size.y * 0.5f);
@@ -2697,6 +2698,7 @@ namespace QuickMedia {
load_sprite.setPosition(window_size.x * 0.5f, window_size.y * 0.5f);
load_sprite.setRotation(load_sprite_timer.getElapsedTime().asSeconds() * 400.0);
window.draw(load_sprite);
+ AsyncImageLoader::get_instance().update();
window.display();
}
}
@@ -2952,6 +2954,7 @@ namespace QuickMedia {
current_page = PageType::IMAGES;
break;
}
+ AsyncImageLoader::get_instance().update();
window.display();
int focused_page = image_viewer.get_focused_page();
@@ -3071,6 +3074,8 @@ namespace QuickMedia {
});
};
+ bool redraw = true;
+
Entry comment_input("Press i to begin writing a comment...", &rounded_rectangle_shader);
comment_input.draw_background = false;
comment_input.set_editable(false);
@@ -3151,7 +3156,8 @@ namespace QuickMedia {
sf::Vector2f logo_size(std::floor(plugin_logo.getSize().x * logo_sprite.getScale().x), std::floor(plugin_logo.getSize().y * logo_sprite.getScale().y));
sf::Sprite file_to_upload_sprite;
- auto file_to_upload_thumbnail_data = std::make_shared<ThumbnailData>();
+ bool sprite_applied_texture = false;
+ std::shared_ptr<ThumbnailData> file_to_upload_thumbnail_data;
const float logo_file_to_upload_spacing = std::floor(10.0f * get_ui_scale());
@@ -3163,7 +3169,6 @@ namespace QuickMedia {
sf::Vector2f body_pos;
sf::Vector2f body_size;
- bool redraw = true;
sf::Event event;
std::stack<int> comment_navigation_stack;
@@ -3408,22 +3413,28 @@ namespace QuickMedia {
update_idle_state();
handle_window_close();
- if(!selected_file_for_upload.empty() && file_to_upload_thumbnail_data->loading_state == LoadingState::NOT_LOADED)
- AsyncImageLoader::get_instance().load_thumbnail(selected_file_for_upload, true, sf::Vector2i(logo_size.x, logo_size.y * 4), file_to_upload_thumbnail_data);
-
- if(selected_file_for_upload.empty() && file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE) {
- file_to_upload_thumbnail_data = std::make_unique<ThumbnailData>();
- redraw = true;
+ if(selected_file_for_upload.empty()) {
+ if(file_to_upload_thumbnail_data) {
+ file_to_upload_thumbnail_data.reset();
+ redraw = true;
+ }
+ } else {
+ file_to_upload_thumbnail_data = AsyncImageLoader::get_instance().get_thumbnail(selected_file_for_upload, true, sf::Vector2i(logo_size.x, logo_size.y * 4));
}
- if(file_to_upload_thumbnail_data->loading_state == LoadingState::FINISHED_LOADING && file_to_upload_thumbnail_data->image->getSize().x > 0 && file_to_upload_thumbnail_data->image->getSize().y > 0) {
+ if(file_to_upload_thumbnail_data && file_to_upload_thumbnail_data->loading_state == LoadingState::FINISHED_LOADING && file_to_upload_thumbnail_data->image->getSize().x > 0 && file_to_upload_thumbnail_data->image->getSize().y > 0) {
if(!file_to_upload_thumbnail_data->texture.loadFromImage(*file_to_upload_thumbnail_data->image))
fprintf(stderr, "Warning: failed to load texture for attached file\n");
file_to_upload_thumbnail_data->texture.setSmooth(true);
//room_avatar_thumbnail_data->texture.generateMipmap();
file_to_upload_thumbnail_data->image.reset();
file_to_upload_thumbnail_data->loading_state = LoadingState::APPLIED_TO_TEXTURE;
+ sprite_applied_texture = false;
+ }
+
+ if(file_to_upload_thumbnail_data && file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE && !sprite_applied_texture) {
file_to_upload_sprite.setTexture(file_to_upload_thumbnail_data->texture, true);
+ sprite_applied_texture = true;
sf::Vector2f texture_size_f(file_to_upload_thumbnail_data->texture.getSize().x, file_to_upload_thumbnail_data->texture.getSize().y);
sf::Vector2f image_scale = get_ratio(texture_size_f, clamp_to_size_x(texture_size_f, logo_size));
@@ -3432,7 +3443,7 @@ namespace QuickMedia {
}
float chat_input_height_full_images = logo_size.y;
- if(file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE) {
+ if(file_to_upload_thumbnail_data && file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE) {
const float file_to_upload_height = std::floor(logo_file_to_upload_spacing + file_to_upload_sprite.getTexture()->getSize().y * file_to_upload_sprite.getScale().y);
chat_input_height_full_images += file_to_upload_height;
}
@@ -3554,18 +3565,19 @@ namespace QuickMedia {
} else if(navigation_stage == NavigationStage::REPLYING) {
window.draw(comment_input_shade);
window.draw(logo_sprite);
- if(file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE)
+ if(file_to_upload_thumbnail_data && file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE)
window.draw(file_to_upload_sprite);
comment_input.draw(window);
thread_body->draw(window, body_pos, body_size);
} else if(navigation_stage == NavigationStage::VIEWING_COMMENTS) {
window.draw(comment_input_shade);
window.draw(logo_sprite);
- if(file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE)
+ if(file_to_upload_thumbnail_data && file_to_upload_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE)
window.draw(file_to_upload_sprite);
comment_input.draw(window);
thread_body->draw(window, body_pos, body_size);
}
+ AsyncImageLoader::get_instance().update();
window.display();
}
}
@@ -3672,6 +3684,7 @@ namespace QuickMedia {
inputs[i]->update();
inputs[i]->draw(window, background.get_size() - sf::Vector2f(padding_x * 2.0f, 0.0f), false);
}
+ AsyncImageLoader::get_instance().update();
window.display();
}
}
@@ -4170,7 +4183,6 @@ namespace QuickMedia {
std::string room_topic = current_room->get_topic();
room_name_text.setString(sf::String::fromUtf8(room_name.begin(), room_name.end()));
room_topic_text.setString(sf::String::fromUtf8(room_topic.begin(), room_topic.end()));
- room_avatar_thumbnail_data = std::make_shared<ThumbnailData>();
read_marker_timeout_ms = 0;
redraw = true;
@@ -5215,8 +5227,8 @@ namespace QuickMedia {
typing_state_queue.push(false);
}
- 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, AVATAR_THUMBNAIL_SIZE, room_avatar_thumbnail_data);
+ if(!current_room->body_item->thumbnail_url.empty())
+ room_avatar_thumbnail_data = AsyncImageLoader::get_instance().get_thumbnail(current_room->body_item->thumbnail_url, false, AVATAR_THUMBNAIL_SIZE);
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))
@@ -5225,8 +5237,10 @@ namespace QuickMedia {
//room_avatar_thumbnail_data->texture.generateMipmap();
room_avatar_thumbnail_data->image.reset();
room_avatar_thumbnail_data->loading_state = LoadingState::APPLIED_TO_TEXTURE;
- room_avatar_sprite.setTexture(room_avatar_thumbnail_data->texture, true);
+ }
+ if(room_avatar_thumbnail_data->loading_state == LoadingState::APPLIED_TO_TEXTURE && !room_avatar_sprite.getTexture()) {
+ room_avatar_sprite.setTexture(room_avatar_thumbnail_data->texture, true);
auto texture_size = room_avatar_sprite.getTexture()->getSize();
if(texture_size.x > 0 && texture_size.y > 0) {
float width_ratio = (float)texture_size.x / (float)texture_size.y;
@@ -5234,6 +5248,7 @@ namespace QuickMedia {
float width_scale = height_scale * width_ratio;
room_avatar_sprite.setScale(width_scale * get_ui_scale(), height_scale * get_ui_scale());
}
+ redraw = true;
}
const int selected_tab = ui_tabs.get_selected();
@@ -5549,6 +5564,7 @@ namespace QuickMedia {
}
}
+ AsyncImageLoader::get_instance().update();
window.display();
if(selected_tab == MESSAGES_TAB_INDEX)
@@ -6158,6 +6174,7 @@ namespace QuickMedia {
window.draw(status_text);
window.draw(filename_text);
window.draw(download_speed_text);
+ AsyncImageLoader::get_instance().update();
window.display();
frame_timer.restart();
}
@@ -6233,7 +6250,6 @@ namespace QuickMedia {
if(task_result == TaskResult::TRUE) {
if(!new_tabs.empty()) {
- file_manager_body->clear_thumbnails();
file_manager_body->items = std::move(new_tabs[0].body->items);
file_manager_body->select_first_item();
search_bar->clear();
@@ -6371,6 +6387,7 @@ namespace QuickMedia {
save_button.draw(window);
file_name_entry.draw(window);
+ AsyncImageLoader::get_instance().update();
window.display();
}