aboutsummaryrefslogtreecommitdiff
path: root/src/BodyItem.cpp
blob: bf6e45ddb1e303652fc58d3810019a265ca03455 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "../include/BodyItem.hpp"
#include "../include/Theme.hpp"
#include "../include/Utils.hpp"
#include <cmath>

namespace QuickMedia {
    BodyItem::BodyItem(std::string _title) :
        visible(true),
        dirty(false),
        dirty_description(false),
        dirty_author(false),
        dirty_timestamp(false),
        thumbnail_is_local(false),
        userdata(nullptr),
        timestamp(0),
        title_color(get_current_theme().text_color),
        author_color(get_current_theme().text_color),
        description_color(get_current_theme().text_color)
    {
        if(!_title.empty())
            set_title(std::move(_title));
    }

    BodyItem& BodyItem::operator=(const BodyItem &other) {
        url = other.url;
        thumbnail_url = other.thumbnail_url;
        visible = other.visible;
        dirty = !other.title.empty();
        dirty_description = !other.description.empty();
        dirty_author = !other.author.empty();
        dirty_timestamp = other.timestamp != 0;
        thumbnail_is_local = other.thumbnail_is_local;
        title_text.reset();
        description_text.reset();
        author_text.reset();
        timestamp_text.reset();
        replies_to = other.replies_to;
        replies = other.replies;
        post_number = other.post_number;
        userdata = other.userdata;
        loaded_height = 0.0f;
        loaded_image_size = sf::Vector2f(0.0f, 0.0f);
        loaded_content_height = 0.0f;
        embedded_item_status = other.embedded_item_status;
        if(other.embedded_item) {
            embedded_item.reset(new BodyItem(""));
            *embedded_item = *other.embedded_item;
        } else {
            embedded_item.reset();
        }
        thumbnail_mask_type = other.thumbnail_mask_type;
        thumbnail_size = other.thumbnail_size;
        reactions.clear();
        for(auto &reaction : other.reactions) {
            Reaction reaction_copy;
            reaction_copy.text = std::make_unique<Text>(*reaction.text);
            reaction_copy.userdata = reaction.userdata;
            reactions.push_back(std::move(reaction_copy));
        }
        title = other.title;
        description = other.description;
        author = other.author;
        timestamp = other.timestamp;
        title_color = other.title_color;
        author_color = other.author_color;
        description_color = other.description_color;
        extra = other.extra;
        keep_alive_frames = other.keep_alive_frames;
        return *this;
    }

    void BodyItem::add_reaction(std::string text, void *userdata) {
        sf::String str = sf::String::fromUtf8(text.begin(), text.end());
        Reaction reaction;
        reaction.text = std::make_unique<Text>(std::move(str), false, std::floor(14 * get_ui_scale()), 0.0f);
        reaction.userdata = userdata;
        reactions.push_back(std::move(reaction));
    }

    void BodyItem::draw_list(Body *body, sf::RenderTarget &render_target) {

    }
}