Skip to content

Commit cb5bb34

Browse files
committed
Made custom Qt GUI splashscreen that fades out when initialization is finished. Showing splash screen at startup is now a configuration parameter and defaults to off. Can be turned on in GUI config dialog.
1 parent 47098b2 commit cb5bb34

6 files changed

Lines changed: 132 additions & 18 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ set(SRC_DRIVERS_SDL
513513
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleVideoConf.cpp
514514
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleSoundConf.cpp
515515
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/iNesHeaderEditor.cpp
516+
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/SplashScreen.cpp
516517
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/TraceLogger.cpp
517518
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/AboutWindow.cpp
518519
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/fceuWrapper.cpp

src/drivers/Qt/GuiConf.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
6363
QGroupBox *frame, *qssFrame;
6464
QFrame *hline;
6565
std::string qssFile, qpalFile;
66+
QSettings settings;
6667

6768
//resize( 512, 600 );
6869
//printf("Style: %s \n", style()->objectName().toStdString().c_str() );
@@ -128,16 +129,19 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
128129
useNativeMenuBar = new QCheckBox(tr("Use Native OS Menu Bar"));
129130
pauseOnMenuAccess = new QCheckBox(tr("Pause On Main Menu Access"));
130131
ctxMenuEnable = new QCheckBox(tr("Context Menu Enable"));
132+
showSplashScreen = new QCheckBox(tr("Show Splash Screen at Startup"));
131133

132134
useNativeFileDialog->setChecked(useNativeFileDialogVal);
133135
useNativeMenuBar->setChecked(useNativeMenuBarVal);
134136
pauseOnMenuAccess->setChecked(pauseOnMenuAccessVal);
135137
ctxMenuEnable->setChecked(contextMenuEnable);
138+
showSplashScreen->setChecked( settings.value("mainWindow/showSplashScreen", false).toBool() );
136139

137140
connect(useNativeFileDialog, SIGNAL(stateChanged(int)), this, SLOT(useNativeFileDialogChanged(int)));
138141
connect(useNativeMenuBar , SIGNAL(stateChanged(int)), this, SLOT(useNativeMenuBarChanged(int)));
139142
connect(pauseOnMenuAccess , SIGNAL(stateChanged(int)), this, SLOT(pauseOnMenuAccessChanged(int)));
140143
connect(ctxMenuEnable , SIGNAL(stateChanged(int)), this, SLOT(contextMenuEnableChanged(int)));
144+
connect(showSplashScreen , SIGNAL(stateChanged(int)), this, SLOT(showSplashScreenChanged(int)));
141145

142146
styleComboBox = new QComboBox();
143147

@@ -239,6 +243,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
239243
vbox1->addWidget(useNativeMenuBar, 1);
240244
vbox1->addWidget(pauseOnMenuAccess, 1);
241245
vbox1->addWidget(ctxMenuEnable, 1);
246+
vbox1->addWidget(showSplashScreen, 1);
242247
vbox1->addStretch(10);
243248

244249
closeButton = new QPushButton( tr("Close") );
@@ -310,6 +315,15 @@ void GuiConfDialog_t::contextMenuEnableChanged(int state)
310315
consoleWindow->setContextMenuEnable( value );
311316
}
312317
//----------------------------------------------------
318+
void GuiConfDialog_t::showSplashScreenChanged(int state)
319+
{
320+
QSettings settings;
321+
bool value = (state == Qt::Unchecked) ? 0 : 1;
322+
323+
settings.setValue("mainWindow/showSplashScreen", value );
324+
settings.sync();
325+
}
326+
//----------------------------------------------------
313327
void GuiConfDialog_t::useCustomStyleChanged(int state)
314328
{
315329
int value = (state == Qt::Unchecked) ? 0 : 1;

src/drivers/Qt/GuiConf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class GuiConfDialog_t : public QDialog
144144
QCheckBox *useNativeMenuBar;
145145
QCheckBox *pauseOnMenuAccess;
146146
QCheckBox *ctxMenuEnable;
147+
QCheckBox *showSplashScreen;
147148
QCheckBox *useCustomStyle;
148149
QCheckBox *useCustomPalette;
149150
QComboBox *styleComboBox;
@@ -158,6 +159,7 @@ private slots:
158159
void useNativeMenuBarChanged(int v);
159160
void pauseOnMenuAccessChanged(int v);
160161
void contextMenuEnableChanged(int v);
162+
void showSplashScreenChanged(int v);
161163
void useCustomQPaletteChanged(int v);
162164
void useCustomStyleChanged(int v);
163165
void styleChanged(int index);

src/drivers/Qt/SplashScreen.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SplashScreen.cpp
2+
#include "Qt/SplashScreen.h"
3+
4+
fceuSplashScreen::fceuSplashScreen(void)
5+
: QSplashScreen( QPixmap(":/fceux1.png") )
6+
{
7+
8+
alpha = 255;
9+
10+
showMessage("Initializing GUI...");
11+
updateTimer = new QTimer(this);
12+
13+
connect(updateTimer, &QTimer::timeout, this, &fceuSplashScreen::periodicUpdate);
14+
}
15+
16+
fceuSplashScreen::~fceuSplashScreen(void)
17+
{
18+
//printf("SplashScreen Detroyed\n");
19+
updateTimer->stop();
20+
}
21+
22+
void fceuSplashScreen::closeEvent(QCloseEvent *event)
23+
{
24+
//printf("Splash CloseEvent\n");
25+
26+
if ( alpha > 0 )
27+
{
28+
if ( !updateTimer->isActive() )
29+
{
30+
updateTimer->start(33);
31+
}
32+
event->ignore();
33+
}
34+
else
35+
{
36+
updateTimer->stop();
37+
QSplashScreen::closeEvent(event);
38+
}
39+
}
40+
41+
void fceuSplashScreen::periodicUpdate(void)
42+
{
43+
if ( alpha > 0 )
44+
{
45+
alpha -= 20;
46+
47+
if ( alpha < 0 )
48+
{
49+
alpha = 0;
50+
}
51+
setWindowOpacity( (double)alpha / 255.0 );
52+
update();
53+
}
54+
else
55+
{
56+
close();
57+
deleteLater();
58+
updateTimer->stop();
59+
}
60+
}

src/drivers/Qt/SplashScreen.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SplashScreen.h
2+
//
3+
#pragma once
4+
5+
#include <QTimer>
6+
#include <QPixmap>
7+
#include <QCloseEvent>
8+
#include <QSplashScreen>
9+
10+
class fceuSplashScreen : public QSplashScreen
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
fceuSplashScreen(void);
16+
~fceuSplashScreen(void);
17+
18+
protected:
19+
void closeEvent(QCloseEvent *event);
20+
21+
private:
22+
QTimer *updateTimer;
23+
int alpha;
24+
25+
private slots:
26+
void periodicUpdate(void);
27+
28+
};

