Collection of DPF-based plugins for packaging
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.

251 lines
4.9KB

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