1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Added ConfigTransparency and StatsTransparency settings

This commit is contained in:
narzoul 2023-07-02 23:29:14 +02:00
parent eb79dd2ebb
commit 6f17e17bf9
13 changed files with 105 additions and 18 deletions

View File

@ -5,6 +5,7 @@
#include <Config/Settings/BltFilter.h>
#include <Config/Settings/ColorKeyMethod.h>
#include <Config/Settings/ConfigHotKey.h>
#include <Config/Settings/ConfigTransparency.h>
#include <Config/Settings/CpuAffinity.h>
#include <Config/Settings/CpuAffinityRotation.h>
#include <Config/Settings/DepthFormat.h>
@ -35,6 +36,7 @@
#include <Config/Settings/StatsPosX.h>
#include <Config/Settings/StatsPosY.h>
#include <Config/Settings/StatsRows.h>
#include <Config/Settings/StatsTransparency.h>
#include <Config/Settings/StatsUpdateRate.h>
#include <Config/Settings/SupportedResolutions.h>
#include <Config/Settings/SupportedDepthFormats.h>
@ -55,6 +57,7 @@ namespace Config
Settings::BltFilter bltFilter;
Settings::ColorKeyMethod colorKeyMethod;
Settings::ConfigHotKey configHotKey;
Settings::ConfigTransparency configTransparency;
Settings::CpuAffinity cpuAffinity;
Settings::CpuAffinityRotation cpuAffinityRotation;
Settings::DepthFormat depthFormat;
@ -85,6 +88,7 @@ namespace Config
Settings::StatsPosX statsPosX;
Settings::StatsPosY statsPosY;
Settings::StatsRows statsRows;
Settings::StatsTransparency statsTransparency;
Settings::StatsUpdateRate statsUpdateRate;
Settings::SupportedResolutions supportedResolutions;
Settings::SupportedDepthFormats supportedDepthFormats;

View File

@ -0,0 +1,34 @@
#pragma once
#pragma once
#include <Config/MappedSetting.h>
namespace Config
{
namespace Settings
{
class ConfigTransparency : public MappedSetting<int>
{
public:
static const int ALPHA = -1;
ConfigTransparency()
: MappedSetting("ConfigTransparency", "alpha(75)", { {"off", 100}, {"alpha", ALPHA} })
{
}
int get() const
{
return ALPHA == m_value ? m_param : m_value;
}
virtual ParamInfo getParamInfo() const override
{
return ALPHA == m_value ? ParamInfo{ "Alpha", 25, 100, 75 } : ParamInfo{};
}
};
}
extern Settings::ConfigTransparency configTransparency;
}

View File

@ -0,0 +1,34 @@
#pragma once
#pragma once
#include <Config/MappedSetting.h>
namespace Config
{
namespace Settings
{
class StatsTransparency : public MappedSetting<int>
{
public:
static const int ALPHA = -1;
StatsTransparency()
: MappedSetting("StatsTransparency", "alpha(75)", { {"off", 100}, {"alpha", ALPHA} })
{
}
int get() const
{
return ALPHA == m_value ? m_param : m_value;
}
virtual ParamInfo getParamInfo() const override
{
return ALPHA == m_value ? ParamInfo{ "Alpha", 25, 100, 75 } : ParamInfo{};
}
};
}
extern Settings::StatsTransparency statsTransparency;
}

View File

@ -170,6 +170,7 @@
<ClInclude Include="Config\Settings\BltFilter.h" />
<ClInclude Include="Config\Settings\ColorKeyMethod.h" />
<ClInclude Include="Config\Settings\ConfigHotKey.h" />
<ClInclude Include="Config\Settings\ConfigTransparency.h" />
<ClInclude Include="Config\Settings\CpuAffinity.h" />
<ClInclude Include="Config\Settings\CpuAffinityRotation.h" />
<ClInclude Include="Config\Settings\DepthFormat.h" />
@ -200,6 +201,7 @@
<ClInclude Include="Config\Settings\StatsPosX.h" />
<ClInclude Include="Config\Settings\StatsPosY.h" />
<ClInclude Include="Config\Settings\StatsRows.h" />
<ClInclude Include="Config\Settings\StatsTransparency.h" />
<ClInclude Include="Config\Settings\StatsUpdateRate.h" />
<ClInclude Include="Config\Settings\SupportedDepthFormats.h" />
<ClInclude Include="Config\Settings\SupportedResolutions.h" />

View File

