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.

239 lines
4.1KB

  1. /*
  2. * DISTRHO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012-2013 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 "../App.hpp"
  17. #include "../Widget.hpp"
  18. #include "../Window.hpp"
  19. #include <cassert>
  20. START_NAMESPACE_DGL
  21. // -----------------------------------------------------------------------
  22. // Widget
  23. Widget::Widget(Window& parent)
  24. : fParent(parent),
  25. fVisible(true)
  26. {
  27. fParent._addWidget(this);
  28. }
  29. Widget::~Widget()
  30. {
  31. fParent._removeWidget(this);
  32. }
  33. bool Widget::isVisible() const noexcept
  34. {
  35. return fVisible;
  36. }
  37. void Widget::setVisible(bool yesNo)
  38. {
  39. if (fVisible == yesNo)
  40. return;
  41. fVisible = yesNo;
  42. fParent.repaint();
  43. }
  44. void Widget::show()
  45. {
  46. setVisible(true);
  47. }
  48. void Widget::hide()
  49. {
  50. setVisible(false);
  51. }
  52. int Widget::getX() const noexcept
  53. {
  54. return fArea.getX();
  55. }
  56. int Widget::getY() const noexcept
  57. {
  58. return fArea.getY();
  59. }
  60. const Point<int>& Widget::getPos() const noexcept
  61. {
  62. return fArea.getPos();
  63. }
  64. void Widget::setX(int x)
  65. {
  66. if (fArea.getX() == x)
  67. return;
  68. fArea.setX(x);
  69. fParent.repaint();
  70. }
  71. void Widget::setY(int y)
  72. {
  73. if (fArea.getY() == y)
  74. return;
  75. fArea.setY(y);
  76. fParent.repaint();
  77. }
  78. void Widget::setPos(int x, int y)
  79. {
  80. setPos(Point<int>(x, y));
  81. }
  82. void Widget::setPos(const Point<int>& pos)
  83. {
  84. if (fArea.getPos() == pos)
  85. return;
  86. fArea.setPos(pos);
  87. fParent.repaint();
  88. }
  89. void Widget::move(int x, int y)
  90. {
  91. fArea.move(x, y);
  92. fParent.repaint();
  93. }
  94. void Widget::move(const Point<int>& pos)
  95. {
  96. fArea.move(pos);
  97. fParent.repaint();
  98. }
  99. int Widget::getWidth() const noexcept
  100. {
  101. return fArea.getWidth();
  102. }
  103. int Widget::getHeight() const noexcept
  104. {
  105. return fArea.getHeight();
  106. }
  107. const Size<int>& Widget::getSize() const noexcept
  108. {
  109. return fArea.getSize();
  110. }
  111. void Widget::setWidth(int width)
  112. {
  113. if (fArea.getWidth() == width)
  114. return;
  115. fArea.setWidth(width);
  116. fParent.repaint();
  117. }
  118. void Widget::setHeight(int height)
  119. {
  120. if (fArea.getHeight() == height)
  121. return;
  122. fArea.setHeight(height);
  123. fParent.repaint();
  124. }
  125. void Widget::setSize(const Size<int>& size)
  126. {
  127. if (fArea.getSize() == size)
  128. return;
  129. fArea.setSize(size);
  130. fParent.repaint();
  131. }
  132. const Rectangle<int>& Widget::getArea() const noexcept
  133. {
  134. return fArea;
  135. }
  136. uint32_t Widget::getEventTimestamp()
  137. {
  138. return fParent.getEventTimestamp();
  139. }
  140. int Widget::getModifiers()
  141. {
  142. return fParent.getModifiers();
  143. }
  144. App& Widget::getParentApp() const noexcept
  145. {
  146. return fParent.getApp();
  147. }
  148. Window& Widget::getParentWindow() const noexcept
  149. {
  150. return fParent;
  151. }
  152. void Widget::repaint()
  153. {
  154. fParent.repaint();
  155. }
  156. bool Widget::onKeyboard(bool, uint32_t)
  157. {
  158. return false;
  159. }
  160. bool Widget::onMouse(int, bool, int, int)
  161. {
  162. return false;
  163. }
  164. bool Widget::onMotion(int, int)
  165. {
  166. return false;
  167. }
  168. bool Widget::onScroll(int, int, float, float)
  169. {
  170. return false;
  171. }
  172. bool Widget::onSpecial(bool, Key)
  173. {
  174. return false;
  175. }
  176. void Widget::onReshape(int width, int height)
  177. {
  178. glEnable(GL_BLEND);
  179. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  180. glMatrixMode(GL_PROJECTION);
  181. glLoadIdentity();
  182. glOrtho(0, width, height, 0, 0.0f, 1.0f);
  183. glViewport(0, 0, width, height);
  184. glMatrixMode(GL_MODELVIEW);
  185. glLoadIdentity();
  186. }
  187. void Widget::onClose()
  188. {
  189. }
  190. // -----------------------------------------------------------------------
  191. END_NAMESPACE_DGL