Skip to content

Commit b87dd4d

Browse files
committed
Merge pull request OpenXcom#871 from HueponiK/master
Option to enable 1:1.2 pixel aspect ratio
2 parents 8d8ad35 + 23638b7 commit b87dd4d

3 files changed

Lines changed: 37 additions & 12 deletions

File tree

src/Engine/Options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void create()
119119
_info.push_back(OptionInfo("captureMouse", (bool*)&captureMouse, false));
120120
_info.push_back(OptionInfo("battleTooltips", &battleTooltips, true));
121121
_info.push_back(OptionInfo("keepAspectRatio", &keepAspectRatio, true));
122+
_info.push_back(OptionInfo("nonSquarePixelRatio", &nonSquarePixelRatio, false));
122123
_info.push_back(OptionInfo("cursorInBlackBandsInFullscreen", &cursorInBlackBandsInFullscreen, false));
123124
_info.push_back(OptionInfo("cursorInBlackBandsInWindow", &cursorInBlackBandsInWindow, true));
124125
_info.push_back(OptionInfo("cursorInBlackBandsInBorderlessWindow", &cursorInBlackBandsInBorderlessWindow, false));

src/Engine/Options.inc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ OPT int displayWidth, displayHeight, maxFrameSkip, baseXResolution, baseYResolut
66
soundVolume, musicVolume, uiVolume, audioSampleRate, audioBitDepth, pauseMode, windowedModePositionX, windowedModePositionY, FPS,
77
changeValueByMouseWheel, dragScrollTimeTolerance, dragScrollPixelTolerance, mousewheelSpeed, autosaveFrequency;
88
OPT bool fullscreen, asyncBlit, playIntro, useScaleFilter, useHQXFilter, useOpenGL, checkOpenGLErrors, vSyncForOpenGL, useOpenGLSmoothing,
9-
autosave, allowResize, borderless, debug, debugUi, fpsCounter, newSeedOnLoad, keepAspectRatio,
9+
autosave, allowResize, borderless, debug, debugUi, fpsCounter, newSeedOnLoad, keepAspectRatio, nonSquarePixelRatio,
1010
cursorInBlackBandsInFullscreen, cursorInBlackBandsInWindow, cursorInBlackBandsInBorderlessWindow, maximizeInfoScreens, musicAlwaysLoop;
1111
OPT std::string language, useOpenGLShader;
1212
OPT KeyboardType keyboardMode;

src/Engine/Screen.cpp

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ void Screen::resetDisplay(bool resetVideo)
368368
_clear.w = getWidth();
369369
_clear.h = getHeight();
370370

371+
double pixelRatioX = 1.0;
372+
double pixelRatioY = 1.0;
373+
if (Options::nonSquarePixelRatio && !Options::allowResize)
374+
{
375+
pixelRatioX = 0.75;
376+
pixelRatioY = 1.2;
377+
}
371378
bool cursorInBlackBands;
372379
if (!Options::keepAspectRatio)
373380
{
@@ -410,13 +417,17 @@ void Screen::resetDisplay(bool resetVideo)
410417
}
411418
else if (_scaleY > _scaleX && Options::keepAspectRatio)
412419
{
413-
int targetHeight = (int)floor(_scaleX * (double)_baseHeight);
420+
int targetHeight = (int)floor(_scaleX * (double)_baseHeight * pixelRatioY);
414421
_topBlackBand = (getHeight() - targetHeight) / 2;
415422
if (_topBlackBand < 0)
416423
{
417424
_topBlackBand = 0;
418425
}
419426
_bottomBlackBand = getHeight() - targetHeight - _topBlackBand;
427+
if (_bottomBlackBand < 0)
428+
{
429+
_bottomBlackBand = 0;
430+
}
420431
_leftBlackBand = _rightBlackBand = 0;
421432
_cursorLeftBlackBand = 0;
422433

@@ -587,28 +598,41 @@ int Screen::getDY()
587598
*/
588599
void Screen::updateScale(int &type, int selection, int &width, int &height, bool change)
589600
{
601+
double pixelRatioY = 1.0;
602+
double pixelRatioX = 1.0;
603+
if (Options::nonSquarePixelRatio && !Options::allowResize)
604+
{
605+
pixelRatioX = 0.75;
606+
pixelRatioY = 1.2;
607+
}
590608
type = selection;
591609
switch (type)
592610
{
593611
case SCALE_15X:
594-
width = Screen::ORIGINAL_WIDTH * 1.5;
595-
height = Screen::ORIGINAL_HEIGHT * 1.5;
612+
width = int(floor(Screen::ORIGINAL_WIDTH * 1.5));
613+
height = int(floor(Screen::ORIGINAL_HEIGHT * 1.5));
596614
break;
597615
case SCALE_2X:
598-
width = Screen::ORIGINAL_WIDTH * 2;
599-
height = Screen::ORIGINAL_HEIGHT * 2;
616+
width = int(floor(Screen::ORIGINAL_WIDTH * 2));
617+
height = int(floor(Screen::ORIGINAL_HEIGHT * 2));
600618
break;
601619
case SCALE_SCREEN_DIV_3:
602-
width = Options::newDisplayWidth / 3;
603-
height = Options::newDisplayHeight / 3;
620+
width = int(floor(Options::displayWidth / 3 * pixelRatioY));
621+
height = int(floor(Options::displayHeight / 3));
622+
width = std::max(width, int(floor(Screen::ORIGINAL_WIDTH / pixelRatioX * pixelRatioY)));
623+
height = std::max(height, int(floor(Screen::ORIGINAL_HEIGHT * pixelRatioY)));
604624
break;
605625
case SCALE_SCREEN_DIV_2:
606-
width = Options::newDisplayWidth / 2;
607-
height = Options::newDisplayHeight / 2;
626+
width = int(floor(Options::displayWidth / 2 * pixelRatioY));
627+
height = int(floor(Options::displayHeight / 2));
628+
width = std::max(width, int(floor(Screen::ORIGINAL_WIDTH / pixelRatioX * pixelRatioY)));
629+
height = std::max(height, int(floor(Screen::ORIGINAL_HEIGHT * pixelRatioY)));
608630
break;
609631
case SCALE_SCREEN:
610-
width = Options::newDisplayWidth;
611-
height = Options::newDisplayHeight;
632+
width = int(floor(Options::displayWidth * pixelRatioY));
633+
height = int(floor(Options::displayHeight));
634+
width = std::max(width, int(floor(Screen::ORIGINAL_WIDTH / pixelRatioX * pixelRatioY)));
635+
height = std::max(height, int(floor(Screen::ORIGINAL_HEIGHT * pixelRatioY)));
612636
break;
613637
case SCALE_ORIGINAL:
614638
default:

0 commit comments

Comments
 (0)