aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index f6800b8..11692aa 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -2,6 +2,7 @@
#include "../include/QuickMedia.hpp"
#include "../include/Scale.hpp"
#include "../plugins/Plugin.hpp"
+#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/OpenGL.hpp>
#include <assert.h>
#include <cmath>
@@ -43,6 +44,8 @@ namespace QuickMedia {
draw_thumbnails(false),
wrap_around(false),
line_seperator_color(sf::Color(32, 37, 43, 255)),
+ body_item_render_callback(nullptr),
+ thumbnail_mask_shader(nullptr),
program(program),
selected_item(0),
prev_selected_item(0),
@@ -179,18 +182,12 @@ namespace QuickMedia {
page_scroll = 0.0f;
}
- // TODO: Optimize with memcpy and changing capacity before loop
void Body::prepend_items(BodyItems new_items) {
- for(auto &body_item : new_items) {
- items.insert(items.begin(), std::move(body_item));
- }
+ items.insert(items.begin(), std::make_move_iterator(new_items.begin()), std::make_move_iterator(new_items.end()));
}
- // TODO: Optimize with memcpy and changing capacity before loop
void Body::append_items(BodyItems new_items) {
- for(auto &body_item : new_items) {
- items.push_back(std::move(body_item));
- }
+ items.insert(items.end(), std::make_move_iterator(new_items.begin()), std::make_move_iterator(new_items.end()));
}
void Body::insert_item_by_timestamp(std::shared_ptr<BodyItem> body_item) {
@@ -383,19 +380,13 @@ namespace QuickMedia {
if(!item->visible)
continue;
- update_dirty_state(item.get(), size);
- item->last_drawn_time = elapsed_time;
-
- float item_height = get_item_height(item.get());
-
- if((after_pos.y - start_y) + item_height + spacing_y > size.y)
- last_item_fully_visible = false;
- else
- last_fully_visible_item = i;
-
if(after_pos.y - start_y >= size.y)
break;
+ float item_height = get_item_height(item.get());
+ update_dirty_state(item.get(), size);
+ item->last_drawn_time = elapsed_time;
+
// 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);
glScissor(scissor_pos.x, (int)window_size.y - (int)scissor_pos.y - (int)scissor_size.y, scissor_size.x, scissor_size.y);
@@ -403,6 +394,11 @@ namespace QuickMedia {
glDisable(GL_SCISSOR_TEST);
after_pos.y += item_height + spacing_y;
++num_visible_items;
+
+ if(after_pos.y - start_y > size.y)
+ last_item_fully_visible = false;
+ else
+ last_fully_visible_item = i;
}
if(last_fully_visible_item == -1)
@@ -576,13 +572,26 @@ namespace QuickMedia {
const float width_ratio = height_ratio * image_scale_ratio;
image.setScale(width_ratio, height_ratio);
image.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
- window.draw(image);
+ if(thumbnail_mask_shader && item->thumbnail_mask_type == ThumbnailMaskType::CIRCLE)
+ window.draw(image, thumbnail_mask_shader);
+ else
+ window.draw(image);
text_offset_x += image_padding_x + width_ratio * image_size.x;
// We want the next image fallback to have the same size as the successful image rendering, because its likely the image fallback will have the same size (for example thumbnails on youtube)
//image_fallback.setSize(sf::Vector2f(width_ratio * image_size.x, height_ratio * image_size.y));
} else if(!item->thumbnail_url.empty()) {
- image_fallback.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
- window.draw(image_fallback);
+ 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.
+ // TODO: Cache circle shape
+ sf::CircleShape circle_shape(image_fallback.getSize().x * 0.5f);
+ circle_shape.setFillColor(sf::Color::White);
+ circle_shape.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
+ window.draw(circle_shape);
+ } else {
+ image_fallback.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
+ window.draw(image_fallback);
+ }
text_offset_x += image_padding_x + image_fallback.getSize().x;
}
}