Merge pull request #136 from mjbudd77/master

Qt SDL Port Video Driver and Menu Bar Config Options
This commit is contained in:
mjbudd77 2020-07-21 21:42:57 -04:00 committed by GitHub
commit 3fad48edea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 227 additions and 69 deletions

View File

@ -391,6 +391,7 @@ set(SRC_DRIVERS_SDL
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/PaletteConf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/GuiConf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/LuaControl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleUtilities.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleVideoConf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleSoundConf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/AboutWindow.cpp

View File

@ -0,0 +1,37 @@
// ConsoleUtilities.cpp
#include <stdio.h>
#include <string.h>
#include "Qt/ConsoleUtilities.h"
//---------------------------------------------------------------------------
int getDirFromFile( const char *path, char *dir )
{
int i, lastSlash = -1, lastPeriod = -1;
i=0;
while ( path[i] != 0 )
{
if ( path[i] == '/' )
{
lastSlash = i;
}
else if ( path[i] == '.' )
{
lastPeriod = i;
}
dir[i] = path[i]; i++;
}
dir[i] = 0;
if ( lastPeriod >= 0 )
{
if ( lastPeriod > lastSlash )
{
dir[lastSlash] = 0;
}
}
return 0;
}
//---------------------------------------------------------------------------

View File

@ -0,0 +1,3 @@
// ConsoleUtilities.h
int getDirFromFile( const char *path, char *dir );

View File

@ -26,7 +26,7 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
driverSelect = new QComboBox();
driverSelect->addItem( tr("OpenGL"), 0 );
//driverSelect->addItem( tr("SDL"), 1 );
driverSelect->addItem( tr("SDL"), 1 );
hbox1 = new QHBoxLayout();
@ -52,8 +52,10 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
regionSelect->addItem( tr("Dendy"), 2 );
setComboBoxFromProperty( regionSelect, "SDL.PAL");
setComboBoxFromProperty( driverSelect, "SDL.VideoDriver");
connect(regionSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(regionChanged(int)) );
connect(driverSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(driverChanged(int)) );
hbox1 = new QHBoxLayout();
@ -199,6 +201,20 @@ void ConsoleVideoConfDialog_t::showFPSChanged( int value )
fceuWrapperUnLock();
}
//----------------------------------------------------
void ConsoleVideoConfDialog_t::driverChanged(int index)
{
int driver;
//printf("Driver: %i : %i \n", index, driverSelect->itemData(index).toInt() );
driver = driverSelect->itemData(index).toInt();
g_config->setOption ("SDL.VideoDriver", driver);
g_config->save ();
printf("Note: A restart of the application is needed for video driver change to take effect...\n");
}
//----------------------------------------------------
void ConsoleVideoConfDialog_t::regionChanged(int index)
{
int region;

View File

@ -47,6 +47,7 @@ class ConsoleVideoConfDialog_t : public QDialog
void clipSidesChanged( int value );
void showFPSChanged( int value );
void regionChanged(int index);
void driverChanged(int index);
void applyChanges( void );
void closewindow( void );

View File

@ -15,6 +15,12 @@ extern unsigned int gui_draw_area_height;
ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
: QWidget( parent )
{
QPalette pal = palette();
pal.setColor(QPalette::Background, Qt::black);
setAutoFillBackground(true);
setPalette(pal);
view_width = GL_NES_WIDTH;
view_height = GL_NES_HEIGHT;
@ -30,11 +36,29 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
sdlTexture = NULL;
vsyncEnabled = false;
localBufSize = GL_NES_WIDTH * GL_NES_HEIGHT * sizeof(uint32_t);
localBuf = (uint32_t*)malloc( localBufSize );
if ( localBuf )
{
memset( localBuf, 0, localBufSize );
}
}
ConsoleViewSDL_t::~ConsoleViewSDL_t(void)
{
if ( localBuf )
{
free( localBuf ); localBuf = NULL;
}
}
void ConsoleViewSDL_t::transfer2LocalBuffer(void)
{
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
}
int ConsoleViewSDL_t::init(void)
@ -46,10 +70,16 @@ int ConsoleViewSDL_t::init(void)
printf("[SDL] Failed to initialize video subsystem.\n");
return -1;
}
//else
//{
// printf("Initialized SDL Video Subsystem\n");
//}
else
{
printf("Initialized SDL Video Subsystem\n");
}
for (int i=0; i<SDL_GetNumVideoDrivers(); i++)
{
printf("SDL Video Driver %i: %s\n", i, SDL_GetVideoDriver(i) );
}
printf("Using Video Driver: %s \n", SDL_GetCurrentVideoDriver() );
windowHandle = this->winId();
@ -132,17 +162,18 @@ void ConsoleViewSDL_t::resizeEvent(QResizeEvent *event)
s = event->size();
view_width = s.width();
view_height = s.height();
//printf("SDL Resize: %i x %i \n", view_width, view_height);
printf("SDL Resize: %i x %i \n", view_width, view_height);
reset();
sdlViewport.x = sdlRendW - view_width;
sdlViewport.y = sdlRendH - view_height;
sdlViewport.w = view_width;
sdlViewport.h = view_height;
//sdlViewport.x = sdlRendW - view_width;
//sdlViewport.y = sdlRendH - view_height;
//sdlViewport.w = view_width;
//sdlViewport.h = view_height;
}
void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
//void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
void ConsoleViewSDL_t::render(void)
{
int nesWidth = GL_NES_WIDTH;
int nesHeight = GL_NES_HEIGHT;
@ -167,8 +198,10 @@ void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
rw=(int)(nesWidth*xscale);
rh=(int)(nesHeight*yscale);
sx=sdlViewport.x + (view_width-rw)/2;
sy=sdlViewport.y + (view_height-rh)/2;
//sx=sdlViewport.x + (view_width-rw)/2;
//sy=sdlViewport.y + (view_height-rh)/2;
sx=(view_width-rw)/2;
sy=(view_height-rh)/2;
if ( (sdlRenderer == NULL) || (sdlTexture == NULL) )
{
@ -183,13 +216,13 @@ void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
int rowPitch;
SDL_LockTexture( sdlTexture, nullptr, (void**)&textureBuffer, &rowPitch);
{
memcpy( textureBuffer, nes_shm->pixbuf, GL_NES_HEIGHT*GL_NES_WIDTH*sizeof(uint32_t) );
memcpy( textureBuffer, localBuf, GL_NES_HEIGHT*GL_NES_WIDTH*sizeof(uint32_t) );
}
SDL_UnlockTexture(sdlTexture);
SDL_RenderSetViewport( sdlRenderer, &sdlViewport );
//SDL_RenderSetViewport( sdlRenderer, &sdlViewport );
SDL_Rect source = {0, 0, GL_NES_WIDTH, GL_NES_HEIGHT };
SDL_Rect source = {0, 0, nesWidth, nesHeight };
SDL_Rect dest = { sx, sy, rw, rh };
SDL_RenderCopy(sdlRenderer, sdlTexture, &source, &dest);

View File

@ -19,10 +19,13 @@ class ConsoleViewSDL_t : public QWidget
int init(void);
void reset(void);
void cleanup(void);
void render(void);
void transfer2LocalBuffer(void);
protected:
void paintEvent(QPaintEvent *event);
//void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
int view_width;
int view_height;
@ -37,10 +40,13 @@ class ConsoleViewSDL_t : public QWidget
bool vsyncEnabled;
uint32_t *localBuf;
uint32_t localBufSize;
SDL_Window *sdlWindow;
SDL_Renderer *sdlRenderer;
SDL_Texture *sdlTexture;
SDL_Rect sdlViewport;
//SDL_Rect sdlViewport;
private slots:
};

View File

@ -22,6 +22,7 @@
#include "Qt/PaletteConf.h"
#include "Qt/GuiConf.h"
#include "Qt/LuaControl.h"
#include "Qt/ConsoleUtilities.h"
#include "Qt/ConsoleSoundConf.h"
#include "Qt/ConsoleVideoConf.h"
#include "Qt/AboutWindow.h"
@ -32,13 +33,28 @@
consoleWin_t::consoleWin_t(QWidget *parent)
: QMainWindow( parent )
{
int use_SDL_video = false;
createMainMenu();
viewport = new ConsoleViewGL_t(this);
//viewport = new ConsoleViewSDL_t(this);
g_config->getOption( "SDL.VideoDriver", &use_SDL_video );
viewport_GL = NULL;
viewport_SDL = NULL;
if ( use_SDL_video )
{
viewport_SDL = new ConsoleViewSDL_t(this);
setCentralWidget(viewport_SDL);
}
else
{
viewport_GL = new ConsoleViewGL_t(this);
setCentralWidget(viewport_GL);
}
setCentralWidget(viewport);
setWindowIcon(QIcon(":fceux1.png"));
gameTimer = new QTimer( this );
@ -74,7 +90,14 @@ consoleWin_t::~consoleWin_t(void)
emulatorThread->quit();
emulatorThread->wait();
delete viewport;
if ( viewport_GL != NULL )
{
delete viewport_GL; viewport_GL = NULL;
}
if ( viewport_SDL != NULL )
{
delete viewport_SDL; viewport_SDL = NULL;
}
delete mutex;
// LoadGame() checks for an IP and if it finds one begins a network session
@ -121,9 +144,12 @@ void consoleWin_t::createMainMenu(void)
{
QMenu *subMenu;
QActionGroup *group;
int useNativeMenuBar;
// This is needed for menu bar to show up on MacOS
menuBar()->setNativeMenuBar(false);
// This is needed for menu bar to show up on MacOS
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
menuBar()->setNativeMenuBar( useNativeMenuBar ? true : false );
//-----------------------------------------------------------------------
// File
@ -487,36 +513,6 @@ void consoleWin_t::closeApp(void)
qApp->quit();
}
//---------------------------------------------------------------------------
int consoleWin_t::getDirFromFile( const char *path, char *dir )
{
int i, lastSlash = -1, lastPeriod = -1;
i=0;
while ( path[i] != 0 )
{
if ( path[i] == '/' )
{
lastSlash = i;
}
else if ( path[i] == '.' )
{
lastPeriod = i;
}
dir[i] = path[i]; i++;
}
dir[i] = 0;
if ( lastPeriod >= 0 )
{
if ( lastPeriod > lastSlash )
{
dir[lastSlash] = 0;
}
}
return 0;
}
//---------------------------------------------------------------------------
void consoleWin_t::openROMFile(void)
{
@ -531,6 +527,8 @@ void consoleWin_t::openROMFile(void)
dialog.setNameFilter(tr("NES files (*.nes *.NES) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Open") );
g_config->getOption ("SDL.LastOpenFile", &last );
@ -593,6 +591,8 @@ void consoleWin_t::loadNSF(void)
dialog.setNameFilter(tr("NSF Sound Files (*.nsf *.NSF) ;; Zip Files (*.zip *.ZIP) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
g_config->getOption ("SDL.LastOpenNSF", &last );
@ -642,9 +642,11 @@ void consoleWin_t::loadStateFrom(void)
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("FCS Files (*.fc? *.FC?) ;; SAV Files (*.sav *.SAV) ;; All files (*)"));
dialog.setNameFilter(tr("FCS & SAV Files (*.sav *.SAV *.fc? *.FC?) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
g_config->getOption ("SDL.LastLoadStateFrom", &last );
@ -697,6 +699,9 @@ void consoleWin_t::saveStateAs(void)
dialog.setNameFilter(tr("SAV Files (*.sav *.SAV) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Save") );
dialog.setDefaultSuffix( tr(".sav") );
g_config->getOption ("SDL.LastSaveStateAs", &last );
@ -1022,6 +1027,8 @@ void consoleWin_t::loadGameGenieROM(void)
dialog.setNameFilter(tr("GG ROM File (gg.rom *Genie*.nes) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
g_config->getOption ("SDL.LastOpenFile", &last );
@ -1103,6 +1110,8 @@ void consoleWin_t::fdsLoadBiosFile(void)
dialog.setNameFilter(tr("ROM files (*.rom *.ROM) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
g_config->getOption ("SDL.LastOpenFile", &last );
@ -1168,6 +1177,8 @@ void consoleWin_t::openMovie(void)
dialog.setNameFilter(tr("FM2 Movies (*.fm2) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Open") );
g_config->getOption ("SDL.LastOpenFile", &last );
@ -1251,6 +1262,8 @@ void consoleWin_t::recordMovieAs(void)
dialog.setNameFilter(tr("FM2 Movies (*.fm2) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Save") );
g_config->getOption ("SDL.LastOpenFile", &last );
@ -1345,10 +1358,17 @@ void consoleWin_t::updatePeriodic(void)
{
nes_shm->blitUpdated = 0;
viewport->transfer2LocalBuffer();
//viewport->repaint();
viewport->update();
if ( viewport_SDL )
{
viewport_SDL->transfer2LocalBuffer();
viewport_SDL->render();
}
else
{
viewport_GL->transfer2LocalBuffer();
//viewport_GL->repaint();
viewport_GL->update();
}
}
return;

View File

@ -39,8 +39,8 @@ class consoleWin_t : public QMainWindow
consoleWin_t(QWidget *parent = 0);
~consoleWin_t(void);
ConsoleViewGL_t *viewport;
//ConsoleViewSDL_t *viewport;
ConsoleViewGL_t *viewport_GL;
ConsoleViewSDL_t *viewport_SDL;
void setCyclePeriodms( int ms );
@ -99,8 +99,6 @@ class consoleWin_t : public QMainWindow
void keyReleaseEvent(QKeyEvent *event);
void syncActionConfig( QAction *act, const char *property );
int getDirFromFile( const char *path, char *dir );
private:
void createMainMenu(void);

View File

@ -8,30 +8,37 @@
#include "Qt/config.h"
#include "Qt/keyscan.h"
#include "Qt/fceuWrapper.h"
#include "Qt/ConsoleWindow.h"
//----------------------------------------------------
GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
: QDialog( parent )
{
int useNativeFileDialogVal;
int useNativeMenuBarVal;
QVBoxLayout *mainLayout;
//resize( 512, 600 );
// sync with config
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
g_config->getOption ("SDL.UseNativeMenuBar", &useNativeMenuBarVal);
setWindowTitle( tr("GUI Config") );
mainLayout = new QVBoxLayout();
useNativeFileDialog = new QCheckBox( tr("Use Native OS File Dialog") );
useNativeMenuBar = new QCheckBox( tr("Use Native OS Menu Bar") );
useNativeFileDialog->setChecked( useNativeFileDialogVal );
useNativeMenuBar->setChecked( useNativeMenuBarVal );
connect(useNativeFileDialog , SIGNAL(stateChanged(int)), this, SLOT(useNativeFileDialogChanged(int)) );
connect(useNativeMenuBar , SIGNAL(stateChanged(int)), this, SLOT(useNativeMenuBarChanged(int)) );
mainLayout->addWidget( useNativeFileDialog );
mainLayout->addWidget( useNativeMenuBar );
setLayout( mainLayout );
}
@ -53,6 +60,14 @@ void GuiConfDialog_t::useNativeFileDialogChanged(int state)
int value = (state == Qt::Unchecked) ? 0 : 1;
g_config->setOption ("SDL.UseNativeFileDialog", value);
}
//----------------------------------------------------
void GuiConfDialog_t::useNativeMenuBarChanged(int state)
{
int value = (state == Qt::Unchecked) ? 0 : 1;
g_config->setOption ("SDL.UseNativeMenuBar", value);
consoleWindow->menuBar()->setNativeMenuBar( value );
}
//----------------------------------------------------

View File

@ -27,11 +27,13 @@ class GuiConfDialog_t : public QDialog
protected:
QCheckBox *useNativeFileDialog;
QCheckBox *useNativeMenuBar;
private:
public slots:
void closeWindow(void);
private slots:
void useNativeFileDialogChanged(int v);
void useNativeMenuBarChanged(int v);
};

View File

@ -17,6 +17,7 @@
#include "Qt/config.h"
#include "Qt/keyscan.h"
#include "Qt/fceuWrapper.h"
#include "Qt/ConsoleUtilities.h"
static bool luaScriptRunning = false;
@ -124,7 +125,7 @@ void LuaControlDialog_t::openLuaScriptFile(void)
int ret, useNativeFileDialogVal;
QString filename;
std::string last;
//char dir[512];
char dir[512];
QFileDialog dialog(this, tr("Open LUA Script") );
dialog.setFileMode(QFileDialog::ExistingFile);
@ -132,6 +133,8 @@ void LuaControlDialog_t::openLuaScriptFile(void)
dialog.setNameFilter(tr("LUA Scripts (*.lua *.LUA) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
g_config->getOption ("SDL.LastLoadLua", &last );
@ -140,9 +143,9 @@ void LuaControlDialog_t::openLuaScriptFile(void)
last.assign( "/usr/share/fceux/luaScripts" );
}
//getDirFromFile( last.c_str(), dir );
getDirFromFile( last.c_str(), dir );
dialog.setDirectory( tr("/usr/share/fceux/luaScripts") );
dialog.setDirectory( tr(dir) );
// Check config option to use native file dialog or not
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);

View File

@ -9,6 +9,7 @@
#include "Qt/config.h"
#include "Qt/keyscan.h"
#include "Qt/fceuWrapper.h"
#include "Qt/ConsoleUtilities.h"
#include "../../ppu.h"
@ -289,6 +290,8 @@ void PaletteConfDialog_t::openPaletteFile(void)
{
int ret, useNativeFileDialogVal;
QString filename;
std::string last;
char dir[512];
QFileDialog dialog(this, tr("Open NES Palette") );
dialog.setFileMode(QFileDialog::ExistingFile);
@ -296,8 +299,19 @@ void PaletteConfDialog_t::openPaletteFile(void)
dialog.setNameFilter(tr("NES Palettes (*.pal *.PAL) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
dialog.setDirectory( tr("/usr/share/fceux/palettes") );
g_config->getOption ("SDL.Palette", &last );
if ( last.size() == 0 )
{
last.assign( "/usr/share/fceux/palettes" );
}
getDirFromFile( last.c_str(), dir );
dialog.setDirectory( tr(dir) );
// Check config option to use native file dialog or not
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);

View File

@ -199,6 +199,7 @@ InitConfig()
// video controls
config->addOption('f', "fullscreen", "SDL.Fullscreen", 0);
config->addOption("videoDriver", "SDL.VideoDriver", 0);
// set x/y res to 0 for automatic fullscreen resolution detection (no change)
config->addOption('x', "xres", "SDL.XResolution", 0);
@ -294,6 +295,7 @@ InitConfig()
config->addOption("_lastloadlua", "SDL.LastLoadLua", "");
config->addOption("_useNativeFileDialog", "SDL.UseNativeFileDialog", false);
config->addOption("_useNativeMenuBar" , "SDL.UseNativeMenuBar", false);
// fcm -> fm2 conversion
config->addOption("fcmconvert", "SDL.FCMConvert", "");

View File

@ -17,7 +17,14 @@ int main( int argc, char *argv[] )
consoleWindow->resize( 512, 512 );
consoleWindow->show();
consoleWindow->viewport->init();
if ( consoleWindow->viewport_SDL )
{
consoleWindow->viewport_SDL->init();
}
else
{
consoleWindow->viewport_GL->init();
}
retval = app.exec();