Qt: Fix screen background improperly stretching
Vicki Pfau vi@endrift.com
Sat, 15 Jul 2017 20:38:45 -0700
3 files changed,
24 insertions(+),
9 deletions(-)
M
CHANGES
→
CHANGES
@@ -74,6 +74,7 @@ - Qt: Fix crash when changing audio settings after a game is closed
- 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
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -132,8 +132,9 @@ #elif defined(M_CORE_GB)
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 @@ width * BYTES_PER_PIXEL, QImage::Format_RGBX8888);
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 @@ unsigned width, height;
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 @@ }
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 @@ ConfigOption* lockAspectRatio = m_config->addOption("lockAspectRatio");
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 @@ painter.setRenderHint(QPainter::SmoothPixmapTransform);
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);
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -214,8 +214,9 @@ WindowBackground(QWidget* parent = 0);
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; };