launcher: add custom button and spacer plugin config options

This commit is contained in:
somewhatlurker
2019-08-30 00:16:35 +10:00
parent f5989b74ac
commit b70fd18dd3
5 changed files with 119 additions and 2 deletions
@@ -56,7 +56,9 @@ namespace PluginConfig
CONFIG_DROPDOWN_NUMBER,
CONFIG_RESOLUTION,
CONFIG_GROUP_START,
CONFIG_GROUP_END
CONFIG_GROUP_END,
CONFIG_BUTTON,
CONFIG_SPACER
};
struct PluginConfigBooleanData {
@@ -141,6 +143,16 @@ namespace PluginConfig
int height;
};
struct PluginConfigButtonData {
LPCWSTR friendlyName;
LPCWSTR description;
void(*func)();
};
struct PluginConfigSpacerData {
int height;
};
struct PluginConfigOption
{
ConfigType cfgType;
@@ -8,6 +8,7 @@
#include <vector>
#include <strsafe.h>
#include <bassasio.h>
#include <shellapi.h>
void InjectCode(void* address, const std::vector<uint8_t> data)
{
@@ -414,6 +415,11 @@ BOOL APIENTRY DllMain(HMODULE hModule,
using namespace PluginConfig;
void OpenWiki()
{
ShellExecuteW(NULL, L"open", L"https://github.com/somewhatlurker/DivaSound/wiki", NULL, NULL, SW_SHOW);
}
PluginConfigOption config[] = {
{ CONFIG_DROPDOWN_TEXT, new PluginConfigDropdownTextData{L"backend", L"general", CONFIG_FILE, L"Backend:", L"Sets the audio output protocol.", L"WASAPI", std::vector<LPCWSTR>({ L"WASAPI", L"WASAPI_Exclusive" }), true, false } },
{ CONFIG_DROPDOWN_NUMBER, new PluginConfigDropdownNumberData{ L"channels", L"general", CONFIG_FILE, L"Channels:", L"Sets the number of channels.", 2, std::vector<int>({ 2, 4 }), false } },
@@ -421,6 +427,9 @@ PluginConfigOption config[] = {
{ CONFIG_NUMERIC, new PluginConfigNumericData{ L"buffer_size", L"buffer", CONFIG_FILE, L"Target Buffer Size:", L"Sets the target buffer size in ms.\nWASAPI will often ignore this and adapt to your hardware config automatically.", 10, 1, 100 } },
{ CONFIG_NUMERIC, new PluginConfigNumericData{ L"periods", L"buffer", CONFIG_FILE, L"Buffer Periods:", L"Sets how often the buffer should be filled.\nFewer periods usually allows for lower latency, but lowering this may cause issues.", 2, 1, 8 } },
{ CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"alternate_init", L"general", CONFIG_FILE, L"Use new init", L"Use the full initialisation replacement.\nTry unchecking this if DivaSound seems to cause crashes.", true } },
{ CONFIG_SPACER, new PluginConfigSpacerData{ 8 } },
{ CONFIG_BUTTON, new PluginConfigButtonData{ L"Help", L"Get help on the DivaSound wiki.", OpenWiki } },
{ CONFIG_SPACER, new PluginConfigSpacerData{ 8 } },
};
extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void)
@@ -231,6 +231,22 @@ public:
}
};
ref class CustomFuncHandler
{
public:
void(*_func)();
CustomFuncHandler(void(*func)())
{
_func = func;
}
System::Void RunFunc(System::Object^ sender, System::EventArgs^ e)
{
_func();
}
};
class ConfigOptionBase
{
@@ -276,6 +292,22 @@ public:
}
};
class OptionMetaSpacer : public ConfigOptionBase
{
public:
int _height;
OptionMetaSpacer(int height)
{
_height = height;
}
virtual int AddToPanel(Panel^ panel, unsigned int left, unsigned int top, ToolTip^ tooltip)
{
return _height;
}
};
class BooleanOption : public ConfigOptionBase
{
@@ -945,6 +977,52 @@ public:
};
class ButtonOption : public ConfigOptionBase
{
public:
void(*_func)();
ButtonOption(LPCWSTR friendlyName, LPCWSTR description, void(*func)())
{
_friendlyName = friendlyName;
_description = description;
_func = func;
}
virtual int AddToPanel(Panel^ panel, unsigned int left, unsigned int top, ToolTip^ tooltip)
{
Button^ button = gcnew Button();
button->Text = gcnew String(_friendlyName);
button->Left = left;
button->Top = top;
button->AutoSize = true;
button->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
Form^ RootForm = panel->FindForm();
float ScaleWidth = 1.0f;
float ScaleHeight = 1.0f;
if (RootForm)
{
Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions;
ScaleWidth = CurrentScaleSize.Width / BaseScaleSize;
ScaleHeight = CurrentScaleSize.Height / BaseScaleSize;
}
button->Scale(ScaleWidth, ScaleHeight);
tooltip->SetToolTip(button, gcnew String(_description));
CustomFuncHandler^ funchandler = gcnew CustomFuncHandler(_func);
button->Click += gcnew System::EventHandler(funchandler, &CustomFuncHandler::RunFunc);
panel->Controls->Add(button);
int ControlHeight = button->Height / ScaleHeight;
return ControlHeight + ControlSpacing;
}
};
class PluginOption : public ConfigOptionBase
{
public:
@@ -14,6 +14,8 @@ namespace PluginConfig
PluginConfigDropdownNumberData* ddNumberData = (PluginConfigDropdownNumberData*)(cfg.data);
PluginConfigResolutionData* resData = (PluginConfigResolutionData*)(cfg.data);
PluginConfigGroupData* groupData = (PluginConfigGroupData*)(cfg.data);
PluginConfigButtonData* btnData = (PluginConfigButtonData*)(cfg.data);
PluginConfigSpacerData* spacerData = (PluginConfigSpacerData*)(cfg.data);
switch (cfg.cfgType)
{
@@ -35,6 +37,10 @@ namespace PluginConfig
return new OptionMetaGroupStart(groupData->name, groupData->height);
case CONFIG_GROUP_END:
return new OptionMetaGroupEnd();
case CONFIG_BUTTON:
return new ButtonOption(btnData->friendlyName, btnData->description, btnData->func);
case CONFIG_SPACER:
return new OptionMetaSpacer(spacerData->height);
default:
return new ConfigOptionBase();
}
@@ -56,7 +56,9 @@ namespace PluginConfig
CONFIG_DROPDOWN_NUMBER,
CONFIG_RESOLUTION,
CONFIG_GROUP_START,
CONFIG_GROUP_END
CONFIG_GROUP_END,
CONFIG_BUTTON,
CONFIG_SPACER
};
struct PluginConfigBooleanData {
@@ -141,6 +143,16 @@ namespace PluginConfig
int height;
};
struct PluginConfigButtonData {
LPCWSTR friendlyName;
LPCWSTR description;
void(*func)();
};
struct PluginConfigSpacerData {
int height;
};
struct PluginConfigOption
{
ConfigType cfgType;