Collection of tools useful for audio production
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.

308 lines
7.4KB

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