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
+13 -6
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;