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.

114 lines
3.6KB

  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 "Window.hpp"
  18. #include "extra/WebView.hpp"
  19. START_NAMESPACE_DISTRHO
  20. // --------------------------------------------------------------------------------------------------------------------
  21. class EmbedExternalExampleUI : public UI
  22. {
  23. WebViewHandle webview;
  24. public:
  25. EmbedExternalExampleUI()
  26. : UI(),
  27. webview(nullptr)
  28. {
  29. const double scaleFactor = getScaleFactor();
  30. const uint width = DISTRHO_UI_DEFAULT_WIDTH * scaleFactor;
  31. const uint height = DISTRHO_UI_DEFAULT_HEIGHT * scaleFactor;
  32. setGeometryConstraints(width, height);
  33. if (d_isNotEqual(scaleFactor, 1.0))
  34. setSize(width, height);
  35. webview = webViewCreate("https://distrho.github.io/DPF/",
  36. getWindow().getNativeWindowHandle(),
  37. width, height, scaleFactor);
  38. }
  39. ~EmbedExternalExampleUI()
  40. {
  41. if (webview != nullptr)
  42. webViewDestroy(webview);
  43. }
  44. protected:
  45. /* --------------------------------------------------------------------------------------------------------
  46. * DSP/Plugin Callbacks */
  47. /**
  48. A parameter has changed on the plugin side.
  49. This is called by the host to inform the UI about parameter changes.
  50. */
  51. void parameterChanged(uint32_t index, float value) override
  52. {
  53. d_stdout("parameterChanged %u %f", index, value);
  54. switch (index)
  55. {
  56. case kParameterWidth:
  57. setWidth(static_cast<int>(value + 0.5f));
  58. break;
  59. case kParameterHeight:
  60. setHeight(static_cast<int>(value + 0.5f));
  61. break;
  62. }
  63. }
  64. /* --------------------------------------------------------------------------------------------------------
  65. * UI overrides */
  66. void onResize(const ResizeEvent& ev) override
  67. {
  68. UI::onResize(ev);
  69. if (webview != nullptr)
  70. webViewResize(webview, ev.size.getWidth(), ev.size.getHeight(), getScaleFactor());
  71. }
  72. void uiIdle() override
  73. {
  74. if (webview != nullptr)
  75. webViewIdle(webview);
  76. }
  77. // -------------------------------------------------------------------------------------------------------
  78. /**
  79. Set our UI class as non-copyable and add a leak detector just in case.
  80. */
  81. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EmbedExternalExampleUI)
  82. };
  83. /* ------------------------------------------------------------------------------------------------------------
  84. * UI entry point, called by DPF to create a new UI instance. */
  85. UI* createUI()
  86. {
  87. return new EmbedExternalExampleUI();
  88. }
  89. // -----------------------------------------------------------------------------------------------------------
  90. END_NAMESPACE_DISTRHO