Aspect ratio pixel scaling fixes for Qt GUI. For issue #341.

This commit is contained in:
mjbudd77 2021-03-21 13:47:12 -04:00
parent b825454fee
commit 95aa96a14e
4 changed files with 108 additions and 13 deletions

View File

@ -853,8 +853,7 @@ QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void)
if ( aspectCbx->isChecked() )
{
xscale = xScaleBox->value();
yscale = xscale * aspectRatio * (double)nes_shm->video.xyRatio;
yscale = xscale * (double)nes_shm->video.xyRatio;
}
else
{
@ -864,6 +863,21 @@ QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void)
rw=(int)((r-l)*xscale);
rh=(int)((b-t)*yscale);
if ( aspectCbx->isChecked() )
{
double rr;
rr = (double)rh / (double)rw;
if ( rr > aspectRatio )
{
rw = (int)( (((double)rh) / aspectRatio) + 0.50);
}
else
{
rh = (int)( (((double)rw) * aspectRatio) + 0.50);
}
}
out.setWidth( rw + dw );
out.setHeight( rh + dh );
}

View File

@ -206,8 +206,6 @@ void ConsoleViewGL_t::setScaleXY( double xs, double ys )
if ( forceAspect )
{
xyRatio = xyRatio * aspectRatio;
if ( (xscale*xyRatio) < yscale )
{
yscale = (xscale*xyRatio);
@ -340,15 +338,13 @@ void ConsoleViewGL_t::paintGL(void)
if ( forceAspect )
{
xyRatio = xyRatio * aspectRatio;
if ( (xscaleTmp*xyRatio) < yscaleTmp )
{
yscaleTmp = (xscaleTmp*xyRatio);
yscaleTmp = xscaleTmp * xyRatio;
}
else
{
xscaleTmp = (yscaleTmp/xyRatio);
xscaleTmp = yscaleTmp / xyRatio;
}
}
@ -368,8 +364,45 @@ void ConsoleViewGL_t::paintGL(void)
yscaleTmp = yscale;
}
}
rw=(int)((r-l)*xscaleTmp);
rh=(int)((b-t)*yscaleTmp);
if ( forceAspect )
{
int iw, ih, ax, ay;
ax = (int)(aspectX+0.50);
ay = (int)(aspectY+0.50);
iw = rw * ay;
ih = rh * ax;
if ( iw > ih )
{
rh = (rw * ay) / ax;
}
else
{
rw = (rh * ax) / ay;
}
if ( rw > view_width )
{
rw = view_width;
rh = (rw * ay) / ax;
}
if ( rh > view_height )
{
rh = view_height;
rw = (rh * ax) / ay;
}
}
if ( rw > view_width ) rw = view_width;
if ( rh > view_height) rh = view_height;
sx=(view_width-rw)/2;
sy=(view_height-rh)/2;

View File

@ -124,8 +124,6 @@ void ConsoleViewSDL_t::setScaleXY( double xs, double ys )
if ( forceAspect )
{
xyRatio = xyRatio * aspectRatio;
if ( (xscale*xyRatio) < yscale )
{
yscale = (xscale*xyRatio);
@ -381,8 +379,6 @@ void ConsoleViewSDL_t::render(void)
if ( forceAspect )
{
xyRatio = xyRatio * aspectRatio;
if ( (xscaleTmp*xyRatio) < yscaleTmp )
{
yscaleTmp = (xscaleTmp*xyRatio);
@ -412,6 +408,42 @@ void ConsoleViewSDL_t::render(void)
rw=(int)(nesWidth*xscaleTmp);
rh=(int)(nesHeight*yscaleTmp);
if ( forceAspect )
{
int iw, ih, ax, ay;
ax = (int)(aspectX+0.50);
ay = (int)(aspectY+0.50);
iw = rw * ay;
ih = rh * ax;
if ( iw > ih )
{
rh = (rw * ay) / ax;
}
else
{
rw = (rh * ax) / ay;
}
if ( rw > view_width )
{
rw = view_width;
rh = (rw * ay) / ax;
}
if ( rh > view_height )
{
rh = view_height;
rw = (rh * ax) / ay;
}
}
if ( rw > view_width ) rw = view_width;
if ( rh > view_height) rh = view_height;
sx=(view_width-rw)/2;
sy=(view_height-rh)/2;

View File

@ -314,13 +314,29 @@ QSize consoleWin_t::calcRequiredSize(void)
if ( forceAspect )
{
yscale = xscale * aspectRatio * (double)nes_shm->video.xyRatio;
yscale = xscale * (double)nes_shm->video.xyRatio;
}
rw=(int)((r-l)*xscale);
rh=(int)((b-t)*yscale);
//printf("view %i x %i \n", rw, rh );
if ( forceAspect )
{
double rr;
rr = (double)rh / (double)rw;
if ( rr > aspectRatio )
{
rw = (int)( (((double)rh) / aspectRatio) + 0.50);
}
else
{
rh = (int)( (((double)rw) * aspectRatio) + 0.50);
}
}
out.setWidth( rw + dw );
out.setHeight( rh + dh );