aboutsummaryrefslogtreecommitdiff
path: root/src/MessagePart.cpp
blob: dcef3f33fc5099b9cbdc0bb0b6128c116c06873d (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
55
56
57
58
59
60
61
#include "../include/MessagePart.hpp"
#include "../include/ResourceCache.hpp"
#include "../include/Settings.hpp"

using namespace std;

namespace dchat
{
    const float MESSAGE_PART_SIZE = 27;
    
    float MessagePart::getSizeScaled()
    {
        return MESSAGE_PART_SIZE * Settings::getScaling();
    }
    
    MessagePartText::MessagePartText(const string &_text) : 
        MessagePart(Type::TEXT),
        text("", ResourceCache::getFont("fonts/Roboto-Regular.ttf"), MessagePartText::getFontSizeScaled())
    {
        text.setString(sf::String::fromUtf8(_text.begin(), _text.end()));
    }
    
    float MessagePartText::getFontSizeScaled()
    {
        return MessagePart::getSizeScaled() * 0.8f;
    }
    
    sf::Vector2f MessagePartText::getPosition() const
    {
        return text.getPosition();
    }
    
    sf::Vector2f MessagePartText::getSize() const
    {
        return sf::Vector2f(text.getLocalBounds().width, getFontSizeScaled());
    }
    
    MessagePartEmoji::MessagePartEmoji(const string &_url) : 
        MessagePart(Type::EMOJI),
        url(_url)
    {
        
    }
    
    float MessagePartEmoji::getHeightScaled()
    {
        return MessagePart::getSizeScaled() * 1.0f;
    }
    
    sf::Vector2f MessagePartEmoji::getPosition() const
    {
        return sprite.getPosition();
    }
    
    sf::Vector2f MessagePartEmoji::getSize() const
    {
        auto spriteScale = sprite.getScale();
        auto textureSize = sprite.getTexture()->getSize();
        return { (float)textureSize.x * spriteScale.x, (float)textureSize.y * spriteScale.y };
    }
}