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.

255 lines
7.1KB

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