sync gif emotes of same length

This commit is contained in:
fourtf 2020-02-16 14:24:11 +01:00
parent 59296075e8
commit 6229b2f434
5 changed files with 22 additions and 8 deletions

View file

@ -41,6 +41,14 @@ namespace detail {
getApp()->emotes->gifTimer.signal.connect(
[this] { this->advance(); });
}
auto totalLength = std::accumulate(
this->items_.begin(), this->items_.end(), 0UL,
[](auto init, auto &&frame) { return init + frame.duration; });
this->durationOffset_ = std::min<int>(
int(getApp()->emotes->gifTimer.position() % totalLength), 60000);
this->processOffset();
}
Frames::~Frames()
@ -58,17 +66,16 @@ namespace detail {
void Frames::advance()
{
this->durationOffset_ += GIF_FRAME_LENGTH;
this->durationOffset_ += gifFrameLength;
this->processOffset();
}
void Frames::processOffset()
{
while (true)
{
this->index_ %= this->items_.size();
// TODO: Figure out what this was supposed to achieve
// if (this->index_ >= this->items_.size()) {
// this->index_ = this->index_;
// }
if (this->durationOffset_ > this->items_[this->index_].duration)
{
this->durationOffset_ -= this->items_[this->index_].duration;

View file

@ -35,6 +35,7 @@ namespace detail {
boost::optional<QPixmap> first() const;
private:
void processOffset();
QVector<Frame<QPixmap>> items_;
int index_{0};
int durationOffset_{0};

View file

@ -2,8 +2,6 @@
#include "common/Singleton.hpp"
#define GIF_FRAME_LENGTH 33
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/emoji/Emojis.hpp"
#include "providers/ffz/FfzEmotes.hpp"

View file

@ -22,6 +22,7 @@ void GIFTimer::initialize()
qApp->activeWindow() == nullptr)
return;
this->position_ += gifFrameLength;
this->signal.invoke();
getApp()->windows->repaintGifEmotes();
});

View file

@ -5,15 +5,22 @@
namespace chatterino {
constexpr long unsigned gifFrameLength = 33;
class GIFTimer
{
public:
void initialize();
pajlada::Signals::NoArgSignal signal;
long unsigned position()
{
return this->position_;
}
private:
QTimer timer;
long unsigned position_{};
};
} // namespace chatterino