From 412ca246c77140e3c5f5a082db412a722114c68c Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Fri, 6 Nov 2020 23:45:39 -0500 Subject: [PATCH] Successful loading of a movie from the movie play window. Styling update for debugger window for dark themes. --- src/drivers/Qt/ConsoleDebugger.cpp | 52 +++++- src/drivers/Qt/ConsoleDebugger.h | 1 + src/drivers/Qt/MoviePlay.cpp | 252 +++++++++++++++++++++++++++-- src/drivers/Qt/MoviePlay.h | 5 + 4 files changed, 292 insertions(+), 18 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 111aa93c..a01200f2 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -2734,15 +2734,45 @@ QAsmView::QAsmView(QWidget *parent) { QPalette pal; QColor fg("black"), bg("white"); + QColor c; + + useDarkTheme = false; font.setFamily("Courier New"); font.setStyle( QFont::StyleNormal ); font.setStyleHint( QFont::Monospace ); pal = this->palette(); - pal.setColor(QPalette::Base , bg ); - pal.setColor(QPalette::Background, bg ); - pal.setColor(QPalette::WindowText, fg ); + + //c = pal.color(QPalette::Base); + //printf("Base: R:%i G:%i B:%i \n", c.red(), c.green(), c.blue() ); + + //c = pal.color(QPalette::Background); + //printf("BackGround: R:%i G:%i B:%i \n", c.red(), c.green(), c.blue() ); + + // Figure out if we are using a light or dark theme by checking the + // default window text grayscale color. If more white, then we will + // use white text on black background, else we do the opposite. + c = pal.color(QPalette::WindowText); + + if ( qGray( c.red(), c.green(), c.blue() ) > 128 ) + { + useDarkTheme = true; + } + //printf("WindowText: R:%i G:%i B:%i \n", c.red(), c.green(), c.blue() ); + + if ( useDarkTheme ) + { + pal.setColor(QPalette::Base , fg ); + pal.setColor(QPalette::Background, fg ); + pal.setColor(QPalette::WindowText, bg ); + } + else + { + pal.setColor(QPalette::Base , bg ); + pal.setColor(QPalette::Background, bg ); + pal.setColor(QPalette::WindowText, fg ); + } this->parent = (ConsoleDebugger*)parent; this->setPalette(pal); @@ -3047,6 +3077,8 @@ void QAsmView::paintEvent(QPaintEvent *event) { int x,y,l, row, nrow, selAddr; QPainter painter(this); + QColor black("black"); + bool forceDarkColor = false; painter.setFont(font); viewWidth = event->rect().width(); @@ -3087,13 +3119,15 @@ void QAsmView::paintEvent(QPaintEvent *event) { x = -pxLineXScroll; l = lineOffset + row; - painter.setPen( this->palette().color(QPalette::WindowText)); + + forceDarkColor = false; if ( asmPC != NULL ) { if ( l == asmPC->line ) { painter.fillRect( 0, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, QColor("pink") ); + forceDarkColor = true; } } @@ -3102,6 +3136,16 @@ void QAsmView::paintEvent(QPaintEvent *event) if ( asmEntry[l]->type != dbg_asm_entry_t::ASM_TEXT ) { painter.fillRect( 0, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, QColor("light blue") ); + forceDarkColor = true; + } + + if ( forceDarkColor ) + { + painter.setPen( black ); + } + else + { + painter.setPen( this->palette().color(QPalette::WindowText)); } painter.drawText( x, y, tr(asmEntry[l]->text.c_str()) ); diff --git a/src/drivers/Qt/ConsoleDebugger.h b/src/drivers/Qt/ConsoleDebugger.h index 8b71c345..3e5e97e4 100644 --- a/src/drivers/Qt/ConsoleDebugger.h +++ b/src/drivers/Qt/ConsoleDebugger.h @@ -148,6 +148,7 @@ class QAsmView : public QWidget dbg_asm_entry_t *asmPC; std::vector asmEntry; + bool useDarkTheme; bool displayROMoffsets; bool symbolicDebugEnable; bool registerNameEnable; diff --git a/src/drivers/Qt/MoviePlay.cpp b/src/drivers/Qt/MoviePlay.cpp index 5009ac71..fdd603ba 100644 --- a/src/drivers/Qt/MoviePlay.cpp +++ b/src/drivers/Qt/MoviePlay.cpp @@ -116,8 +116,13 @@ MoviePlayDialog_t::MoviePlayDialog_t(QWidget *parent) setLayout( mainLayout ); connect( cancelButton , SIGNAL(clicked(void)), this, SLOT(closeWindow(void)) ); + connect( okButton , SIGNAL(clicked(void)), this, SLOT(playMovie(void)) ); connect( movBrowseBtn , SIGNAL(clicked(void)), this, SLOT(openMovie(void)) ); + + doScan(); + + updateMovieText(); } //---------------------------------------------------------------------------- MoviePlayDialog_t::~MoviePlayDialog_t(void) @@ -145,13 +150,228 @@ void MoviePlayDialog_t::closeWindow(void) // suggestReadOnlyReplay = (state != Qt::Unchecked); //} //---------------------------------------------------------------------------- +void MoviePlayDialog_t::updateMovieText(void) +{ + int idx; + std::string path; + FCEUFILE* fp; + MOVIE_INFO info; + bool scanok; + char stmp[256]; + + if ( movSelBox->count() == 0 ) + { + return; + } + idx = movSelBox->currentIndex(); + + path = movSelBox->itemText(idx).toStdString(); + + fp = FCEU_fopen( path.c_str(),0,"rb",0); + + if ( fp == NULL ) + { + return; + } + scanok = FCEUI_MovieGetInfo(fp, info, false); + + if ( scanok ) + { + double div; + + sprintf(stmp, "%u", (unsigned)info.num_frames); + + movFramesLbl->setText( tr(stmp) ); + + div = (FCEUI_GetCurrentVidSystem(0,0)) ? 50.006977968268290849 : 60.098813897440515532; // PAL timing + double tempCount = (info.num_frames / div) + 0.005; // +0.005s for rounding + int num_seconds = (int)tempCount; + int fraction = (int)((tempCount - num_seconds) * 100); + int seconds = num_seconds % 60; + int minutes = (num_seconds / 60) % 60; + int hours = (num_seconds / 60 / 60) % 60; + sprintf(stmp, "%02d:%02d:%02d.%02d", hours, minutes, seconds, fraction); + + movLenLbl->setText( tr(stmp) ); + + sprintf(stmp, "%u", (unsigned)info.rerecord_count); + + recCountLbl->setText( tr(stmp) ); + + recFromLbl->setText( tr(info.poweron ? "Power-On" : (info.reset?"Soft-Reset":"Savestate") ) ); + + romUsedLbl->setText( tr(info.name_of_rom_used.c_str()) ); + + romCsumLbl->setText( tr(md5_asciistr(info.md5_of_rom_used)) ); + + if ( GameInfo ) + { + curCsumLbl->setText( tr(md5_asciistr(GameInfo->MD5)) ); + } + else + { + curCsumLbl->clear(); + } + + if (info.emu_version_used < 20000 ) + { + sprintf( stmp, "FCEU %d.%02d.%02d%s", info.emu_version_used/10000, (info.emu_version_used/100)%100, (info.emu_version_used)%100, info.emu_version_used < 9813 ? " (blip)" : ""); + } + else + { + sprintf( stmp, "FCEUX %d.%02d.%02d", info.emu_version_used/10000, (info.emu_version_used/100)%100, (info.emu_version_used)%100); + } + emuUsedLbl->setText( tr(stmp) ); + + palUsedLbl->setText( tr(info.pal ? "On" : "Off") ); + + newppuUsedLbl->setText( tr(info.ppuflag ? "On" : "Off") ); + } + delete fp; + + return; +} +//---------------------------------------------------------------------------- +int MoviePlayDialog_t::addFileToList( const char *file, bool setActive ) +{ + int n=0; + + for (int i=0; icount(); i++) + { + if ( strcmp( file, movSelBox->itemText(i).toStdString().c_str() ) == 0 ) + { + if ( setActive ) + { + movSelBox->setCurrentIndex(i); + } + return -1; + } + } + + n = movSelBox->count(); + + movSelBox->addItem( tr(file), n ); + + if ( setActive ) + { + movSelBox->setCurrentIndex(n); + } + + return 0; +} +//---------------------------------------------------------------------------- +bool MoviePlayDialog_t::checkMD5Sum( const char *path, const char *md5 ) +{ + FCEUFILE* fp; + MOVIE_INFO info; + bool scanok, md5Match = false; + + fp = FCEU_fopen( path,0,"rb",0); + + if ( fp == NULL ) + { + return md5Match; + } + scanok = FCEUI_MovieGetInfo(fp, info, true); + + if ( scanok ) + { + if ( strcmp( md5, md5_asciistr(info.md5_of_rom_used) ) == 0 ) + { + md5Match = true; + } + } + delete fp; + + return md5Match; +} +//---------------------------------------------------------------------------- +void MoviePlayDialog_t::doScan(void) +{ + std::string path; + QDir dir; + QFileInfoList list; + const char *baseDir = FCEUI_GetBaseDirectory(); + const QStringList filters( { "*.fm2" } ); + char md5[256]; + + md5[0] = 0; + + if ( GameInfo ) + { + strcpy( md5, md5_asciistr(GameInfo->MD5) ); + } + + path = std::string(baseDir) + "/movies/"; + + dir.setPath( QString::fromStdString(path) ); + + list = dir.entryInfoList( filters, QDir::Files ); + + for (int i = 0; i < list.size(); ++i) + { + QFileInfo fileInfo = list.at(i); + + path = std::string(baseDir) + "/movies/" + fileInfo.fileName().toStdString(); + + //printf("File: '%s'\n", path.c_str() ); + + if ( checkMD5Sum( path.c_str(), md5 ) ) + { + addFileToList( path.c_str() ); + } + } +} +//---------------------------------------------------------------------------- +void MoviePlayDialog_t::playMovie(void) +{ + int idx, pauseframe = 0; + bool replayReadOnlySetting, movieLoadError = false; + + if ( movSelBox->count() == 0 ) + { + return; + } + std::string path; + + idx = movSelBox->currentIndex(); + + path = movSelBox->itemText(idx).toStdString(); + + if (suggestReadOnlyReplay) + { + replayReadOnlySetting = true; + } + else + { + replayReadOnlySetting = FCEUI_GetMovieToggleReadOnly(); + } + + fceuWrapperLock(); + if (FCEUI_LoadMovie( path.c_str(), + replayReadOnlySetting, pauseframe ? pauseframe : false) == false) + { + movieLoadError = true; + } + fceuWrapperUnLock(); + + if ( movieLoadError ) + { + printf("Error: Could not open movie file: %s \n", path.c_str() ); + } + else + { + closeWindow(); + } +} +//---------------------------------------------------------------------------- void MoviePlayDialog_t::openMovie(void) { int ret, useNativeFileDialogVal; QString filename; std::string last; char dir[512]; - char replayReadOnlySetting; + char md5Match = 0; QFileDialog dialog(this, tr("Open FM2 Movie") ); dialog.setFileMode(QFileDialog::ExistingFile); @@ -193,22 +413,26 @@ void MoviePlayDialog_t::openMovie(void) } 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() ); - - if (suggestReadOnlyReplay) + if ( GameInfo ) { - replayReadOnlySetting = true; - } - else - { - replayReadOnlySetting = FCEUI_GetMovieToggleReadOnly(); + char md5[256]; + + strcpy( md5, md5_asciistr(GameInfo->MD5) ); + + if ( checkMD5Sum( filename.toStdString().c_str(), md5 ) ) + { + md5Match = 1; + } + + if ( !md5Match ) + { + printf("Warning MD5 Mismatch\n"); + } } - movSelBox->addItem( filename, movSelBox->count() ); + addFileToList( filename.toStdString().c_str(), true ); + + updateMovieText(); //fceuWrapperLock(); //if (FCEUI_LoadMovie( filename.toStdString().c_str(), // replayReadOnlySetting, pauseframe ? pauseframe : false) == false) diff --git a/src/drivers/Qt/MoviePlay.h b/src/drivers/Qt/MoviePlay.h index 691f0753..5018a4d6 100644 --- a/src/drivers/Qt/MoviePlay.h +++ b/src/drivers/Qt/MoviePlay.h @@ -46,11 +46,16 @@ class MoviePlayDialog_t : public QDialog QLabel *newppuUsedLbl; private: + void doScan(void); + void updateMovieText(void); + int addFileToList( const char *file, bool setActive = false ); + bool checkMD5Sum( const char *path, const char *md5 ); public slots: void closeWindow(void); private slots: void openMovie(void); + void playMovie(void); //void readOnlyReplayChanged( int state ); };