mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Added StatsColumns setting
This commit is contained in:
parent
7ec4d076f6
commit
324d6bd6de
@ -29,6 +29,7 @@
|
||||
#include <Config/Settings/SpriteDetection.h>
|
||||
#include <Config/Settings/SpriteFilter.h>
|
||||
#include <Config/Settings/SpriteTexCoord.h>
|
||||
#include <Config/Settings/StatsColumns.h>
|
||||
#include <Config/Settings/StatsHotKey.h>
|
||||
#include <Config/Settings/SupportedResolutions.h>
|
||||
#include <Config/Settings/SupportedDepthFormats.h>
|
||||
@ -73,6 +74,7 @@ namespace Config
|
||||
Settings::SpriteDetection spriteDetection;
|
||||
Settings::SpriteFilter spriteFilter;
|
||||
Settings::SpriteTexCoord spriteTexCoord;
|
||||
Settings::StatsColumns statsColumns;
|
||||
Settings::StatsHotKey statsHotKey;
|
||||
Settings::SupportedResolutions supportedResolutions;
|
||||
Settings::SupportedDepthFormats supportedDepthFormats;
|
||||
|
47
DDrawCompat/Config/EnumListSetting.cpp
Normal file
47
DDrawCompat/Config/EnumListSetting.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <Config/EnumListSetting.h>
|
||||
#include <Config/Parser.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
EnumListSetting::EnumListSetting(const std::string& name, const std::string& default,
|
||||
const std::vector<std::string>& enumNames)
|
||||
: ListSetting(name, default)
|
||||
, m_enumNames(enumNames)
|
||||
{
|
||||
}
|
||||
|
||||
std::string EnumListSetting::getValueStr() const
|
||||
{
|
||||
std::string result;
|
||||
for (auto value : m_values)
|
||||
{
|
||||
result += ", " + m_enumNames[value];
|
||||
}
|
||||
return result.substr(2);
|
||||
}
|
||||
|
||||
void EnumListSetting::setValues(const std::vector<std::string>& values)
|
||||
{
|
||||
if (values.empty())
|
||||
{
|
||||
throw ParsingError("empty list is not allowed");
|
||||
}
|
||||
|
||||
std::vector<unsigned> result;
|
||||
for (auto valueName : values)
|
||||
{
|
||||
auto it = std::find(m_enumNames.begin(), m_enumNames.end(), valueName);
|
||||
if (it == m_enumNames.end())
|
||||
{
|
||||
throw ParsingError("invalid value: '" + valueName + "'");
|
||||
}
|
||||
|
||||
unsigned value = it - m_enumNames.begin();
|
||||
if (std::find(result.begin(), result.end(), value) == result.end())
|
||||
{
|
||||
result.push_back(value);
|
||||
}
|
||||
}
|
||||
m_values = result;
|
||||
}
|
||||
}
|
24
DDrawCompat/Config/EnumListSetting.h
Normal file
24
DDrawCompat/Config/EnumListSetting.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Config/ListSetting.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
class EnumListSetting : public ListSetting
|
||||
{
|
||||
public:
|
||||
EnumListSetting(const std::string& name, const std::string& default, const std::vector<std::string>& enumNames);
|
||||
|
||||
virtual std::string getValueStr() const override;
|
||||
|
||||
const std::vector<unsigned>& get() const { return m_values; }
|
||||
|
||||
private:
|
||||
void setValues(const std::vector<std::string>& values) override;
|
||||
|
||||
const std::vector<std::string> m_enumNames;
|
||||
std::vector<unsigned> m_values;
|
||||
};
|
||||
}
|
22
DDrawCompat/Config/Settings/StatsColumns.h
Normal file
22
DDrawCompat/Config/Settings/StatsColumns.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <Config/EnumListSetting.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
class StatsColumns : public EnumListSetting
|
||||
{
|
||||
public:
|
||||
enum Column { CUR, AVG, MIN, MAX, LABEL };
|
||||
|
||||
StatsColumns()
|
||||
: EnumListSetting("StatsColumns", "label, cur, avg, min, max", { "cur", "avg", "min", "max", "label"})
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
extern Settings::StatsColumns statsColumns;
|
||||
}
|
@ -153,6 +153,7 @@
|
||||
<ClInclude Include="Common\Hook.h" />
|
||||
<ClInclude Include="Common\ScopedCriticalSection.h" />
|
||||
<ClInclude Include="Common\Time.h" />
|
||||
<ClInclude Include="Config\EnumListSetting.h" />
|
||||
<ClInclude Include="Config\EnumSetting.h" />
|
||||
<ClInclude Include="Config\FormatListSetting.h" />
|
||||
<ClInclude Include="Config\HotKeySetting.h" />
|
||||
@ -191,6 +192,7 @@
|
||||
<ClInclude Include="Config\Settings\SpriteDetection.h" />
|
||||
<ClInclude Include="Config\Settings\SpriteFilter.h" />
|
||||
<ClInclude Include="Config\Settings\SpriteTexCoord.h" />
|
||||
<ClInclude Include="Config\Settings\StatsColumns.h" />
|
||||
<ClInclude Include="Config\Settings\StatsHotKey.h" />
|
||||
<ClInclude Include="Config\Settings\SupportedDepthFormats.h" />
|
||||
<ClInclude Include="Config\Settings\SupportedResolutions.h" />
|
||||
@ -328,6 +330,7 @@
|
||||
<ClCompile Include="Common\Rect.cpp" />
|
||||
<ClCompile Include="Common\Time.cpp" />
|
||||
<ClCompile Include="Config\Config.cpp" />
|
||||
<ClCompile Include="Config\EnumListSetting.cpp" />
|
||||
<ClCompile Include="Config\EnumSetting.cpp" />
|
||||
<ClCompile Include="Config\FormatListSetting.cpp" />
|
||||
<ClCompile Include="Config\ListSetting.cpp" />
|
||||
|
@ -666,6 +666,12 @@
|
||||
<ClInclude Include="Config\Settings\ColorKeyMethod.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\Settings\StatsColumns.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\EnumListSetting.h">
|
||||
<Filter>Header Files\Config</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Gdi\Gdi.cpp">
|
||||
@ -1055,6 +1061,9 @@
|
||||
<ClCompile Include="Config\Settings\ColorKeyMethod.cpp">
|
||||
<Filter>Source Files\Config\Settings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Config\EnumListSetting.cpp">
|
||||
<Filter>Source Files\Config</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="DDrawCompat.rc">
|
||||
|
@ -1,30 +1,69 @@
|
||||
#include <Config/Settings/StatsColumns.h>
|
||||
#include <Overlay/StatsWindow.h>
|
||||
#include <Overlay/StatsControl.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
const int NAME_LABEL_WIDTH = 70;
|
||||
const int VALUE_LABEL_WIDTH = 40;
|
||||
}
|
||||
|
||||
namespace Overlay
|
||||
{
|
||||
StatsControl::StatsControl(StatsWindow& parent, const RECT& rect, const std::string& caption, UpdateFunc updateFunc, DWORD style)
|
||||
: Control(&parent, rect, style)
|
||||
, m_captionLabel(*this, { rect.left, rect.top,
|
||||
rect.left + NAME_LABEL_WIDTH, rect.bottom }, caption, 0, WS_DISABLED | WS_VISIBLE)
|
||||
, m_curLabel(*this, { m_captionLabel.getRect().right, rect.top,
|
||||
m_captionLabel.getRect().right + VALUE_LABEL_WIDTH, rect.bottom}, std::string(), DT_RIGHT)
|
||||
, m_avgLabel(*this, { m_curLabel.getRect().right, rect.top,
|
||||
m_curLabel.getRect().right + VALUE_LABEL_WIDTH, rect.bottom }, std::string(), DT_RIGHT)
|
||||
, m_minLabel(*this, { m_avgLabel.getRect().right, rect.top,
|
||||
m_avgLabel.getRect().right + VALUE_LABEL_WIDTH, rect.bottom }, std::string(), DT_RIGHT)
|
||||
, m_maxLabel(*this, { m_minLabel.getRect().right, rect.top,
|
||||
m_minLabel.getRect().right + VALUE_LABEL_WIDTH, rect.bottom }, std::string(), DT_RIGHT)
|
||||
, m_updateFunc(updateFunc)
|
||||
{
|
||||
auto& columns = Config::statsColumns.get();
|
||||
RECT r = rect;
|
||||
for (unsigned i = 0; i < columns.size(); ++i)
|
||||
{
|
||||
r.right = r.left + getColumnWidth(i);
|
||||
if (Config::Settings::StatsColumns::LABEL == columns[i])
|
||||
{
|
||||
m_labels.emplace_back(*this, r, caption, 0, WS_DISABLED | WS_VISIBLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_labels.emplace_back(*this, r, std::string(), DT_RIGHT);
|
||||
}
|
||||
r.left = r.right;
|
||||
}
|
||||
}
|
||||
|
||||
int StatsControl::getColumnWidth(unsigned index)
|
||||
{
|
||||
auto& columns = Config::statsColumns.get();
|
||||
if (index >= columns.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return Config::Settings::StatsColumns::LABEL == columns[index] ? NAME_LABEL_WIDTH : VALUE_LABEL_WIDTH;
|
||||
}
|
||||
|
||||
int StatsControl::getWidth()
|
||||
{
|
||||
int width = 0;
|
||||
auto& columns = Config::statsColumns.get();
|
||||
for (unsigned i = 0; i < columns.size(); ++i)
|
||||
{
|
||||
width += getColumnWidth(i);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
void StatsControl::update(StatsQueue::TickCount tickCount)
|
||||
{
|
||||
auto stats = m_updateFunc(tickCount);
|
||||
m_curLabel.setLabel(stats[0]);
|
||||
m_avgLabel.setLabel(stats[1]);
|
||||
m_minLabel.setLabel(stats[2]);
|
||||
m_maxLabel.setLabel(stats[3]);
|
||||
auto& columns = Config::statsColumns.get();
|
||||
auto label = m_labels.begin();
|
||||
for (unsigned i = 0; i < columns.size(); ++i)
|
||||
{
|
||||
if (Config::Settings::StatsColumns::LABEL != columns[i])
|
||||
{
|
||||
label->setLabel(stats[columns[i]]);
|
||||
}
|
||||
++label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
|
||||
#include <Overlay/LabelControl.h>
|
||||
#include <Overlay/StatsQueue.h>
|
||||
@ -13,21 +14,17 @@ namespace Overlay
|
||||
class StatsControl : public Control
|
||||
{
|
||||
public:
|
||||
static const int NAME_LABEL_WIDTH = 70;
|
||||
static const int VALUE_LABEL_WIDTH = 40;
|
||||
|
||||
typedef std::function<std::array<std::string, 4>(StatsQueue::TickCount)> UpdateFunc;
|
||||
|
||||
StatsControl(StatsWindow& parent, const RECT& rect, const std::string& caption, UpdateFunc updateFunc, DWORD style);
|
||||
|
||||
void update(StatsQueue::TickCount tickCount);
|
||||
|
||||
static int getColumnWidth(unsigned index);
|
||||
static int getWidth();
|
||||
|
||||
private:
|
||||
LabelControl m_captionLabel;
|
||||
LabelControl m_curLabel;
|
||||
LabelControl m_avgLabel;
|
||||
LabelControl m_minLabel;
|
||||
LabelControl m_maxLabel;
|
||||
std::list<LabelControl> m_labels;
|
||||
UpdateFunc m_updateFunc;
|
||||
};
|
||||
}
|
||||
|
@ -66,8 +66,7 @@ namespace
|
||||
namespace Overlay
|
||||
{
|
||||
StatsWindow::StatsWindow()
|
||||
: Window(nullptr, { 0, 0, StatsControl::NAME_LABEL_WIDTH + 4 * StatsControl::VALUE_LABEL_WIDTH, 105 + BORDER },
|
||||
0, Config::statsHotKey.get())
|
||||
: Window(nullptr, { 0, 0, StatsControl::getWidth(), 105 + BORDER}, 0, Config::statsHotKey.get())
|
||||
{
|
||||
addControl("", [](StatsQueue::TickCount) { return std::array<std::string, 4>{ "cur", "avg", "min", "max" }; },
|
||||
WS_VISIBLE | WS_DISABLED).update(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user