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-2016 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 "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);
  50. explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageDown);
  51. explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown);
  52. explicit ImageButton(Widget* widget, const Image& image);
  53. explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageDown);
  54. explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown);
  55. ~ImageButton() override;
  56. void setCallback(Callback* callback) noexcept;
  57. protected:
  58. void onDisplay() override;
  59. bool onMouse(const MouseEvent&) override;
  60. bool onMotion(const MotionEvent&) override;
  61. private:
  62. struct PrivateData;
  63. PrivateData* const pData;
  64. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageButton)
  65. };
  66. // -----------------------------------------------------------------------
  67. class ImageKnob : public Widget
  68. {
  69. public:
  70. enum Orientation {
  71. Horizontal,
  72. Vertical
  73. };
  74. class Callback
  75. {
  76. public:
  77. virtual ~Callback() {}
  78. virtual void imageKnobDragStarted(ImageKnob* imageKnob) = 0;
  79. virtual void imageKnobDragFinished(ImageKnob* imageKnob) = 0;
  80. virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0;
  81. };
  82. explicit ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical) noexcept;
  83. explicit ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical) noexcept;
  84. explicit ImageKnob(const ImageKnob& imageKnob);
  85. ImageKnob& operator=(const ImageKnob& imageKnob);
  86. ~ImageKnob() override;
  87. float getValue() const noexcept;
  88. void setDefault(float def) noexcept;
  89. void setRange(float min, float max) noexcept;
  90. void setStep(float step) noexcept;
  91. void setScrollStep(float step) noexcept;
  92. void setValue(float value, bool sendCallback = false) noexcept;
  93. void setUsingLogScale(bool yesNo) noexcept;
  94. void setCallback(Callback* callback) noexcept;
  95. void setOrientation(Orientation orientation) noexcept;
  96. void setRotationAngle(int angle);
  97. void setImageLayerCount(uint count) noexcept;
  98. protected:
  99. void onDisplay() override;
  100. bool onMouse(const MouseEvent&) override;
  101. bool onMotion(const MotionEvent&) override;
  102. bool onScroll(const ScrollEvent&) override;
  103. private:
  104. Image fImage;
  105. float fMinimum;
  106. float fMaximum;
  107. float fScrollStep;
  108. float fStep;
  109. float fValue;
  110. float fValueDef;
  111. float fValueTmp;
  112. bool fUsingDefault;
  113. bool fUsingLog;
  114. Orientation fOrientation;
  115. int fRotationAngle;
  116. bool fDragging;
  117. int fLastX;
  118. int fLastY;
  119. Callback* fCallback;
  120. bool fIsImgVertical;
  121. uint fImgLayerWidth;
  122. uint fImgLayerHeight;
  123. uint fImgLayerCount;
  124. bool fIsReady;
  125. GLuint fTextureId;
  126. float _logscale(float value) const;
  127. float _invlogscale(float value) const;
  128. DISTRHO_LEAK_DETECTOR(ImageKnob)
  129. };
  130. // -----------------------------------------------------------------------
  131. // note set range and step before setting the value
  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. float getValue() const noexcept;
  146. void setValue(float value, bool sendCallback = false) noexcept;
  147. void setStartPos(const Point<int>& startPos) noexcept;
  148. void setStartPos(int x, int y) noexcept;
  149. void setEndPos(const Point<int>& endPos) noexcept;
  150. void setEndPos(int x, int y) noexcept;
  151. void setInverted(bool inverted) noexcept;
  152. void setRange(float min, float max) noexcept;
  153. void setStep(float step) noexcept;
  154. void setCallback(Callback* callback) noexcept;
  155. protected:
  156. void onDisplay() override;
  157. bool onMouse(const MouseEvent&) override;
  158. bool onMotion(const MotionEvent&) override;
  159. private:
  160. Image fImage;
  161. float fMinimum;
  162. float fMaximum;
  163. float fStep;
  164. float fValue;
  165. float fValueTmp;
  166. bool fDragging;
  167. bool fInverted;
  168. bool fValueIsSet;
  169. int fStartedX;
  170. int fStartedY;
  171. Callback* fCallback;
  172. Point<int> fStartPos;
  173. Point<int> fEndPos;
  174. Rectangle<int> fSliderArea;
  175. void _recheckArea() noexcept;
  176. // these should not be used
  177. void setAbsoluteX(int) const noexcept {}
  178. void setAbsoluteY(int) const noexcept {}
  179. void setAbsolutePos(int, int) const noexcept {}
  180. void setAbsolutePos(const Point<int>&) const noexcept {}
  181. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageSlider)
  182. };
  183. // -----------------------------------------------------------------------
  184. class ImageSwitch : public Widget
  185. {
  186. public:
  187. class Callback
  188. {
  189. public:
  190. virtual ~Callback() {}
  191. virtual void imageSwitchClicked(ImageSwitch* imageButton, bool down) = 0;
  192. };
  193. explicit ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept;
  194. explicit ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept;
  195. explicit ImageSwitch(const ImageSwitch& imageSwitch) noexcept;
  196. ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept;
  197. bool isDown() const noexcept;
  198. void setDown(bool down) noexcept;
  199. void setCallback(Callback* callback) noexcept;
  200. protected:
  201. void onDisplay() override;
  202. bool onMouse(const MouseEvent&) override;
  203. private:
  204. Image fImageNormal;
  205. Image fImageDown;
  206. bool fIsDown;
  207. Callback* fCallback;
  208. DISTRHO_LEAK_DETECTOR(ImageSwitch)
  209. };
  210. // -----------------------------------------------------------------------
  211. END_NAMESPACE_DGL
  212. #endif // DGL_IMAGE_WIDGETS_HPP_INCLUDED