Merge pull request #207 from mjbudd77/master

For Qt, added logic to allow for auto video scaling on window resize …
This commit is contained in:
mjbudd77 2020-10-27 07:35:47 -04:00 committed by GitHub
commit 1eb226b41d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 141 additions and 41 deletions

View File

@ -85,6 +85,9 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
// Show FPS Checkbox
showFPS_cbx = new QCheckBox( tr("Show FPS") );
// Auto Scale on Resize
autoScaleCbx = new QCheckBox( tr("Auto Scale on Resize") );
// Square Pixels
sqrPixCbx = new QCheckBox( tr("Square Pixels") );
@ -98,10 +101,12 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
{
if ( consoleWindow->viewport_GL )
{
autoScaleCbx->setChecked( consoleWindow->viewport_GL->getAutoScaleOpt() );
sqrPixCbx->setChecked( consoleWindow->viewport_GL->getSqrPixelOpt() );
}
else if ( consoleWindow->viewport_SDL )
{
autoScaleCbx->setChecked( consoleWindow->viewport_SDL->getAutoScaleOpt() );
sqrPixCbx->setChecked( consoleWindow->viewport_SDL->getSqrPixelOpt() );
}
}
@ -118,6 +123,7 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
main_vbox->addWidget( sprtLimCbx );
main_vbox->addWidget( clipSidesCbx);
main_vbox->addWidget( showFPS_cbx );
main_vbox->addWidget( autoScaleCbx);
main_vbox->addWidget( sqrPixCbx );
xScaleBox = new QDoubleSpinBox(this);
@ -411,15 +417,30 @@ void ConsoleVideoConfDialog_t::applyChanges( void )
if ( consoleWindow )
{
float xscale, yscale;
QSize s = calcNewScreenSize();
if ( sqrPixCbx->isChecked() )
{
yscale = xscale = xScaleBox->value();
}
else
{
xscale = xScaleBox->value();
yscale = yScaleBox->value();
}
if ( consoleWindow->viewport_GL )
{
consoleWindow->viewport_GL->setSqrPixelOpt( sqrPixCbx->isChecked() );
consoleWindow->viewport_GL->setAutoScaleOpt( autoScaleCbx->isChecked() );
consoleWindow->viewport_GL->setScaleXY( xscale, yscale );
}
if ( consoleWindow->viewport_SDL )
{
consoleWindow->viewport_SDL->setSqrPixelOpt( sqrPixCbx->isChecked() );
consoleWindow->viewport_SDL->setAutoScaleOpt( autoScaleCbx->isChecked() );
consoleWindow->viewport_SDL->setScaleXY( xscale, yscale );
}
consoleWindow->resize( s );

View File

@ -36,6 +36,7 @@ class ConsoleVideoConfDialog_t : public QDialog
QCheckBox *sprtLimCbx;
QCheckBox *clipSidesCbx;
QCheckBox *showFPS_cbx;
QCheckBox *autoScaleCbx;
QCheckBox *sqrPixCbx;
QDoubleSpinBox *xScaleBox;
QDoubleSpinBox *yScaleBox;

View File

@ -24,6 +24,7 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
devPixRatio = 1.0f;
linearFilter = false;
sqrPixels = true;
autoScaleEna = true;
xscale = 2.0;
yscale = 2.0;
@ -149,20 +150,10 @@ void ConsoleViewGL_t::setLinearFilterEnable( bool ena )
}
}
void ConsoleViewGL_t::transfer2LocalBuffer(void)
void ConsoleViewGL_t::setScaleXY( double xs, double ys )
{
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
}
void ConsoleViewGL_t::paintGL(void)
{
int texture_width = nes_shm->ncol;
int texture_height = nes_shm->nrow;
int l=0, r=texture_width;
int t=0, b=texture_height;
xscale = (float)view_width / (float)texture_width;
yscale = (float)view_height / (float)texture_height;
xscale = xs;
yscale = ys;
if ( sqrPixels )
{
@ -175,8 +166,53 @@ void ConsoleViewGL_t::paintGL(void)
xscale = yscale;
}
}
int rw=(int)((r-l)*xscale);
int rh=(int)((b-t)*yscale);
}
void ConsoleViewGL_t::transfer2LocalBuffer(void)
{
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
}
void ConsoleViewGL_t::paintGL(void)
{
int texture_width = nes_shm->ncol;
int texture_height = nes_shm->nrow;
int l=0, r=texture_width;
int t=0, b=texture_height;
float xscaleTmp = (float)view_width / (float)texture_width;
float yscaleTmp = (float)view_height / (float)texture_height;
if ( sqrPixels )
{
if (xscaleTmp < yscaleTmp )
{
yscaleTmp = xscaleTmp;
}
else
{
xscaleTmp = yscaleTmp;
}
}
if ( autoScaleEna )
{
xscale = xscaleTmp;
yscale = yscaleTmp;
}
else
{
if ( xscaleTmp > xscale )
{
xscaleTmp = xscale;
}
if ( yscaleTmp > yscale )
{
yscaleTmp = yscale;
}
}
int rw=(int)((r-l)*xscaleTmp);
int rh=(int)((b-t)*yscaleTmp);
int sx=(view_width-rw)/2;
int sy=(view_height-rh)/2;

View File

@ -24,8 +24,11 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
bool getSqrPixelOpt(void){ return sqrPixels; };
void setSqrPixelOpt( bool val ){ sqrPixels = val; return; };
bool getAutoScaleOpt(void){ return autoScaleEna; };
void setAutoScaleOpt( bool val ){ autoScaleEna = val; return; };
double getScaleX(void){ return xscale; };
double getScaleY(void){ return yscale; };
void setScaleXY( double xs, double ys );
protected:
void initializeGL(void);
@ -44,6 +47,7 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
GLuint gltexture;
bool linearFilter;
bool sqrPixels;
bool autoScaleEna;
uint32_t *localBuf;
uint32_t localBufSize;

View File

@ -53,6 +53,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
}
sqrPixels = true;
autoScaleEna = true;
linearFilter = false;
if ( g_config )
@ -82,6 +83,24 @@ void ConsoleViewSDL_t::setLinearFilterEnable( bool ena )
}
}
void ConsoleViewSDL_t::setScaleXY( double xs, double ys )
{
xscale = xs;
yscale = ys;
if ( sqrPixels )
{
if (xscale < yscale )
{
yscale = xscale;
}
else
{
xscale = yscale;
}
}
}
void ConsoleViewSDL_t::transfer2LocalBuffer(void)
{
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
@ -219,25 +238,40 @@ void ConsoleViewSDL_t::render(void)
nesHeight = nes_shm->nrow;
}
//printf(" %i x %i \n", nesWidth, nesHeight );
xscale = (float)view_width / (float)nesWidth;
yscale = (float)view_height / (float)nesHeight;
float xscaleTmp = (float)view_width / (float)nesWidth;
float yscaleTmp = (float)view_height / (float)nesHeight;
if ( sqrPixels )
{
if (xscale < yscale )
if (xscaleTmp < yscaleTmp )
{
yscale = xscale;
yscaleTmp = xscaleTmp;
}
else
{
xscale = yscale;
xscaleTmp = yscaleTmp;
}
}
rw=(int)(nesWidth*xscale);
rh=(int)(nesHeight*yscale);
//sx=sdlViewport.x + (view_width-rw)/2;
//sy=sdlViewport.y + (view_height-rh)/2;
if ( autoScaleEna )
{
xscale = xscaleTmp;
yscale = yscaleTmp;
}
else
{
if ( xscaleTmp > xscale )
{
xscaleTmp = xscale;
}
if ( yscaleTmp > yscale )
{
yscaleTmp = yscale;
}
}
rw=(int)(nesWidth*xscaleTmp);
rh=(int)(nesHeight*yscaleTmp);
sx=(view_width-rw)/2;
sy=(view_height-rh)/2;

View File

@ -27,8 +27,11 @@ class ConsoleViewSDL_t : public QWidget
bool getSqrPixelOpt(void){ return sqrPixels; };
void setSqrPixelOpt( bool val ){ sqrPixels = val; return; };
bool getAutoScaleOpt(void){ return autoScaleEna; };
void setAutoScaleOpt( bool val ){ autoScaleEna = val; return; };
double getScaleX(void){ return xscale; };
double getScaleY(void){ return yscale; };
void setScaleXY( double xs, double ys );
protected:
@ -50,6 +53,7 @@ class ConsoleViewSDL_t : public QWidget
bool vsyncEnabled;
bool linearFilter;
bool sqrPixels;
bool autoScaleEna;
uint32_t *localBuf;
uint32_t localBufSize;