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.

223 lines
6.2KB

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