diff options
Diffstat (limited to 'src/Suggestions.cpp')
-rw-r--r-- | src/Suggestions.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Suggestions.cpp b/src/Suggestions.cpp new file mode 100644 index 0000000..113cd7e --- /dev/null +++ b/src/Suggestions.cpp @@ -0,0 +1,54 @@ +#include "../include/Suggestions.hpp" +#include "../include/Text.hpp" +#include "../include/ResourceCache.hpp" +#include "../include/Settings.hpp" +#include "../include/ColorScheme.hpp" +#include "../include/Chatbar.hpp" +#include <cmath> + +namespace dchat +{ + static const char *FONT_PATH = "fonts/Nunito-Regular.ttf"; + static float FONT_SCALING = 18.0f; + + static sf::Vector2f floor(const sf::Vector2f &vec) + { + return { std::floor(vec.x), std::floor(vec.y) }; + } + + void Suggestions::show(const std::vector<std::string> &_texts) + { + for(const auto &text : _texts) + { + sf::String str = sf::String::fromUtf8(text.begin(), text.end()); + texts.emplace_back(std::make_unique<Text>(str, ResourceCache::getFont(FONT_PATH), FONT_SCALING * Settings::getScaling(), 0.0f, false)); + } + } + + void Suggestions::draw(sf::RenderWindow &window, Cache &cache) + { + if(texts.empty()) return; + + sf::Vector2f position = Chatbar::getInputPosition(window); + sf::Vector2f size = Chatbar::getInputSize(window); + size.y = FONT_SCALING * Settings::getScaling() * (1 + texts.size()) * 1.7f; + position.y -= size.y; + + position = floor(position); + size = floor(size); + + sf::RectangleShape rect(size); + rect.setPosition(position); + rect.setFillColor(ColorScheme::getPanelColor()); + window.draw(rect); + + for(const auto &text : texts) + { + text->setCharacterSize(FONT_SCALING * Settings::getScaling()); + text->setMaxWidth(size.x); + text->setPosition(position.x, std::floor(position.y)); + text->draw(window, cache); + position.y += text->getHeight(); + } + } +}
\ No newline at end of file |