src/drivers/Qt/main.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
#include <stdlib.h>
2222
#include <QApplication>
2323
#include <QSplashScreen>
24+
#include <QSettings>
2425
//#include <QProxyStyle>
2526

2627
#include "Qt/ConsoleWindow.h"
2728
#include "Qt/fceuWrapper.h"
29+
#include "Qt/SplashScreen.h"
2830

2931
#ifdef WIN32
3032
#include <QtPlatformHeaders/QWindowsWindowFunctions>
@@ -81,28 +83,35 @@ static void MessageOutput(QtMsgType type, const QMessageLogContext &context, con
8183

8284
#undef main // undef main in case SDL_Main
8385

84-
//#define SPLASH_SCREEN_ENABLE
86+
static bool showSplashScreen(void)
87+
{
88+
bool show = false;
89+
QSettings settings;
90+
91+
show = settings.value("mainWindow/showSplashScreen", false).toBool();
92+
93+
return show;
94+
}
8595

8696
int main( int argc, char *argv[] )
8797
{
8898
int retval;
8999
qInstallMessageHandler(MessageOutput);
90100
QApplication app(argc, argv);
91-
#ifdef SPLASH_SCREEN_ENABLE
92-
QSplashScreen *splash;
93-
QPixmap pixmap(":/fceux1.png");
94-
95-
splash = new QSplashScreen( pixmap );
96-
splash->show();
97-
98-
splash->showMessage("Initializing GUI...");
99-
app.processEvents();
100-
#endif
101101

102-
QCoreApplication::setOrganizationName("TasVideos");
103-
QCoreApplication::setOrganizationDomain("TasVideos.org");
102+
QCoreApplication::setOrganizationName("TasEmulators");
103+
QCoreApplication::setOrganizationDomain("TasEmulators.org");
104104
QCoreApplication::setApplicationName("fceux");
105105

106+
fceuSplashScreen *splash = NULL;
107+
108+
if ( showSplashScreen() )
109+
{
110+
splash = new fceuSplashScreen();
111+
splash->show();
112+
app.processEvents();
113+
}
114+
106115
#ifdef WIN32
107116
if (AttachConsole(ATTACH_PARENT_PROCESS))
108117
{
@@ -148,11 +157,11 @@ int main( int argc, char *argv[] )
148157
QWindowsWindowFunctions::setHasBorderInFullScreen( consoleWindow->windowHandle(), true);
149158
#endif
150159

151-
#ifdef SPLASH_SCREEN_ENABLE
152-
splash->finish( consoleWindow );
153-
154-
delete splash;
155-
#endif
160+
if ( splash )
161+
{
162+
splash->finish( consoleWindow );
163+
//delete splash; this is handled by Qt event loop
164+
}
156165

157166
retval = app.exec();
158167

0 commit comments

Comments
 (0)