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.

SubWidget.hpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_SUBWIDGET_HPP_INCLUDED
  17. #define DGL_SUBWIDGET_HPP_INCLUDED
  18. #include "Widget.hpp"
  19. START_NAMESPACE_DGL
  20. // --------------------------------------------------------------------------------------------------------------------
  21. /**
  22. Sub-Widget class.
  23. This class is the main entry point for creating any reusable widgets from within DGL.
  24. It can be freely positioned from within a parent widget, thus being named subwidget.
  25. Many subwidgets can share the same parent, and subwidgets themselves can also have its own subwidgets.
  26. It is subwidgets all the way down.
  27. TODO check absolute vs relative position and see what makes more sense.
  28. @see CairoSubWidget
  29. */
  30. class SubWidget : public Widget
  31. {
  32. public:
  33. /**
  34. Constructor.
  35. */
  36. explicit SubWidget(Widget* parentWidget);
  37. /**
  38. Destructor.
  39. */
  40. ~SubWidget() override;
  41. /**
  42. Check if this widget contains the point defined by @a x and @a y.
  43. */
  44. // TODO rename as containsRelativePos
  45. template<typename T>
  46. bool contains(T x, T y) const noexcept;
  47. /**
  48. Check if this widget contains the point @a pos.
  49. */
  50. // TODO rename as containsRelativePos
  51. template<typename T>
  52. bool contains(const Point<T>& pos) const noexcept;
  53. /**
  54. Get absolute X.
  55. */
  56. int getAbsoluteX() const noexcept;
  57. /**
  58. Get absolute Y.
  59. */
  60. int getAbsoluteY() const noexcept;
  61. /**
  62. Get absolute position.
  63. */
  64. Point<int> getAbsolutePos() const noexcept;
  65. /**
  66. Get absolute area of this subwidget.
  67. This is the same as `Rectangle<int>(getAbsolutePos(), getSize());`
  68. @see getConstrainedAbsoluteArea()
  69. */
  70. Rectangle<int> getAbsoluteArea() const noexcept;
  71. /**
  72. Get absolute area of this subwidget, with special consideration for not allowing negative values.
  73. @see getAbsoluteArea()
  74. */
  75. Rectangle<uint> getConstrainedAbsoluteArea() const noexcept;
  76. /**
  77. Set absolute X.
  78. */
  79. void setAbsoluteX(int x) noexcept;
  80. /**
  81. Set absolute Y.
  82. */
  83. void setAbsoluteY(int y) noexcept;
  84. /**
  85. Set absolute position using @a x and @a y values.
  86. */
  87. void setAbsolutePos(int x, int y) noexcept;
  88. /**
  89. Set absolute position.
  90. */
  91. void setAbsolutePos(const Point<int>& pos) noexcept;
  92. /**
  93. Get the margin currently in use for widget coordinates.
  94. By default this value is (0,0).
  95. */
  96. Point<int> getMargin() const noexcept;
  97. /**
  98. Set a margin to be used for widget coordinates using @a x and @a y values.
  99. */
  100. void setMargin(int x, int y) noexcept;
  101. /**
  102. Set a margin to be used for widget coordinates.
  103. */
  104. void setMargin(const Point<int>& offset) noexcept;
  105. /**
  106. Get parent Widget, as passed in the constructor.
  107. */
  108. Widget* getParentWidget() const noexcept;
  109. /**
  110. Request repaint of this subwidget's area to the window this widget belongs to.
  111. */
  112. void repaint() noexcept override;
  113. /**
  114. Bring this widget to the "front" of the parent widget.
  115. Makes the widget behave as if it was the last to be registered on the parent widget, thus being "in front".
  116. */
  117. virtual void toFront();
  118. /**
  119. Indicate that this subwidget will draw out of bounds, and thus needs the entire viewport available for drawing.
  120. */
  121. void setNeedsFullViewportDrawing(bool needsFullViewportForDrawing = true);
  122. /**
  123. Indicate that this subwidget will always draw at its own internal size and needs scaling to fit target size.
  124. */
  125. void setNeedsViewportScaling(bool needsViewportScaling = true, double autoScaleFactor = 0.0);
  126. /**
  127. Indicate that this subwidget should not be drawn on screen, typically because it is managed by something else.
  128. */
  129. void setSkipDrawing(bool skipDrawing = true);
  130. protected:
  131. /**
  132. A function called when the subwidget's absolute position is changed.
  133. */
  134. virtual void onPositionChanged(const PositionChangedEvent&);
  135. private:
  136. struct PrivateData;
  137. PrivateData* const pData;
  138. friend class Widget;
  139. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SubWidget)
  140. };
  141. // --------------------------------------------------------------------------------------------------------------------
  142. END_NAMESPACE_DGL
  143. #endif // DGL_SUBWIDGET_HPP_INCLUDED