diff options
author | m0dB <79429057+m0dB@users.noreply.github.com> | 2023-05-18 00:24:51 +0200 |
---|---|---|
committer | m0dB <79429057+m0dB@users.noreply.github.com> | 2023-05-27 01:28:25 +0200 |
commit | 4ec3fba1e34910897dd68d4b5832ad2f62fdd4ce (patch) | |
tree | 2f91845f017c1ac94f0f226a704a0270443245b2 /src | |
parent | 0fbf597e758f93f3dcab4d4a62aaff36bd7c8fef (diff) |
apply devicePixelRatio when scaling images to widget size (reducing code duplication with helper scaleToSize), regenerate the textures after the images have been resized
Diffstat (limited to 'src')
-rw-r--r-- | src/widget/wspinnybase.cpp | 46 | ||||
-rw-r--r-- | src/widget/wspinnybase.h | 5 | ||||
-rw-r--r-- | src/widget/wspinnyglsl.cpp | 21 | ||||
-rw-r--r-- | src/widget/wspinnyglsl.h | 3 |
4 files changed, 46 insertions, 29 deletions
diff --git a/src/widget/wspinnybase.cpp b/src/widget/wspinnybase.cpp index a060a806b6..0dd7a9b4fd 100644 --- a/src/widget/wspinnybase.cpp +++ b/src/widget/wspinnybase.cpp @@ -165,17 +165,11 @@ void WSpinnyBase::setup(const QDomNode& node, m_pFgImage = WImageStore::getImage( context.getPixmapSource(context.selectNode(node, "PathForeground")), context.getScaleFactor()); - if (m_pFgImage && !m_pFgImage->isNull()) { - m_fgImageScaled = m_pFgImage->scaled( - size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - } + m_fgImageScaled = scaleToSize(m_pFgImage); m_pGhostImage = WImageStore::getImage( context.getPixmapSource(context.selectNode(node, "PathGhost")), context.getScaleFactor()); - if (m_pGhostImage && !m_pGhostImage->isNull()) { - m_ghostImageScaled = m_pGhostImage->scaled( - size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - } + m_ghostImageScaled = scaleToSize(m_pGhostImage); // Dynamic skin option, set in WSpinnyBase's <ShowCoverControl> node. if (showCoverConfigKey.isValid()) { @@ -248,7 +242,7 @@ void WSpinnyBase::setup(const QDomNode& node, void WSpinnyBase::setLoadedCover(const QPixmap& pixmap) { m_loadedCover = pixmap; - m_loadedCoverScaled = scaledCoverArt(pixmap); + m_loadedCoverScaled = scaleToSize(pixmap); } void WSpinnyBase::slotLoadTrack(TrackPointer pTrack) { @@ -364,11 +358,26 @@ void WSpinnyBase::swap() { doneCurrent(); } -QPixmap WSpinnyBase::scaledCoverArt(const QPixmap& normal) { - if (normal.isNull()) { +QImage WSpinnyBase::scaleToSize(const QImage& image) const { + if (image.isNull()) { + return QImage(); + } + QImage scaled = image.scaled(size() * devicePixelRatioF(), + Qt::KeepAspectRatio, + Qt::SmoothTransformation); + scaled.setDevicePixelRatio(devicePixelRatioF()); + return scaled; +} + +QImage WSpinnyBase::scaleToSize(const std::shared_ptr<QImage>& image) const { + return image ? scaleToSize(*image) : QImage(); +} + +QPixmap WSpinnyBase::scaleToSize(const QPixmap& pixmap) const { + if (pixmap.isNull()) { return QPixmap(); } - QPixmap scaled = normal.scaled(size() * devicePixelRatioF(), + QPixmap scaled = pixmap.scaled(size() * devicePixelRatioF(), Qt::KeepAspectRatio, Qt::SmoothTransformation); scaled.setDevicePixelRatio(devicePixelRatioF()); @@ -376,15 +385,10 @@ QPixmap WSpinnyBase::scaledCoverArt(const QPixmap& normal) { } void WSpinnyBase::resizeEvent(QResizeEvent* event) { - m_loadedCoverScaled = scaledCoverArt(m_loadedCover); - if (m_pFgImage && !m_pFgImage->isNull()) { - m_fgImageScaled = m_pFgImage->scaled( - size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - } - if (m_pGhostImage && !m_pGhostImage->isNull()) { - m_ghostImageScaled = m_pGhostImage->scaled( - size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - } + m_loadedCoverScaled = scaleToSize(m_loadedCover); + m_fgImageScaled = scaleToSize(m_pFgImage); + m_ghostImageScaled = scaleToSize(m_pGhostImage); + WGLWidget::resizeEvent(event); } diff --git a/src/widget/wspinnybase.h b/src/widget/wspinnybase.h index c42d1a900d..33f9f3d4bf 100644 --- a/src/widget/wspinnybase.h +++ b/src/widget/wspinnybase.h @@ -85,7 +85,6 @@ class WSpinnyBase : public WGLWidget, double calculateAngle(double playpos); int calculateFullRotations(double playpos); double calculatePositionFromAngle(double angle); - QPixmap scaledCoverArt(const QPixmap& normal); void setLoadedCover(const QPixmap& pixmap); @@ -93,6 +92,10 @@ class WSpinnyBase : public WGLWidget, virtual void draw() = 0; virtual void coverChanged() = 0; + QPixmap scaleToSize(const QPixmap& pixmap) const; + QImage scaleToSize(const QImage& image) const; + QImage scaleToSize(const std::shared_ptr<QImage>& image) const; + const QString m_group; UserSettingsPointer m_pConfig; diff --git a/src/widget/wspinnyglsl.cpp b/src/widget/wspinnyglsl.cpp index ca9363511c..a2153e622c 100644 --- a/src/widget/wspinnyglsl.cpp +++ b/src/widget/wspinnyglsl.cpp @@ -44,6 +44,20 @@ void WSpinnyGLSL::draw() { } } +void WSpinnyGLSL::resizeGL(int w, int h) { + // The images were resized in WSpinnyBase::resizeEvent. + updateTextures(); +} + +void WSpinnyGLSL::updateTextures() { + m_pBgTexture.reset(createTexture(m_pBgImage)); + m_pMaskTexture.reset(createTexture(m_pMaskImage)); + m_pFgTextureScaled.reset(createTexture(m_fgImageScaled)); + m_pGhostTextureScaled.reset(createTexture(m_ghostImageScaled)); + m_pLoadedCoverTextureScaled.reset(createTexture(m_loadedCoverScaled)); + m_pQTexture.reset(createTexture(m_qImage)); +} + void WSpinnyGLSL::paintGL() { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); @@ -112,12 +126,7 @@ void WSpinnyGLSL::paintGL() { } void WSpinnyGLSL::initializeGL() { - m_pBgTexture.reset(createTexture(m_pBgImage)); - m_pMaskTexture.reset(createTexture(m_pMaskImage)); - m_pFgTextureScaled.reset(createTexture(m_fgImageScaled)); - m_pGhostTextureScaled.reset(createTexture(m_ghostImageScaled)); - m_pLoadedCoverTextureScaled.reset(createTexture(m_loadedCoverScaled)); - m_pQTexture.reset(createTexture(m_qImage)); + updateTextures(); m_textureShader.init(); } diff --git a/src/widget/wspinnyglsl.h b/src/widget/wspinnyglsl.h index 861e7bdd0f..f2263d8ffa 100644 --- a/src/widget/wspinnyglsl.h +++ b/src/widget/wspinnyglsl.h @@ -20,9 +20,10 @@ class WSpinnyGLSL : public WSpinnyBase { void initializeGL() override; void paintGL() override; + void resizeGL(int w, int h) override; void drawTexture(QOpenGLTexture* texture); void cleanupGL(); - void updateLoaderCoverGL(); + void updateTextures(); mixxx::TextureShader m_textureShader; std::unique_ptr<QOpenGLTexture> m_pBgTexture; |