From b70fd18dd35ea88175efa684dee58f0aaf2dfa29 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Tue, 27 Aug 2019 12:16:45 +1000 Subject: [PATCH] launcher: add custom button and spacer plugin config options --- .../plugins/DivaSound/src/PluginConfigApi.h | 14 +++- .../source/plugins/DivaSound/src/dllmain.cpp | 9 +++ .../source/plugins/Launcher/ConfigOption.h | 78 +++++++++++++++++++ .../source/plugins/Launcher/PluginConfig.h | 6 ++ .../source/plugins/Launcher/PluginConfigApi.h | 14 +++- 5 files changed, 119 insertions(+), 2 deletions(-) diff --git a/source-code/source/plugins/DivaSound/src/PluginConfigApi.h b/source-code/source/plugins/DivaSound/src/PluginConfigApi.h index f053d5c..d0ffd94 100644 --- a/source-code/source/plugins/DivaSound/src/PluginConfigApi.h +++ b/source-code/source/plugins/DivaSound/src/PluginConfigApi.h @@ -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; diff --git a/source-code/source/plugins/DivaSound/src/dllmain.cpp b/source-code/source/plugins/DivaSound/src/dllmain.cpp index 1ab0c2e..a22837f 100644 --- a/source-code/source/plugins/DivaSound/src/dllmain.cpp +++ b/source-code/source/plugins/DivaSound/src/dllmain.cpp @@ -8,6 +8,7 @@ #include #include #include +#include void InjectCode(void* address, const std::vector 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({ 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({ 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) diff --git a/source-code/source/plugins/Launcher/ConfigOption.h b/source-code/source/plugins/Launcher/ConfigOption.h index 88477b1..ea48108 100644 --- a/source-code/source/plugins/Launcher/ConfigOption.h +++ b/source-code/source/plugins/Launcher/ConfigOption.h @@ -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: diff --git a/source-code/source/plugins/Launcher/PluginConfig.h b/source-code/source/plugins/Launcher/PluginConfig.h index d365afe..b2d3e35 100644 --- a/source-code/source/plugins/Launcher/PluginConfig.h +++ b/source-code/source/plugins/Launcher/PluginConfig.h @@ -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(); } diff --git a/source-code/source/plugins/Launcher/PluginConfigApi.h b/source-code/source/plugins/Launcher/PluginConfigApi.h index f053d5c..d0ffd94 100644 --- a/source-code/source/plugins/Launcher/PluginConfigApi.h +++ b/source-code/source/plugins/Launcher/PluginConfigApi.h @@ -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;