Skip to content
Permalink
Browse files

Add DPI awareness experimental option to settings

  • Loading branch information...
botder committed Aug 2, 2019
1 parent 4e0b185 commit 65020e4d6ad9fe51537778b5de1d0fa3ff5aad66
Showing with 87 additions and 1 deletion.
  1. +1 −0 Client/core/CClientVariables.cpp
  2. +16 −0 Client/core/CCore.cpp
  3. +4 −0 Client/core/CCore.h
  4. +64 −1 Client/core/CSettings.cpp
  5. +2 −0 Client/core/CSettings.h
@@ -337,6 +337,7 @@ void CClientVariables::LoadDefaults()
DEFAULT("multimon_fullscreen_minimize", 1); // 0-off 1-on
DEFAULT("vertical_aim_sensitivity", 0.0015f); // 0.0015f is GTA default setting
DEFAULT("process_priority", 0); // 0-normal 1-above normal 2-high
DEFAULT("process_dpi_aware", false); // Enable DPI awareness in core initialization
DEFAULT("mute_master_when_minimized", 0); // 0-off 1-on
DEFAULT("mute_sfx_when_minimized", 0); // 0-off 1-on
DEFAULT("mute_radio_when_minimized", 0); // 0-off 1-on
@@ -53,6 +53,7 @@ CCore::CCore()

// Load our settings and localization as early as possible
CreateXML();
ApplyCoreInitSettings();
g_pLocalization = new CLocalization;

// Create a logger instance.
@@ -1663,6 +1664,21 @@ void CCore::UpdateRecentlyPlayed()
CCore::GetSingleton().SaveConfig();
}

void CCore::ApplyCoreInitSettings()
{
#if (_WIN32_WINNT >= _WIN32_WINNT_LONGHORN) // Windows Vista
bool bValue;
CVARS_GET("process_dpi_aware", bValue);

if (bValue)
{
// Minimum supported client for the function below is Windows Vista
// See also: https://technet.microsoft.com/en-us/evalcenter/dn469266(v=vs.90)
SetProcessDPIAware();
}
#endif
}

//
// Called just before GTA calculates frame time deltas
//
@@ -275,6 +275,10 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
bool IsFakeLagCommandEnabled() { return m_bFakeLagCommandEnabled; }
SString GetBlueCopyrightString();
HANDLE SetThreadHardwareBreakPoint(HANDLE hThread, HWBRK_TYPE Type, HWBRK_SIZE Size, DWORD dwAddress);

private:
void ApplyCoreInitSettings();

private:
// Core devices.
CXML* m_pXML;
@@ -619,6 +619,12 @@ void CSettings::CreateGUI()
m_pCheckBoxWindowed = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabVideo, _("Windowed"), true));
m_pCheckBoxWindowed->SetPosition(CVector2D(vecTemp.fX + vecSize.fX + 10.0f, vecTemp.fY + 3.0f));
m_pCheckBoxWindowed->AutoSize(NULL, 20.0f);
m_pCheckBoxWindowed->GetPosition(vecTemp, false);
m_pCheckBoxWindowed->GetSize(vecSize);

m_pCheckBoxDPIAware = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabVideo, _("DPI aware"), false));
m_pCheckBoxDPIAware->SetPosition(CVector2D(vecTemp.fX + vecSize.fX + 10.0f, vecTemp.fY));
m_pCheckBoxDPIAware->AutoSize(NULL, 20.0f);

m_pVideoResolutionLabel->GetPosition(vecTemp, false); // Restore our label position

@@ -1209,6 +1215,7 @@ void CSettings::CreateGUI()
m_pCheckBoxAllowScreenUpload->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowScreenUploadClick, this));
m_pCheckBoxCustomizedSAFiles->SetClickHandler(GUI_CALLBACK(&CSettings::OnCustomizedSAFilesClick, this));
m_pCheckBoxWindowed->SetClickHandler(GUI_CALLBACK(&CSettings::OnWindowedClick, this));
m_pCheckBoxDPIAware->SetClickHandler(GUI_CALLBACK(&CSettings::OnDPIAwareClick, this));
m_pCheckBoxShowUnsafeResolutions->SetClickHandler(GUI_CALLBACK(&CSettings::ShowUnsafeResolutionsClick, this));
m_pButtonBrowserBlacklistAdd->SetClickHandler(GUI_CALLBACK(&CSettings::OnBrowserBlacklistAdd, this));
m_pButtonBrowserBlacklistRemove->SetClickHandler(GUI_CALLBACK(&CSettings::OnBrowserBlacklistRemove, this));
@@ -1429,6 +1436,11 @@ void CSettings::UpdateVideoTab()
m_pDrawDistance->SetScrollPosition((gameSettings->GetDrawDistance() - 0.925f) / 0.8749f);
m_pBrightness->SetScrollPosition((float)gameSettings->GetBrightness() / 384);

