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.

275 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 setValue(float value, bool sendCallback = false) noexcept;
  92. void setUsingLogScale(bool yesNo) noexcept;
  93. void setCallback(Callback* callback) noexcept;
  94. void setOrientation(Orientation orientation) noexcept;
  95. void setRotationAngle(int angle);
  96. void setImageLayerCount(uint count) noexcept;
  97. protected:
  98. void onDisplay() override;
  99. bool onMouse(const MouseEvent&) override;
  100. bool onMotion(const MotionEvent&) override;
  101. bool onScroll(const ScrollEvent&) override;
  102. private:
  103. Image fImage;
  104. float fMinimum;
  105. float fMaximum;
  106. float fStep;
  107. float fValue;
  108. float fValueDef;
  109. float fValueTmp;
  110. bool fUsingDefault;
  111. bool fUsingLog;
  112. Orientation fOrientation;
  113. int fRotationAngle;
  114. bool fDragging;
  115. int fLastX;
  116. int fLastY;
  117. Callback* fCallback;
  118. bool fIsImgVertical;
  119. uint fImgLayerWidth;
  120. uint fImgLayerHeight;
  121. uint fImgLayerCount;
  122. bool fIsReady;
  123. GLuint fTextureId;
  124. float _logscale(float value) const;
  125. float _invlogscale(float value) const;
  126. DISTRHO_LEAK_DETECTOR(ImageKnob)
  127. };
  128. // -----------------------------------------------------------------------
  129. // note set range and step before setting the value
  130. class ImageSlider : public Widget
  131. {
  132. public:
  133. class Callback
  134. {
  135. public:
  136. virtual ~Callback() {}
  137. virtual void imageSliderDragStarted(ImageSlider* imageSlider) = 0;
  138. virtual void imageSliderDragFinished(ImageSlider* imageSlider) = 0;
  139. virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0;
  140. };
  141. explicit ImageSlider(Window& parent, const Image& image) noexcept;
  142. explicit ImageSlider(Widget* widget, const Image& image) noexcept;
  143. float getValue() const noexcept;
  144. void setValue(float value, bool sendCallback = false) noexcept;
  145. void setDefault(float def) noexcept;
  146. void setStartPos(const Point<int>& startPos) noexcept;
  147. void setStartPos(int x, int y) noexcept;
  148. void setEndPos(const Point<int>& endPos) noexcept;
  149. void setEndPos(int x, int y) noexcept;
  150. void setInverted(bool inverted) noexcept;
  151. void setRange(float min, float max) noexcept;
  152. void setStep(float step) noexcept;
  153. void setCallback(Callback* callback) noexcept;
  154. protected:
  155. void onDisplay() override;
  156. bool onMouse(const MouseEvent&) override;
  157. bool onMotion(const MotionEvent&) override;
  158. private:
  159. Image fImage;
  160. float fMinimum;
  161. float fMaximum;
  162. float fStep;
  163. float fValue;
  164. float fValueDef;
  165. float fValueTmp;
  166. bool fUsingDefault;
  167. bool fDragging;
  168. bool fInverted;
  169. bool fValueIsSet;
  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_DECLARE_NON_COPYABLE_WITH_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_IMAGE_WIDGETS_HPP_INCLUDED