diff --git a/CHANGES b/CHANGES index 5c29d3390..03ce886ce 100644 --- a/CHANGES +++ b/CHANGES @@ -74,6 +74,7 @@ Bugfixes: - Qt: Ensure CLI backend is attached when submitting commands (fixes mgba.io/i/662) - Qt: Disable "New multiplayer window" when MAX_GBAS is reached (fixes mgba.io/i/107) - Qt: Fix game unpausing after frame advancing and refocusing + - Qt: Fix screen background improperly stretching - SDL: Fix game crash check - SDL: Fix race condition with audio thread when starting - SDL: Fix showing version number diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 4c480a487..046983b81 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -132,8 +132,9 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent) resizeFrame(QSize(GB_VIDEO_HORIZONTAL_PIXELS * i, GB_VIDEO_VERTICAL_PIXELS * i)); #endif m_screenWidget->setPixmap(m_logo); - m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height()); + m_screenWidget->setDimensions(m_logo.width(), m_logo.height()); m_screenWidget->setLockIntegerScaling(false); + m_screenWidget->setLockAspectRatio(true); setCentralWidget(m_screenWidget); connect(m_controller, &GameController::gameStarted, this, &Window::gameStarted); @@ -151,7 +152,6 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent) QPixmap pixmap; pixmap.convertFromImage(currentImage); m_screenWidget->setPixmap(pixmap); - m_screenWidget->setLockAspectRatio(width, height); }); connect(m_controller, &GameController::gamePaused, m_display, &Display::pauseDrawing); #ifndef Q_OS_MAC @@ -740,7 +740,9 @@ void Window::gameStarted(mCoreThread* context, const QString& fname) { context->core->desiredVideoDimensions(context->core, &width, &height); m_display->setMinimumSize(width, height); m_screenWidget->setMinimumSize(m_display->minimumSize()); + m_screenWidget->setDimensions(width, height); m_config->updateOption("lockIntegerScaling"); + m_config->updateOption("lockAspectRatio"); if (m_savedScale > 0) { resizeFrame(QSize(width, height) * m_savedScale); } @@ -802,8 +804,9 @@ void Window::gameStopped() { setWindowFilePath(QString()); updateTitle(); detachWidget(m_display); - m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height()); + m_screenWidget->setDimensions(m_logo.width(), m_logo.height()); m_screenWidget->setLockIntegerScaling(false); + m_screenWidget->setLockAspectRatio(true); m_screenWidget->setPixmap(m_logo); m_screenWidget->unsetCursor(); #ifdef M_CORE_GB @@ -1272,6 +1275,9 @@ void Window::setupMenu(QMenuBar* menubar) { lockAspectRatio->addBoolean(tr("Lock aspect ratio"), avMenu); lockAspectRatio->connect([this](const QVariant& value) { m_display->lockAspectRatio(value.toBool()); + if (m_controller->isLoaded()) { + m_screenWidget->setLockAspectRatio(value.toBool()); + } }, this); m_config->updateOption("lockAspectRatio"); @@ -1662,7 +1668,7 @@ QSize WindowBackground::sizeHint() const { return m_sizeHint; } -void WindowBackground::setLockAspectRatio(int width, int height) { +void WindowBackground::setDimensions(int width, int height) { m_aspectWidth = width; m_aspectHeight = height; } @@ -1671,6 +1677,10 @@ void WindowBackground::setLockIntegerScaling(bool lock) { m_lockIntegerScaling = lock; } +void WindowBackground::setLockAspectRatio(bool lock) { + m_lockAspectRatio = lock; +} + void WindowBackground::paintEvent(QPaintEvent*) { const QPixmap* logo = pixmap(); if (!logo) { @@ -1681,10 +1691,12 @@ void WindowBackground::paintEvent(QPaintEvent*) { painter.fillRect(QRect(QPoint(), size()), Qt::black); QSize s = size(); QSize ds = s; - if (ds.width() * m_aspectHeight > ds.height() * m_aspectWidth) { - ds.setWidth(ds.height() * m_aspectWidth / m_aspectHeight); - } else if (ds.width() * m_aspectHeight < ds.height() * m_aspectWidth) { - ds.setHeight(ds.width() * m_aspectHeight / m_aspectWidth); + if (m_lockAspectRatio) { + if (ds.width() * m_aspectHeight > ds.height() * m_aspectWidth) { + ds.setWidth(ds.height() * m_aspectWidth / m_aspectHeight); + } else if (ds.width() * m_aspectHeight < ds.height() * m_aspectWidth) { + ds.setHeight(ds.width() * m_aspectHeight / m_aspectWidth); + } } if (m_lockIntegerScaling) { ds.setWidth(ds.width() - ds.width() % m_aspectWidth); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 7b1fec72a..c009c7ffa 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -214,8 +214,9 @@ public: void setSizeHint(const QSize& size); virtual QSize sizeHint() const override; - void setLockAspectRatio(int width, int height); + void setDimensions(int width, int height); void setLockIntegerScaling(bool lock); + void setLockAspectRatio(bool lock); protected: virtual void paintEvent(QPaintEvent*) override; @@ -224,6 +225,7 @@ private: QSize m_sizeHint; int m_aspectWidth; int m_aspectHeight; + bool m_lockAspectRatio; bool m_lockIntegerScaling; };