Audio plugin host https://kx.studio/carla
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.

241 lines
3.8KB

  1. /*
  2. * DISTRHO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * For a full copy of the license see the LGPL.txt file
  15. */
  16. #include "../App.hpp"
  17. #include "../Widget.hpp"
  18. #include "../Window.hpp"
  19. #include <cstdio>
  20. START_NAMESPACE_DISTRHO
  21. // -------------------------------------------------
  22. // Widget
  23. Widget::Widget(Window* parent)
  24. : fParent(parent),
  25. fVisible(true)
  26. {
  27. parent->addWidget(this);
  28. }
  29. Widget::~Widget()
  30. {
  31. }
  32. bool Widget::isVisible()
  33. {
  34. return fVisible;
  35. }
  36. void Widget::setVisible(bool yesNo)
  37. {
  38. if (yesNo == fVisible)
  39. return;
  40. fVisible = yesNo;
  41. fParent->repaint();
  42. }
  43. int Widget::getX() const
  44. {
  45. return fArea.getX();
  46. }
  47. int Widget::getY() const
  48. {
  49. return fArea.getY();
  50. }
  51. const Point<int>& Widget::getPos() const
  52. {
  53. return fArea.getPos();
  54. }
  55. void Widget::setX(int x)
  56. {
  57. if (fArea.getX() == x)
  58. return;
  59. fArea.setX(x);
  60. repaint();
  61. }
  62. void Widget::setY(int y)
  63. {
  64. if (fArea.getY() == y)
  65. return;
  66. fArea.setY(y);
  67. repaint();
  68. }
  69. void Widget::setPos(int x, int y)
  70. {
  71. setPos(Point<int>(x, y));
  72. }
  73. void Widget::setPos(const Point<int>& pos)
  74. {
  75. if (fArea.getPos() == pos)
  76. return;
  77. fArea.setPos(pos);
  78. repaint();
  79. }
  80. void Widget::move(int x, int y)
  81. {
  82. fArea.move(x, y);
  83. repaint();
  84. }
  85. void Widget::move(const Point<int>& pos)
  86. {
  87. fArea.move(pos);
  88. repaint();
  89. }
  90. int Widget::getWidth() const
  91. {
  92. return fArea.getWidth();
  93. }
  94. int Widget::getHeight() const
  95. {
  96. return fArea.getHeight();
  97. }
  98. const Size<int>& Widget::getSize() const
  99. {
  100. return fArea.getSize();
  101. }
  102. void Widget::setWidth(int width)
  103. {
  104. if (fArea.getWidth() == width)
  105. return;
  106. fArea.setWidth(width);
  107. fParent->repaint();
  108. }
  109. void Widget::setHeight(int height)
  110. {
  111. if (fArea.getHeight() == height)
  112. return;
  113. fArea.setHeight(height);
  114. fParent->repaint();
  115. }
  116. void Widget::setSize(int width, int height)
  117. {
  118. setSize(Size<int>(width, height));
  119. }
  120. void Widget::setSize(const Size<int>& size)
  121. {
  122. if (fArea.getSize() == size)
  123. return;
  124. fArea.setSize(size);
  125. fParent->repaint();
  126. }
  127. const Rectangle<int>& Widget::getArea() const
  128. {
  129. return fArea;
  130. }
  131. int Widget::getModifiers()
  132. {
  133. return fParent->getModifiers();
  134. }
  135. App* Widget::getApp() const
  136. {
  137. return fParent->getApp();
  138. }
  139. Window* Widget::getParent() const
  140. {
  141. return fParent;
  142. }
  143. void Widget::repaint()
  144. {
  145. fParent->repaint();
  146. }
  147. void Widget::onDisplay()
  148. {
  149. }
  150. bool Widget::onKeyboard(bool, uint32_t)
  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(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. #if DISTRHO_OS_WINDOWS
  177. Rectangle<int> r(fParent->getBounds());
  178. glOrtho(r.getX(), r.getWidth(), r.getHeight(), r.getY(), -1.0f, 1.0f);
  179. glViewport(0, 0, r.getWidth() - r.getX(), r.getHeight() - r.getY());
  180. #else
  181. glOrtho(0, width, height, 0, 0.0f, 1.0f);
  182. glViewport(0, 0, width, height);
  183. #endif
  184. glMatrixMode(GL_MODELVIEW);
  185. glLoadIdentity();
  186. }
  187. void Widget::onClose()
  188. {
  189. }
  190. // -------------------------------------------------
  191. END_NAMESPACE_DISTRHO