aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-04-21 13:29:01 +0200
committerdec05eba <dec05eba@protonmail.com>2021-04-21 13:29:01 +0200
commit3ac1120fd40b84507c51f867559bd05adff4eecf (patch)
tree32a3d7e037dd0fa07f764e563cfaa304470ad7f1 /src/Body.cpp
parent0f151afa58c1f725a652eaa4444ce3e2b2509770 (diff)
Use shader for rounded rectangle, improve circle shader
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 534f2b5..a84256e 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -113,7 +113,7 @@ namespace QuickMedia {
reactions.push_back(std::move(reaction));
}
- Body::Body(Program *program, sf::Texture &loading_icon_texture) :
+ Body::Body(Program *program, sf::Texture &loading_icon_texture, sf::Shader *rounded_rectangle_shader) :
progress_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(14 * get_ui_scale())),
replies_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(14 * get_ui_scale())),
embedded_item_load_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), embedded_item_font_size),
@@ -126,19 +126,20 @@ namespace QuickMedia {
selected_item(0),
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),
first_item_fully_visible(true),
last_item_fully_visible(true),
first_fully_visible_item(-1),
- last_fully_visible_item(-1)
+ last_fully_visible_item(-1),
+ item_background(sf::Vector2f(1.0f, 1.0f), 10.0f, sf::Color(55, 60, 68), rounded_rectangle_shader),
+ reaction_background(sf::Vector2f(1.0f, 1.0f), 10.0f, sf::Color(33, 37, 44), rounded_rectangle_shader)
{
+ assert(rounded_rectangle_shader);
progress_text.setFillColor(sf::Color::White);
replies_text.setFillColor(sf::Color(129, 162, 190));
thumbnail_max_size.x = 250;
thumbnail_max_size.y = 141;
- 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);
}
@@ -982,9 +983,9 @@ namespace QuickMedia {
//window.draw(item_separator);
if(item_index == selected_item) {
- item_background.setPosition(item_pos);
- item_background.setSize(sf::Vector2f(size.x, item_height));
- window.draw(item_background);
+ item_background.set_position(item_pos);
+ item_background.set_size(sf::Vector2f(size.x, item_height));
+ item_background.draw(window);
}
float text_offset_x = padding_x;
@@ -1011,10 +1012,12 @@ namespace QuickMedia {
image.setColor(sf::Color(255, 255, 255, thumbnail_fade_progress * 255));
image.setScale(image_scale);
image.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
- if(thumbnail_mask_shader && item->thumbnail_mask_type == ThumbnailMaskType::CIRCLE)
+ if(thumbnail_mask_shader && item->thumbnail_mask_type == ThumbnailMaskType::CIRCLE) {
+ thumbnail_mask_shader->setUniform("resolution", new_image_size);
window.draw(image, thumbnail_mask_shader);
- else
+ } else {
window.draw(image);
+ }
text_offset_x += image_padding_x + new_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));
@@ -1113,8 +1116,6 @@ namespace QuickMedia {
}
if(!item->reactions.empty() && include_embedded_item) {
- sf::RoundedRectangleShape reaction_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10);
- reaction_background.setFillColor(sf::Color(33, 37, 44));
float reaction_offset_x = 0.0f;
item_pos.y += reaction_padding_y;
float reaction_max_height = 0.0f;
@@ -1125,9 +1126,9 @@ namespace QuickMedia {
reaction.text->updateGeometry();
reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight());
reaction.text->setPosition(std::floor(item_pos.x + text_offset_x + reaction_offset_x + reaction_background_padding_x), std::floor(item_pos.y + padding_y - 4.0f + reaction_background_padding_y));
- reaction_background.setPosition(std::floor(item_pos.x + text_offset_x + reaction_offset_x), std::floor(item_pos.y + padding_y));
- reaction_background.setSize(sf::Vector2f(reaction.text->getWidth() + reaction_background_padding_x * 2.0f, reaction.text->getHeight() + reaction_background_padding_y * 2.0f));
- window.draw(reaction_background);
+ reaction_background.set_position(sf::Vector2f(std::floor(item_pos.x + text_offset_x + reaction_offset_x), std::floor(item_pos.y + padding_y)));
+ reaction_background.set_size(sf::Vector2f(reaction.text->getWidth() + reaction_background_padding_x * 2.0f, reaction.text->getHeight() + reaction_background_padding_y * 2.0f));
+ reaction_background.draw(window);
reaction_offset_x += reaction.text->getWidth() + reaction_background_padding_x * 2.0f + reaction_spacing_x;
reaction.text->draw(window);
if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > size.x && i < (int)item->reactions.size() - 1) {