From 2c7c87e3c852108c90fdff0ecbd76fa3ef9bc390 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 26 Oct 2020 17:28:11 -0400 Subject: [PATCH 1/2] Deleted unused icon file. --- src/drivers/Qt/icon.xpm | 55 ----------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/drivers/Qt/icon.xpm diff --git a/src/drivers/Qt/icon.xpm b/src/drivers/Qt/icon.xpm deleted file mode 100644 index 7c817653..00000000 --- a/src/drivers/Qt/icon.xpm +++ /dev/null @@ -1,55 +0,0 @@ -/* XPM */ -static const char * icon_xpm[] = { -"32 32 20 1", -" c None", -". c #040204", -"+ c #84A284", -"@ c #C42204", -"# c #8482C4", -"$ c #FCFEFC", -"% c #848284", -"& c #648284", -"* c #646284", -"= c #444244", -"- c #A4A284", -"; c #C4A284", -"> c #C48284", -", c #A4CAF4", -"' c #244244", -") c #444204", -"! c #442204", -"~ c #446244", -"{ c #646244", -"] c #644244", -" ", -" ........ ", -" ............... ", -" ........................ ", -" ...........................+ ", -" ............@@..@@........... ", -" .#............@@............$$ ", -" .##..........@@.@.....$$%%%%$$ ", -" &...........@....@$$$$$$%%&%$$ ", -" *&...............$$$$$$$%%&%$$ ", -" =&*.......-;;>;...$$,$$$%**&.. ", -" '&&..............$$,,,%=)!~.. ", -" ~&&............-%%##%*.~'=%& ", -" *&&.....+%%****&&%%&*.&!!' ", -" **&%&***********&&&*~{'= ", -" ********=**~**~**~ ", -" *****~******] ", -" **~***]' ", -" ~]== ", -" ", -" ..... .... .... .. ..@@ @@", -" ..... .... .... .. ..@@@ @@@", -" .. .. .. .. .. @@@ @@@ ", -" .... .. .. .. .. @@@@@@ ", -" .... .. ... .. .. @@@@ ", -" .. .. ... .. .. @@@@ ", -" .. .. .. .. .. @@@@@@ ", -" .. .. .. .. .. @@@ @@@ ", -" .. .... .... .....@@@ @@@", -" .. .... .... ... @@ @@", -" ", -" "}; From 8f336bf8d3bf1a064accf29341254fa30274bf4c Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 26 Oct 2020 20:53:36 -0400 Subject: [PATCH 2/2] Added logic to the Qt GUI Video Config Window to allow for the image pixel scaling to be numerically set. Also added a square pixel option to allow for the X and Y scales to either be set separately or tied together. This addresses issue #205. --- src/drivers/Qt/ConsoleVideoConf.cpp | 150 ++++++++++++++++++++++++++++ src/drivers/Qt/ConsoleVideoConf.h | 8 ++ src/drivers/Qt/ConsoleViewerGL.cpp | 33 +++--- src/drivers/Qt/ConsoleViewerGL.h | 8 ++ src/drivers/Qt/ConsoleViewerSDL.cpp | 25 +++-- src/drivers/Qt/ConsoleViewerSDL.h | 32 +++--- src/drivers/Qt/sdl-video.cpp | 4 + 7 files changed, 228 insertions(+), 32 deletions(-) diff --git a/src/drivers/Qt/ConsoleVideoConf.cpp b/src/drivers/Qt/ConsoleVideoConf.cpp index f85db198..1e8a4f8f 100644 --- a/src/drivers/Qt/ConsoleVideoConf.cpp +++ b/src/drivers/Qt/ConsoleVideoConf.cpp @@ -9,6 +9,7 @@ #include "Qt/fceuWrapper.h" #include "Qt/ConsoleWindow.h" #include "Qt/ConsoleVideoConf.h" +#include "Qt/nes_shm.h" //---------------------------------------------------- ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) @@ -84,23 +85,89 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) // Show FPS Checkbox showFPS_cbx = new QCheckBox( tr("Show FPS") ); + // Square Pixels + sqrPixCbx = new QCheckBox( tr("Square Pixels") ); + setCheckBoxFromProperty( new_PPU_ena , "SDL.NewPPU"); setCheckBoxFromProperty( frmskipcbx , "SDL.Frameskip"); setCheckBoxFromProperty( sprtLimCbx , "SDL.DisableSpriteLimit"); setCheckBoxFromProperty( clipSidesCbx , "SDL.ClipSides"); setCheckBoxFromProperty( showFPS_cbx , "SDL.ShowFPS"); + + if ( consoleWindow ) + { + if ( consoleWindow->viewport_GL ) + { + sqrPixCbx->setChecked( consoleWindow->viewport_GL->getSqrPixelOpt() ); + } + else if ( consoleWindow->viewport_SDL ) + { + sqrPixCbx->setChecked( consoleWindow->viewport_SDL->getSqrPixelOpt() ); + } + } connect(new_PPU_ena , SIGNAL(stateChanged(int)), this, SLOT(use_new_PPU_changed(int)) ); connect(frmskipcbx , SIGNAL(stateChanged(int)), this, SLOT(frameskip_changed(int)) ); connect(sprtLimCbx , SIGNAL(stateChanged(int)), this, SLOT(useSpriteLimitChanged(int)) ); connect(clipSidesCbx, SIGNAL(stateChanged(int)), this, SLOT(clipSidesChanged(int)) ); connect(showFPS_cbx , SIGNAL(stateChanged(int)), this, SLOT(showFPSChanged(int)) ); + connect(sqrPixCbx , SIGNAL(stateChanged(int)), this, SLOT(sqrPixChanged(int)) ); main_vbox->addWidget( new_PPU_ena ); main_vbox->addWidget( frmskipcbx ); main_vbox->addWidget( sprtLimCbx ); main_vbox->addWidget( clipSidesCbx); main_vbox->addWidget( showFPS_cbx ); + main_vbox->addWidget( sqrPixCbx ); + + xScaleBox = new QDoubleSpinBox(this); + yScaleBox = new QDoubleSpinBox(this); + + xScaleBox->setRange( 1.0, 16.0 ); + yScaleBox->setRange( 1.0, 16.0 ); + + xScaleBox->setSingleStep( 0.10 ); + yScaleBox->setSingleStep( 0.10 ); + + if ( consoleWindow ) + { + if ( consoleWindow->viewport_GL ) + { + xScaleBox->setValue( consoleWindow->viewport_GL->getScaleX() ); + yScaleBox->setValue( consoleWindow->viewport_GL->getScaleY() ); + } + else if ( consoleWindow->viewport_SDL ) + { + xScaleBox->setValue( consoleWindow->viewport_SDL->getScaleX() ); + yScaleBox->setValue( consoleWindow->viewport_SDL->getScaleY() ); + } + } + + if ( sqrPixCbx->isChecked() ) + { + xScaleLabel = new QLabel( tr("Scale:") ); + } + else + { + xScaleLabel = new QLabel( tr("X Scale:") ); + } + yScaleLabel = new QLabel( tr("Y Scale:") ); + + hbox1 = new QHBoxLayout(); + hbox1->addWidget( xScaleLabel ); + hbox1->addWidget( xScaleBox ); + main_vbox->addLayout( hbox1 ); + + hbox1 = new QHBoxLayout(); + hbox1->addWidget( yScaleLabel ); + hbox1->addWidget( yScaleBox ); + main_vbox->addLayout( hbox1 ); + + if ( sqrPixCbx->isChecked() ) + { + yScaleLabel->hide(); + yScaleBox->hide(); + } hbox1 = new QHBoxLayout(); @@ -241,6 +308,26 @@ void ConsoleVideoConfDialog_t::showFPSChanged( int value ) fceuWrapperUnLock(); } //---------------------------------------------------- +void ConsoleVideoConfDialog_t::sqrPixChanged( int value ) +{ + //printf("Value:%i \n", value ); + int useSqrPix = (value != Qt::Unchecked); + + if ( useSqrPix ) + { + xScaleLabel->setText( tr("Scale:") ); + yScaleLabel->hide(); + yScaleBox->hide(); + } + else + { + xScaleLabel->setText( tr("X Scale:") ); + yScaleLabel->show(); + yScaleBox->show(); + } + +} +//---------------------------------------------------- void ConsoleVideoConfDialog_t::driverChanged(int index) { int driver; @@ -272,8 +359,71 @@ void ConsoleVideoConfDialog_t::regionChanged(int index) fceuWrapperUnLock(); } //---------------------------------------------------- +QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void) +{ + QSize out( GL_NES_WIDTH, GL_NES_HEIGHT ); + + if ( consoleWindow ) + { + QSize w, v; + double xscale, yscale; + int texture_width = nes_shm->ncol; + int texture_height = nes_shm->nrow; + int l=0, r=texture_width; + int t=0, b=texture_height; + int dw=0, dh=0, rw, rh; + + w = consoleWindow->size(); + + if ( consoleWindow->viewport_GL ) + { + v = consoleWindow->viewport_GL->size(); + } + else if ( consoleWindow->viewport_SDL ) + { + v = consoleWindow->viewport_SDL->size(); + } + + dw = w.width() - v.width(); + dh = w.height() - v.height(); + + if ( sqrPixCbx->isChecked() ) + { + yscale = xscale = xScaleBox->value(); + } + else + { + xscale = xScaleBox->value(); + yscale = yScaleBox->value(); + } + rw=(int)((r-l)*xscale); + rh=(int)((b-t)*yscale); + + out.setWidth( rw + dw ); + out.setHeight( rh + dh ); + } + return out; +} +//---------------------------------------------------- void ConsoleVideoConfDialog_t::applyChanges( void ) { resetVideo(); + + if ( consoleWindow ) + { + QSize s = calcNewScreenSize(); + + if ( consoleWindow->viewport_GL ) + { + consoleWindow->viewport_GL->setSqrPixelOpt( sqrPixCbx->isChecked() ); + } + if ( consoleWindow->viewport_SDL ) + { + consoleWindow->viewport_SDL->setSqrPixelOpt( sqrPixCbx->isChecked() ); + } + + consoleWindow->resize( s ); + } + } //---------------------------------------------------- diff --git a/src/drivers/Qt/ConsoleVideoConf.h b/src/drivers/Qt/ConsoleVideoConf.h index d6d12691..2d5eee6e 100644 --- a/src/drivers/Qt/ConsoleVideoConf.h +++ b/src/drivers/Qt/ConsoleVideoConf.h @@ -15,6 +15,7 @@ #include #include #include +#include class ConsoleVideoConfDialog_t : public QDialog { @@ -35,18 +36,25 @@ class ConsoleVideoConfDialog_t : public QDialog QCheckBox *sprtLimCbx; QCheckBox *clipSidesCbx; QCheckBox *showFPS_cbx; + QCheckBox *sqrPixCbx; + QDoubleSpinBox *xScaleBox; + QDoubleSpinBox *yScaleBox; + QLabel *xScaleLabel; + QLabel *yScaleLabel; void setCheckBoxFromProperty( QCheckBox *cbx, const char *property ); void setComboBoxFromProperty( QComboBox *cbx, const char *property ); //void setSliderFromProperty( QSlider *slider, QLabel *lbl, const char *property ); void resetVideo(void); + QSize calcNewScreenSize(void); public slots: void closeWindow(void); private slots: void openGL_linearFilterChanged( int value ); + void sqrPixChanged( int value ); void use_new_PPU_changed( int value ); void frameskip_changed( int value ); void useSpriteLimitChanged( int value ); diff --git a/src/drivers/Qt/ConsoleViewerGL.cpp b/src/drivers/Qt/ConsoleViewerGL.cpp index e4258997..f27c5122 100644 --- a/src/drivers/Qt/ConsoleViewerGL.cpp +++ b/src/drivers/Qt/ConsoleViewerGL.cpp @@ -23,13 +23,19 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) gltexture = 0; devPixRatio = 1.0f; linearFilter = false; + sqrPixels = true; + xscale = 2.0; + yscale = 2.0; - QScreen *screen = QGuiApplication::primaryScreen(); + setMinimumWidth( GL_NES_WIDTH ); + setMinimumHeight( GL_NES_HEIGHT ); - if ( screen != NULL ) - { + QScreen *screen = QGuiApplication::primaryScreen(); + + if ( screen != NULL ) + { devPixRatio = screen->devicePixelRatio(); - //printf("Ratio: %f \n", screen->devicePixelRatio() ); + //printf("Ratio: %f \n", screen->devicePixelRatio() ); } localBufSize = GL_NES_WIDTH * GL_NES_HEIGHT * sizeof(uint32_t); @@ -155,16 +161,19 @@ void ConsoleViewGL_t::paintGL(void) int l=0, r=texture_width; int t=0, b=texture_height; - float xscale = (float)view_width / (float)texture_width; - float yscale = (float)view_height / (float)texture_height; + xscale = (float)view_width / (float)texture_width; + yscale = (float)view_height / (float)texture_height; - if (xscale < yscale ) + if ( sqrPixels ) { - yscale = xscale; - } - else - { - xscale = yscale; + if (xscale < yscale ) + { + yscale = xscale; + } + else + { + xscale = yscale; + } } int rw=(int)((r-l)*xscale); int rh=(int)((b-t)*yscale); diff --git a/src/drivers/Qt/ConsoleViewerGL.h b/src/drivers/Qt/ConsoleViewerGL.h index cad8811e..a06adaae 100644 --- a/src/drivers/Qt/ConsoleViewerGL.h +++ b/src/drivers/Qt/ConsoleViewerGL.h @@ -22,6 +22,11 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions void setLinearFilterEnable( bool ena ); + bool getSqrPixelOpt(void){ return sqrPixels; }; + void setSqrPixelOpt( bool val ){ sqrPixels = val; return; }; + double getScaleX(void){ return xscale; }; + double getScaleY(void){ return yscale; }; + protected: void initializeGL(void); void resizeGL(int w, int h); @@ -32,10 +37,13 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions void doRemap(void); double devPixRatio; + double xscale; + double yscale; int view_width; int view_height; GLuint gltexture; bool linearFilter; + bool sqrPixels; uint32_t *localBuf; uint32_t localBufSize; diff --git a/src/drivers/Qt/ConsoleViewerSDL.cpp b/src/drivers/Qt/ConsoleViewerSDL.cpp index 139d5812..7aeeff72 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.cpp +++ b/src/drivers/Qt/ConsoleViewerSDL.cpp @@ -22,6 +22,9 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent) setAutoFillBackground(true); setPalette(pal); + setMinimumWidth( GL_NES_WIDTH ); + setMinimumHeight( GL_NES_HEIGHT ); + view_width = GL_NES_WIDTH; view_height = GL_NES_HEIGHT; @@ -30,6 +33,8 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent) rh = view_height; sdlRendW = 0; sdlRendH = 0; + xscale = 2.0; + yscale = 2.0; devPixRatio = 1.0f; sdlWindow = NULL; @@ -47,6 +52,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent) memset( localBuf, 0, localBufSize ); } + sqrPixels = true; linearFilter = false; if ( g_config ) @@ -213,16 +219,19 @@ void ConsoleViewSDL_t::render(void) nesHeight = nes_shm->nrow; } //printf(" %i x %i \n", nesWidth, nesHeight ); - float xscale = (float)view_width / (float)nesWidth; - float yscale = (float)view_height / (float)nesHeight; + xscale = (float)view_width / (float)nesWidth; + yscale = (float)view_height / (float)nesHeight; - if (xscale < yscale ) + if ( sqrPixels ) { - yscale = xscale; - } - else - { - xscale = yscale; + if (xscale < yscale ) + { + yscale = xscale; + } + else + { + xscale = yscale; + } } rw=(int)(nesWidth*xscale); diff --git a/src/drivers/Qt/ConsoleViewerSDL.h b/src/drivers/Qt/ConsoleViewerSDL.h index a7ccbd83..a6305f87 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.h +++ b/src/drivers/Qt/ConsoleViewerSDL.h @@ -25,25 +25,33 @@ class ConsoleViewSDL_t : public QWidget void setLinearFilterEnable( bool ena ); + bool getSqrPixelOpt(void){ return sqrPixels; }; + void setSqrPixelOpt( bool val ){ sqrPixels = val; return; }; + double getScaleX(void){ return xscale; }; + double getScaleY(void){ return yscale; }; + protected: //void paintEvent(QPaintEvent *event); void resizeEvent(QResizeEvent *event); - int view_width; - int view_height; + int view_width; + int view_height; - double devPixRatio; - int rw; - int rh; - int sx; - int sy; - int sdlRendW; - int sdlRendH; + double devPixRatio; + double xscale; + double yscale; + int rw; + int rh; + int sx; + int sy; + int sdlRendW; + int sdlRendH; - bool vsyncEnabled; - bool linearFilter; + bool vsyncEnabled; + bool linearFilter; + bool sqrPixels; - uint32_t *localBuf; + uint32_t *localBuf; uint32_t localBufSize; SDL_Window *sdlWindow; diff --git a/src/drivers/Qt/sdl-video.cpp b/src/drivers/Qt/sdl-video.cpp index c7d614bf..17087f2e 100644 --- a/src/drivers/Qt/sdl-video.cpp +++ b/src/drivers/Qt/sdl-video.cpp @@ -183,6 +183,10 @@ int InitVideo(FCEUGI *gi) // check to see if we are showing FPS FCEUI_SetShowFPS(show_fps); + nes_shm->ncol = NWIDTH; + nes_shm->nrow = s_tlines; + nes_shm->pitch = GL_NES_WIDTH * 4; + #ifdef LSB_FIRST rmask = 0x00FF0000; gmask = 0x0000FF00;