Merge pull request #206 from mjbudd77/master

Numerical Video Pixel Scaling Feature Added to Qt GUI Video Config Window
This commit is contained in:
mjbudd77 2020-10-26 21:45:01 -04:00 committed by GitHub
commit 77f621e676
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 228 additions and 87 deletions

View File

@ -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 );
}
}
//----------------------------------------------------

View File

@ -15,6 +15,7 @@
#include <QSlider>
#include <QFrame>
#include <QGroupBox>
#include <QDoubleSpinBox>
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 );

View File

@ -23,6 +23,12 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
gltexture = 0;
devPixRatio = 1.0f;
linearFilter = false;
sqrPixels = true;
xscale = 2.0;
yscale = 2.0;
setMinimumWidth( GL_NES_WIDTH );
setMinimumHeight( GL_NES_HEIGHT );
QScreen *screen = QGuiApplication::primaryScreen();
@ -155,9 +161,11 @@ 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 ( sqrPixels )
{
if (xscale < yscale )
{
yscale = xscale;
@ -166,6 +174,7 @@ void ConsoleViewGL_t::paintGL(void)
{
xscale = yscale;
}
}
int rw=(int)((r-l)*xscale);
int rh=(int)((b-t)*yscale);
int sx=(view_width-rw)/2;

View File

@ -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;

View File

@ -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,9 +219,11 @@ 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 ( sqrPixels )
{
if (xscale < yscale )
{
yscale = xscale;
@ -224,6 +232,7 @@ void ConsoleViewSDL_t::render(void)
{
xscale = yscale;
}
}
rw=(int)(nesWidth*xscale);
rh=(int)(nesHeight*yscale);

View File

@ -25,6 +25,11 @@ 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);
@ -33,6 +38,8 @@ class ConsoleViewSDL_t : public QWidget
int view_height;
double devPixRatio;
double xscale;
double yscale;
int rw;
int rh;
int sx;
@ -42,6 +49,7 @@ class ConsoleViewSDL_t : public QWidget
bool vsyncEnabled;
bool linearFilter;
bool sqrPixels;
uint32_t *localBuf;
uint32_t localBufSize;

View File

@ -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",
" ",
" ........ ",
" ............... ",
" ........................ ",
" ...........................+ ",
" ............@@..@@........... ",
" .#............@@............$$ ",
" .##..........@@.@.....$$%%%%$$ ",
" &...........@....@$$$$$$%%&%$$ ",
" *&...............$$$$$$$%%&%$$ ",
" =&*.......-;;>;...$$,$$$%**&.. ",
" '&&..............$$,,,%=)!~.. ",
" ~&&............-%%##%*.~'=%& ",
" *&&.....+%%****&&%%&*.&!!' ",
" **&%&***********&&&*~{'= ",
" ********=**~**~**~ ",
" *****~******] ",
" **~***]' ",
" ~]== ",
" ",
" ..... .... .... .. ..@@ @@",
" ..... .... .... .. ..@@@ @@@",
" .. .. .. .. .. @@@ @@@ ",
" .... .. .. .. .. @@@@@@ ",
" .... .. ... .. .. @@@@ ",
" .. .. ... .. .. @@@@ ",
" .. .. .. .. .. @@@@@@ ",
" .. .. .. .. .. @@@ @@@ ",
" .. .... .... .....@@@ @@@",
" .. .... .... ... @@ @@",
" ",
" "};

View File

@ -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;