blob: 2fbbd72f415c5287e347adec9214ad59fe61be7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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();
}
}
}
|