From d3c980b09e23a9c85c7a4cc8a9d61b268f11d2b7 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 12 Jan 2021 00:11:59 -0500 Subject: try and speed some stuff up --- components/chatmessage.cpp | 73 ++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 48 deletions(-) (limited to 'components/chatmessage.cpp') diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 08ca0b9..40d706b 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -713,60 +713,37 @@ void ChatMessageItemContainer::HandleCustomEmojis(Gtk::TextView &tv) { startpos = mend; if (is_animated && show_animations) { - auto pixbuf = img.GetAnimationFromURLIfCached(EmojiData::URLFromID(match.fetch(2), "gif"), EmojiSize, EmojiSize); - if (pixbuf) { - const auto it = buf->erase(start_it, end_it); - const int alen = text.size(); - text = GetText(buf); - const int blen = text.size(); - startpos -= (alen - blen); + const auto mark_start = buf->create_mark(start_it, false); + end_it.backward_char(); + const auto mark_end = buf->create_mark(end_it, false); + const auto cb = [this, &tv, buf, mark_start, mark_end](const Glib::RefPtr &pixbuf) { + auto start_it = mark_start->get_iter(); + auto end_it = mark_end->get_iter(); + end_it.forward_char(); + buf->delete_mark(mark_start); + buf->delete_mark(mark_end); + auto it = buf->erase(start_it, end_it); const auto anchor = buf->create_child_anchor(it); auto img = Gtk::manage(new Gtk::Image(pixbuf)); img->show(); tv.add_child_at_anchor(*img, anchor); - } else { - const auto mark_start = buf->create_mark(start_it, false); - end_it.backward_char(); - const auto mark_end = buf->create_mark(end_it, false); - const auto cb = [this, &tv, buf, mark_start, mark_end](const Glib::RefPtr &pixbuf) { - auto start_it = mark_start->get_iter(); - auto end_it = mark_end->get_iter(); - end_it.forward_char(); - buf->delete_mark(mark_start); - buf->delete_mark(mark_end); - auto it = buf->erase(start_it, end_it); - const auto anchor = buf->create_child_anchor(it); - auto img = Gtk::manage(new Gtk::Image(pixbuf)); - img->show(); - tv.add_child_at_anchor(*img, anchor); - }; - img.LoadAnimationFromURL(EmojiData::URLFromID(match.fetch(2), "gif"), EmojiSize, EmojiSize, sigc::track_obj(cb, tv)); - } + }; + img.LoadAnimationFromURL(EmojiData::URLFromID(match.fetch(2), "gif"), EmojiSize, EmojiSize, sigc::track_obj(cb, tv)); } else { - auto pixbuf = img.GetFromURLIfCached(EmojiData::URLFromID(match.fetch(2))); - if (pixbuf) { - const auto it = buf->erase(start_it, end_it); - const int alen = text.size(); - text = GetText(buf); - const int blen = text.size(); - startpos -= (alen - blen); + // can't erase before pixbuf is ready or else marks that are in the same pos get mixed up + const auto mark_start = buf->create_mark(start_it, false); + end_it.backward_char(); + const auto mark_end = buf->create_mark(end_it, false); + const auto cb = [this, buf, mark_start, mark_end](const Glib::RefPtr &pixbuf) { + auto start_it = mark_start->get_iter(); + auto end_it = mark_end->get_iter(); + end_it.forward_char(); + buf->delete_mark(mark_start); + buf->delete_mark(mark_end); + auto it = buf->erase(start_it, end_it); buf->insert_pixbuf(it, pixbuf->scale_simple(EmojiSize, EmojiSize, Gdk::INTERP_BILINEAR)); - } else { - // can't erase before pixbuf is ready or else marks that are in the same pos get mixed up - const auto mark_start = buf->create_mark(start_it, false); - end_it.backward_char(); - const auto mark_end = buf->create_mark(end_it, false); - const auto cb = [this, buf, mark_start, mark_end](const Glib::RefPtr &pixbuf) { - auto start_it = mark_start->get_iter(); - auto end_it = mark_end->get_iter(); - end_it.forward_char(); - buf->delete_mark(mark_start); - buf->delete_mark(mark_end); - auto it = buf->erase(start_it, end_it); - buf->insert_pixbuf(it, pixbuf->scale_simple(EmojiSize, EmojiSize, Gdk::INTERP_BILINEAR)); - }; - img.LoadFromURL(EmojiData::URLFromID(match.fetch(2)), sigc::track_obj(cb, tv)); - } + }; + img.LoadFromURL(EmojiData::URLFromID(match.fetch(2)), sigc::track_obj(cb, tv)); } text = GetText(buf); -- cgit v1.2.3