Audio plugin host https://kx.studio/carla
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.

147 lines
4.7KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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. #ifndef DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
  17. #define DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
  18. #include "Widget.hpp"
  19. #ifdef DISTRHO_DEFINES_H_INCLUDED
  20. START_NAMESPACE_DISTRHO
  21. class UI;
  22. END_NAMESPACE_DISTRHO
  23. #endif
  24. START_NAMESPACE_DGL
  25. class Window;
  26. // -----------------------------------------------------------------------
  27. /**
  28. Top-Level Widget class.
  29. This is the only Widget class that is allowed to be used directly on a Window.
  30. This widget takes the full size of the Window it is mapped to.
  31. Sub-widgets can be added on top of this top-level widget, by creating them with this class as parent.
  32. Doing so allows for custom position and sizes.
  33. This class is used as the type for DPF Plugin UIs.
  34. So anything that a plugin UI might need that does not belong in a simple Widget will go here.
  35. */
  36. class TopLevelWidget : public Widget
  37. {
  38. public:
  39. /**
  40. Constructor.
  41. */
  42. explicit TopLevelWidget(Window& windowToMapTo);
  43. /**
  44. Destructor.
  45. */
  46. ~TopLevelWidget() override;
  47. /**
  48. Get the application associated with this top-level widget's window.
  49. */
  50. Application& getApp() const noexcept;
  51. /**
  52. Get the window associated with this top-level widget.
  53. */
  54. Window& getWindow() const noexcept;
  55. /**
  56. Set width of this widget's window.
  57. @note This will not change the widget's size right away, but be pending on the OS resizing the window
  58. */
  59. void setWidth(uint width);
  60. /**
  61. Set height of this widget's window.
  62. @note This will not change the widget's size right away, but be pending on the OS resizing the window
  63. */
  64. void setHeight(uint height);
  65. /**
  66. Set size of this widget's window, using @a width and @a height values.
  67. @note This will not change the widget's size right away, but be pending on the OS resizing the window
  68. */
  69. void setSize(uint width, uint height);
  70. /**
  71. Set size of this widget's window.
  72. @note This will not change the widget's size right away, but be pending on the OS resizing the window
  73. */
  74. void setSize(const Size<uint>& size);
  75. /**
  76. TODO document this.
  77. */
  78. void repaint() noexcept override;
  79. /**
  80. TODO document this.
  81. */
  82. void repaint(const Rectangle<uint>& rect) noexcept;
  83. // TODO group stuff after here, convenience functions present in Window class
  84. const void* getClipboard(size_t& dataSize);
  85. bool setClipboard(const char* mimeType, const void* data, size_t dataSize);
  86. bool setCursor(MouseCursor cursor);
  87. bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs = 0);
  88. bool removeIdleCallback(IdleCallback* callback);
  89. double getScaleFactor() const noexcept;
  90. void setGeometryConstraints(uint minimumWidth,
  91. uint minimumHeight,
  92. bool keepAspectRatio = false,
  93. bool automaticallyScale = false,
  94. bool resizeNowIfAutoScaling = true);
  95. DISTRHO_DEPRECATED_BY("getApp()")
  96. Application& getParentApp() const noexcept { return getApp(); }
  97. DISTRHO_DEPRECATED_BY("getWindow()")
  98. Window& getParentWindow() const noexcept { return getWindow(); }
  99. protected:
  100. bool onKeyboard(const KeyboardEvent&) override;
  101. bool onCharacterInput(const CharacterInputEvent&) override;
  102. bool onMouse(const MouseEvent&) override;
  103. bool onMotion(const MotionEvent&) override;
  104. bool onScroll(const ScrollEvent&) override;
  105. private:
  106. struct PrivateData;
  107. PrivateData* const pData;
  108. friend class Window;
  109. #ifdef DISTRHO_DEFINES_H_INCLUDED
  110. friend class DISTRHO_NAMESPACE::UI;
  111. #endif
  112. /** @internal */
  113. virtual void requestSizeChange(uint width, uint height);
  114. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TopLevelWidget)
  115. };
  116. // -----------------------------------------------------------------------
  117. END_NAMESPACE_DGL
  118. #endif // DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED