For Qt, added logic to allow for auto video scaling on window resize to be optional. An 'Auto scale on resize' checkbox has been added to the video config window. When this box is checked (and applied) the window will always auto rescale the video image to a best fit on a resize. If not checked, window will use the specified numerical scale values as a maximum scaling limit. This means that the window will allow scaling the image down if the window is not large enough to fit image at the requested scale, but will never scale the image up past the request scale. So if the window is at a large size and the requested scale is small, the result will be a small video image on a big window with a lot of black space. This is for issue #205.
This commit is contained in:
parent
8f336bf8d3
commit
81cbabbf1f
|
@ -85,6 +85,9 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
|
||||||
// Show FPS Checkbox
|
// Show FPS Checkbox
|
||||||
showFPS_cbx = new QCheckBox( tr("Show FPS") );
|
showFPS_cbx = new QCheckBox( tr("Show FPS") );
|
||||||
|
|
||||||
|
// Auto Scale on Resize
|
||||||
|
autoScaleCbx = new QCheckBox( tr("Auto Scale on Resize") );
|
||||||
|
|
||||||
// Square Pixels
|
// Square Pixels
|
||||||
sqrPixCbx = new QCheckBox( tr("Square Pixels") );
|
sqrPixCbx = new QCheckBox( tr("Square Pixels") );
|
||||||
|
|
||||||
|
@ -98,10 +101,12 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
|
||||||
{
|
{
|
||||||
if ( consoleWindow->viewport_GL )
|
if ( consoleWindow->viewport_GL )
|
||||||
{
|
{
|
||||||
|
autoScaleCbx->setChecked( consoleWindow->viewport_GL->getAutoScaleOpt() );
|
||||||
sqrPixCbx->setChecked( consoleWindow->viewport_GL->getSqrPixelOpt() );
|
sqrPixCbx->setChecked( consoleWindow->viewport_GL->getSqrPixelOpt() );
|
||||||
}
|
}
|
||||||
else if ( consoleWindow->viewport_SDL )
|
else if ( consoleWindow->viewport_SDL )
|
||||||
{
|
{
|
||||||
|
autoScaleCbx->setChecked( consoleWindow->viewport_SDL->getAutoScaleOpt() );
|
||||||
sqrPixCbx->setChecked( consoleWindow->viewport_SDL->getSqrPixelOpt() );
|
sqrPixCbx->setChecked( consoleWindow->viewport_SDL->getSqrPixelOpt() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,6 +123,7 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
|
||||||
main_vbox->addWidget( sprtLimCbx );
|
main_vbox->addWidget( sprtLimCbx );
|
||||||
main_vbox->addWidget( clipSidesCbx);
|
main_vbox->addWidget( clipSidesCbx);
|
||||||
main_vbox->addWidget( showFPS_cbx );
|
main_vbox->addWidget( showFPS_cbx );
|
||||||
|
main_vbox->addWidget( autoScaleCbx);
|
||||||
main_vbox->addWidget( sqrPixCbx );
|
main_vbox->addWidget( sqrPixCbx );
|
||||||
|
|
||||||
xScaleBox = new QDoubleSpinBox(this);
|
xScaleBox = new QDoubleSpinBox(this);
|
||||||
|
@ -411,15 +417,30 @@ void ConsoleVideoConfDialog_t::applyChanges( void )
|
||||||
|
|
||||||
if ( consoleWindow )
|
if ( consoleWindow )
|
||||||
{
|
{
|
||||||
|
float xscale, yscale;
|
||||||
QSize s = calcNewScreenSize();
|
QSize s = calcNewScreenSize();
|
||||||
|
|
||||||
|
if ( sqrPixCbx->isChecked() )
|
||||||
|
{
|
||||||
|
yscale = xscale = xScaleBox->value();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xscale = xScaleBox->value();
|
||||||
|
yscale = yScaleBox->value();
|
||||||
|
}
|
||||||
|
|
||||||
if ( consoleWindow->viewport_GL )
|
if ( consoleWindow->viewport_GL )
|
||||||
{
|
{
|
||||||
consoleWindow->viewport_GL->setSqrPixelOpt( sqrPixCbx->isChecked() );
|
consoleWindow->viewport_GL->setSqrPixelOpt( sqrPixCbx->isChecked() );
|
||||||
|
consoleWindow->viewport_GL->setAutoScaleOpt( autoScaleCbx->isChecked() );
|
||||||
|
consoleWindow->viewport_GL->setScaleXY( xscale, yscale );
|
||||||
}
|
}
|
||||||
if ( consoleWindow->viewport_SDL )
|
if ( consoleWindow->viewport_SDL )
|
||||||
{
|
{
|
||||||
consoleWindow->viewport_SDL->setSqrPixelOpt( sqrPixCbx->isChecked() );
|
consoleWindow->viewport_SDL->setSqrPixelOpt( sqrPixCbx->isChecked() );
|
||||||
|
consoleWindow->viewport_SDL->setAutoScaleOpt( autoScaleCbx->isChecked() );
|
||||||
|
consoleWindow->viewport_SDL->setScaleXY( xscale, yscale );
|
||||||
}
|
}
|
||||||
|
|
||||||
consoleWindow->resize( s );
|
consoleWindow->resize( s );
|
||||||
|
|
|
@ -36,6 +36,7 @@ class ConsoleVideoConfDialog_t : public QDialog
|
||||||
QCheckBox *sprtLimCbx;
|
QCheckBox *sprtLimCbx;
|
||||||
QCheckBox *clipSidesCbx;
|
QCheckBox *clipSidesCbx;
|
||||||
QCheckBox *showFPS_cbx;
|
QCheckBox *showFPS_cbx;
|
||||||
|
QCheckBox *autoScaleCbx;
|
||||||
QCheckBox *sqrPixCbx;
|
QCheckBox *sqrPixCbx;
|
||||||
QDoubleSpinBox *xScaleBox;
|
QDoubleSpinBox *xScaleBox;
|
||||||
QDoubleSpinBox *yScaleBox;
|
QDoubleSpinBox *yScaleBox;
|
||||||
|
|
|
@ -24,6 +24,7 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
|
||||||
devPixRatio = 1.0f;
|
devPixRatio = 1.0f;
|
||||||
linearFilter = false;
|
linearFilter = false;
|
||||||
sqrPixels = true;
|
sqrPixels = true;
|
||||||
|
autoScaleEna = true;
|
||||||
xscale = 2.0;
|
xscale = 2.0;
|
||||||
yscale = 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 );
|
xscale = xs;
|
||||||
}
|
yscale = ys;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if ( sqrPixels )
|
if ( sqrPixels )
|
||||||
{
|
{
|
||||||
|
@ -175,8 +166,53 @@ void ConsoleViewGL_t::paintGL(void)
|
||||||
xscale = yscale;
|
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 sx=(view_width-rw)/2;
|
||||||
int sy=(view_height-rh)/2;
|
int sy=(view_height-rh)/2;
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,11 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
|
|
||||||
bool getSqrPixelOpt(void){ return sqrPixels; };
|
bool getSqrPixelOpt(void){ return sqrPixels; };
|
||||||
void setSqrPixelOpt( bool val ){ sqrPixels = val; return; };
|
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 getScaleX(void){ return xscale; };
|
||||||
double getScaleY(void){ return yscale; };
|
double getScaleY(void){ return yscale; };
|
||||||
|
void setScaleXY( double xs, double ys );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializeGL(void);
|
void initializeGL(void);
|
||||||
|
@ -44,6 +47,7 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
GLuint gltexture;
|
GLuint gltexture;
|
||||||
bool linearFilter;
|
bool linearFilter;
|
||||||
bool sqrPixels;
|
bool sqrPixels;
|
||||||
|
bool autoScaleEna;
|
||||||
|
|
||||||
uint32_t *localBuf;
|
uint32_t *localBuf;
|
||||||
uint32_t localBufSize;
|
uint32_t localBufSize;
|
||||||
|
|
|
@ -53,6 +53,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
sqrPixels = true;
|
sqrPixels = true;
|
||||||
|
autoScaleEna = true;
|
||||||
linearFilter = false;
|
linearFilter = false;
|
||||||
|
|
||||||
if ( g_config )
|
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)
|
void ConsoleViewSDL_t::transfer2LocalBuffer(void)
|
||||||
{
|
{
|
||||||
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
|
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
|
||||||
|
@ -219,25 +238,40 @@ void ConsoleViewSDL_t::render(void)
|
||||||
nesHeight = nes_shm->nrow;
|
nesHeight = nes_shm->nrow;
|
||||||
}
|
}
|
||||||
//printf(" %i x %i \n", nesWidth, nesHeight );
|
//printf(" %i x %i \n", nesWidth, nesHeight );
|
||||||
xscale = (float)view_width / (float)nesWidth;
|
float xscaleTmp = (float)view_width / (float)nesWidth;
|
||||||
yscale = (float)view_height / (float)nesHeight;
|
float yscaleTmp = (float)view_height / (float)nesHeight;
|
||||||
|
|
||||||
if ( sqrPixels )
|
if ( sqrPixels )
|
||||||
{
|
{
|
||||||
if (xscale < yscale )
|
if (xscaleTmp < yscaleTmp )
|
||||||
{
|
{
|
||||||
yscale = xscale;
|
yscaleTmp = xscaleTmp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xscale = yscale;
|
xscaleTmp = yscaleTmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rw=(int)(nesWidth*xscale);
|
if ( autoScaleEna )
|
||||||
rh=(int)(nesHeight*yscale);
|
{
|
||||||
//sx=sdlViewport.x + (view_width-rw)/2;
|
xscale = xscaleTmp;
|
||||||
//sy=sdlViewport.y + (view_height-rh)/2;
|
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;
|
sx=(view_width-rw)/2;
|
||||||
sy=(view_height-rh)/2;
|
sy=(view_height-rh)/2;
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,11 @@ class ConsoleViewSDL_t : public QWidget
|
||||||
|
|
||||||
bool getSqrPixelOpt(void){ return sqrPixels; };
|
bool getSqrPixelOpt(void){ return sqrPixels; };
|
||||||
void setSqrPixelOpt( bool val ){ sqrPixels = val; return; };
|
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 getScaleX(void){ return xscale; };
|
||||||
double getScaleY(void){ return yscale; };
|
double getScaleY(void){ return yscale; };
|
||||||
|
void setScaleXY( double xs, double ys );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -50,6 +53,7 @@ class ConsoleViewSDL_t : public QWidget
|
||||||
bool vsyncEnabled;
|
bool vsyncEnabled;
|
||||||
bool linearFilter;
|
bool linearFilter;
|
||||||
bool sqrPixels;
|
bool sqrPixels;
|
||||||
|
bool autoScaleEna;
|
||||||
|
|
||||||
uint32_t *localBuf;
|
uint32_t *localBuf;
|
||||||
uint32_t localBufSize;
|
uint32_t localBufSize;
|
||||||
|
|
Loading…
Reference in New Issue