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.

245 lines
6.8KB

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