Add option to enable or disable auto-scale

This commit is contained in:
elasota
2020-06-20 01:33:26 -04:00
parent 1981320afe
commit 3c662845b4
8 changed files with 70 additions and 29 deletions

View File

@@ -81,6 +81,14 @@
"id" : 0,
"enabled" : true
},
{
"name" : "Adjust resolution to fit window",
"itemType" : "CheckBox",
"pos" : [ 8, 182 ],
"size" : [ 256, 18 ],
"id" : 0,
"enabled" : true
},
{
"name" : "",
"itemType" : "UserItem",

View File

@@ -31,6 +31,8 @@
#define kDisplay12Inch 2
#define kDisplay13Inch 3
extern Boolean isAutoScale;
typedef struct
{
@@ -327,15 +329,20 @@ public:
if (physicalHeight < 480)
physicalHeight = 480;
double xMul = static_cast<double>(physicalWidth) / 640;
double yMul = static_cast<double>(physicalHeight) / 480;
double minMul = 1.0;
double granularity = 2.0;
if (isAutoScale)
{
double xMul = static_cast<double>(physicalWidth) / 640.0;
double yMul = static_cast<double>(physicalHeight) / 480.0;
xMul = floor(xMul * granularity) / granularity;
yMul = floor(yMul * granularity) / granularity;
double granularity = 2.0;
double minMul = std::max<double>(1.0, std::min(xMul, yMul));
xMul = floor(xMul * granularity) / granularity;
yMul = floor(yMul * granularity) / granularity;
minMul = std::max<double>(1.0, std::min(xMul, yMul));
}
virtualWidth = physicalWidth / minMul;
virtualHeight = physicalHeight / minMul;

View File

@@ -116,7 +116,7 @@ typedef struct
Boolean wasCoordOpen, wasQuickTrans;
Boolean wasIdleMusic, wasGameMusic;
Boolean wasEscPauseKey;
Boolean wasDoAutoDemo, wasScreen2;
Boolean wasDoAutoDemo, wasAutoScale;
Boolean wasDoBackground, wasHouseChecks;
Boolean wasPrettyMap, wasBitchDialogs;
} prefsInfo;

View File

@@ -25,7 +25,7 @@ int main(int argc, const char **argv);
short isVolume, wasVolume;
short isDepthPref, dataResFile, numSMWarnings;
Boolean quitting, doZooms, quickerTransitions, isUseSecondScreen;
Boolean quitting, doZooms, quickerTransitions, isAutoScale;
extern Str31 highBanner;
@@ -122,9 +122,7 @@ void ReadInPrefs (void)
toolMode = thePrefs.wasToolGroup;
doAutoDemo = thePrefs.wasDoAutoDemo;
isEscPauseKey = thePrefs.wasEscPauseKey;
isUseSecondScreen = thePrefs.wasScreen2;
if (thisMac.numScreens < 2)
isUseSecondScreen = false;
isAutoScale = thePrefs.wasAutoScale;
doBackground = thePrefs.wasDoBackground;
doPrettyMap = thePrefs.wasPrettyMap;
doBitchDialogs = thePrefs.wasBitchDialogs;
@@ -199,7 +197,7 @@ void ReadInPrefs (void)
toolMode = kBlowerMode;
doAutoDemo = true;
isEscPauseKey = false;
isUseSecondScreen = false;
isAutoScale = true;
doBackground = false;
doPrettyMap = false;
doBitchDialogs = true;
@@ -291,7 +289,7 @@ void WriteOutPrefs (void)
thePrefs.wasToolGroup = toolMode;
thePrefs.wasDoAutoDemo = doAutoDemo;
thePrefs.wasEscPauseKey = isEscPauseKey;
thePrefs.wasScreen2 = isUseSecondScreen;
thePrefs.wasAutoScale = isAutoScale;
thePrefs.wasDoBackground = doBackground;
thePrefs.wasPrettyMap = doPrettyMap;
thePrefs.wasBitchDialogs = doBitchDialogs;

View File

@@ -16,7 +16,9 @@
#include "DialogUtils.h"
#include "Externs.h"
#include "Environ.h"
#include "HostDisplayDriver.h"
#include "House.h"
#include "IGpDisplayDriver.h"
#include "WindowManager.h"
@@ -35,13 +37,10 @@
#define kBorder1Item 8
#define kDoColorFadeItem 9
#define k32BitColorItem 10
//#define k256Depth 11
//#define k16Depth 12
#define kBorder2Item 11
#define kBorder3Item 12
#define kDispDefault 13
//#define kUseQDItem 13
//#define kUseScreen2Item 14
#define kScaleResolutionItem 11
#define kBorder2Item 12
#define kBorder3Item 13
#define kDispDefault 14
#define kSofterItem 4
#define kLouderItem 5
#define kVolNumberItem 7
@@ -98,11 +97,11 @@ Str15 tempLeftStr, tempRightStr, tempBattStr, tempBandStr;
long tempLeftMap, tempRightMap, tempBattMap, tempBandMap;
short whichCtrl, wasDepthPref;
Boolean wasFade, wasIdle, wasPlay, wasTransit, wasZooms, wasBackground;
Boolean wasEscPauseKey, wasDemos, wasScreen2, nextRestartChange, wasErrorCheck;
Boolean wasEscPauseKey, wasDemos, wasAutoScale, nextRestartChange, wasErrorCheck, needResolutionReset;
Boolean wasPrettyMap, wasBitchDialogs;
extern short numNeighbors, isDepthPref, maxFiles, willMaxFiles;
extern Boolean isDoColorFade, isPlayMusicIdle, isUseSecondScreen;
extern Boolean isDoColorFade, isPlayMusicIdle, isAutoScale;
extern Boolean isHouseChecks, doBitchDialogs;
extern Boolean isEscPauseKey, failedMusic, isSoundOn, doBackground;
extern Boolean isMusicOn, quickerTransitions, doAutoDemo;
@@ -862,7 +861,7 @@ void DisplayDefaults (void)
numNeighbors = 9;
wasDepthPref = kSwitchIfNeeded;
wasFade = true;
wasScreen2 = false;
wasAutoScale = true;
}
//-------------------------------------------------------------- FrameDisplayIcon
@@ -907,6 +906,7 @@ void DisplayUpdate (Dialog *theDialog)
SetDialogItemValue(theDialog, kDoColorFadeItem, (short)wasFade);
SetDialogItemValue(theDialog, k32BitColorItem, wasDepthPref == 32);
SetDialogItemValue(theDialog, kScaleResolutionItem, (short)isAutoScale);
FrameDisplayIcon(theDialog, StdColors::Red());
FrameDialogItemC(theDialog, kBorder1Item, kRedOrangeColor8);
@@ -1005,7 +1005,7 @@ void DoDisplayPrefs (void)
wasNeighbors = numNeighbors;
wasFade = isDoColorFade;
wasDepthPref = isDepthPref;
wasScreen2 = isUseSecondScreen;
wasAutoScale = isAutoScale;
leaving = false;
DisplayUpdate(prefDlg);
@@ -1017,10 +1017,12 @@ void DoDisplayPrefs (void)
{
case kOkayButton:
isDoColorFade = wasFade;
isDepthPref = wasDepthPref;
if (isUseSecondScreen != wasScreen2)
if (isDepthPref != wasDepthPref)
nextRestartChange = true;
isUseSecondScreen = wasScreen2;
if (isAutoScale != wasAutoScale)
needResolutionReset = true;
isDepthPref = wasDepthPref;
isAutoScale = wasAutoScale;
leaving = true;
break;
@@ -1066,6 +1068,11 @@ void DoDisplayPrefs (void)
SetDialogItemValue(prefDlg, k32BitColorItem, wasDepthPref == 32);
break;
case kScaleResolutionItem:
wasAutoScale = !wasAutoScale;
SetDialogItemValue(prefDlg, kScaleResolutionItem, (short)wasAutoScale);
break;
case kDispDefault:
FrameDisplayIcon(prefDlg, StdColors::White());
DisplayDefaults();
@@ -1126,6 +1133,8 @@ void SetAllDefaults (void)
quickerTransitions = false;
isDepthPref = kSwitchIfNeeded;
isDoColorFade = true;
needResolutionReset = true;
}
//-------------------------------------------------------------- FlashSettingsButton
@@ -1307,7 +1316,16 @@ void DoSettingsMain (void)
prefDlg->Destroy();
if (nextRestartChange)
{
BitchAboutChanges();
nextRestartChange = false;
}
if (needResolutionReset)
{
PortabilityLayer::HostDisplayDriver::GetInstance()->RequestResetVirtualResolution();
needResolutionReset = false;
}
}
//-------------------------------------------------------------- BitchAboutChanges

