all repos — mgba @ 3c01e3569642aa51ba60946bcc8ec342c0998582

mGBA Game Boy Advance Emulator

Qt: Fancier background image
Vicki Pfau vi@endrift.com
Tue, 11 Apr 2017 12:11:45 -0700
commit

3c01e3569642aa51ba60946bcc8ec342c0998582

parent

b6ce1799c6003fdf487198b358b660f5555dc63b

M src/platform/qt/AboutScreen.cppsrc/platform/qt/AboutScreen.cpp

@@ -17,7 +17,7 @@ : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)

{ m_ui.setupUi(this); - QPixmap logo(":/res/medusa-1024.png"); + QPixmap logo(":/res/medusa-bg.jpg"); logo = logo.scaled(m_ui.logo->minimumSize() * devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation); logo.setDevicePixelRatio(devicePixelRatio()); m_ui.logo->setPixmap(logo);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -88,7 +88,7 @@ , m_log(0)

, m_logView(new LogView(&m_log)) , m_stateWindow(nullptr) , m_screenWidget(new WindowBackground()) - , m_logo(":/res/medusa-1024.png") + , m_logo(":/res/medusa-bg.jpg") , m_config(config) , m_inputModel(new InputModel(this)) , m_inputController(m_inputModel, playerId, this)

@@ -157,7 +157,7 @@ #elif defined(M_CORE_GBA)

m_screenWidget->setSizeHint(QSize(VIDEO_HORIZONTAL_PIXELS * i, VIDEO_VERTICAL_PIXELS * i)); #endif m_screenWidget->setPixmap(m_logo); - m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height()); + m_screenWidget->setCenteredAspectRatio(m_logo.width(), m_logo.height()); setCentralWidget(m_screenWidget); connect(m_controller, SIGNAL(gameStarted(mCoreThread*, const QString&)), this, SLOT(gameStarted(mCoreThread*, const QString&)));

@@ -833,7 +833,7 @@ }

setWindowFilePath(QString()); updateTitle(); detachWidget(m_display); - m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height()); + m_screenWidget->setCenteredAspectRatio(m_logo.width(), m_logo.height()); m_screenWidget->setPixmap(m_logo); m_screenWidget->unsetCursor(); #ifdef M_CORE_GB

@@ -1648,6 +1648,13 @@ return m_sizeHint;

} void WindowBackground::setLockAspectRatio(int width, int height) { + m_centered = false; + m_aspectWidth = width; + m_aspectHeight = height; +} + +void WindowBackground::setCenteredAspectRatio(int width, int height) { + m_centered = true; m_aspectWidth = width; m_aspectHeight = height; }

@@ -1659,13 +1666,21 @@ return;

} QPainter painter(this); painter.setRenderHint(QPainter::SmoothPixmapTransform); - painter.fillRect(QRect(QPoint(), size()), Qt::white); + 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_centered) { + 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); + } + } else { + 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); + } } QPoint origin = QPoint((s.width() - ds.width()) / 2, (s.height() - ds.height()) / 2); QRect full(origin, ds);
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -206,12 +206,14 @@

void setSizeHint(const QSize& size); virtual QSize sizeHint() const override; void setLockAspectRatio(int width, int height); + void setCenteredAspectRatio(int width, int height); protected: virtual void paintEvent(QPaintEvent*) override; private: QSize m_sizeHint; + bool m_centered; int m_aspectWidth; int m_aspectHeight; };
M src/platform/qt/resources.qrcsrc/platform/qt/resources.qrc

@@ -1,6 +1,6 @@

<!DOCTYPE RCC><RCC version="1.0"> <qresource> - <file>../../../res/medusa-1024.png</file> + <file>../../../res/medusa-bg.jpg</file> <file>../../../res/patrons.txt</file> </qresource> </RCC>