From 48a01f0b2254daa0b6e26f63673db8a90336bf43 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 10 Jul 2022 03:56:35 +0100 Subject: [PATCH] Add wasm things to menus, fix up event handling Signed-off-by: falkTX --- dpf | 2 +- plugins/Cardinal/src/ImGuiWidget.cpp | 3 -- src/CardinalPlugin.cpp | 4 +++ src/override/MenuBar.cpp | 21 ++++++++++-- src/override/Scene.cpp | 6 ++++ src/override/Window.cpp | 49 +++++++++++++++++++++++++--- 6 files changed, 74 insertions(+), 11 deletions(-) diff --git a/dpf b/dpf index 02216ab..f022c76 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit 02216aba747685fe3d8c1e7b95d7fc008249fee2 +Subproject commit f022c766bd315b5bb22800b9ab78a4e1ec991edc diff --git a/plugins/Cardinal/src/ImGuiWidget.cpp b/plugins/Cardinal/src/ImGuiWidget.cpp index 64e8848..65d129b 100644 --- a/plugins/Cardinal/src/ImGuiWidget.cpp +++ b/plugins/Cardinal/src/ImGuiWidget.cpp @@ -504,7 +504,4 @@ void ImGuiWidget::drawFramebufferCommon(const Vec& fbSize, const float scaleFact ImGui_ImplOpenGL2_RenderDrawData(data); #endif } - - // FIXME - io.KeysDown[GLFW_KEY_DELETE] = io.KeysDown[GLFW_KEY_BACKSPACE] = io.KeysDown[GLFW_KEY_ENTER] = false; } diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index 7677bae..81b1b2f 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -136,7 +136,11 @@ struct Initializer { using namespace rack; +#ifdef DISTRHO_OS_WASM + settings::allowCursorLock = true; +#else settings::allowCursorLock = false; +#endif settings::autoCheckUpdates = false; settings::autosaveInterval = 0; settings::devMode = true; diff --git a/src/override/MenuBar.cpp b/src/override/MenuBar.cpp index 43e14dd..8d29563 100644 --- a/src/override/MenuBar.cpp +++ b/src/override/MenuBar.cpp @@ -110,7 +110,12 @@ struct FileButton : MenuButton { menu->cornerFlags = BND_CORNER_TOP; menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); - menu->addChild(createMenuItem("New", RACK_MOD_CTRL_NAME "+N", []() { +#ifndef DISTRHO_OS_WASM + const char* const NewShortcut = RACK_MOD_CTRL_NAME "+N"; +#else + const char* const NewShortcut = ""; +#endif + menu->addChild(createMenuItem("New", NewShortcut, []() { patchUtils::loadTemplateDialog(); })); @@ -523,7 +528,9 @@ struct ViewButton : MenuButton { menu->addChild(new ui::MenuSeparator); menu->addChild(createMenuLabel("Parameters")); - // menu->addChild(createBoolPtrMenuItem("Lock cursor while dragging", "", &settings::allowCursorLock)); +#ifdef DISTRHO_OS_WASM + menu->addChild(createBoolPtrMenuItem("Lock cursor while dragging", "", &settings::allowCursorLock)); +#endif static const std::vector knobModeLabels = { "Linear", @@ -550,6 +557,16 @@ struct ViewButton : MenuButton { menu->addChild(new ui::MenuSeparator); menu->addChild(createMenuLabel("Window")); +#ifdef DISTRHO_OS_WASM + const bool fullscreen = APP->window->isFullScreen(); + std::string fullscreenText = "F11"; + if (fullscreen) + fullscreenText += " " CHECKMARK_STRING; + menu->addChild(createMenuItem("Fullscreen", fullscreenText, [=]() { + APP->window->setFullScreen(!fullscreen); + })); +#endif + menu->addChild(createBoolPtrMenuItem("Invert zoom", "", &settings::invertZoom)); static const std::vector rateLimitLabels = { diff --git a/src/override/Scene.cpp b/src/override/Scene.cpp index 77978e4..8f4a9e8 100644 --- a/src/override/Scene.cpp +++ b/src/override/Scene.cpp @@ -360,6 +360,12 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { window::generateScreenshot(); e.consume(this); } +#ifdef DISTRHO_OS_WASM + if (e.key == GLFW_KEY_F11 && (e.mods & RACK_MOD_MASK) == 0) { + APP->window->setFullScreen(!APP->window->isFullScreen()); + e.consume(this); + } +#endif // Module selections if (e.keyName == "a" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { diff --git a/src/override/Window.cpp b/src/override/Window.cpp index dfecf3e..867e571 100644 --- a/src/override/Window.cpp +++ b/src/override/Window.cpp @@ -62,6 +62,10 @@ # include "src/Resources.hpp" #endif +#ifdef DISTRHO_OS_WASM +# include +#endif + namespace rack { namespace window { @@ -172,7 +176,11 @@ struct Window::Internal { Internal() : hiddenApp(false), - hiddenWindow(hiddenApp) { hiddenApp.idle(); } + hiddenWindow(hiddenApp) + { + hiddenWindow.setIgnoringKeyRepeat(true); + hiddenApp.idle(); + } }; @@ -224,6 +232,10 @@ Window::Window() { if (uiFont != nullptr) bndSetFont(uiFont->handle); + +#ifdef DISTRHO_OS_WASM + emscripten_lock_orientation(EMSCRIPTEN_ORIENTATION_LANDSCAPE_PRIMARY); +#endif } void WindowSetPluginUI(Window* const window, DISTRHO_NAMESPACE::UI* const ui) @@ -536,7 +548,7 @@ void Window::step() { #ifdef STBI_WRITE_NO_STDIO Window__downscaleBitmap(pixelsWithOffset, winWidth, winHeight); stbi_write_png_to_func(Window__writeImagePNG, internal->ui, - winWidth, winHeight, depth, pixelsWithOffset, stride); + winWidth, winHeight, depth, pixelsWithOffset, stride); #else stbi_write_png("screenshot.png", winWidth, winHeight, depth, pixelsWithOffset, stride); #endif @@ -572,14 +584,31 @@ void Window::close() { void Window::cursorLock() { +#ifdef DISTRHO_OS_WASM + if (!settings::allowCursorLock) + return; + + emscripten_request_pointerlock(internal->ui->getWindow().getApp().getClassName(), false); +#endif } void Window::cursorUnlock() { +#ifdef DISTRHO_OS_WASM + if (!settings::allowCursorLock) + return; + + emscripten_exit_pointerlock(); +#endif } bool Window::isCursorLocked() { +#ifdef DISTRHO_OS_WASM + EmscriptenPointerlockChangeEvent status; + if (emscripten_get_pointerlock_status(&status) == EMSCRIPTEN_RESULT_SUCCESS) + return status.isActive; +#endif return false; } @@ -589,19 +618,29 @@ int Window::getMods() { } -void Window::setFullScreen(bool) { +void Window::setFullScreen(const bool fullscreen) { +#ifdef DISTRHO_OS_WASM + if (fullscreen) + emscripten_request_fullscreen(internal->ui->getWindow().getApp().getClassName(), false); + else + emscripten_exit_fullscreen(); +#endif } bool Window::isFullScreen() { -#if defined(CARDINAL_TRANSPARENT_SCREENSHOTS) && !defined(DGL_USE_GLES) +#ifdef DISTRHO_OS_WASM + EmscriptenFullscreenChangeEvent status; + if (emscripten_get_fullscreen_status(&status) == EMSCRIPTEN_RESULT_SUCCESS) + return status.isFullscreen; + return false; +#elif defined(CARDINAL_TRANSPARENT_SCREENSHOTS) && !defined(DGL_USE_GLES) return internal->generateScreenshotStep != kScreenshotStepNone; #else return false; #endif } - double Window::getMonitorRefreshRate() { return internal->monitorRefreshRate; }