From 9bdecbc275318b4c9f3d9e9cde81e76bad247944 Mon Sep 17 00:00:00 2001 From: redtide Date: Wed, 29 Mar 2023 21:10:05 +0200 Subject: [PATCH] Better VSTGUI compat, new and old versions --- plugins/editor/src/editor/DlgAbout.cpp | 13 +++++++++++++ plugins/editor/src/editor/DlgAbout.h | 20 ++++++++------------ plugins/editor/src/editor/GUIHelpers.cpp | 4 ++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/plugins/editor/src/editor/DlgAbout.cpp b/plugins/editor/src/editor/DlgAbout.cpp index e701f352..aefd17e3 100644 --- a/plugins/editor/src/editor/DlgAbout.cpp +++ b/plugins/editor/src/editor/DlgAbout.cpp @@ -223,6 +223,18 @@ CMouseEventResult SAboutDialog::onMouseDown(CPoint& where, const CButtonState& b return result; } +#if VSTGUI_MORE_THAN_4_10 +void SAboutDialog::onKeyboardEvent (KeyboardEvent& event, CFrame* frame) +{ + auto vstKeyCode = toVstKeyCode (event); + if (event.type == EventType::KeyDown && vstKeyCode.virt == VKEY_ESCAPE) + { + setVisible(false); + frame->unregisterKeyboardHook(this); + event.consumed = true; + } +} +#else int32_t SAboutDialog::onKeyDown (const VstKeyCode& keyCode, CFrame* frame) { if (keyCode.virt == VKEY_ESCAPE) { @@ -240,6 +252,7 @@ int32_t SAboutDialog::onKeyUp (const VstKeyCode& keyCode, CFrame* frame) (void)frame; return -1; } +#endif void SAboutDialog::valueChanged(CControl *ctl) { diff --git a/plugins/editor/src/editor/DlgAbout.h b/plugins/editor/src/editor/DlgAbout.h index 65a95b7d..4f36c217 100644 --- a/plugins/editor/src/editor/DlgAbout.h +++ b/plugins/editor/src/editor/DlgAbout.h @@ -14,18 +14,9 @@ #define VSTGUI_MORE_THAN_4_10 ((VSTGUI_VERSION_MAJOR > 4) \ || (VSTGUI_VERSION_MAJOR == 4 && VSTGUI_VERSION_MINOR > 10)) -#if VSTGUI_MORE_THAN_4_10 - #define OVERRIDE override - // FIXME: Use KeyboardEvent instead - #define IKEYBOARDHOOK OldKeyboardHookAdapter -#else - #define OVERRIDE - #define IKEYBOARDHOOK IKeyboardHook -#endif - using namespace VSTGUI; -class SAboutDialog : public CViewContainer, public IControlListener, public IKEYBOARDHOOK { +class SAboutDialog : public CViewContainer, public IControlListener, public IKeyboardHook { enum { kTagButtonSfztools, @@ -40,8 +31,13 @@ public: void setPluginFormat(const std::string& pluginFormat); void setPluginHost(const std::string& pluginHost); - int32_t onKeyDown(const VstKeyCode& code, CFrame* frame) OVERRIDE; - int32_t onKeyUp(const VstKeyCode& code, CFrame* frame) OVERRIDE; + +#if VSTGUI_MORE_THAN_4_10 + void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) override; +#else + int32_t onKeyDown(const VstKeyCode& code, CFrame* frame) override; + int32_t onKeyUp(const VstKeyCode& code, CFrame* frame) override; +#endif protected: CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override; diff --git a/plugins/editor/src/editor/GUIHelpers.cpp b/plugins/editor/src/editor/GUIHelpers.cpp index e0ab2197..9faf7ef4 100644 --- a/plugins/editor/src/editor/GUIHelpers.cpp +++ b/plugins/editor/src/editor/GUIHelpers.cpp @@ -64,13 +64,13 @@ void SFrameDisabler::disable() } #if VSTGUI_MORE_THAN_4_10 -void SFrameDisabler::KeyAndMouseHook::onKeyboardEvent(KeyboardEvent& event, CFrame* frame) +void SFrameDisabler::KeyAndMouseHook::onKeyboardEvent(KeyboardEvent& event, CFrame*) { if (!enabled_) event.consumed = true; } -void SFrameDisabler::KeyAndMouseHook::onMouseEvent(MouseEvent& event, CFrame* frame) +void SFrameDisabler::KeyAndMouseHook::onMouseEvent(MouseEvent& event, CFrame*) { if (!enabled_) event.consumed = true;