View File

@@ -41,6 +41,7 @@ public:
virtual void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0;
virtual void RequestToggleFullScreen(uint32_t timestamp) = 0;
virtual void RequestResetVirtualResolution() = 0;
virtual const GpDisplayDriverProperties &GetProperties() const = 0;
};

View File

@@ -1152,7 +1152,7 @@ void GpDisplayDriverD3D11::Run()
unsigned int desiredWidth = clientRect.right - clientRect.left;
unsigned int desiredHeight = clientRect.bottom - clientRect.top;
if (clientRect.right - clientRect.left != m_windowWidthPhysical || clientRect.bottom - clientRect.top != m_windowHeightPhysical)
if (clientRect.right - clientRect.left != m_windowWidthPhysical || clientRect.bottom - clientRect.top != m_windowHeightPhysical || m_isResolutionResetDesired)
{
uint32_t prevWidthPhysical = m_windowWidthPhysical;
uint32_t prevHeightPhysical = m_windowHeightPhysical;
@@ -1177,6 +1177,7 @@ void GpDisplayDriverD3D11::Run()
m_windowHeightVirtual = virtualHeight;
m_pixelScaleX = pixelScaleX;
m_pixelScaleY = pixelScaleY;
m_isResolutionResetDesired = false;
if (GpVOSEvent *resizeEvent = m_properties.m_eventQueue->QueueEvent())
{
@@ -1422,6 +1423,11 @@ void GpDisplayDriverD3D11::RequestToggleFullScreen(uint32_t timestamp)
}
}
void GpDisplayDriverD3D11::RequestResetVirtualResolution()
{
m_isResolutionResetDesired = true;
}
const GpDisplayDriverProperties &GpDisplayDriverD3D11::GetProperties() const
{
return m_properties;
@@ -1454,6 +1460,7 @@ GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &prop
, m_mouseIsInClientArea(false)
, m_isFullScreen(false)
, m_isFullScreenDesired(false)
, m_isResolutionResetDesired(false)
, m_lastFullScreenToggleTimeStamp(0)
{
memset(&m_syncTimeBase, 0, sizeof(m_syncTimeBase));

View File

@@ -50,6 +50,7 @@ public:
void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
void RequestToggleFullScreen(uint32_t timestamp) override;
void RequestResetVirtualResolution() override;
const GpDisplayDriverProperties &GetProperties() const override;
@@ -146,6 +147,7 @@ private:
bool m_isFullScreen;
bool m_isFullScreenDesired;
bool m_isResolutionResetDesired;
RECT m_windowModeRevertRect;
uint32_t m_lastFullScreenToggleTimeStamp;
@@ -154,7 +156,7 @@ private:
DWORD m_windowWidthPhysical; // Physical resolution is the resolution of the actual window
DWORD m_windowHeightPhysical;
DWORD m_windowWidthVirtual; // Virtual resolution is the resolution reported to teh game
DWORD m_windowWidthVirtual; // Virtual resolution is the resolution reported to the game
DWORD m_windowHeightVirtual;
float m_pixelScaleX;
float m_pixelScaleY;