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
|
#include "../include/ChatMessage.hpp"
#include "../include/GlobalCache.hpp"
#include "../include/GtkGif.hpp"
namespace dchat
{
ChatMessage::ChatMessage(const Glib::ustring &_username, const Glib::ustring &_text, uint32_t _timestampSeconds) :
username(_username),
text(_text),
timestampSeconds(_timestampSeconds)
{
avatar.set_halign(Gtk::ALIGN_START);
avatar.set_valign(Gtk::ALIGN_START);
username.set_selectable(true);
username.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START);
username.get_style_context()->add_class("chat-message-username");
text.set_selectable(true);
text.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START);
text.set_line_wrap(true);
text.set_line_wrap_mode(Pango::WRAP_WORD_CHAR);
text.get_style_context()->add_class("chat-message-text");
attach(avatar, 0, 0, 1, 2);
attach_next_to(username, avatar, Gtk::POS_RIGHT, 1, 1);
attach_next_to(text, username, Gtk::POS_BOTTOM, 1, 1);
get_style_context()->add_class("chat-message");
signal_draw().connect(sigc::mem_fun(*this, &ChatMessage::updateContent));
}
bool ChatMessage::updateContent(const Cairo::RefPtr<Cairo::Context> &cairo)
{
#if 0
auto result = getGlobalCache().getContentByUrl("https://discordemoji.com/assets/emoji/3644_epicKirby.gif");
printf("result type: %d\n", result.type);
if(result.type == ContentByUrlResult::Type::CACHED && result.gif)
{
Gtk::Widget *child = avatar.get_child_at(0, 0);
if(!child)
{
printf("add gif!\n");
//GtkGif *gif = new GtkGif(GtkGif*)result.gif;
//gif->copy
//avatar.attach(*(GtkGif*)result.gif, 0, 0, 1, 1);
}
}
#endif
return true;
}
}
|