From 3ae5f8c09f1ab595f32b56a0544ea2a1c3ec15ea Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Nov 2017 22:03:18 +0100 Subject: [PATCH] - initial work on a reverb editor based on the menu system. This is to get rid of some ugly Windows code and make this platform independent. --- src/win32/eaxedit.cpp | 83 ++++++++ wadsrc/static/menudef.txt | 60 ++++++ wadsrc/static/zscript.txt | 1 + .../static/zscript/menu/optionmenuitems.txt | 10 +- wadsrc/static/zscript/menu/reverbedit.txt | 181 ++++++++++++++++++ 5 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 wadsrc/static/zscript/menu/reverbedit.txt diff --git a/src/win32/eaxedit.cpp b/src/win32/eaxedit.cpp index a5a4b8116..b40b5c548 100644 --- a/src/win32/eaxedit.cpp +++ b/src/win32/eaxedit.cpp @@ -50,6 +50,9 @@ #include "c_cvars.h" #include "doomstat.h" #include "v_video.h" +#include "vm.h" +#include "symbols.h" +#include "menu/menu.h" #ifdef _MSC_VER #pragma warning(disable:4244) @@ -1410,3 +1413,83 @@ CCMD (reverbedit) } } } + +DEFINE_ACTION_FUNCTION(DReverbEdit, GetValue) +{ + PARAM_PROLOGUE; + PARAM_INT(index); + ACTION_RETURN_FLOAT(0); + return 1; +} + +DEFINE_ACTION_FUNCTION(DReverbEdit, SetValue) +{ + PARAM_PROLOGUE; + PARAM_INT(index); + PARAM_FLOAT(value); + return 0; +} + +DEFINE_ACTION_FUNCTION(DReverbEdit, GrayCheck) +{ + PARAM_PROLOGUE; + ACTION_RETURN_BOOL(false); + return 1; +} + +DEFINE_ACTION_FUNCTION(DReverbEdit, GetSelectedEnvironment) +{ + PARAM_PROLOGUE; + if (numret > 1) + { + numret = 2; + ret[1].SetInt(CurrentEnv ? CurrentEnv->ID : -1); + } + if (numret > 0) + { + ret[0].SetString(CurrentEnv ? CurrentEnv->Name : nullptr); + } + return numret; +} + +DEFINE_ACTION_FUNCTION(DReverbEdit, FillSelectMenu) +{ + PARAM_PROLOGUE; + PARAM_OBJECT(desc, DOptionMenuDescriptor); + desc->mItems.Clear(); + for (auto env = Environments; env != nullptr; env = env->Next) + { + FStringf text("(%d, %d) %s", (env->ID >> 8) & 255, env->ID & 255, env->Name); + FStringf cmd("selectenvironment \"%s\"", env->Name); + PClass *cls = PClass::FindClass("OptionMenuItemCommand"); + if (cls != nullptr && cls->IsDescendantOf("OptionMenuItem")) + { + auto func = dyn_cast(cls->FindSymbol("Init", true)); + if (func != nullptr) + { + DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew(); + VMValue params[] = { item, &text, FName(cmd).GetIndex(), false, true }; + VMCall(func->Variants[0].Implementation, params, 5, nullptr, 0); + desc->mItems.Push((DMenuItemBase*)item); + } + } + } + return 0; +} + +CCMD(selectenvironment) +{ + if (argv.argc() > 1) + { + for (auto env = Environments; env != nullptr; env = env->Next) + { + if (!strcmp(env->Name, argv[1])) + { + CurrentEnv = env; + if (eaxedit_test) ForcedEnvironment = env; + return; + } + } + } + CurrentEnv = nullptr; +} diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 3d0621c3f..47ce9fa14 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -2203,3 +2203,63 @@ OptionMenu "OpenGLOptions" protected Slider "$GLPREFMNU_PALTONEMAPPOWER", gl_paltonemap_powtable, 0.2, 3.0, 0.1, 1 Option "$GLPREFMNU_PALTONEMAPORDER", gl_paltonemap_reverselookup, "LookupOrder" } + +OptionMenu "ReverbEdit" protected +{ + Class "ReverbEdit" + Title "Reverb Environment Editor" + StaticTextSwitchable "", "", "EvironmentName", 1 + StaticTextSwitchable "", "", "EvironmentID" + StaticText " " + Submenu "Select Environment", "ReverbSelect" + Option "Test Environment", "eaxedit_test", OnOff + StaticText " " + Submenu "New Environment", "ReverbNew" + Submenu "Save Environments", "ReverbSave" + Submenu "Edit Environment", "ReverbEdit" +} + +OptionMenu "ReverbSelect" protected +{ + Class "ReverbSelect" + Title "Select Environment" + // filled in by code +} + +/* + CONTROL "Reflections Scale",IDC_REFLECTIONSSCALE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,353,70,10 + CONTROL "Reflections Delay Scale",IDC_REFLECTIONSDELAYSCALE, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,366,90,10 + CONTROL "Decay Time Scale",IDC_DECAYTIMESCALE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,377,71,10 + CONTROL "Decay HF Limit",IDC_DECAYHFLIMIT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,390,63,10 + CONTROL "Reverb Scale",IDC_REVERBSCALE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,353,58,10 + CONTROL "Reverb Delay Scale",IDC_REVERBDELAYSCALE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,366,78,10 + CONTROL "Echo Time Scale",IDC_ECHOTIMESCALE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,377,67,10 + CONTROL "Modulation Time Scale",IDC_MODULATIONTIMESCALE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,390,86,10 + LTEXT "Environment Size",IDC_STATIC,17,9,56,8,0,WS_EX_RIGHT + LTEXT "Environment Diffusion",IDC_STATIC,2,22,71,8,0,WS_EX_RIGHT + LTEXT "Room",IDC_STATIC,53,35,19,8,0,WS_EX_RIGHT + LTEXT "Room HF",IDC_STATIC,43,48,30,8,0,WS_EX_RIGHT + LTEXT "Room LF",IDC_STATIC,45,60,28,8,0,WS_EX_RIGHT + LTEXT "Decay Time",IDC_STATIC,35,74,38,8,0,WS_EX_RIGHT + LTEXT "Decay HF Ratio",IDC_STATIC,23,87,50,8,0,WS_EX_RIGHT + LTEXT "Decay LF Ratio",IDC_STATIC,24,100,49,8,0,WS_EX_RIGHT + LTEXT "Reflections",IDC_STATIC,37,113,36,8,0,WS_EX_RIGHT + LTEXT "Reflections Delay",IDC_STATIC,17,126,56,8,0,WS_EX_RIGHT + LTEXT "Reflections Pan X",IDC_STATIC,17,267,56,8,0,WS_EX_RIGHT + LTEXT "Reflections Pan Y",IDC_STATIC,17,280,56,8,0,WS_EX_RIGHT + LTEXT "Reflections Pan Z",IDC_STATIC,17,293,56,8,0,WS_EX_RIGHT + LTEXT "Reverb",IDC_STATIC,49,137,24,8,0,WS_EX_RIGHT + LTEXT "Reverb Delay",IDC_STATIC,29,150,44,8,0,WS_EX_RIGHT + LTEXT "Reverb Pan X",IDC_STATIC,29,306,44,8,0,WS_EX_RIGHT + LTEXT "Reverb Pan Y",IDC_STATIC,29,319,44,8,0,WS_EX_RIGHT + LTEXT "Reverb Pan Z",IDC_STATIC,29,332,44,8,0,WS_EX_RIGHT + LTEXT "Echo Time",IDC_STATIC,40,163,33,8,0,WS_EX_RIGHT + LTEXT "Echo Depth",IDC_STATIC,35,176,38,8,0,WS_EX_RIGHT + LTEXT "Modulation Time",IDC_STATIC,21,189,52,8,0,WS_EX_RIGHT + LTEXT "Modulation Depth",IDC_STATIC,16,202,57,8,0,WS_EX_RIGHT + LTEXT "Air Absorption HF",IDC_STATIC,16,215,57,8,0,WS_EX_RIGHT + LTEXT "HF Reference",IDC_STATIC,28,228,45,8,0,WS_EX_RIGHT + LTEXT "LF Reference",IDC_STATIC,29,241,44,8,0,WS_EX_RIGHT + LTEXT "Room Rolloff Factor",IDC_STATIC,9,254,64,8,0,WS_EX_RIGHT +*/ \ No newline at end of file diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index 919e2f97f..755e427dd 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -25,6 +25,7 @@ version "3.3" #include "zscript/menu/videomenu.txt" #include "zscript/menu/readthis.txt" #include "zscript/menu/conversationmenu.txt" +#include "zscript/menu/reverbedit.txt" #include "zscript/statscreen/types.txt" #include "zscript/statscreen/statscreen.txt" diff --git a/wadsrc/static/zscript/menu/optionmenuitems.txt b/wadsrc/static/zscript/menu/optionmenuitems.txt index f08dca713..fc9b132a9 100644 --- a/wadsrc/static/zscript/menu/optionmenuitems.txt +++ b/wadsrc/static/zscript/menu/optionmenuitems.txt @@ -126,9 +126,12 @@ class OptionMenuItemSubmenu : OptionMenuItem class OptionMenuItemCommand : OptionMenuItemSubmenu { - OptionMenuItemCommand Init(String label, Name command, bool centered = false) + bool mCloseOnSelect; + + OptionMenuItemCommand Init(String label, Name command, bool centered = false, bool closeonselect = false) { Super.Init(label, command, 0, centered); + mCloseOnSelect = closeonselect; return self; } @@ -147,6 +150,11 @@ class OptionMenuItemCommand : OptionMenuItemSubmenu } Menu.MenuSound("menu/choose"); DoCommand(mAction); + if (mCloseOnSelect) + { + let curmenu = Menu.GetCurrentMenu(); + if (curmenu != null) curmenu.Close(); + } return true; } diff --git a/wadsrc/static/zscript/menu/reverbedit.txt b/wadsrc/static/zscript/menu/reverbedit.txt new file mode 100644 index 000000000..c51897bdf --- /dev/null +++ b/wadsrc/static/zscript/menu/reverbedit.txt @@ -0,0 +1,181 @@ + +class ReverbEdit : OptionMenu +{ + static native double GetValue(int index); + static native void SetValue(int index, double value); + static native bool GrayCheck(); + static native string, int GetSelectedEnvironment(); + static native void FillSelectMenu(OptionMenuDescriptor desc); + + override void Init(Menu parent, OptionMenuDescriptor desc) + { + super.Init(parent, desc); + OnReturn(); + } + + override void OnReturn() + { + string env; + int id; + + [env, id] = GetSelectedEnvironment(); + + let li = GetItem('EvironmentName'); + if (li != NULL) + { + if (id != -1) + { + li.SetValue(0, 1); + li.SetString(0, env); + } + else + { + li.SetValue(0, 0); + } + } + li = GetItem('EvironmentID'); + if (li != NULL) + { + if (id != -1) + { + li.SetValue(0, 1); + li.SetString(0, String.Format("%d, %d", (id >> 8) & 255, id & 255)); + } + else + { + li.SetValue(0, 0); + } + } + } +} + +class ReverbSelect : OptionMenu +{ + //============================================================================= + // + // + // + //============================================================================= + + override void Init(Menu parent, OptionMenuDescriptor desc) + { + ReverbEdit.FillSelectMenu(desc); + super.Init(parent, desc); + } +} + +//============================================================================= +// +// opens a submenu, command is a submenu name +// +//============================================================================= + +/* +class OptionMenuItemReverbEditSelected : OptionMenuItemSubMenu +{ + OptionMenuItemSubmenu Init(String label, Name command) + { + Super.init(label, command, 0, false); + return self; + } + + + override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) + { + int x = drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor); + + String text = GetSelected(); + screen.DrawText (SmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay); + + return indent; + } +} +*/ + + + +//============================================================================= +// +// +// +//============================================================================= + +class OptionMenuSliderReverbEditOption : OptionMenuSliderBase +{ + int mValIndex; + String mEditValue; + TextEnterMenu mEnter; + + OptionMenuSliderReverbEditOption Init(String label, double min, double max, double step, int showval, int valindex) + { + Super.Init(label, min, max, step, showval); + mValIndex = valindex; + mEnter = null; + return self; + } + + + override double GetSliderValue() + { + return ReverbEdit.GetValue(mValIndex); + } + + override void SetSliderValue(double val) + { + ReverbEdit.SetValue(mValIndex, val); + } + + override bool Selectable() + { + return ReverbEdit.GrayCheck(); + } + + virtual String Represent() + { + return mEnter.GetText() .. SmallFont.GetCursor(); + } + + //============================================================================= + override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) + { + drawLabel(indent, y, selected ? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, Selectable()); + + int DrawX = indent + CursorSpace(); + if (mEnter) + { + screen.DrawText(SmallFont, OptionMenuSettings.mFontColorValue, DrawX, y, Represent(), DTA_CleanNoMove_1, true); + } + else + { + DrawSlider (DrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent); + } + return indent; + } + + override bool MenuEvent (int mkey, bool fromcontroller) + { + if (mkey == Menu.MKEY_Enter) + { + Menu.MenuSound("menu/choose"); + mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), String.Format("%.3f", GetSliderValue()), -1, 2, fromcontroller); + mEnter.ActivateMenu(); + return true; + } + else if (mkey == Menu.MKEY_Input) + { + String val = mEnter.GetText(); + SetSliderValue(val.toDouble()); + mEnter = null; + return true; + } + else if (mkey == Menu.MKEY_Abort) + { + mEnter = null; + return true; + } + + return Super.MenuEvent(mkey, fromcontroller); + } + +} +