mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-03 05:21:57 +01:00
visualisations: Properly scale projectM view
In version 5.6, Qt introduced an automatic scaling feature for high DPI displays. Since projectM is not part of the Qt framework, it's necessary to convert coordinates when specifying view size. Reference: https://doc.qt.io/qt-5/highdpi.html
This commit is contained in:
parent
354f6a23e0
commit
e8875faf83
@ -48,12 +48,14 @@
|
|||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ProjectMVisualisation::ProjectMVisualisation(QObject* parent)
|
ProjectMVisualisation::ProjectMVisualisation(VisualisationContainer* container)
|
||||||
: QGraphicsScene(parent),
|
: QGraphicsScene(container),
|
||||||
preset_model_(nullptr),
|
preset_model_(nullptr),
|
||||||
mode_(Random),
|
mode_(Random),
|
||||||
duration_(15),
|
duration_(15),
|
||||||
texture_size_(512) {
|
texture_size_(512),
|
||||||
|
pixel_ratio_(container->devicePixelRatio()),
|
||||||
|
container_(container) {
|
||||||
connect(this, SIGNAL(sceneRectChanged(QRectF)),
|
connect(this, SIGNAL(sceneRectChanged(QRectF)),
|
||||||
SLOT(SceneRectChanged(QRectF)));
|
SLOT(SceneRectChanged(QRectF)));
|
||||||
|
|
||||||
@ -143,14 +145,21 @@ void ProjectMVisualisation::drawBackground(QPainter* p, const QRectF&) {
|
|||||||
InitProjectM();
|
InitProjectM();
|
||||||
}
|
}
|
||||||
|
|
||||||
projectm_->projectM_resetGL(sceneRect().width(), sceneRect().height());
|
projectm_->projectM_resetGL(sceneRect().width() * pixel_ratio_,
|
||||||
|
sceneRect().height() * pixel_ratio_);
|
||||||
projectm_->renderFrame();
|
projectm_->renderFrame();
|
||||||
|
|
||||||
p->endNativePainting();
|
p->endNativePainting();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectMVisualisation::SceneRectChanged(const QRectF& rect) {
|
void ProjectMVisualisation::SceneRectChanged(const QRectF& rect) {
|
||||||
if (projectm_) projectm_->projectM_resetGL(rect.width(), rect.height());
|
// NOTE: This should be updated on a QScreen dpi change signal. Accessing the
|
||||||
|
// QScreen becomes a lot easier in Qt 5.14 with QWidget::screen().
|
||||||
|
pixel_ratio_ = container_->devicePixelRatio();
|
||||||
|
|
||||||
|
if (projectm_)
|
||||||
|
projectm_->projectM_resetGL(rect.width() * pixel_ratio_,
|
||||||
|
rect.height() * pixel_ratio_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectMVisualisation::SetTextureSize(int size) {
|
void ProjectMVisualisation::SetTextureSize(int size) {
|
||||||
|
@ -29,12 +29,14 @@ class projectM;
|
|||||||
|
|
||||||
class ProjectMPresetModel;
|
class ProjectMPresetModel;
|
||||||
|
|
||||||
|
class VisualisationContainer;
|
||||||
|
|
||||||
class QTemporaryFile;
|
class QTemporaryFile;
|
||||||
|
|
||||||
class ProjectMVisualisation : public QGraphicsScene, public BufferConsumer {
|
class ProjectMVisualisation : public QGraphicsScene, public BufferConsumer {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ProjectMVisualisation(QObject* parent = nullptr);
|
ProjectMVisualisation(VisualisationContainer* container);
|
||||||
~ProjectMVisualisation();
|
~ProjectMVisualisation();
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
@ -87,6 +89,12 @@ class ProjectMVisualisation : public QGraphicsScene, public BufferConsumer {
|
|||||||
std::vector<int> default_rating_list_;
|
std::vector<int> default_rating_list_;
|
||||||
|
|
||||||
int texture_size_;
|
int texture_size_;
|
||||||
|
// As of version 5.6, Qt supports automatic scaling for high-DPI displays. We
|
||||||
|
// need to know the pixel ratio so that we can convert coordinates for
|
||||||
|
// projectM.
|
||||||
|
// https://doc.qt.io/qt-5/highdpi.html
|
||||||
|
qreal pixel_ratio_;
|
||||||
|
VisualisationContainer* container_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROJECTMVISUALISATION_H
|
#endif // PROJECTMVISUALISATION_H
|
||||||
|
Loading…
Reference in New Issue
Block a user