mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Restore font smoothing settings
This commit is contained in:
parent
f29c371b8b
commit
abb1b32f2c
@ -2,6 +2,7 @@
|
||||
#include "CompatDirectDraw.h"
|
||||
#include "CompatDirectDrawSurface.h"
|
||||
#include "CompatDisplayMode.h"
|
||||
#include "CompatFontSmoothing.h"
|
||||
#include "CompatGdi.h"
|
||||
#include "CompatPrimarySurface.h"
|
||||
#include "CompatPtr.h"
|
||||
@ -16,6 +17,7 @@ namespace
|
||||
CompatWeakPtr<IUnknown> g_fullScreenDirectDraw = nullptr;
|
||||
HWND g_fullScreenCooperativeWindow = nullptr;
|
||||
DWORD g_fullScreenCooperativeFlags = 0;
|
||||
CompatFontSmoothing::SystemSettings g_fontSmoothingSettings = {};
|
||||
HHOOK g_callWndProcHook = nullptr;
|
||||
|
||||
void handleActivateApp(bool isActivated);
|
||||
@ -42,6 +44,8 @@ namespace
|
||||
CompatDirectDrawSurface<IDirectDrawSurface7>::fixSurfacePtrs(*primary);
|
||||
CompatGdi::invalidate(nullptr);
|
||||
}
|
||||
|
||||
CompatFontSmoothing::setSystemSettings(g_fontSmoothingSettings);
|
||||
}
|
||||
|
||||
void deactivateApp(CompatRef<IDirectDraw7> dd)
|
||||
@ -53,6 +57,9 @@ namespace
|
||||
{
|
||||
ShowWindow(g_fullScreenCooperativeWindow, SW_SHOWMINNOACTIVE);
|
||||
}
|
||||
|
||||
g_fontSmoothingSettings = CompatFontSmoothing::getSystemSettings();
|
||||
CompatFontSmoothing::setSystemSettings(CompatFontSmoothing::g_origSystemSettings);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK callWndProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
|
57
DDrawCompat/CompatFontSmoothing.cpp
Normal file
57
DDrawCompat/CompatFontSmoothing.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include "CompatFontSmoothing.h"
|
||||
|
||||
namespace CompatFontSmoothing
|
||||
{
|
||||
SystemSettings g_origSystemSettings = {};
|
||||
|
||||
bool SystemSettings::operator==(const SystemSettings& rhs) const
|
||||
{
|
||||
return isEnabled == rhs.isEnabled &&
|
||||
type == rhs.type &&
|
||||
contrast == rhs.contrast &&
|
||||
orientation == rhs.orientation;
|
||||
}
|
||||
|
||||
bool SystemSettings::operator!=(const SystemSettings& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
SystemSettings getSystemSettings()
|
||||
{
|
||||
SystemSettings settings = {};
|
||||
SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &settings.isEnabled, 0);
|
||||
SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &settings.type, 0);
|
||||
SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &settings.contrast, 0);
|
||||
SystemParametersInfo(SPI_GETFONTSMOOTHINGORIENTATION, 0, &settings.orientation, 0);
|
||||
return settings;
|
||||
}
|
||||
|
||||
void setSystemSettings(const SystemSettings& settings)
|
||||
{
|
||||
if (settings != getSystemSettings())
|
||||
{
|
||||
setSystemSettingsForced(settings);
|
||||
}
|
||||
}
|
||||
|
||||
void setSystemSettingsForced(const SystemSettings& settings)
|
||||
{
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHING, settings.isEnabled, nullptr, 0);
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHINGTYPE, 0,
|
||||
reinterpret_cast<void*>(settings.type), 0);
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0,
|
||||
reinterpret_cast<void*>(settings.contrast), 0);
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHINGORIENTATION, 0,
|
||||
reinterpret_cast<void*>(settings.orientation), 0);
|
||||
|
||||
const char* regKey = "FontSmoothing";
|
||||
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETFONTSMOOTHING,
|
||||
reinterpret_cast<LPARAM>(regKey), SMTO_BLOCK, 100, nullptr);
|
||||
RedrawWindow(nullptr, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
|
||||
}
|
||||
}
|
21
DDrawCompat/CompatFontSmoothing.h
Normal file
21
DDrawCompat/CompatFontSmoothing.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
namespace CompatFontSmoothing
|
||||
{
|
||||
struct SystemSettings
|
||||
{
|
||||
BOOL isEnabled;
|
||||
UINT type;
|
||||
UINT contrast;
|
||||
UINT orientation;
|
||||
|
||||
bool operator==(const SystemSettings& rhs) const;
|
||||
bool operator!=(const SystemSettings& rhs) const;
|
||||
};
|
||||
|
||||
extern SystemSettings g_origSystemSettings;
|
||||
|
||||
SystemSettings getSystemSettings();
|
||||
void setSystemSettings(const SystemSettings& settings);
|
||||
void setSystemSettingsForced(const SystemSettings& settings);
|
||||
}
|
@ -147,6 +147,7 @@
|
||||
<ClInclude Include="CompatActivateAppHandler.h" />
|
||||
<ClInclude Include="CompatDirectDrawPalette.h" />
|
||||
<ClInclude Include="CompatDisplayMode.h" />
|
||||
<ClInclude Include="CompatFontSmoothing.h" />
|
||||
<ClInclude Include="CompatGdi.h" />
|
||||
<ClInclude Include="CompatGdiCaret.h" />
|
||||
<ClInclude Include="CompatGdiDc.h" />
|
||||
@ -189,6 +190,7 @@
|
||||
<ClCompile Include="CompatDirectDrawPalette.cpp" />
|
||||
<ClCompile Include="CompatDirectDrawSurface.cpp" />
|
||||
<ClCompile Include="CompatDisplayMode.cpp" />
|
||||
<ClCompile Include="CompatFontSmoothing.cpp" />
|
||||
<ClCompile Include="CompatGdi.cpp" />
|
||||
<ClCompile Include="CompatGdiCaret.cpp" />
|
||||
<ClCompile Include="CompatGdiDcCache.cpp" />
|
||||
|
@ -129,6 +129,9 @@
|
||||
<ClInclude Include="CompatDisplayMode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CompatFontSmoothing.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="DllMain.cpp">
|
||||
@ -212,6 +215,9 @@
|
||||
<ClCompile Include="CompatDisplayMode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompatFontSmoothing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="DDrawCompat.def">
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "CompatDirectDraw.h"
|
||||
#include "CompatDirectDrawSurface.h"
|
||||
#include "CompatDirectDrawPalette.h"
|
||||
#include "CompatFontSmoothing.h"
|
||||
#include "CompatGdi.h"
|
||||
#include "CompatRegistry.h"
|
||||
#include "CompatPtr.h"
|
||||
@ -183,6 +184,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/)
|
||||
SetProcessPriorityBoost(GetCurrentProcess(), disablePriorityBoost);
|
||||
SetProcessAffinityMask(GetCurrentProcess(), 1);
|
||||
SetThemeAppProperties(0);
|
||||
CompatFontSmoothing::g_origSystemSettings = CompatFontSmoothing::getSystemSettings();
|
||||
Time::init();
|
||||
|
||||
if (Compat::origProcs.SetAppCompatData)
|
||||
@ -204,6 +206,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/)
|
||||
Compat::unhookAllFunctions();
|
||||
FreeLibrary(g_origDInputModule);
|
||||
FreeLibrary(g_origDDrawModule);
|
||||
CompatFontSmoothing::setSystemSettingsForced(CompatFontSmoothing::g_origSystemSettings);
|
||||
Compat::Log() << "DDrawCompat detached successfully";
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user