mirror of https://github.com/mgba-emu/mgba.git
Qt: Fancier background image
This commit is contained in:
parent
b6ce1799c6
commit
3c01e35696
Binary file not shown.
After Width: | Height: | Size: 200 KiB |
|
@ -17,7 +17,7 @@ AboutScreen::AboutScreen(QWidget* parent)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
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 = logo.scaled(m_ui.logo->minimumSize() * devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
logo.setDevicePixelRatio(devicePixelRatio());
|
logo.setDevicePixelRatio(devicePixelRatio());
|
||||||
m_ui.logo->setPixmap(logo);
|
m_ui.logo->setPixmap(logo);
|
||||||
|
|
|
@ -88,7 +88,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
|
||||||
, m_logView(new LogView(&m_log))
|
, m_logView(new LogView(&m_log))
|
||||||
, m_stateWindow(nullptr)
|
, m_stateWindow(nullptr)
|
||||||
, m_screenWidget(new WindowBackground())
|
, m_screenWidget(new WindowBackground())
|
||||||
, m_logo(":/res/medusa-1024.png")
|
, m_logo(":/res/medusa-bg.jpg")
|
||||||
, m_config(config)
|
, m_config(config)
|
||||||
, m_inputModel(new InputModel(this))
|
, m_inputModel(new InputModel(this))
|
||||||
, m_inputController(m_inputModel, playerId, this)
|
, m_inputController(m_inputModel, playerId, this)
|
||||||
|
@ -157,7 +157,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
|
||||||
m_screenWidget->setSizeHint(QSize(VIDEO_HORIZONTAL_PIXELS * i, VIDEO_VERTICAL_PIXELS * i));
|
m_screenWidget->setSizeHint(QSize(VIDEO_HORIZONTAL_PIXELS * i, VIDEO_VERTICAL_PIXELS * i));
|
||||||
#endif
|
#endif
|
||||||
m_screenWidget->setPixmap(m_logo);
|
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);
|
setCentralWidget(m_screenWidget);
|
||||||
|
|
||||||
connect(m_controller, SIGNAL(gameStarted(mCoreThread*, const QString&)), this, SLOT(gameStarted(mCoreThread*, const QString&)));
|
connect(m_controller, SIGNAL(gameStarted(mCoreThread*, const QString&)), this, SLOT(gameStarted(mCoreThread*, const QString&)));
|
||||||
|
@ -833,7 +833,7 @@ void Window::gameStopped() {
|
||||||
setWindowFilePath(QString());
|
setWindowFilePath(QString());
|
||||||
updateTitle();
|
updateTitle();
|
||||||
detachWidget(m_display);
|
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->setPixmap(m_logo);
|
||||||
m_screenWidget->unsetCursor();
|
m_screenWidget->unsetCursor();
|
||||||
#ifdef M_CORE_GB
|
#ifdef M_CORE_GB
|
||||||
|
@ -1648,6 +1648,13 @@ QSize WindowBackground::sizeHint() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowBackground::setLockAspectRatio(int width, int height) {
|
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_aspectWidth = width;
|
||||||
m_aspectHeight = height;
|
m_aspectHeight = height;
|
||||||
}
|
}
|
||||||
|
@ -1659,13 +1666,21 @@ void WindowBackground::paintEvent(QPaintEvent*) {
|
||||||
}
|
}
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
painter.fillRect(QRect(QPoint(), size()), Qt::white);
|
painter.fillRect(QRect(QPoint(), size()), Qt::black);
|
||||||
QSize s = size();
|
QSize s = size();
|
||||||
QSize ds = s;
|
QSize ds = s;
|
||||||
if (ds.width() * m_aspectHeight > ds.height() * m_aspectWidth) {
|
if (m_centered) {
|
||||||
ds.setWidth(ds.height() * m_aspectWidth / m_aspectHeight);
|
if (ds.width() * m_aspectHeight < ds.height() * m_aspectWidth) {
|
||||||
} else if (ds.width() * m_aspectHeight < ds.height() * m_aspectWidth) {
|
ds.setWidth(ds.height() * m_aspectWidth / m_aspectHeight);
|
||||||
ds.setHeight(ds.width() * m_aspectHeight / m_aspectWidth);
|
} 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);
|
QPoint origin = QPoint((s.width() - ds.width()) / 2, (s.height() - ds.height()) / 2);
|
||||||
QRect full(origin, ds);
|
QRect full(origin, ds);
|
||||||
|
|
|
@ -206,12 +206,14 @@ public:
|
||||||
void setSizeHint(const QSize& size);
|
void setSizeHint(const QSize& size);
|
||||||
virtual QSize sizeHint() const override;
|
virtual QSize sizeHint() const override;
|
||||||
void setLockAspectRatio(int width, int height);
|
void setLockAspectRatio(int width, int height);
|
||||||
|
void setCenteredAspectRatio(int width, int height);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent(QPaintEvent*) override;
|
virtual void paintEvent(QPaintEvent*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSize m_sizeHint;
|
QSize m_sizeHint;
|
||||||
|
bool m_centered;
|
||||||
int m_aspectWidth;
|
int m_aspectWidth;
|
||||||
int m_aspectHeight;
|
int m_aspectHeight;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<!DOCTYPE RCC><RCC version="1.0">
|
<!DOCTYPE RCC><RCC version="1.0">
|
||||||
<qresource>
|
<qresource>
|
||||||
<file>../../../res/medusa-1024.png</file>
|
<file>../../../res/medusa-bg.jpg</file>
|
||||||
<file>../../../res/patrons.txt</file>
|
<file>../../../res/patrons.txt</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Loading…
Reference in New Issue