all repos — mgba @ 62a0447cc9afc218fb0e6a6b3da2a5a0d8cfe976

mGBA Game Boy Advance Emulator

Draw logo when a game is not loaded
Jeffrey Pfau jeffrey@endrift.com
Fri, 17 Oct 2014 01:45:34 -0700
commit

62a0447cc9afc218fb0e6a6b3da2a5a0d8cfe976

parent

c91ad7f85f8e24f9641e8f15c297fb9d2d10e13a

M src/platform/qt/CMakeLists.txtsrc/platform/qt/CMakeLists.txt

@@ -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)
M src/platform/qt/Display.cppsrc/platform/qt/Display.cpp

@@ -29,7 +29,7 @@ , m_painter(nullptr)

, m_drawThread(nullptr) { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - setMinimumSize(240, 160); + setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); setAutoBufferSwap(false); }
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -34,6 +34,7 @@ const uint32_t* drawContext() const { return m_drawContext; }

GBAThread* thread() { return &m_threadContext; } bool isPaused(); + bool isLoaded() { return m_rom; } #ifdef USE_GDB_STUB ARMDebugger* debugger();
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -19,6 +19,7 @@ : QMainWindow(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 @@ m_controller = new GameController(this);

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 @@ m_controller->keyReleased(key);

event->accept(); } +void Window::resizeEvent(QResizeEvent*) { + redoLogo(); +} + void Window::closeEvent(QCloseEvent* event) { emit shutdown(); QMainWindow::closeEvent(event);

@@ -156,12 +167,24 @@ emit startDrawing(m_controller->drawContext(), 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); +}
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -40,6 +40,7 @@

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 @@

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 @@ QList<QAction*> m_gameActions;

LogView* m_logView; LoadSaveState* m_stateWindow; QLabel* m_screenWidget; + QPixmap m_logo; #ifdef USE_GDB_STUB GDBController* m_gdbController;
A src/platform/qt/resources.qrc

@@ -0,0 +1,5 @@

+ <!DOCTYPE RCC><RCC version="1.0"> + <qresource> + <file>../../../res/mgba-1024.png</file> + </qresource> + </RCC>