#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 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 &_texts) { for(const auto &text : _texts) { sf::String str = sf::String::fromUtf8(text.begin(), text.end()); texts.emplace_back(std::make_unique(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(); } } }