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.

232 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. #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. int Widget::getWidth() const noexcept
  90. {
  91. return fArea.getWidth();
  92. }
  93. int Widget::getHeight() const noexcept
  94. {
  95. return fArea.getHeight();
  96. }
  97. const Size<int>& Widget::getSize() const noexcept
  98. {
  99. return fArea.getSize();
  100. }
  101. void Widget::setWidth(int width)
  102. {
  103. if (fArea.getWidth() == width)
  104. return;
  105. fArea.setWidth(width);
  106. fParent.repaint();
  107. }
  108. void Widget::setHeight(int height)
  109. {
  110. if (fArea.getHeight() == height)
  111. return;
  112. fArea.setHeight(height);
  113. fParent.repaint();
  114. }
  115. void Widget::setSize(int width, int height)
  116. {
  117. setSize(Size<int>(width, height));
  118. }
  119. void Widget::setSize(const Size<int>& size)
  120. {
  121. if (fArea.getSize() == size)
  122. return;
  123. fArea.setSize(size);
  124. fParent.repaint();
  125. }
  126. const Rectangle<int>& Widget::getArea() const noexcept
  127. {
  128. return fArea;
  129. }
  130. uint Widget::getEventTimestamp()
  131. {
  132. return fParent.getEventTimestamp();
  133. }
  134. int Widget::getModifiers()
  135. {
  136. return fParent.getModifiers();
  137. }
  138. App& Widget::getParentApp() const noexcept
  139. {
  140. return fParent.getApp();
  141. }
  142. Window& Widget::getParentWindow() const noexcept
  143. {
  144. return fParent;
  145. }
  146. void Widget::repaint()
  147. {
  148. fParent.repaint();
  149. }
  150. bool Widget::onKeyboard(bool, uint)
  151. {
  152. return false;
  153. }
  154. bool Widget::onMouse(int, bool, int, int)
  155. {
  156. return false;
  157. }
  158. bool Widget::onMotion(int, int)
  159. {
  160. return false;
  161. }
  162. bool Widget::onScroll(int, int, float, float)
  163. {
  164. return false;
  165. }
  166. bool Widget::onSpecial(bool, Key)
  167. {
  168. return false;
  169. }
  170. void Widget::onReshape(int width, int height)
  171. {
  172. glEnable(GL_BLEND);
  173. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  174. glMatrixMode(GL_PROJECTION);
  175. glLoadIdentity();
  176. glOrtho(0, width, height, 0, 0.0f, 1.0f);
  177. glViewport(0, 0, width, height);
  178. glMatrixMode(GL_MODELVIEW);
  179. glLoadIdentity();
  180. }
  181. void Widget::onClose()
  182. {
  183. }
  184. // -----------------------------------------------------------------------
  185. END_NAMESPACE_DGL