DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.2KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "DistrhoUI.hpp"
  17. #include "NativeWindow.hpp"
  18. #include "extra/WebView.hpp"
  19. START_NAMESPACE_DISTRHO
  20. // --------------------------------------------------------------------------------------------------------------------
  21. class EmbedExternalExampleUI : public UI,
  22. public NativeWindow::Callbacks
  23. {
  24. ScopedPointer<NativeWindow> window;
  25. WebViewHandle webview;
  26. public:
  27. EmbedExternalExampleUI()
  28. : UI(),
  29. webview(nullptr)
  30. {
  31. const bool standalone = isStandalone();
  32. const double scaleFactor = getScaleFactor();
  33. d_stdout("isStandalone %d", (int)standalone);
  34. const uint width = DISTRHO_UI_DEFAULT_WIDTH * scaleFactor;
  35. const uint height = DISTRHO_UI_DEFAULT_HEIGHT * scaleFactor;
  36. window = new NativeWindow(this, getTitle(), getParentWindowHandle(), width, height, standalone);
  37. webview = webViewCreate("https://distrho.github.io/DPF/",
  38. window->getNativeWindowHandle(),
  39. width, height, scaleFactor);
  40. setGeometryConstraints(width, height);
  41. if (d_isNotEqual(scaleFactor, 1.0))
  42. setSize(width, height);
  43. d_stdout("created external window with size %u %u", getWidth(), getHeight());
  44. }
  45. ~EmbedExternalExampleUI()
  46. {
  47. if (webview != nullptr)
  48. webViewDestroy(webview);
  49. }
  50. protected:
  51. /* --------------------------------------------------------------------------------------------------------
  52. * DSP/Plugin Callbacks */
  53. /**
  54. A parameter has changed on the plugin side.
  55. This is called by the host to inform the UI about parameter changes.
  56. */
  57. void parameterChanged(uint32_t index, float value) override
  58. {
  59. d_stdout("parameterChanged %u %f", index, value);
  60. switch (index)
  61. {
  62. case kParameterWidth:
  63. setWidth(static_cast<int>(value + 0.5f));
  64. break;
  65. case kParameterHeight:
  66. setHeight(static_cast<int>(value + 0.5f));
  67. break;
  68. }
  69. }
  70. /* --------------------------------------------------------------------------------------------------------
  71. * External Window callbacks */
  72. void nativeHide() override
  73. {
  74. d_stdout("nativeHide");
  75. UI::hide();
  76. }
  77. void nativeResize(const uint width, const uint height) override
  78. {
  79. d_stdout("nativeResize");
  80. setSize(width, height);
  81. }
  82. /* --------------------------------------------------------------------------------------------------------
  83. * External Window overrides */
  84. void focus() override
  85. {
  86. d_stdout("focus");
  87. window->focus();
  88. }
  89. uintptr_t getNativeWindowHandle() const noexcept override
  90. {
  91. return window->getNativeWindowHandle();
  92. }
  93. void sizeChanged(const uint width, const uint height) override
  94. {
  95. d_stdout("sizeChanged %u %u", width, height);
  96. UI::sizeChanged(width, height);
  97. window->setSize(width, height);
  98. if (webview != nullptr)
  99. webViewResize(webview, width, height, getScaleFactor());
  100. }
  101. void titleChanged(const char* const title) override
  102. {
  103. d_stdout("titleChanged %s", title);
  104. window->setTitle(title);
  105. }
  106. void transientParentWindowChanged(const uintptr_t winId) override
  107. {
  108. d_stdout("transientParentWindowChanged %lu", winId);
  109. window->setTransientParentWindow(winId);
  110. }
  111. void visibilityChanged(const bool visible) override
  112. {
  113. d_stdout("visibilityChanged %d", visible);
  114. window->setVisible(visible);
  115. }
  116. void uiIdle() override
  117. {
  118. // d_stdout("uiIdle");
  119. window->idle();
  120. if (webview != nullptr)
  121. webViewIdle(webview);
  122. }
  123. // -------------------------------------------------------------------------------------------------------
  124. /**
  125. Set our UI class as non-copyable and add a leak detector just in case.
  126. */
  127. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EmbedExternalExampleUI)
  128. };
  129. /* ------------------------------------------------------------------------------------------------------------
  130. * UI entry point, called by DPF to create a new UI instance. */
  131. UI* createUI()
  132. {
  133. return new EmbedExternalExampleUI();
  134. }
  135. // -----------------------------------------------------------------------------------------------------------
  136. END_NAMESPACE_DISTRHO