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.

243 lines
4.7KB

  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. Get size.
  80. */
  81. Size<int> getSize() const
  82. {
  83. return Size<int>(w(), h());
  84. }
  85. /**
  86. Set width.
  87. */
  88. void setWidth(int width)
  89. {
  90. resize(x(), y(), width, h());
  91. }
  92. /**
  93. Set height.
  94. */
  95. void setHeight(int height)
  96. {
  97. resize(x(), y(), w(), height);
  98. }
  99. /**
  100. Set size using @a width and @a height values.
  101. */
  102. void setSize(int width, int height)
  103. {
  104. resize(x(), y(), width, height);
  105. }
  106. /**
  107. Set size.
  108. */
  109. void setSize(const Size<int>& size)
  110. {
  111. resize(x(), y(), size.getWidth(), size.getHeight());
  112. }
  113. /**
  114. Get absolute X.
  115. */
  116. int getAbsoluteX() const
  117. {
  118. return x();
  119. }
  120. /**
  121. Get absolute Y.
  122. */
  123. int getAbsoluteY() const
  124. {
  125. return y();
  126. }
  127. /**
  128. Get absolute position.
  129. */
  130. Point<int> getAbsolutePos() const
  131. {
  132. return Point<int>(x(), y());
  133. }
  134. /**
  135. Set absolute X.
  136. */
  137. void setAbsoluteX(int x)
  138. {
  139. resize(x, y(), w(), h());
  140. }
  141. /**
  142. Set absolute Y.
  143. */
  144. void setAbsoluteY(int y)
  145. {
  146. resize(x(), y, w(), h());
  147. }
  148. /**
  149. Set absolute position using @a x and @a y values.
  150. */
  151. void setAbsolutePos(int x, int y)
  152. {
  153. resize(x, y, w(), h());
  154. }
  155. /**
  156. Set absolute position.
  157. */
  158. void setAbsolutePos(const Point<int>& pos)
  159. {
  160. resize(pos.getX(), pos.getY(), w(), h());
  161. }
  162. /**
  163. Get this widget's window application.
  164. Same as calling getParentWindow().getApp().
  165. */
  166. NtkApp& getParentApp() const noexcept
  167. {
  168. return fParent.getApp();
  169. }
  170. /**
  171. Get parent window, as passed in the constructor.
  172. */
  173. NtkWindow& getParentWindow() const noexcept
  174. {
  175. return fParent;
  176. }
  177. /**
  178. Check if this widget contains the point defined by @a x and @a y.
  179. */
  180. bool contains(int x, int y) const
  181. {
  182. return (x >= 0 && y >= 0 && x < w() && y < h());
  183. }
  184. /**
  185. Check if this widget contains the point @a pos.
  186. */
  187. bool contains(const Point<int>& pos) const
  188. {
  189. return contains(pos.getX(), pos.getY());
  190. }
  191. /**
  192. Tell this widget's window to repaint itself.
  193. */
  194. void repaint()
  195. {
  196. redraw();
  197. }
  198. protected:
  199. /** @internal used for DGL compatibility. */
  200. void setNeedsFullViewport(bool) noexcept {}
  201. /** @internal used for DGL compatibility. */
  202. void setNeedsScaling(bool) noexcept {}
  203. private:
  204. NtkWindow& fParent;
  205. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NtkWidget)
  206. };
  207. // -----------------------------------------------------------------------
  208. END_NAMESPACE_DGL
  209. #endif // DGL_NTK_WIDGET_HPP_INCLUDED