diff --git a/emotes.h b/emotes.h index 62d1f7a33..c733ed7d4 100644 --- a/emotes.h +++ b/emotes.h @@ -1,6 +1,8 @@ #ifndef EMOTES_H #define EMOTES_H +#define GIF_FRAME_LENGTH 33 + #include "concurrentmap.h" #include "messages/lazyloadedimage.h" #include "twitchemotevalue.h" @@ -89,7 +91,7 @@ public: if (!gifUpdateTimerInitiated) { gifUpdateTimerInitiated = true; - gifUpdateTimer.setInterval(33); + gifUpdateTimer.setInterval(GIF_FRAME_LENGTH); gifUpdateTimer.start(); } diff --git a/messages/lazyloadedimage.cpp b/messages/lazyloadedimage.cpp index 3854d1e7a..1fbbf5725 100644 --- a/messages/lazyloadedimage.cpp +++ b/messages/lazyloadedimage.cpp @@ -22,6 +22,7 @@ LazyLoadedImage::LazyLoadedImage(const QString &url, qreal scale, : currentPixmap(NULL) , allFrames() , currentFrame(0) + , currentFrameOffset(0) , url(url) , name(name) , tooltip(tooltip) @@ -39,6 +40,7 @@ LazyLoadedImage::LazyLoadedImage(QPixmap *image, qreal scale, : currentPixmap(image) , allFrames() , currentFrame(0) + , currentFrameOffset(0) , url() , name(name) , tooltip(tooltip) @@ -103,12 +105,21 @@ LazyLoadedImage::loadImage() void LazyLoadedImage::gifUpdateTimout() { - if (this->currentFrame >= this->allFrames.size() - 1) { - this->currentFrame = 0; - this->currentPixmap = this->allFrames.at(0).image; - } else { - this->currentPixmap = this->allFrames.at(++this->currentFrame).image; + this->currentFrameOffset += GIF_FRAME_LENGTH; + + while (true) { + if (this->currentFrameOffset > + this->allFrames.at(this->currentFrame).duration) { + this->currentFrameOffset -= + this->allFrames.at(this->currentFrame).duration; + this->currentFrame = + (this->currentFrame + 1) % this->allFrames.size(); + } else { + break; + } } + + this->currentPixmap = this->allFrames[this->currentFrame].image; } } } diff --git a/messages/lazyloadedimage.h b/messages/lazyloadedimage.h index 138f731bb..564d3c21c 100644 --- a/messages/lazyloadedimage.h +++ b/messages/lazyloadedimage.h @@ -95,12 +95,13 @@ public: private: struct FrameData { QPixmap *image; - float duration; + int duration; }; QPixmap *currentPixmap; std::vector allFrames; int currentFrame; + int currentFrameOffset; QString url; QString name; diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index b5b9045f9..290595685 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -49,33 +49,26 @@ ChatWidgetView::layoutMessages() int start = this->scrollbar.getCurrentValue(); - if (messages.getLength() <= start) { - // The scrollbar wants to show more values than we can offer + // layout the visible messages in the view + if (messages.getLength() > start) { + int y = -(messages[start].get()->getHeight() * + (fmod(this->scrollbar.getCurrentValue(), 1))); - // just return for now - return false; + for (int i = start; i < messages.getLength(); ++i) { + auto messagePtr = messages[i]; + auto message = messagePtr.get(); + redraw |= message->layout(this->width(), true); - // Lower start value to the last message - // start = messages.getLength() - 1; - } + y += message->getHeight(); - int y = -(messages[start].get()->getHeight() * - (fmod(this->scrollbar.getCurrentValue(), 1))); - - for (int i = start; i < messages.getLength(); ++i) { - auto messagePtr = messages[i]; - auto message = messagePtr.get(); - - redraw |= message->layout(this->width(), true); - - y += message->getHeight(); - - if (y >= height()) { - break; + if (y >= height()) { + break; + } } } + // layout the messages at the bottom to determine the scrollbar thumb size int h = this->height() - 8; for (int i = messages.getLength() - 1; i >= 0; i--) { @@ -236,11 +229,13 @@ ChatWidgetView::paintEvent(QPaintEvent *) void ChatWidgetView::wheelEvent(QWheelEvent *event) { - this->scrollbar.setDesiredValue( - this->scrollbar.getDesiredValue() - - event->delta() / 10.0 * - Settings::getInstance().mouseScrollMultiplier.get(), - true); + if (this->scrollbar.isVisible()) { + this->scrollbar.setDesiredValue( + this->scrollbar.getDesiredValue() - + event->delta() / 10.0 * + Settings::getInstance().mouseScrollMultiplier.get(), + true); + } } } }