From 5b8c2237147336fd44b9deaa24e933abd797f8a3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 23 Sep 2020 06:36:04 +0200 Subject: Testing redesign --- external/RoundedRectangleShape.cpp | 100 ++++++++++++++++++++++++ external/RoundedRectangleShape.hpp | 151 +++++++++++++++++++++++++++++++++++++ include/Body.hpp | 1 + include/SearchBar.hpp | 4 +- src/Body.cpp | 33 ++++---- src/QuickMedia.cpp | 11 ++- src/SearchBar.cpp | 22 ++++-- 7 files changed, 291 insertions(+), 31 deletions(-) create mode 100644 external/RoundedRectangleShape.cpp create mode 100644 external/RoundedRectangleShape.hpp diff --git a/external/RoundedRectangleShape.cpp b/external/RoundedRectangleShape.cpp new file mode 100644 index 0000000..3dc3274 --- /dev/null +++ b/external/RoundedRectangleShape.cpp @@ -0,0 +1,100 @@ +//////////////////////////////////////////////////////////// +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include "RoundedRectangleShape.hpp" +#include + +namespace sf +{ +//////////////////////////////////////////////////////////// +RoundedRectangleShape::RoundedRectangleShape(const Vector2f& size, float radius, unsigned int cornerPointCount) +{ + mySize = size; + myRadius = radius; + myCornerPointCount = cornerPointCount; + update(); +} + +//////////////////////////////////////////////////////////// +void RoundedRectangleShape::setSize(const Vector2f& size) +{ + mySize = size; + update(); +} + +//////////////////////////////////////////////////////////// +const Vector2f& RoundedRectangleShape::getSize() const +{ + return mySize; +} + +//////////////////////////////////////////////////////////// +void RoundedRectangleShape::setCornersRadius(float radius) +{ + myRadius = radius; + update(); +} + +//////////////////////////////////////////////////////////// +float RoundedRectangleShape::getCornersRadius() const +{ + return myRadius; +} + +//////////////////////////////////////////////////////////// +void RoundedRectangleShape::setCornerPointCount(unsigned int count) +{ + myCornerPointCount = count; + update(); +} + +//////////////////////////////////////////////////////////// +std::size_t RoundedRectangleShape::getPointCount() const +{ + return myCornerPointCount*4; +} + +//////////////////////////////////////////////////////////// +sf::Vector2f RoundedRectangleShape::getPoint(std::size_t index) const +{ + if(index >= myCornerPointCount*4) + return sf::Vector2f(0,0); + + float deltaAngle = 90.0f/(myCornerPointCount-1); + sf::Vector2f center; + unsigned int centerIndex = index/myCornerPointCount; + static const float pi = 3.141592654f; + + switch(centerIndex) + { + case 0: center.x = mySize.x - myRadius; center.y = myRadius; break; + case 1: center.x = myRadius; center.y = myRadius; break; + case 2: center.x = myRadius; center.y = mySize.y - myRadius; break; + case 3: center.x = mySize.x - myRadius; center.y = mySize.y - myRadius; break; + } + + return sf::Vector2f(myRadius*cos(deltaAngle*(index-centerIndex)*pi/180)+center.x, + -myRadius*sin(deltaAngle*(index-centerIndex)*pi/180)+center.y); +} +} // namespace sf \ No newline at end of file diff --git a/external/RoundedRectangleShape.hpp b/external/RoundedRectangleShape.hpp new file mode 100644 index 0000000..ab1c880 --- /dev/null +++ b/external/RoundedRectangleShape.hpp @@ -0,0 +1,151 @@ +//////////////////////////////////////////////////////////// +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef ROUNDEDRECTANGLESHAPE_HPP +#define ROUNDEDRECTANGLESHAPE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// \brief Specialized shape representing a rectangle +/// with rounded corners +//////////////////////////////////////////////////////////// +class RoundedRectangleShape : public sf::Shape +{ + public: + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// \param size Size of the rectangle + /// \param radius Radius for each rounded corner + /// \param cornerPointCount Number of points of each corner + /// + //////////////////////////////////////////////////////////// + explicit RoundedRectangleShape(const Vector2f& size = Vector2f(0, 0), float radius = 0, unsigned int cornerPointCount = 0); + + //////////////////////////////////////////////////////////// + /// \brief Set the size of the rounded rectangle + /// + /// \param size New size of the rounded rectangle + /// + /// \see getSize + /// + //////////////////////////////////////////////////////////// + void setSize(const Vector2f& size); + + //////////////////////////////////////////////////////////// + /// \brief Get the size of the rounded rectangle + /// + /// \return Size of the rounded rectangle + /// + /// \see setSize + /// + //////////////////////////////////////////////////////////// + const Vector2f& getSize() const; + + //////////////////////////////////////////////////////////// + /// \brief Set the radius of the rounded corners + /// + /// \param radius Radius of the rounded corners + /// + /// \see getCornersRadius + /// + //////////////////////////////////////////////////////////// + void setCornersRadius(float radius); + + //////////////////////////////////////////////////////////// + /// \brief Get the radius of the rounded corners + /// + /// \return Radius of the rounded corners + /// + /// \see setCornersRadius + /// + //////////////////////////////////////////////////////////// + float getCornersRadius() const; + + //////////////////////////////////////////////////////////// + /// \brief Set the number of points of each corner + /// + /// \param count New number of points of the rounded rectangle + /// + /// \see getPointCount + /// + //////////////////////////////////////////////////////////// + void setCornerPointCount(unsigned int count); + + //////////////////////////////////////////////////////////// + /// \brief Get the number of points defining the rounded rectangle + /// + /// \return Number of points of the rounded rectangle + /// + //////////////////////////////////////////////////////////// + virtual std::size_t getPointCount() const; + + //////////////////////////////////////////////////////////// + /// \brief Get a point of the rounded rectangle + /// + /// The result is undefined if \a index is out of the valid range. + /// + /// \param index Index of the point to get, in range [0 .. GetPointCount() - 1] + /// + /// \return Index-th point of the shape + /// + //////////////////////////////////////////////////////////// + virtual sf::Vector2f getPoint(std::size_t index) const; + + private: + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Vector2f mySize; + float myRadius; + unsigned int myCornerPointCount; +}; +} +#endif // ROUNDEDRECTANGLESHAPE_HPP + +//////////////////////////////////////////////////////////// +/// \class sf::RoundedRectangleShape +/// \ingroup graphics +/// +/// This class inherits all the functions of sf::Transformable +/// (position, rotation, scale, bounds, ...) as well as the +/// functions of sf::Shape (outline, color, texture, ...). +/// +/// Usage example: +/// \code +/// sf::RoundedRectangleShape roundedRectangle; +/// rectangle.setSize(sf::Vector2f(100, 50)); +/// rectangle.setCornersRadius(5); +/// rectangle.setOutlineThickness(5); +/// rectangle.setPosition(10, 20); +/// ... +/// window.draw(rectangle); +/// \endcode +/// +/// \see sf::Shape, sf::CircleShape, sf::ConvexShape +/// +//////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/include/Body.hpp b/include/Body.hpp index 4e30684..2cd7b5f 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -107,6 +107,7 @@ namespace QuickMedia { // Set to {0, 0} to disable resizing sf::Vector2i thumbnail_resize_target_size; sf::Vector2f thumbnail_fallback_size; + sf::Color line_seperator_color; private: struct ThumbnailData { bool referenced; diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index ac15a90..b4abd77 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -5,6 +5,7 @@ #include #include #include +#include "../external/RoundedRectangleShape.hpp" #include namespace QuickMedia { @@ -28,6 +29,7 @@ namespace QuickMedia { void set_to_autocomplete(); void set_autocomplete_text(const std::string &text); void set_vertical_position(float vertical_pos); + void set_background_color(sf::Color color); float getBottom() const; float getBottomWithoutShadow() const; @@ -47,7 +49,7 @@ namespace QuickMedia { private: sf::Text text; sf::Text autocomplete_text; - sf::RectangleShape background; + sf::RoundedRectangleShape background; sf::RectangleShape background_shadow; sf::RectangleShape shade; sf::RectangleShape caret; diff --git a/src/Body.cpp b/src/Body.cpp index d650d20..238ea8c 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -4,17 +4,18 @@ #include "../include/base64_url.hpp" #include "../include/ImageUtils.hpp" #include "../plugins/Plugin.hpp" +#include "../external/RoundedRectangleShape.hpp" #include #include #include #include #include -const sf::Color front_color(43, 45, 47); +const sf::Color front_color(32, 36, 42); const sf::Color back_color(33, 35, 37); namespace QuickMedia { - BodyItem::BodyItem(std::string _title): visible(true), dirty(false), dirty_description(false), thumbnail_is_local(false), background_color(front_color) { + BodyItem::BodyItem(std::string _title): visible(true), dirty(false), dirty_description(false), thumbnail_is_local(false), background_color(sf::Color::Transparent) { set_title(std::move(_title)); } @@ -49,6 +50,7 @@ namespace QuickMedia { replies_text("", *font, 14), draw_thumbnails(false), wrap_around(false), + line_seperator_color(sf::Color(32, 37, 43, 255)), program(program), loading_thumbnail(false), selected_item(0) @@ -257,7 +259,7 @@ namespace QuickMedia { Path thumbnail_path = get_cache_dir().join("thumbnails").join(base64_url::encode(url)); std::string texture_data; - if(file_get_content(thumbnail_path, texture_data) == 0) { + if(thumbnail_resize_target_size.x != 0 && thumbnail_resize_target_size.y != 0 && file_get_content(thumbnail_path, texture_data) == 0) { fprintf(stderr, "Loaded %s from thumbnail cache\n", url.c_str()); result->loadFromMemory(texture_data.data(), texture_data.size()); loading_thumbnail = false; @@ -337,15 +339,12 @@ namespace QuickMedia { sf::Sprite image; - sf::RectangleShape item_background; + sf::RoundedRectangleShape item_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10); item_background.setFillColor(front_color); //item_background.setOutlineThickness(1.0f); //item_background.setOutlineColor(sf::Color(13, 15, 17)); sf::RectangleShape item_background_shadow; - item_background_shadow.setFillColor(sf::Color(23, 25, 27)); - - sf::RectangleShape selected_border; - selected_border.setFillColor(sf::Color(0, 85, 119)); + item_background_shadow.setFillColor(line_seperator_color); int num_items = items.size(); if(num_items == 0) @@ -465,7 +464,7 @@ namespace QuickMedia { //selected_border.setSize(sf::Vector2f(selected_border_width, item_height)); //window.draw(selected_border); //item_pos.x += selected_border_width; - item_background.setFillColor(sf::Color(0, 85, 119)); + item_background.setFillColor(sf::Color(32, 37, 43)); } else { item_background.setFillColor(item->background_color); } @@ -473,17 +472,15 @@ namespace QuickMedia { item_pos.x = std::floor(item_pos.x); item_pos.y = std::floor(item_pos.y); - item_background_shadow.setPosition(item_pos + sf::Vector2f(size.x, 0.0f) + sf::Vector2f(0.0, 5.0f)); - item_background_shadow.setSize(sf::Vector2f(5.0f, item_height)); - window.draw(item_background_shadow); - - item_background_shadow.setPosition(item_pos + sf::Vector2f(0.0f, item_height) + sf::Vector2f(5.0, 0.0f)); - item_background_shadow.setSize(sf::Vector2f(size.x - 5.0f, 5.0f)); + item_background_shadow.setSize(sf::Vector2f(std::max(0.0f, size.x - 20.0f), 1.0f)); + item_background_shadow.setPosition(item_pos + sf::Vector2f(10.0f, std::floor(item_height + spacing_y * 0.5f))); window.draw(item_background_shadow); - item_background.setPosition(item_pos); - item_background.setSize(sf::Vector2f(size.x, item_height)); - window.draw(item_background); + if(i == selected_item) { + item_background.setPosition(item_pos); + item_background.setSize(sf::Vector2f(size.x, item_height)); + window.draw(item_background); + } float text_offset_x = padding_x; if(draw_thumbnails) { diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index a2fd42b..ce5a414 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -34,13 +34,13 @@ #include #include -static const sf::Color back_color(34, 34, 34); +static const sf::Color back_color(21, 25, 30); static const int DOUBLE_CLICK_TIME = 500; static const std::string fourchan_google_captcha_api_key = "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc"; static const float tab_text_size = 18.0f; static const float tab_height = tab_text_size + 10.0f; -static const sf::Color tab_selected_color(0, 85, 119); -static const sf::Color tab_unselected_color(43, 45, 47); +static const sf::Color tab_selected_color(55, 60, 68); +static const sf::Color tab_unselected_color(32, 36, 42); // Prevent writing to broken pipe from exiting the program static void sigpipe_handler(int) { @@ -2681,7 +2681,7 @@ namespace QuickMedia { } sf::RectangleShape captcha_selection_rect; captcha_selection_rect.setOutlineThickness(5.0f); - captcha_selection_rect.setOutlineColor(sf::Color(0, 85, 119)); + captcha_selection_rect.setOutlineColor(sf::Color(55, 60, 68)); // TODO: Draw only the outline instead of a transparent rectangle captcha_selection_rect.setFillColor(sf::Color::Transparent); @@ -3159,6 +3159,7 @@ namespace QuickMedia { messages_tab.type = ChatTabType::MESSAGES; messages_tab.body = std::make_unique(this, &font, &bold_font); messages_tab.body->draw_thumbnails = true; + messages_tab.body->line_seperator_color = sf::Color::Transparent; messages_tab.text = sf::Text("Messages", font, tab_text_size); tabs.push_back(std::move(messages_tab)); @@ -3166,6 +3167,7 @@ namespace QuickMedia { rooms_tab.type = ChatTabType::ROOMS; rooms_tab.body = std::make_unique(this, &font, &bold_font); rooms_tab.body->draw_thumbnails = true; + rooms_tab.body->line_seperator_color = sf::Color::Transparent; rooms_tab.text = sf::Text("Rooms", font, tab_text_size); tabs.push_back(std::move(rooms_tab)); @@ -3212,6 +3214,7 @@ namespace QuickMedia { } SearchBar chat_input(font, &plugin_logo, "Send a message..."); + chat_input.set_background_color(sf::Color::Transparent); // TODO: Filer for rooms and settings chat_input.onTextUpdateCallback = nullptr; diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index f790de8..b04a9a1 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -6,8 +6,8 @@ #include const sf::Color text_placeholder_color(255, 255, 255, 100); -const sf::Color front_color(34, 34, 34); -const float background_margin_horizontal = 8.0f; +const sf::Color front_color(55, 60, 68); +const float background_margin_horizontal = 15.0f; const float background_margin_vertical = 4.0f; const float PADDING_HORIZONTAL = 50.0f; const float padding_vertical = 20.0f; @@ -23,6 +23,7 @@ namespace QuickMedia { caret_visible(true), text(placeholder, font, 18), autocomplete_text("", font, 18), + background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10), placeholder_str(placeholder), show_placeholder(true), updated_search(false), @@ -35,9 +36,10 @@ namespace QuickMedia { text.setFillColor(text_placeholder_color); autocomplete_text.setFillColor(text_placeholder_color); background.setFillColor(front_color); + //background.setCornersRadius(5); background_shadow.setFillColor(sf::Color(23, 25, 27)); //background_shadow.setPosition(background.getPosition() + sf::Vector2f(5.0f, 5.0f)); - shade.setFillColor(sf::Color(0, 85, 119)); + shade.setFillColor(sf::Color(55, 60, 68)); //background.setOutlineThickness(1.0f); //background.setOutlineColor(sf::Color(13, 15, 17)); if(plugin_logo && plugin_logo->getNativeHandle() != 0) @@ -52,7 +54,7 @@ namespace QuickMedia { } if(draw_shadow) window.draw(background_shadow); - window.draw(shade); + //window.draw(shade); window.draw(background); // TODO: Render starting from the character after text length window.draw(autocomplete_text); @@ -61,13 +63,13 @@ namespace QuickMedia { sf::Text masked_text(std::move(masked_str), *text.getFont(), text.getCharacterSize()); masked_text.setPosition(text.getPosition()); window.draw(masked_text); - caret.setPosition(masked_text.findCharacterPos(masked_text.getString().getSize())); + caret.setPosition(masked_text.findCharacterPos(masked_text.getString().getSize()) + sf::Vector2f(0.0f, 2.0f)); } else { window.draw(text); if(show_placeholder || text.getString().isEmpty()) - caret.setPosition(text.getPosition() - sf::Vector2f(2.0f, 0.0f)); + caret.setPosition(text.getPosition() - sf::Vector2f(2.0f, 0.0f) + sf::Vector2f(0.0f, 2.0f)); else - caret.setPosition(text.findCharacterPos(text.getString().getSize())); + caret.setPosition(text.findCharacterPos(text.getString().getSize()) + sf::Vector2f(0.0f, 2.0f)); } if(caret_visible) @@ -124,7 +126,7 @@ namespace QuickMedia { background.setSize(sf::Vector2f(width, rect_height)); shade.setSize(sf::Vector2f(window_size.x, padding_vertical + rect_height + padding_vertical)); - caret.setSize(sf::Vector2f(2.0f, text.getCharacterSize() + 8.0f)); + caret.setSize(sf::Vector2f(2.0f, text.getCharacterSize() + 2.0f)); background_shadow.setSize(sf::Vector2f(window_size.x, 5.0f)); background.setPosition(offset_x, padding_vertical + vertical_pos); @@ -242,6 +244,10 @@ namespace QuickMedia { } } + void SearchBar::set_background_color(sf::Color color) { + background.setFillColor(color); + } + void SearchBar::clear_autocomplete_if_text_not_substring() { const sf::String &text_str = text.getString(); const sf::String &autocomplete_str = autocomplete_text.getString(); -- cgit v1.2.3