From 767c8d28ee59e6759c828c26eaccf199bb515b0e Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 23 Jun 2024 22:12:28 +0200 Subject: [PATCH] Added GdiStretchBltMode setting See issue #330. --- DDrawCompat/Config/Config.cpp | 2 ++ .../Config/Settings/GdiStretchBltMode.h | 25 +++++++++++++++++++ DDrawCompat/DDrawCompat.vcxproj | 1 + DDrawCompat/DDrawCompat.vcxproj.filters | 3 +++ DDrawCompat/Gdi/DcFunctions.cpp | 20 +++++++++++++++ DDrawCompat/Overlay/ConfigWindow.cpp | 3 +++ 6 files changed, 54 insertions(+) create mode 100644 DDrawCompat/Config/Settings/GdiStretchBltMode.h diff --git a/DDrawCompat/Config/Config.cpp b/DDrawCompat/Config/Config.cpp index 6021fda..ccd4431 100644 --- a/DDrawCompat/Config/Config.cpp +++ b/DDrawCompat/Config/Config.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,7 @@ namespace Config Settings::ForceD3D9On12 forceD3D9On12; Settings::FpsLimiter fpsLimiter; Settings::FullscreenMode fullscreenMode; + Settings::GdiStretchBltMode gdiStretchBltMode; Settings::LogLevel logLevel; Settings::PalettizedTextures palettizedTextures; Settings::RemoveBorders removeBorders; diff --git a/DDrawCompat/Config/Settings/GdiStretchBltMode.h b/DDrawCompat/Config/Settings/GdiStretchBltMode.h new file mode 100644 index 0000000..559f14b --- /dev/null +++ b/DDrawCompat/Config/Settings/GdiStretchBltMode.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +namespace Config +{ + namespace Settings + { + class GdiStretchBltMode : public MappedSetting + { + public: + static const UINT APP = 0; + + GdiStretchBltMode() : MappedSetting("GdiStretchBltMode", "app", { + {"app", APP}, + {"coloroncolor", COLORONCOLOR}, + {"halftone", HALFTONE} + }) + { + } + }; + } + + extern Settings::GdiStretchBltMode gdiStretchBltMode; +} diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index 16c5531..6a21872 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -188,6 +188,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 3d49705..32aa36f 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -720,6 +720,9 @@ Header Files\Config\Settings + + Header Files\Config\Settings + diff --git a/DDrawCompat/Gdi/DcFunctions.cpp b/DDrawCompat/Gdi/DcFunctions.cpp index 1e2c9be..5bf039e 100644 --- a/DDrawCompat/Gdi/DcFunctions.cpp +++ b/DDrawCompat/Gdi/DcFunctions.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -342,6 +343,24 @@ namespace Compat::hookFunction(moduleName, funcName, &compatGdiTextDcFunc); } + int WINAPI setStretchBltMode(HDC hdc, int mode) + { + LOG_FUNC("SetStretchBltMode", hdc, mode); + if (COLORONCOLOR == mode && HALFTONE == Config::gdiStretchBltMode.get()) + { + POINT org = {}; + GetBrushOrgEx(hdc, &org); + auto result = CALL_ORIG_FUNC(SetStretchBltMode)(hdc, HALFTONE); + SetBrushOrgEx(hdc, org.x, org.y, nullptr); + return LOG_RESULT(result); + } + if (HALFTONE == mode && COLORONCOLOR == Config::gdiStretchBltMode.get()) + { + mode = COLORONCOLOR; + } + return LOG_RESULT(CALL_ORIG_FUNC(SetStretchBltMode)(hdc, mode)); + } + HWND WINAPI windowFromDc(HDC dc) { return CALL_ORIG_FUNC(WindowFromDC)(Gdi::Dc::getOrigDc(dc)); @@ -394,6 +413,7 @@ namespace Gdi // Device context functions HOOK_GDI_DC_FUNCTION(gdi32, DrawEscape); + HOOK_FUNCTION(gdi32, SetStretchBltMode, setStretchBltMode); HOOK_FUNCTION(user32, WindowFromDC, windowFromDc); // Filled shape functions diff --git a/DDrawCompat/Overlay/ConfigWindow.cpp b/DDrawCompat/Overlay/ConfigWindow.cpp index 1179855..b5e3141 100644 --- a/DDrawCompat/Overlay/ConfigWindow.cpp +++ b/DDrawCompat/Overlay/ConfigWindow.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +59,7 @@ namespace { &Config::displayFilter }, { &Config::fontAntialiasing }, { &Config::fpsLimiter }, + { &Config::gdiStretchBltMode, []() { Gdi::redraw(nullptr); } }, { &Config::renderColorDepth, &D3dDdi::Device::updateAllConfig }, { &Config::resolutionScale, &D3dDdi::Device::updateAllConfig }, { &Config::resolutionScaleFilter },