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( getApp()->emotes->gifTimer.signal.connect(
[this] { this->advance(); }); [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() Frames::~Frames()
@ -58,17 +66,16 @@ namespace detail {
void Frames::advance() void Frames::advance()
{ {
this->durationOffset_ += GIF_FRAME_LENGTH; this->durationOffset_ += gifFrameLength;
this->processOffset();
}
void Frames::processOffset()
{
while (true) while (true)
{ {
this->index_ %= this->items_.size(); 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) if (this->durationOffset_ > this->items_[this->index_].duration)
{ {
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; boost::optional<QPixmap> first() const;
private: private:
void processOffset();
QVector<Frame<QPixmap>> items_; QVector<Frame<QPixmap>> items_;
int index_{0}; int index_{0};
int durationOffset_{0}; int durationOffset_{0};

View file

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

View file

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

View file

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