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.

231 lines
4.2KB

  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. #include "../Widget.hpp"
  17. #include "../Window.hpp"
  18. START_NAMESPACE_DGL
  19. // -----------------------------------------------------------------------
  20. // Widget
  21. Widget::Widget(Window& parent)
  22. : fInvertedY(false),
  23. fParent(parent),
  24. fVisible(true)
  25. {
  26. fParent._addWidget(this);
  27. }
  28. Widget::~Widget()
  29. {
  30. fParent._removeWidget(this);
  31. }
  32. bool Widget::isVisible() const noexcept
  33. {
  34. return fVisible;
  35. }
  36. void Widget::setVisible(bool yesNo)
  37. {
  38. if (fVisible == yesNo)
  39. return;
  40. fVisible = yesNo;
  41. fParent.repaint();
  42. }
  43. void Widget::show()
  44. {
  45. setVisible(true);
  46. }
  47. void Widget::hide()
  48. {
  49. setVisible(false);
  50. }
  51. int Widget::getWidth() const noexcept
  52. {
  53. return fArea.getWidth();
  54. }
  55. int Widget::getHeight() const noexcept
  56. {
  57. return fArea.getHeight();
  58. }
  59. const Size<int>& Widget::getSize() const noexcept
  60. {
  61. return fArea.getSize();
  62. }
  63. void Widget::setWidth(int width) noexcept
  64. {
  65. if (fArea.getWidth() == width)
  66. return;
  67. ResizeEvent ev;
  68. ev.oldSize = fArea.getSize();
  69. ev.size = Size<int>(width, fArea.getHeight());
  70. fArea.setWidth(width);
  71. onResize(ev);
  72. fParent.repaint();
  73. }
  74. void Widget::setHeight(int height) noexcept
  75. {
  76. if (fArea.getHeight() == height)
  77. return;
  78. ResizeEvent ev;
  79. ev.oldSize = fArea.getSize();
  80. ev.size = Size<int>(fArea.getWidth(), height);
  81. fArea.setHeight(height);
  82. onResize(ev);
  83. fParent.repaint();
  84. }
  85. void Widget::setSize(int width, int height) noexcept
  86. {
  87. setSize(Size<int>(width, height));
  88. }
  89. void Widget::setSize(const Size<int>& size) noexcept
  90. {
  91. if (fArea.getSize() == size)
  92. return;
  93. ResizeEvent ev;
  94. ev.oldSize = fArea.getSize();
  95. ev.size = size;
  96. fArea.setSize(size);
  97. onResize(ev);
  98. fParent.repaint();
  99. }
  100. int Widget::getAbsoluteX() const noexcept
  101. {
  102. return fArea.getX();
  103. }
  104. int Widget::getAbsoluteY() const noexcept
  105. {
  106. return fArea.getY();
  107. }
  108. const Point<int>& Widget::getAbsolutePos() const noexcept
  109. {
  110. return fArea.getPos();
  111. }
  112. void Widget::setAbsoluteX(int x) noexcept
  113. {
  114. if (fArea.getX() == x)
  115. return;
  116. fArea.setX(x);
  117. fParent.repaint();
  118. }
  119. void Widget::setAbsoluteY(int y) noexcept
  120. {
  121. if (fArea.getY() == y)
  122. return;
  123. fArea.setY(y);
  124. fParent.repaint();
  125. }
  126. void Widget::setAbsolutePos(int x, int y) noexcept
  127. {
  128. setAbsolutePos(Point<int>(x, y));
  129. }
  130. void Widget::setAbsolutePos(const Point<int>& pos) noexcept
  131. {
  132. if (fArea.getPos() == pos)
  133. return;
  134. fArea.setPos(pos);
  135. fParent.repaint();
  136. }
  137. App& Widget::getParentApp() const noexcept
  138. {
  139. return fParent.getApp();
  140. }
  141. Window& Widget::getParentWindow() const noexcept
  142. {
  143. return fParent;
  144. }
  145. bool Widget::contains(int x, int y) const noexcept
  146. {
  147. return (x >= 0 && y >= 0 && x < fArea.getWidth() && y < fArea.getHeight());
  148. }
  149. bool Widget::contains(const Point<int>& pos) const noexcept
  150. {
  151. return contains(pos.getX(), pos.getY());
  152. }
  153. void Widget::repaint() noexcept
  154. {
  155. fParent.repaint();
  156. }
  157. bool Widget::onKeyboard(const KeyboardEvent&)
  158. {
  159. return false;
  160. }
  161. bool Widget::onSpecial(const SpecialEvent&)
  162. {
  163. return false;
  164. }
  165. bool Widget::onMouse(const MouseEvent&)
  166. {
  167. return false;
  168. }
  169. bool Widget::onMotion(const MotionEvent&)
  170. {
  171. return false;
  172. }
  173. bool Widget::onScroll(const ScrollEvent&)
  174. {
  175. return false;
  176. }
  177. void Widget::onResize(const ResizeEvent&)
  178. {
  179. }
  180. // -----------------------------------------------------------------------
  181. END_NAMESPACE_DGL