// DPI aware
bool processDPIAware = false;
CVARS_GET("process_dpi_aware", processDPIAware);
m_pCheckBoxDPIAware->SetSelected(processDPIAware);

// FieldOfView
int iFieldOfView;
CVARS_GET("fov", iFieldOfView);
@@ -3268,6 +3280,15 @@ void CSettings::SaveData()
gameSettings->SetMipMappingEnabled(m_pCheckBoxMipMapping->GetSelected());
SetApplicationSettingInt("customized-sa-files-request", bCustomizedSAFilesEnabled ? 1 : 0);

// Process DPI awareness
bool previousProcessDPIAware = false;
CVARS_GET("process_dpi_aware", previousProcessDPIAware);

const bool processsDPIAwareChanged = (m_pCheckBoxDPIAware->GetSelected() != previousProcessDPIAware);

if (processsDPIAwareChanged)
CVARS_SET("process_dpi_aware", !previousProcessDPIAware);

// iFieldOfView
int iFieldOfView = std::min<int>(4, (m_pFieldOfView->GetScrollPosition()) * (4 + 1)) * 5 + 70;
CVARS_SET("fov", iFieldOfView);
@@ -3527,7 +3548,7 @@ void CSettings::SaveData()
gameSettings->Save();

// Ask to restart?
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged)
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged)
ShowRestartQuestion();
else if (CModManager::GetSingleton().IsLoaded() && bBrowserSettingChanged)
ShowDisconnectQuestion();
@@ -4366,6 +4387,48 @@ bool CSettings::OnWindowedClick(CGUIElement* pElement)
return true;
}

//
// OnDPIAwareClick
//
static void DPIAwareQuestionCallBack(void* userdata, unsigned int uiButton);

bool CSettings::OnDPIAwareClick(CGUIElement* pElement)
{
static bool shownWarning = false;

if (m_pCheckBoxDPIAware->GetSelected() && !shownWarning)
{
shownWarning = true;

SStringX strMessage(
_("Enabling DPI awareness is an experimental feature and\n"
"we only recommend it when you play MTA:SA on a scaled monitor.\n"
"You may experience graphical issues if you enable this option."
"\n\nAre you sure you want to enable this option?"));
CQuestionBox* pQuestionBox = CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow();
pQuestionBox->Reset();
pQuestionBox->SetTitle(_("EXPERIMENTAL FEATURE"));
pQuestionBox->SetMessage(strMessage);
pQuestionBox->SetButton(0, _("No"));
pQuestionBox->SetButton(1, _("Yes"));
pQuestionBox->SetCallback(DPIAwareQuestionCallBack, m_pCheckBoxDPIAware);
pQuestionBox->Show();
}

return true;
}

static void DPIAwareQuestionCallBack(void* userdata, unsigned int uiButton)
{
CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow()->Reset();

if (uiButton == 0)
{
auto const checkBox = reinterpret_cast<CGUICheckBox*>(userdata);
checkBox->SetSelected(false);
}
}

bool CSettings::OnBrowserBlacklistAdd(CGUIElement* pElement)
{
SString strDomain = m_pEditBrowserBlacklistAdd->GetText();
@@ -140,6 +140,7 @@ class CSettings
CGUIComboBox* m_pComboResolution;
CGUICheckBox* m_pCheckBoxMipMapping;
CGUICheckBox* m_pCheckBoxWindowed;
CGUICheckBox* m_pCheckBoxDPIAware = nullptr;
CGUICheckBox* m_pCheckBoxHudMatchAspectRatio;
CGUICheckBox* m_pCheckBoxMinimize;
CGUILabel* m_pMapRenderingLabel;
@@ -379,6 +380,7 @@ class CSettings
bool OnCustomizedSAFilesClick(CGUIElement* pElement);
bool ShowUnsafeResolutionsClick(CGUIElement* pElement);
bool OnWindowedClick(CGUIElement* pElement);
bool OnDPIAwareClick(CGUIElement* pElement);
bool OnShowAdvancedSettingDescription(CGUIElement* pElement);
bool OnHideAdvancedSettingDescription(CGUIElement* pElement);
bool OnTabChanged(CGUIElement* pElement);

0 comments on commit 65020e4

Please sign in to comment.
You can’t perform that action at this time.