aboutsummaryrefslogtreecommitdiff
path: root/src/BodyItem.cpp
blob: 86f0dfb7cb8b7c065bdbc766dd96cb09cf8f50b1 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "../include/BodyItem.hpp"
#include "../include/Theme.hpp"
#include "../include/Config.hpp"

namespace QuickMedia {
    // static
    std::shared_ptr<BodyItem> BodyItem::create(std::string title, bool selectable) {
        return std::shared_ptr<BodyItem>(new BodyItem(std::move(title), selectable));
    }

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

    BodyItem& BodyItem::operator=(const BodyItem &other) {
        url = other.url;
        thumbnail_url = other.thumbnail_url;
        title_max_lines = other.title_max_lines;
        description_max_lines = other.description_max_lines;
        visible = other.visible;
        dirty = !other.title.empty();
        dirty_description = !other.description.empty();
        dirty_author = !other.author.empty();
        dirty_timestamp = other.timestamp != 0;
        dirty_reactions = !other.reactions.empty();
        thumbnail_is_local = other.thumbnail_is_local;
        title_text.reset();
        description_text.reset();
        author_text.reset();
        timestamp_text.reset();
        userdata = other.userdata;
        loaded_height = 0.0f;
        loaded_image_size = mgl::vec2f(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("", true));
            *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_str = reaction.text_str;
            reaction_copy.userdata = reaction.userdata;
            reaction_copy.text_color = reaction.text_color;
            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;
        force_title_color = other.force_title_color;
        force_description_color = other.force_description_color;
        force_author_color = other.force_author_color;
        extra = other.extra;
        keep_alive_frames = other.keep_alive_frames;
        selectable = other.selectable;
        return *this;
    }

    void BodyItem::add_reaction(std::string text, void *userdata, mgl::Color text_color) {
        Reaction reaction;
        reaction.text_str = std::move(text);
        reaction.text = nullptr;
        reaction.userdata = userdata;
        reaction.text_color = text_color;
        reactions.push_back(std::move(reaction));
        dirty_reactions = true;
    }

    void BodyItem::add_reaction(std::string text, void *userdata) {
        add_reaction(std::move(text), userdata, get_theme().text_color);
    }

    void BodyItem::draw_list(Body *body, mgl::Window &render_target) {

    }
}