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:
commit
1eb226b41d
|
@ -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,7 +123,8 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
|
|||
main_vbox->addWidget( sprtLimCbx );
|
||||
main_vbox->addWidget( clipSidesCbx);
|
||||
main_vbox->addWidget( showFPS_cbx );
|
||||
main_vbox->addWidget( sqrPixCbx );
|
||||
main_vbox->addWidget( autoScaleCbx);
|
||||
main_vbox->addWidget( sqrPixCbx );
|
||||
|
||||
xScaleBox = new QDoubleSpinBox(this);
|
||||
yScaleBox = 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 );
|
||||
|
|
|
@ -36,6 +36,7 @@ class ConsoleVideoConfDialog_t : public QDialog
|
|||
QCheckBox *sprtLimCbx;
|
||||
QCheckBox *clipSidesCbx;
|
||||
QCheckBox *showFPS_cbx;
|
||||
QCheckBox *autoScaleCbx;
|
||||
QCheckBox *sqrPixCbx;
|
||||
QDoubleSpinBox *xScaleBox;
|
||||
QDoubleSpinBox *yScaleBox;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -46,15 +47,15 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
|
|||
memset( localBuf, 0, localBufSize );
|
||||
}
|
||||
|
||||
linearFilter = false;
|
||||
linearFilter = false;
|
||||
|
||||
if ( g_config )
|
||||
{
|
||||
int opt;
|
||||
g_config->getOption("SDL.OpenGLip", &opt );
|
||||
|
||||
linearFilter = (opt) ? true : false;
|
||||
}
|
||||
if ( g_config )
|
||||
{
|
||||
int opt;
|
||||
g_config->getOption("SDL.OpenGLip", &opt );
|
||||
|
||||
linearFilter = (opt) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleViewGL_t::~ConsoleViewGL_t(void)
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -53,15 +53,16 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
|
|||
}
|
||||
|
||||
sqrPixels = true;
|
||||
linearFilter = false;
|
||||
autoScaleEna = true;
|
||||
linearFilter = false;
|
||||
|
||||
if ( g_config )
|
||||
{
|
||||
int opt;
|
||||
g_config->getOption("SDL.OpenGLip", &opt );
|
||||
|
||||
linearFilter = (opt) ? true : false;
|
||||
}
|
||||
if ( g_config )
|
||||
{
|
||||
int opt;
|
||||
g_config->getOption("SDL.OpenGLip", &opt );
|
||||
|
||||
linearFilter = (opt) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleViewSDL_t::~ConsoleViewSDL_t(void)
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue