From 2e428330f4933b128f45717b3b13eaa2463ed5ae Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 18 Jan 2025 15:39:25 +0200 Subject: [PATCH] support gif catpacks Signed-off-by: Trial97 --- launcher/ui/themes/CatPainter.cpp | 17 ++++++++++++++++- launcher/ui/themes/CatPainter.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/launcher/ui/themes/CatPainter.cpp b/launcher/ui/themes/CatPainter.cpp index 7ff24932b..7c152fdc9 100644 --- a/launcher/ui/themes/CatPainter.cpp +++ b/launcher/ui/themes/CatPainter.cpp @@ -22,12 +22,27 @@ CatPainter::CatPainter(const QString& path, QObject* parent) : QObject(parent) { - m_image = QPixmap(path); + // Attempt to load as a movie + m_movie = new QMovie(path, QByteArray(), this); + if (m_movie->isValid()) { + // Start the animation if it's a valid movie file + connect(m_movie, &QMovie::frameChanged, this, &CatPainter::updateFrame); + m_movie->start(); + } else { + // Otherwise, load it as a static image + delete m_movie; + m_movie = nullptr; + + m_image = QPixmap(path); + } } void CatPainter::paint(QPainter* painter, const QRect& viewport) { QPixmap frame = m_image; + if (m_movie && m_movie->isValid()) { + frame = m_movie->currentPixmap(); + } auto fit = APPLICATION->settings()->get("CatFit").toString(); painter->setOpacity(APPLICATION->settings()->get("CatOpacity").toFloat() / 100); diff --git a/launcher/ui/themes/CatPainter.h b/launcher/ui/themes/CatPainter.h index 3b790c640..c36cb7617 100644 --- a/launcher/ui/themes/CatPainter.h +++ b/launcher/ui/themes/CatPainter.h @@ -34,5 +34,6 @@ class CatPainter : public QObject { void updateFrame(); private: + QMovie* m_movie = nullptr; QPixmap m_image; };