Draw logo when a game is not loaded

This commit is contained in:
Jeffrey Pfau 2014-10-17 01:45:34 -07:00
parent c91ad7f85f
commit 62a0447cc9
7 changed files with 45 additions and 6 deletions

BIN
res/mgba-1024.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 KiB

View File

@ -44,7 +44,9 @@ set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_executable(mGBA WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${UI_FILES})
qt5_add_resources(RESOURCES resources.qrc)
message(STATUS ${RESOURCES})
add_executable(mGBA WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${UI_FILES} ${RESOURCES})
qt5_use_modules(mGBA Widgets Multimedia OpenGL)
target_link_libraries(mGBA ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY} ${BINARY_NAME} Qt5::Widgets)

View File

@ -29,7 +29,7 @@ Display::Display(QGLFormat format, QWidget* parent)
, m_drawThread(nullptr)
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setMinimumSize(240, 160);
setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
setAutoBufferSwap(false);
}

View File

@ -34,6 +34,7 @@ public:
GBAThread* thread() { return &m_threadContext; }
bool isPaused();
bool isLoaded() { return m_rom; }
#ifdef USE_GDB_STUB
ARMDebugger* debugger();

View File

@ -19,6 +19,7 @@ Window::Window(QWidget* parent)
, m_logView(new LogView())
, m_stateWindow(nullptr)
, m_screenWidget(new QLabel())
, m_logo(":/res/mgba-1024.png")
#ifdef USE_GDB_STUB
, m_gdbController(nullptr)
#endif
@ -27,14 +28,20 @@ Window::Window(QWidget* parent)
QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));
format.setSwapInterval(1);
m_display = new Display(format);
m_screenWidget->setLayout(new QStackedLayout());
m_screenWidget->layout()->setContentsMargins(0, 0, 0, 0);
m_screenWidget->setScaledContents(true);
setCentralWidget(m_screenWidget);
m_display = new Display(format);
m_screenWidget->setAlignment(Qt::AlignCenter);
m_screenWidget->setMinimumSize(m_display->minimumSize());
m_screenWidget->setSizePolicy(m_display->sizePolicy());
attachWidget(m_display);
m_screenWidget->resize(m_display->minimumSize() * 2);
QPalette palette = m_screenWidget->palette();
palette.setColor(m_screenWidget->backgroundRole(), Qt::black);
m_screenWidget->setPalette(palette);
m_screenWidget->setAutoFillBackground(true);
setCentralWidget(m_screenWidget);
connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*)));
connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing()));
connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));
@ -136,6 +143,10 @@ void Window::keyReleaseEvent(QKeyEvent* event) {
event->accept();
}
void Window::resizeEvent(QResizeEvent*) {
redoLogo();
}
void Window::closeEvent(QCloseEvent* event) {
emit shutdown();
QMainWindow::closeEvent(event);
@ -156,12 +167,24 @@ void Window::gameStarted(GBAThread* context) {
foreach (QAction* action, m_gameActions) {
action->setDisabled(false);
}
attachWidget(m_display);
m_screenWidget->setScaledContents(true);
}
void Window::gameStopped() {
foreach (QAction* action, m_gameActions) {
action->setDisabled(true);
}
detachWidget(m_display);
m_screenWidget->setScaledContents(false);
redoLogo();
}
void Window::redoLogo() {
if (m_controller->isLoaded()) {
return;
}
m_screenWidget->setPixmap(m_logo.scaled(m_screenWidget->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
void Window::openStateWindow(LoadSave ls) {
@ -339,3 +362,7 @@ void Window::attachWidget(QWidget* widget) {
m_screenWidget->layout()->addWidget(widget);
static_cast<QStackedLayout*>(m_screenWidget->layout())->setCurrentWidget(widget);
}
void Window::detachWidget(QWidget* widget) {
m_screenWidget->layout()->removeWidget(widget);
}

View File

@ -40,6 +40,7 @@ public slots:
protected:
virtual void keyPressEvent(QKeyEvent* event) override;
virtual void keyReleaseEvent(QKeyEvent* event) override;
virtual void resizeEvent(QResizeEvent*) override;
virtual void closeEvent(QCloseEvent*) override;
signals:
@ -52,12 +53,14 @@ public slots:
private slots:
void gameStarted(GBAThread*);
void gameStopped();
void redoLogo();
private:
void setupMenu(QMenuBar*);
void openStateWindow(LoadSave);
void attachWidget(QWidget* widget);
void detachWidget(QWidget* widget);
GameController* m_controller;
Display* m_display;
@ -65,6 +68,7 @@ private:
LogView* m_logView;
LoadSaveState* m_stateWindow;
QLabel* m_screenWidget;
QPixmap m_logo;
#ifdef USE_GDB_STUB
GDBController* m_gdbController;

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>../../../res/mgba-1024.png</file>
</qresource>
</RCC>