@ -693,6 +693,12 @@
<ClInclude Include="Config\Settings\StatsPosY.h">
<Filter>Header Files\Config\Settings</Filter>
</ClInclude>
<ClInclude Include="Config\Settings\ConfigTransparency.h">
<Filter>Header Files\Config\Settings</Filter>
</ClInclude>
<ClInclude Include="Config\Settings\StatsTransparency.h">
<Filter>Header Files\Config\Settings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Gdi\Gdi.cpp">

View File

@ -1,6 +1,7 @@
#include <Common/Hook.h>
#include <Common/Log.h>
#include <Config/Parser.h>
#include <Config/Settings/ConfigTransparency.h>
#include <Input/Input.h>
#include <Overlay/ComboBoxControl.h>
#include <Overlay/ComboBoxDropDown.h>
@ -8,7 +9,8 @@
namespace Overlay
{
ComboBoxDropDown::ComboBoxDropDown(ComboBoxControl& parent, const std::vector<std::string>& values)
: Window(&static_cast<Window&>(parent.getRoot()), calculateRect(parent, values.size()), WS_BORDER)
: Window(&static_cast<Window&>(parent.getRoot()), calculateRect(parent, values.size()), WS_BORDER,
Config::configTransparency.get())
, m_parent(parent)
{
for (int i = 0; i < static_cast<int>(values.size()); ++i)

View File

@ -8,6 +8,7 @@
#include <Config/Settings/BltFilter.h>
#include <Config/Settings/ColorKeyMethod.h>
#include <Config/Settings/ConfigHotKey.h>
#include <Config/Settings/ConfigTransparency.h>
#include <Config/Settings/DepthFormat.h>
#include <Config/Settings/DisplayFilter.h>
#include <Config/Settings/FontAntialiasing.h>
@ -20,6 +21,7 @@
#include <Config/Settings/SpriteTexCoord.h>
#include <Config/Settings/StatsPosX.h>
#include <Config/Settings/StatsPosY.h>
#include <Config/Settings/StatsTransparency.h>
#include <Config/Settings/TextureFilter.h>
#include <Config/Settings/VSync.h>
#include <D3dDdi/Device.h>
@ -41,11 +43,12 @@ namespace
const int ROW_HEIGHT = 25;
const int ROWS = 15;
std::array<SettingRow, 18> g_settingRows = { {
std::array<SettingRow, 20> g_settingRows = { {
{ &Config::alternatePixelCenter },
{ &Config::antialiasing, &D3dDdi::Device::updateAllConfig },
{ &Config::bltFilter },
{ &Config::colorKeyMethod, &D3dDdi::Device::updateAllConfig },
{ &Config::configTransparency, [&]() { Gdi::GuiThread::getConfigWindow()->setAlpha(Config::configTransparency.get()); }},
{ &Config::depthFormat, &D3dDdi::Device::updateAllConfig },
{ &Config::displayFilter },
{ &Config::fontAntialiasing },
@ -58,6 +61,7 @@ namespace
{ &Config::spriteTexCoord, &D3dDdi::Device::updateAllConfig },
{ &Config::statsPosX, []() { Gdi::GuiThread::getStatsWindow()->updatePos(); } },
{ &Config::statsPosY, []() { Gdi::GuiThread::getStatsWindow()->updatePos(); } },
{ &Config::statsTransparency, [&]() { Gdi::GuiThread::getStatsWindow()->setAlpha(Config::statsTransparency.get()); }},
{ &Config::textureFilter, &D3dDdi::Device::updateAllConfig },
{ &Config::vSync }
} };
@ -67,7 +71,7 @@ namespace Overlay
{
ConfigWindow::ConfigWindow()
: Window(nullptr, { 0, 0, SettingControl::TOTAL_WIDTH + ARROW_SIZE + BORDER / 2, ROWS * ROW_HEIGHT + 80 },
WS_BORDER, Config::configHotKey.get())
WS_BORDER, Config::configTransparency.get(), Config::configHotKey.get())
, m_buttonCount(0)
, m_focus(nullptr)
{
@ -81,7 +85,7 @@ namespace Overlay
r.top = CAPTION_HEIGHT + BORDER;
r.right = r.left + ARROW_SIZE;
r.bottom = r.top + ROWS * ROW_HEIGHT;
m_scrollBar.reset(new ScrollBarControl(*this, r, 0, g_settingRows.size() - ROWS));
m_scrollBar.reset(new ScrollBarControl(*this, r, 0, g_settingRows.size() - ROWS, 0));
addSettingControls();

View File

@ -19,11 +19,11 @@ namespace
namespace Overlay
{
ScrollBarControl::ScrollBarControl(Control& parent, const RECT& rect, int min, int max)
ScrollBarControl::ScrollBarControl(Control& parent, const RECT& rect, int min, int max, int pos)
: Control(&parent, rect, WS_VISIBLE)
, m_min(min)
, m_max(std::max(min, max))
, m_pos(min)
, m_pos(std::max(min, std::min(max, pos)))
, m_state(State::IDLE)
, m_left(isHorizontal() ? &RECT::left : &RECT::top)
, m_top(isHorizontal() ? &RECT::top : &RECT::left)

View File

@ -7,7 +7,7 @@ namespace Overlay
class ScrollBarControl : public Control
{
public:
ScrollBarControl(Control& parent, const RECT& rect, int min, int max);
ScrollBarControl(Control& parent, const RECT& rect, int min, int max, int pos);
virtual void onLButtonDown(POINT pos) override;
virtual void onLButtonUp(POINT pos) override;

View File

@ -128,7 +128,7 @@ namespace Overlay
r.left = r.right;
r.right = r.left + PARAM_CONTROL_WIDTH;
m_paramControl.reset(new ScrollBarControl(*this, r, paramInfo.min, paramInfo.max));
m_paramControl.reset(new ScrollBarControl(*this, r, paramInfo.min, paramInfo.max, m_setting.getParam()));
m_paramControl->setPos(m_setting.getParam());
}
}

View File

@ -6,6 +6,7 @@
#include <Config/Settings/StatsPosX.h>
#include <Config/Settings/StatsPosY.h>
#include <Config/Settings/StatsRows.h>
#include <Config/Settings/StatsTransparency.h>
#include <Gdi/GuiThread.h>
#include <Input/Input.h>
#include <Overlay/ConfigWindow.h>
@ -73,7 +74,7 @@ namespace Overlay
StatsWindow::StatsWindow()
: Window(nullptr,
{ 0, 0, StatsControl::getWidth(), static_cast<int>(Config::statsRows.get().size()) * ROW_HEIGHT + BORDER },
0, Config::statsHotKey.get())
0, Config::statsTransparency.get(), Config::statsHotKey.get())
{
m_statsRows.push_back({ "", [](auto) { return std::array<std::string, 4>{ "cur", "avg", "min", "max" }; },
WS_VISIBLE | WS_DISABLED });

View File

@ -43,11 +43,11 @@ namespace
namespace Overlay
{
Window::Window(Window* parentWindow, const RECT& rect, DWORD style, const Input::HotKey& hotKey)
Window::Window(Window* parentWindow, const RECT& rect, DWORD style, int alpha, const Input::HotKey& hotKey)
: Control(nullptr, rect, style)
, m_hwnd(Gdi::PresentationWindow::create(parentWindow ? parentWindow->m_hwnd : nullptr))
, m_parentWindow(parentWindow)
, m_transparency(25)
, m_alpha(alpha)
, m_scaleFactor(1)
, m_dc(CreateCompatibleDC(nullptr))
, m_bitmap(nullptr)
@ -56,7 +56,7 @@ namespace Overlay
{
g_windows.emplace(m_hwnd, *this);
CALL_ORIG_FUNC(SetWindowLongA)(m_hwnd, GWL_WNDPROC, reinterpret_cast<LONG>(&staticWindowProc));
setTransparency(m_transparency);
setAlpha(alpha);
if (0 != hotKey.vk)
{
@ -108,10 +108,10 @@ namespace Overlay
DDraw::RealPrimarySurface::scheduleOverlayUpdate();
}
void Window::setTransparency(int transparency)
void Window::setAlpha(int alpha)
{
m_transparency = transparency;
CALL_ORIG_FUNC(SetLayeredWindowAttributes)(m_hwnd, 0, static_cast<BYTE>(100 - transparency) * 255 / 100, ULW_ALPHA);
m_alpha = alpha;
CALL_ORIG_FUNC(SetLayeredWindowAttributes)(m_hwnd, 0, static_cast<BYTE>(alpha * 255 / 100), ULW_ALPHA);
}
void Window::setVisible(bool isVisible)

View File

@ -13,7 +13,7 @@ namespace Overlay
class Window : public Control
{
public:
Window(Window* parentWindow, const RECT& rect, DWORD style, const Input::HotKey& hotKey = {});
Window(Window* parentWindow, const RECT& rect, DWORD style, int alpha, const Input::HotKey& hotKey = {});
virtual ~Window() override;
virtual RECT calculateRect(const RECT& monitorRect) const = 0;
@ -22,14 +22,14 @@ namespace Overlay
int getScaleFactor() const { return m_scaleFactor; }
HWND getWindow() const { return m_hwnd; }
void setTransparency(int transparency);
void setAlpha(int alpha);
void update();
void updatePos();
protected:
HWND m_hwnd;
Window* m_parentWindow;
int m_transparency;
int m_alpha;
virtual HWND getTopmost() const;