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.

203 lines
4.0KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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_NTK_WIDGET_HPP_INCLUDED
  17. #define DGL_NTK_WIDGET_HPP_INCLUDED
  18. #include "NtkWindow.hpp"
  19. START_NAMESPACE_DGL
  20. // -----------------------------------------------------------------------
  21. /**
  22. DGL compatible Widget class that uses NTK instead of OpenGL.
  23. @see Widget
  24. */
  25. class NtkWidget : public Fl_Double_Window
  26. {
  27. public:
  28. /**
  29. Constructor.
  30. */
  31. explicit NtkWidget(NtkWindow& parent)
  32. : Fl_Double_Window(100, 100),
  33. fParent(parent)
  34. {
  35. fParent.add(this);
  36. show();
  37. }
  38. /**
  39. Destructor.
  40. */
  41. ~NtkWidget() override
  42. {
  43. hide();
  44. fParent.remove(this);
  45. }
  46. /**
  47. Check if this widget is visible within its parent window.
  48. Invisible widgets do not receive events except resize.
  49. */
  50. bool isVisible() const
  51. {
  52. return visible();
  53. }
  54. /**
  55. Set widget visible (or not) according to @a yesNo.
  56. */
  57. void setVisible(bool yesNo)
  58. {
  59. if (yesNo)
  60. show();
  61. else
  62. hide();
  63. }
  64. /**
  65. Get width.
  66. */
  67. int getWidth() const
  68. {
  69. return w();
  70. }
  71. /**
  72. Get height.
  73. */
  74. int getHeight() const
  75. {
  76. return h();
  77. }
  78. /**
  79. Set width.
  80. */
  81. void setWidth(int width)
  82. {
  83. resize(x(), y(), width, h());
  84. }
  85. /**
  86. Set height.
  87. */
  88. void setHeight(int height)
  89. {
  90. resize(x(), y(), w(), height);
  91. }
  92. /**
  93. Set size using @a width and @a height values.
  94. */
  95. void setSize(int width, int height)
  96. {
  97. resize(x(), y(), width, height);
  98. }
  99. /**
  100. Get absolute X.
  101. */
  102. int getAbsoluteX() const
  103. {
  104. return x();
  105. }
  106. /**
  107. Get absolute Y.
  108. */
  109. int getAbsoluteY() const
  110. {
  111. return y();
  112. }
  113. /**
  114. Set absolute X.
  115. */
  116. void setAbsoluteX(int x)
  117. {
  118. resize(x, y(), w(), h());
  119. }
  120. /**
  121. Set absolute Y.
  122. */
  123. void setAbsoluteY(int y)
  124. {
  125. resize(x(), y, w(), h());
  126. }
  127. /**
  128. Set absolute position using @a x and @a y values.
  129. */
  130. void setAbsolutePos(int x, int y)
  131. {
  132. resize(x, y, w(), h());
  133. }
  134. /**
  135. Get this widget's window application.
  136. Same as calling getParentWindow().getApp().
  137. */
  138. NtkApp& getParentApp() const noexcept
  139. {
  140. return fParent.getApp();
  141. }
  142. /**
  143. Get parent window, as passed in the constructor.
  144. */
  145. NtkWindow& getParentWindow() const noexcept
  146. {
  147. return fParent;
  148. }
  149. /**
  150. Check if this widget contains the point defined by @a x and @a y.
  151. */
  152. bool contains(int x, int y) const
  153. {
  154. return (x >= 0 && y >= 0 && x < w() && y < h());
  155. }
  156. /**
  157. Tell this widget's window to repaint itself.
  158. */
  159. void repaint()
  160. {
  161. redraw();
  162. }
  163. protected:
  164. /** @internal used for DGL compatibility. */
  165. void setNeedsFullViewport(bool) noexcept {}
  166. /** @internal used for DGL compatibility. */
  167. void setNeedsScaling(bool) noexcept {}
  168. private:
  169. NtkWindow& fParent;
  170. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NtkWidget)
  171. };
  172. // -----------------------------------------------------------------------
  173. END_NAMESPACE_DGL
  174. #endif // DGL_NTK_WIDGET_HPP_INCLUDED