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.

274 lines
7.9KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2015 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. #ifndef DGL_WIDGETS_HPP_INCLUDED
  17. #define DGL_WIDGETS_HPP_INCLUDED
  18. #include "Image.hpp"
  19. #include "Widget.hpp"
  20. #include "Window.hpp"
  21. START_NAMESPACE_DGL
  22. // -----------------------------------------------------------------------
  23. class ImageAboutWindow : public Window,
  24. public Widget
  25. {
  26. public:
  27. explicit ImageAboutWindow(Window& parent, const Image& image = Image());
  28. explicit ImageAboutWindow(Widget* widget, const Image& image = Image());
  29. void setImage(const Image& image);
  30. protected:
  31. void onDisplay() override;
  32. bool onKeyboard(const KeyboardEvent&) override;
  33. bool onMouse(const MouseEvent&) override;
  34. void onReshape(uint width, uint height) override;
  35. private:
  36. Image fImgBackground;
  37. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageAboutWindow)
  38. };
  39. // -----------------------------------------------------------------------
  40. class ImageButton : public Widget
  41. {
  42. public:
  43. class Callback
  44. {
  45. public:
  46. virtual ~Callback() {}
  47. virtual void imageButtonClicked(ImageButton* imageButton, int button) = 0;
  48. };
  49. explicit ImageButton(Window& parent, const Image& image) noexcept;
  50. explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept;
  51. explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown) noexcept;
  52. explicit ImageButton(Widget* widget, const Image& image) noexcept;
  53. explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept;
  54. explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown) noexcept;
  55. void setCallback(Callback* callback) noexcept;
  56. protected:
  57. void onDisplay() override;
  58. bool onMouse(const MouseEvent&) override;
  59. bool onMotion(const MotionEvent&) override;
  60. private:
  61. Image fImageNormal;
  62. Image fImageHover;
  63. Image fImageDown;
  64. Image& fCurImage;
  65. int fCurButton;
  66. Callback* fCallback;
  67. DISTRHO_LEAK_DETECTOR(ImageButton)
  68. };
  69. // -----------------------------------------------------------------------
  70. class ImageKnob : public Widget
  71. {
  72. public:
  73. enum Orientation {
  74. Horizontal,
  75. Vertical
  76. };
  77. class Callback
  78. {
  79. public:
  80. virtual ~Callback() {}
  81. virtual void imageKnobDragStarted(ImageKnob* imageKnob) = 0;
  82. virtual void imageKnobDragFinished(ImageKnob* imageKnob) = 0;
  83. virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0;
  84. };
  85. explicit ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical) noexcept;
  86. explicit ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical) noexcept;
  87. explicit ImageKnob(const ImageKnob& imageKnob);
  88. ImageKnob& operator=(const ImageKnob& imageKnob);
  89. ~ImageKnob() override;
  90. float getValue() const noexcept;
  91. void setDefault(float def) noexcept;
  92. void setRange(float min, float max) noexcept;
  93. void setStep(float step) noexcept;
  94. void setValue(float value, bool sendCallback = false) noexcept;
  95. void setUsingLogScale(bool yesNo) noexcept;
  96. void setCallback(Callback* callback) noexcept;
  97. void setOrientation(Orientation orientation) noexcept;
  98. void setRotationAngle(int angle);
  99. void setImageLayerCount(uint count) noexcept;
  100. protected:
  101. void onDisplay() override;
  102. bool onMouse(const MouseEvent&) override;
  103. bool onMotion(const MotionEvent&) override;
  104. bool onScroll(const ScrollEvent&) override;
  105. private:
  106. Image fImage;
  107. float fMinimum;
  108. float fMaximum;
  109. float fStep;
  110. float fValue;
  111. float fValueDef;
  112. float fValueTmp;
  113. bool fUsingDefault;
  114. bool fUsingLog;
  115. Orientation fOrientation;
  116. int fRotationAngle;
  117. bool fDragging;
  118. int fLastX;
  119. int fLastY;
  120. Callback* fCallback;
  121. bool fIsImgVertical;
  122. uint fImgLayerWidth;
  123. uint fImgLayerHeight;
  124. uint fImgLayerCount;
  125. bool fIsReady;
  126. GLuint fTextureId;
  127. float _logscale(float value) const;
  128. float _invlogscale(float value) const;
  129. DISTRHO_LEAK_DETECTOR(ImageKnob)
  130. };
  131. // -----------------------------------------------------------------------
  132. class ImageSlider : public Widget
  133. {
  134. public:
  135. class Callback
  136. {
  137. public:
  138. virtual ~Callback() {}
  139. virtual void imageSliderDragStarted(ImageSlider* imageSlider) = 0;
  140. virtual void imageSliderDragFinished(ImageSlider* imageSlider) = 0;
  141. virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0;
  142. };
  143. explicit ImageSlider(Window& parent, const Image& image) noexcept;
  144. explicit ImageSlider(Widget* widget, const Image& image) noexcept;
  145. explicit ImageSlider(const ImageSlider& imageSlider) noexcept;
  146. ImageSlider& operator=(const ImageSlider& imageSlider) noexcept;
  147. float getValue() const noexcept;
  148. void setStartPos(const Point<int>& startPos) noexcept;
  149. void setStartPos(int x, int y) noexcept;
  150. void setEndPos(const Point<int>& endPos) noexcept;
  151. void setEndPos(int x, int y) noexcept;
  152. void setInverted(bool inverted) noexcept;
  153. void setRange(float min, float max) noexcept;
  154. void setStep(float step) noexcept;
  155. void setValue(float value, bool sendCallback = false) noexcept;
  156. void setCallback(Callback* callback) noexcept;
  157. protected:
  158. void onDisplay() override;
  159. bool onMouse(const MouseEvent&) override;
  160. bool onMotion(const MotionEvent&) override;
  161. private:
  162. Image fImage;
  163. float fMinimum;
  164. float fMaximum;
  165. float fStep;
  166. float fValue;
  167. float fValueTmp;
  168. bool fDragging;
  169. bool fInverted;
  170. int fStartedX;
  171. int fStartedY;
  172. Callback* fCallback;
  173. Point<int> fStartPos;
  174. Point<int> fEndPos;
  175. Rectangle<int> fSliderArea;
  176. void _recheckArea() noexcept;
  177. // these should not be used
  178. void setAbsoluteX(int) const noexcept {}
  179. void setAbsoluteY(int) const noexcept {}
  180. void setAbsolutePos(int, int) const noexcept {}
  181. void setAbsolutePos(const Point<int>&) const noexcept {}
  182. DISTRHO_LEAK_DETECTOR(ImageSlider)
  183. };
  184. // -----------------------------------------------------------------------
  185. class ImageSwitch : public Widget
  186. {
  187. public:
  188. class Callback
  189. {
  190. public:
  191. virtual ~Callback() {}
  192. virtual void imageSwitchClicked(ImageSwitch* imageButton, bool down) = 0;
  193. };
  194. explicit ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept;
  195. explicit ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept;
  196. explicit ImageSwitch(const ImageSwitch& imageSwitch) noexcept;
  197. ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept;
  198. bool isDown() const noexcept;
  199. void setDown(bool down) noexcept;
  200. void setCallback(Callback* callback) noexcept;
  201. protected:
  202. void onDisplay() override;
  203. bool onMouse(const MouseEvent&) override;
  204. private:
  205. Image fImageNormal;
  206. Image fImageDown;
  207. bool fIsDown;
  208. Callback* fCallback;
  209. DISTRHO_LEAK_DETECTOR(ImageSwitch)
  210. };
  211. // -----------------------------------------------------------------------
  212. END_NAMESPACE_DGL
  213. #endif // DGL_WIDGETS_HPP_INCLUDED