From 8032c13df9eafd1539112dc6f72eb9e1a695ad31 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 10 Aug 2019 05:01:51 +0200 Subject: Add drop shadow to items --- README.md | 3 ++- include/SearchBar.hpp | 1 + src/Body.cpp | 15 ++++++++++----- src/SearchBar.cpp | 8 ++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 40b8493..369da9a 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,5 @@ Add scrollbar.\ Add option to scale image to window size.\ The search should wait until there are search results before clearing the search field and selecting the search suggestion.\ Full-screening a video doesn't work.\ -Somehow deal with youtube banning ip when searching too often. \ No newline at end of file +Somehow deal with youtube banning ip when searching too often.\ +Optimize shadow rendering for items (Right now they fill too much space that is behind items). It should also be a blurry shadow. \ No newline at end of file diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index 46f4383..0ddcac9 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -28,6 +28,7 @@ namespace QuickMedia { private: sf::Text text; sf::RectangleShape background; + sf::RectangleShape background_shadow; bool show_placeholder; bool updated_search; sf::Clock time_since_search_update; diff --git a/src/Body.cpp b/src/Body.cpp index 6051e02..1165399 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -126,8 +126,10 @@ namespace QuickMedia { sf::RectangleShape item_background; item_background.setFillColor(front_color); - item_background.setOutlineThickness(1.0f); - item_background.setOutlineColor(sf::Color(63, 65, 67)); + //item_background.setOutlineThickness(1.0f); + //item_background.setOutlineColor(sf::Color(13, 15, 17)); + sf::RectangleShape item_background_shadow; + item_background_shadow.setFillColor(sf::Color(13, 15, 17)); sf::RectangleShape selected_border; selected_border.setFillColor(sf::Color::Red); @@ -143,7 +145,7 @@ namespace QuickMedia { float row_height = font_height; if(draw_thumbnails) row_height = image_height; - const float total_row_height = row_height + 10.0f; + const float total_row_height = row_height + 15.0f; const int max_visible_rows = size.y / total_row_height - 1; // Find the starting row that can be drawn to make selected row visible as well @@ -187,13 +189,16 @@ namespace QuickMedia { selected_border.setSize(sf::Vector2f(selected_border_width, row_height)); window.draw(selected_border); item_pos.x += selected_border_width; - item_background.setFillColor(front_color); + item_background.setFillColor(sf::Color(63, 65, 67)); } else { - item_background.setFillColor(sf::Color(38, 40, 42)); + item_background.setFillColor(front_color); } item_pos.x = std::floor(item_pos.x); item_pos.y = std::floor(item_pos.y); + item_background_shadow.setPosition(item_pos + sf::Vector2f(5.0f, 5.0f)); + item_background_shadow.setSize(sf::Vector2f(size.x, row_height)); + window.draw(item_background_shadow); item_background.setPosition(item_pos); item_background.setSize(sf::Vector2f(size.x, row_height)); window.draw(item_background); diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 5554a37..ae229b5 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -20,11 +20,14 @@ namespace QuickMedia { text.setFillColor(text_placeholder_color); background.setFillColor(front_color); background.setPosition(padding_horizontal, padding_vertical); - //background.setOutlineThickness(1.0f); - //background.setOutlineColor(sf::Color(0, 85, 119)); + background_shadow.setFillColor(sf::Color(13, 15, 17)); + background_shadow.setPosition(background.getPosition() + sf::Vector2f(5.0f, 5.0f)); + //background.setOutlineThickness(2.0f); + //background.setOutlineColor(sf::Color(13, 15, 17)); } void SearchBar::draw(sf::RenderWindow &window) { + window.draw(background_shadow); window.draw(background); window.draw(text); } @@ -45,6 +48,7 @@ namespace QuickMedia { float font_height = text.getCharacterSize() + 8.0f; float rect_height = std::floor(font_height + background_margin_vertical * 2.0f); background.setSize(sf::Vector2f(std::floor(window_size.x - padding_horizontal * 2.0f), rect_height)); + background_shadow.setSize(background.getSize()); text.setPosition(std::floor(padding_horizontal + background_margin_horizontal), std::floor(padding_vertical + background_margin_vertical)); } -- cgit v1.2.3