From b3c51ef4b1206b4468b61c20a0f3700483731cae Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sat, 11 Jul 2020 20:48:48 -0400 Subject: [PATCH] Added movie menu logic to gui. --- src/drivers/Qt/ConsoleWindow.cpp | 175 +++++++++++++++++++++++++++++++ src/drivers/Qt/ConsoleWindow.h | 9 ++ src/drivers/Qt/fceuWrapper.cpp | 5 + src/drivers/Qt/fceuWrapper.h | 1 + 4 files changed, 190 insertions(+) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index cbe778a8..1de89b3b 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -7,6 +7,7 @@ #include "../../fceu.h" #include "../../fds.h" +#include "../../movie.h" #ifdef _S9XLUA_H #include "../../fceulua.h" @@ -395,6 +396,44 @@ void consoleWin_t::createMainMenu(void) subMenu->addAction(fdsLoadBiosAct); + //----------------------------------------------------------------------- + // Movie + movieMenu = menuBar()->addMenu(tr("Movie")); + + // Movie -> Open + openMovAct = new QAction(tr("Open"), this); + openMovAct->setShortcut( QKeySequence(tr("Shift+F7"))); + openMovAct->setStatusTip(tr("Open Movie File")); + connect(openMovAct, SIGNAL(triggered()), this, SLOT(openMovie(void)) ); + + movieMenu->addAction(openMovAct); + + // Movie -> Stop + stopMovAct = new QAction(tr("Stop"), this); + //stopMovAct->setShortcut( QKeySequence(tr("Shift+F7"))); + stopMovAct->setStatusTip(tr("Stop Movie Recording")); + connect(stopMovAct, SIGNAL(triggered()), this, SLOT(stopMovie(void)) ); + + movieMenu->addAction(stopMovAct); + + movieMenu->addSeparator(); + + // Movie -> Record + recMovAct = new QAction(tr("Record"), this); + recMovAct->setShortcut( QKeySequence(tr("Shift+F5"))); + recMovAct->setStatusTip(tr("Record Movie")); + connect(recMovAct, SIGNAL(triggered()), this, SLOT(recordMovie(void)) ); + + movieMenu->addAction(recMovAct); + + // Movie -> Record As + recAsMovAct = new QAction(tr("Record As"), this); + //recAsMovAct->setShortcut( QKeySequence(tr("Shift+F5"))); + recAsMovAct->setStatusTip(tr("Record Movie")); + connect(recAsMovAct, SIGNAL(triggered()), this, SLOT(recordMovieAs(void)) ); + + movieMenu->addAction(recAsMovAct); + //----------------------------------------------------------------------- // Help helpMenu = menuBar()->addMenu(tr("Help")); @@ -1046,6 +1085,142 @@ void consoleWin_t::fdsLoadBiosFile(void) return; } +void consoleWin_t::openMovie(void) +{ + int ret; + QString filename; + std::string last; + QFileDialog dialog(this, tr("Open FM2 Movie") ); + + dialog.setFileMode(QFileDialog::ExistingFile); + + dialog.setNameFilter(tr("FM2 Movies (*.fm2) ;; All files (*)")); + + dialog.setViewMode(QFileDialog::List); + + g_config->getOption ("SDL.LastOpenFile", &last ); + + dialog.setDirectory( tr(last.c_str()) ); + + // the gnome default file dialog is not playing nice with QT. + // TODO make this a config option to use native file dialog. + dialog.setOption(QFileDialog::DontUseNativeDialog, true); + + dialog.show(); + ret = dialog.exec(); + + if ( ret ) + { + QStringList fileList; + fileList = dialog.selectedFiles(); + + if ( fileList.size() > 0 ) + { + filename = fileList[0]; + } + } + + if ( filename.isNull() ) + { + return; + } + qDebug() << "selected file path : " << filename.toUtf8(); + + int pauseframe; + g_config->getOption ("SDL.PauseFrame", &pauseframe); + g_config->setOption ("SDL.PauseFrame", 0); + + FCEUI_printf ("Playing back movie located at %s\n", filename.toStdString().c_str() ); + + fceuWrapperLock(); + if (FCEUI_LoadMovie( filename.toStdString().c_str(), + false, pauseframe ? pauseframe : false) == false) + { + printf("Error: Could not open movie file: %s \n", filename.toStdString().c_str() ); + } + fceuWrapperUnLock(); + + return; +} + +void consoleWin_t::stopMovie(void) +{ + fceuWrapperLock(); + FCEUI_StopMovie(); + fceuWrapperUnLock(); + return; +} + +void consoleWin_t::recordMovie(void) +{ + fceuWrapperLock(); + if (fceuWrapperGameLoaded()) + { + std::string name = FCEU_MakeFName (FCEUMKF_MOVIE, 0, 0); + FCEUI_printf ("Recording movie to %s\n", name.c_str ()); + FCEUI_SaveMovie (name.c_str (), MOVIE_FLAG_NONE, L""); + } + fceuWrapperUnLock(); + return; +} + +void consoleWin_t::recordMovieAs(void) +{ + int ret; + QString filename; + std::string last; + QFileDialog dialog(this, tr("Save FM2 Movie for Recording") ); + + dialog.setFileMode(QFileDialog::AnyFile); + + dialog.setNameFilter(tr("FM2 Movies (*.fm2) ;; All files (*)")); + + dialog.setViewMode(QFileDialog::List); + + g_config->getOption ("SDL.LastOpenFile", &last ); + + dialog.setDirectory( tr(last.c_str()) ); + + // the gnome default file dialog is not playing nice with QT. + // TODO make this a config option to use native file dialog. + dialog.setOption(QFileDialog::DontUseNativeDialog, true); + + dialog.show(); + ret = dialog.exec(); + + if ( ret ) + { + QStringList fileList; + fileList = dialog.selectedFiles(); + + if ( fileList.size() > 0 ) + { + filename = fileList[0]; + } + } + + if ( filename.isNull() ) + { + return; + } + qDebug() << "selected file path : " << filename.toUtf8(); + + int pauseframe; + g_config->getOption ("SDL.PauseFrame", &pauseframe); + g_config->setOption ("SDL.PauseFrame", 0); + + FCEUI_printf ("Recording movie to %s\n", filename.toStdString().c_str() ); + + fceuWrapperLock(); + std::string s = GetUserText ("Author name"); + std::wstring author (s.begin (), s.end ()); + + FCEUI_SaveMovie ( filename.toStdString().c_str(), MOVIE_FLAG_NONE, author); + fceuWrapperUnLock(); + + return; +} + void consoleWin_t::aboutFCEUX(void) { AboutWindow *aboutWin; diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 8464106a..692f7051 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -50,6 +50,7 @@ class consoleWin_t : public QMainWindow QMenu *fileMenu; QMenu *optMenu; QMenu *emuMenu; + QMenu *movieMenu; QMenu *helpMenu; QAction *openROM; @@ -80,6 +81,10 @@ class consoleWin_t : public QMainWindow QAction *fdsSwitchAct; QAction *fdsEjectAct; QAction *fdsLoadBiosAct; + QAction *openMovAct; + QAction *stopMovAct; + QAction *recMovAct; + QAction *recAsMovAct; QTimer *gameTimer; emulatorThread_t *emulatorThread; @@ -134,6 +139,10 @@ class consoleWin_t : public QMainWindow void fdsSwitchDisk(void); void fdsEjectDisk(void); void fdsLoadBiosFile(void); + void openMovie(void); + void stopMovie(void); + void recordMovie(void); + void recordMovieAs(void); }; diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index 5c8943a5..c3601449 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -318,6 +318,11 @@ int fceuWrapperTogglePause(void) return 0; } +bool fceuWrapperGameLoaded(void) +{ + return (isloaded ? true : false); +} + int fceuWrapperInit( int argc, char *argv[] ) { int error; diff --git a/src/drivers/Qt/fceuWrapper.h b/src/drivers/Qt/fceuWrapper.h index ac057025..e3ce55a8 100644 --- a/src/drivers/Qt/fceuWrapper.h +++ b/src/drivers/Qt/fceuWrapper.h @@ -32,4 +32,5 @@ void fceuWrapperUnLock(void); int fceuWrapperSoftReset(void); int fceuWrapperHardReset(void); int fceuWrapperTogglePause(void); +bool fceuWrapperGameLoaded(void);