diff --git a/src/platform/qt/Display.cpp b/src/platform/qt/Display.cpp index 5c427eb69..0eff451f9 100644 --- a/src/platform/qt/Display.cpp +++ b/src/platform/qt/Display.cpp @@ -114,12 +114,15 @@ void Display::configure(ConfigController* config) { } void Display::resizeEvent(QResizeEvent*) { - m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + m_messagePainter.resize(size(), devicePixelRatioF()); +#else + m_messagePainter.resize(size(), devicePixelRatio()); +#endif } void Display::lockAspectRatio(bool lock) { m_lockAspectRatio = lock; - m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio()); } void Display::lockIntegerScaling(bool lock) { diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index 7d30765d5..8b201c0b0 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -98,10 +98,11 @@ void DisplayGL::startDrawing(std::shared_ptr controller) { filter(isFiltered()); #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - messagePainter()->resize(size(), isAspectRatioLocked(), devicePixelRatioF()); + messagePainter()->resize(size(), devicePixelRatioF()); #else - messagePainter()->resize(size(), isAspectRatioLocked(), devicePixelRatio()); + messagePainter()->resize(size(), devicePixelRatio()); #endif + CoreController::Interrupter interrupter(controller); QMetaObject::invokeMethod(m_painter.get(), "start"); setUpdatesEnabled(false); @@ -401,8 +402,10 @@ void PainterGL::setMessagePainter(MessagePainter* messagePainter) { } void PainterGL::resize(const QSize& size) { + qreal r = m_surface->devicePixelRatio(); m_size = size; - m_window->setSize(m_size); + m_window->setSize(m_size * r); + m_window->setDevicePixelRatio(r); if (m_started && !m_active) { forceDraw(); } diff --git a/src/platform/qt/MessagePainter.cpp b/src/platform/qt/MessagePainter.cpp index 15ab748aa..33aac62f5 100644 --- a/src/platform/qt/MessagePainter.cpp +++ b/src/platform/qt/MessagePainter.cpp @@ -25,40 +25,32 @@ MessagePainter::MessagePainter(QObject* parent) clearMessage(); } -void MessagePainter::resize(const QSize& size, bool lockAspectRatio, qreal scaleFactor) { - int w = size.width(); - int h = size.height(); - int drawW = w; - int drawH = h; - if (lockAspectRatio) { - if (w * 2 > h * 3) { - drawW = h * 3 / 2; - } else if (w * 2 < h * 3) { - drawH = w * 2 / 3; - } - } - m_world.reset(); - m_world.scale(qreal(drawW) / GBA_VIDEO_HORIZONTAL_PIXELS, qreal(drawH) / GBA_VIDEO_VERTICAL_PIXELS); +void MessagePainter::resize(const QSize& size, qreal scaleFactor) { + double drawW = size.width(); + double drawH = size.height(); + double area = pow(drawW * drawW * drawW * drawH * drawH, 0.2); m_scaleFactor = scaleFactor; - m_local = QPoint(1, GBA_VIDEO_VERTICAL_PIXELS - m_messageFont.pixelSize() - 1); - m_local = m_world.map(m_local); - m_local += QPoint((w - drawW) / 2, (h - drawH) / 2); - m_pixmapBuffer = QPixmap(drawW * m_scaleFactor, - (m_messageFont.pixelSize() + 2) * m_world.m22() * m_scaleFactor); - m_pixmapBuffer.setDevicePixelRatio(m_scaleFactor); + m_world.reset(); + m_world.scale(area / 220., area / 220.); + m_local = QPoint(area / 100., drawH - m_messageFont.pixelSize() * m_world.m22() * 1.3); + m_mutex.lock(); - m_message.prepare(m_world, m_messageFont); redraw(); m_mutex.unlock(); } void MessagePainter::redraw() { - m_pixmapBuffer.fill(Qt::transparent); if (m_message.text().isEmpty()) { + m_pixmapBuffer.fill(Qt::transparent); m_pixmap = m_pixmapBuffer; - m_pixmap.setDevicePixelRatio(m_scaleFactor); return; } + m_message.prepare(m_world, m_messageFont); + QSizeF sizef = m_message.size() * m_scaleFactor; + m_pixmapBuffer = QPixmap(sizef.width() * m_world.m11(), sizef.height() * m_world.m22()); + m_pixmapBuffer.setDevicePixelRatio(m_scaleFactor); + m_pixmapBuffer.fill(Qt::transparent); + QPainter painter(&m_pixmapBuffer); painter.setWorldTransform(m_world); painter.setRenderHint(QPainter::Antialiasing); @@ -74,7 +66,6 @@ void MessagePainter::redraw() { painter.setPen(Qt::white); painter.drawStaticText(0, 0, m_message); m_pixmap = m_pixmapBuffer; - m_pixmap.setDevicePixelRatio(m_scaleFactor); } void MessagePainter::paint(QPainter* painter) { @@ -83,7 +74,6 @@ void MessagePainter::paint(QPainter* painter) { } } - void MessagePainter::showMessage(const QString& message) { m_mutex.lock(); m_message.setText(message); diff --git a/src/platform/qt/MessagePainter.h b/src/platform/qt/MessagePainter.h index 37f24c766..1a6d82de5 100644 --- a/src/platform/qt/MessagePainter.h +++ b/src/platform/qt/MessagePainter.h @@ -19,7 +19,7 @@ Q_OBJECT public: MessagePainter(QObject* parent = nullptr); - void resize(const QSize& size, bool lockAspectRatio, qreal scaleFactor); + void resize(const QSize& size, qreal scaleFactor); void paint(QPainter* painter); void setScaleFactor(qreal factor); @@ -32,13 +32,13 @@ private: QMutex m_mutex; QStaticText m_message; + qreal m_scaleFactor = 1; QPixmap m_pixmap; QPixmap m_pixmapBuffer; QTimer m_messageTimer{this}; QPoint m_local; QTransform m_world; QFont m_messageFont; - qreal m_scaleFactor = 1; }; }