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.

307 lines
7.3KB

  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. #ifndef __DISTRHO_UI_OPENGL_EXT_H__
  17. #define __DISTRHO_UI_OPENGL_EXT_H__
  18. #include "src/DistrhoMacros.h"
  19. #ifdef DISTRHO_UI_OPENGL
  20. #include "DistrhoUIOpenGL.h"
  21. #include <GL/gl.h>
  22. START_NAMESPACE_DISTRHO
  23. // -------------------------------------------------
  24. class Point
  25. {
  26. public:
  27. Point(int x, int y);
  28. Point(const Point& pos);
  29. int getX() const;
  30. int getY() const;
  31. void setX(int x);
  32. void setY(int y);
  33. Point& operator=(const Point& pos);
  34. Point& operator+=(const Point& pos);
  35. Point& operator-=(const Point& pos);
  36. bool operator==(const Point& pos) const;
  37. bool operator!=(const Point& pos) const;
  38. private:
  39. int _x, _y;
  40. friend class Rectangle;
  41. };
  42. class Size
  43. {
  44. public:
  45. Size(int width, int height);
  46. Size(const Size& size);
  47. int getWidth() const;
  48. int getHeight() const;
  49. void setWidth(int width);
  50. void setHeight(int height);
  51. Size& operator=(const Size& size);
  52. Size& operator+=(const Size& size);
  53. Size& operator-=(const Size& size);
  54. Size& operator*=(int m);
  55. Size& operator/=(int d);
  56. Size& operator*=(float m);
  57. Size& operator/=(float d);
  58. private:
  59. int _width, _height;
  60. friend class Rectangle;
  61. };
  62. class Rectangle
  63. {
  64. public:
  65. Rectangle(int x, int y, int width, int height);
  66. Rectangle(int x, int y, const Size& size);
  67. Rectangle(const Point& pos, int width, int height);
  68. Rectangle(const Point& pos, const Size& size);
  69. Rectangle(const Rectangle& rect);
  70. int getX() const;
  71. int getY() const;
  72. int getWidth() const;
  73. int getHeight() const;
  74. const Point& getPos() const;
  75. const Size& getSize() const;
  76. bool contains(int x, int y) const;
  77. bool contains(const Point& pos) const;
  78. bool containsX(int x) const;
  79. bool containsY(int y) const;
  80. void setX(int x);
  81. void setY(int y);
  82. void setPos(int x, int y);
  83. void setPos(const Point& pos);
  84. void move(int x, int y);
  85. void move(const Point& pos);
  86. void setWidth(int width);
  87. void setHeight(int height);
  88. void setSize(int width, int height);
  89. void setSize(const Size& size);
  90. void grow(int m);
  91. void grow(float m);
  92. void grow(int width, int height);
  93. void grow(const Size& size);
  94. void shrink(int m);
  95. void shrink(float m);
  96. void shrink(int width, int height);
  97. void shrink(const Size& size);
  98. Rectangle& operator=(const Rectangle& rect);
  99. Rectangle& operator+=(const Point& pos);
  100. Rectangle& operator-=(const Point& pos);
  101. Rectangle& operator+=(const Size& size);
  102. Rectangle& operator-=(const Size& size);
  103. private:
  104. Point _pos;
  105. Size _size;
  106. };
  107. // -------------------------------------------------
  108. class Image
  109. {
  110. public:
  111. Image(const char* data, int width, int height, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE);
  112. Image(const char* data, const Size& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE);
  113. Image(const Image& image);
  114. bool isValid() const;
  115. int getWidth() const;
  116. int getHeight() const;
  117. const Size& getSize() const;
  118. const char* getData() const;
  119. GLenum getFormat() const;
  120. GLenum getType() const;
  121. Image& operator=(const Image& image);
  122. private:
  123. const char* _data;
  124. Size _size;
  125. GLenum _format;
  126. GLenum _type;
  127. friend class OpenGLExtUI;
  128. };
  129. class ImageButton
  130. {
  131. public:
  132. ImageButton(const Image& imageNormal, const Image& imageHover, const Image& imageDown, const Point& pos);
  133. ImageButton(const ImageButton& imageButton);
  134. int getWidth() const;
  135. int getHeight() const;
  136. const Size& getSize() const;
  137. ImageButton& operator=(const ImageButton& imageButton);
  138. private:
  139. Image _imageNormal;
  140. Image _imageHover;
  141. Image _imageDown;
  142. Image* _curImage;
  143. Point _pos;
  144. Rectangle _area;
  145. friend class OpenGLExtUI;
  146. };
  147. class ImageKnob
  148. {
  149. public:
  150. enum Orientation {
  151. Horizontal,
  152. Vertical
  153. };
  154. ImageKnob(const Image& image, const Point& pos, Orientation orientation = Vertical);
  155. ImageKnob(const ImageKnob& imageKnob);
  156. void setOrientation(Orientation orientation);
  157. void setRange(float min, float max);
  158. void setValue(float value);
  159. ImageKnob& operator=(const ImageKnob& slider);
  160. private:
  161. Image _image;
  162. Point _pos;
  163. Orientation _orientation;
  164. bool _isVertical;
  165. int _layerSize;
  166. int _layerCount;
  167. Rectangle _area;
  168. float _min, _max, _value;
  169. friend class OpenGLExtUI;
  170. };
  171. class ImageSlider
  172. {
  173. public:
  174. ImageSlider(const Image& image, const Point& startPos, const Point& endPos);
  175. ImageSlider(const ImageSlider& imageSlider);
  176. int getWidth() const;
  177. int getHeight() const;
  178. void setRange(float min, float max);
  179. void setValue(float value);
  180. ImageSlider& operator=(const ImageSlider& slider);
  181. private:
  182. Image _image;
  183. Point _startPos;
  184. Point _endPos;
  185. Rectangle _area;
  186. float _min, _max, _value;
  187. friend class OpenGLExtUI;
  188. };
  189. // -------------------------------------------------
  190. struct OpenGLExtUIPrivateData;
  191. class OpenGLExtUI : public OpenGLUI
  192. {
  193. public:
  194. OpenGLExtUI();
  195. virtual ~OpenGLExtUI();
  196. // ---------------------------------------------
  197. protected:
  198. // Information
  199. virtual int d_width() = 0;
  200. virtual int d_height() = 0;
  201. // DSP Callbacks
  202. virtual void d_parameterChanged(uint32_t index, float value) = 0;
  203. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  204. virtual void d_programChanged(uint32_t index) = 0;
  205. #endif
  206. #if DISTRHO_PLUGIN_WANT_STATE
  207. virtual void d_stateChanged(const char* key, const char* value) = 0;
  208. #endif
  209. // UI Callbacks
  210. virtual void d_uiIdle();
  211. // Extended Calls
  212. void setBackgroundImage(const Image& image);
  213. void addImageButton(ImageButton* button);
  214. void addImageKnob(ImageKnob* knob);
  215. void addImageSlider(ImageSlider* slider);
  216. void showImageModalDialog(const Image& image, const char* title);
  217. // Extended Callbacks
  218. virtual void imageButtonClicked(ImageButton* button);
  219. virtual void imageKnobDragStarted(ImageKnob* knob);
  220. virtual void imageKnobDragFinished(ImageKnob* knob);
  221. virtual void imageKnobValueChanged(ImageKnob* knob, float value);
  222. virtual void imageSliderDragStarted(ImageSlider* slider);
  223. virtual void imageSliderDragFinished(ImageSlider* slider);
  224. virtual void imageSliderValueChanged(ImageSlider* slider, float value);
  225. private:
  226. OpenGLExtUIPrivateData* data;
  227. // Implemented internally
  228. void d_onInit();
  229. void d_onDisplay();
  230. void d_onKeyboard(bool press, uint32_t key);
  231. void d_onMotion(int x, int y);
  232. void d_onMouse(int button, bool press, int x, int y);
  233. void d_onReshape(int width, int height);
  234. void d_onScroll(float dx, float dy);
  235. void d_onSpecial(bool press, Key key);
  236. void d_onClose();
  237. };
  238. // -------------------------------------------------
  239. END_NAMESPACE_DISTRHO
  240. #endif // DISTRHO_UI_OPENGL
  241. #endif // __DISTRHO_UI_OPENGL_EXT_H__