aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-07-23 12:52:59 +0200
committerdec05eba <dec05eba@protonmail.com>2021-07-23 12:55:00 +0200
commit5a2bb738b05253287438df9f1a0bdb95fea92dd9 (patch)
treefd5b576925aead389883a6c78f6f87c383d8b825 /src/Body.cpp
parentd2e0c0a4d819b836690d3c50ddcb3639377abc70 (diff)
Matrix: fix crash when pinned message is removed quickly
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index b11cb51..10911e4 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -922,10 +922,10 @@ namespace QuickMedia {
return -1;
}
- void Body::draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item, bool is_embedded) {
+ void Body::draw_item(sf::RenderWindow &window, std::shared_ptr<BodyItem> &item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item, bool is_embedded) {
// TODO: What about when |card_view| is used?
item->keep_alive_frames = 3;
- get_item_height(item, size.x, true, false, false, -1);
+ get_item_height(item.get(), size.x, true, false, false, -1);
draw_item(window, item, pos, size, size.y + body_spacing[body_theme].spacing_y, -1, Json::Value::nullSingleton(), include_embedded_item);
}
@@ -1001,7 +1001,7 @@ namespace QuickMedia {
// TODO: Improve performance. Skip items that are obviously not visible or anywhere near the body. Limit loop to 100-200 items around the selected item
while(index != -1) {
- BodyItem *item = items[index].get();
+ std::shared_ptr<BodyItem> &item = items[index];
assert(item->visible);
int prev_index;
@@ -1013,11 +1013,11 @@ namespace QuickMedia {
prev_body_item = items[prev_index].get();
}
- const bool merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item, item);
+ const bool merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item, item.get());
if(attach_side == AttachSide::TOP && merge_with_previous)
pos.y -= body_spacing[body_theme].spacing_y;
- get_item_height(item, size.x, false, true, merge_with_previous, index);
+ get_item_height(item.get(), size.x, false, true, merge_with_previous, index);
float top_y;
if(attach_side == AttachSide::TOP)
@@ -1039,7 +1039,7 @@ namespace QuickMedia {
const bool is_item_visible_in_body = top_y + item->loaded_height >= 0.0f && top_y <= size.y;
if(is_item_visible_in_body || index == selected_item) {
- get_item_height(item, size.x, true, true, merge_with_previous, index);
+ get_item_height(item.get(), size.x, true, true, merge_with_previous, index);
if(attach_side == AttachSide::BOTTOM)
pos.y -= (item->loaded_height + body_spacing[body_theme].spacing_y);
//page_scroll += add_height;
@@ -1075,7 +1075,7 @@ namespace QuickMedia {
pos.y -= (item->loaded_height + body_spacing[body_theme].spacing_y);
if(item->keep_alive_frames == 0) {
- clear_body_item_cache(item);
+ clear_body_item_cache(item.get());
// TODO: Make sure the embedded item is not referencing another item in the |items| list
if(item->embedded_item)
clear_body_item_cache(item->embedded_item.get());
@@ -1088,7 +1088,7 @@ namespace QuickMedia {
pos.y += body_spacing[body_theme].spacing_y;
if(attach_side == AttachSide::TOP) {
- prev_body_item = item;
+ prev_body_item = item.get();
index = get_next_visible_item(index);
} else {
index = prev_index;
@@ -1136,9 +1136,9 @@ namespace QuickMedia {
sf::Vector2f pos_offset(space_left_column_each, page_scroll);
while(item_index < num_items) {
- BodyItem *item = items[item_index].get();
+ std::shared_ptr<BodyItem> &item = items[item_index];
- get_item_height(item, card_max_image_size.x, false, false, false, item_index);
+ get_item_height(item.get(), card_max_image_size.x, false, false, false, item_index);
int item_height = item->loaded_height;
item_height = std::min(card_height, item_height + ((draw_thumbnails && !item->thumbnail_url.empty()) ? card_image_text_padding : 0) + card_padding_y * 2 + 5);
row_max_height = std::max(row_max_height, item_height);
@@ -1164,12 +1164,12 @@ namespace QuickMedia {
if(body_item_render_callback)
body_item_render_callback(item);
- sf::Vector2i thumbnail_size = get_item_thumbnail_size(item);
+ sf::Vector2i thumbnail_size = get_item_thumbnail_size(item.get());
std::shared_ptr<ThumbnailData> item_thumbnail;
if(draw_thumbnails && !item->thumbnail_url.empty())
item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, thumbnail_size);
- get_item_height(item, card_max_image_size.x, true, false, false, item_index);
+ get_item_height(item.get(), card_max_image_size.x, true, false, false, item_index);
item_height = item->loaded_height;
item_height = std::min(card_height, item_height + (item_thumbnail ? card_image_text_padding : 0) + card_padding_y * 2 + 5);
row_max_height = std::max(row_max_height, item_height);
@@ -1274,7 +1274,7 @@ namespace QuickMedia {
handle_item_render(pos + pos_offset, card_width, item_height, item_index);
if(item->keep_alive_frames == 0) {
- clear_body_item_cache(item);
+ clear_body_item_cache(item.get());
// TODO: Make sure the embedded item is not referencing another item in the |items| list
if(item->embedded_item)
clear_body_item_cache(item->embedded_item.get());
@@ -1307,8 +1307,8 @@ namespace QuickMedia {
item_background_target_size = sf::Vector2f(card_width, row_max_height);
}
- void Body::draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item, bool merge_with_previous) {
- sf::Vector2i thumbnail_size = get_item_thumbnail_size(item);
+ void Body::draw_item(sf::RenderWindow &window, std::shared_ptr<BodyItem> &item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item, bool merge_with_previous) {
+ sf::Vector2i thumbnail_size = get_item_thumbnail_size(item.get());
std::shared_ptr<ThumbnailData> item_thumbnail;
if(draw_thumbnails && !merge_with_previous && !item->thumbnail_url.empty())
item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, thumbnail_size);
@@ -1422,7 +1422,7 @@ namespace QuickMedia {
if(item->embedded_item) {
sf::Vector2f embedded_item_pos(std::floor(item_pos.x + text_offset_x + embedded_item_border_width + body_spacing[body_theme].padding_x), std::floor(item_pos.y + body_spacing[body_theme].embedded_item_padding_y + 6.0f));
sf::Vector2f embedded_item_size(embedded_item_width, embedded_item_height);
- draw_item(window, item->embedded_item.get(), embedded_item_pos, embedded_item_size, false, true);
+ draw_item(window, item->embedded_item, embedded_item_pos, embedded_item_size, false, true);
} else {
embedded_item_load_text.setString(embedded_item_status_to_string(item->embedded_item_status));
embedded_item_load_text.setPosition(std::floor(item_pos.x + text_offset_x + embedded_item_border_width + body_spacing[body_theme].padding_x), std::floor(item_pos.y + embedded_item_height * 0.5f - (body_spacing[body_theme].embedded_item_font_size + 5.0f) * 0.5f + 6.0f));