Audio plugin host https://kx.studio/carla
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.

ImageWidgets.hpp 7.8KB

8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 setStartPos(const Point<int>& startPos) noexcept;
  146. void setStartPos(int x, int y) noexcept;
  147. void setEndPos(const Point<int>& endPos) noexcept;
  148. void setEndPos(int x, int y) noexcept;
  149. void setInverted(bool inverted) noexcept;
  150. void setRange(float min, float max) noexcept;
  151. void setStep(float step) noexcept;
  152. void setCallback(Callback* callback) noexcept;
  153. protected:
  154. void onDisplay() override;
  155. bool onMouse(const MouseEvent&) override;
  156. bool onMotion(const MotionEvent&) override;
  157. private:
  158. Image fImage;
  159. float fMinimum;
  160. float fMaximum;
  161. float fStep;
  162. float fValue;
  163. float fValueTmp;
  164. bool fDragging;
  165. bool fInverted;
  166. bool fValueIsSet;
  167. int fStartedX;
  168. int fStartedY;
  169. Callback* fCallback;
  170. Point<int> fStartPos;
  171. Point<int> fEndPos;
  172. Rectangle<int> fSliderArea;
  173. void _recheckArea() noexcept;
  174. // these should not be used
  175. void setAbsoluteX(int) const noexcept {}
  176. void setAbsoluteY(int) const noexcept {}
  177. void setAbsolutePos(int, int) const noexcept {}
  178. void setAbsolutePos(const Point<int>&) const noexcept {}
  179. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageSlider)
  180. };
  181. // -----------------------------------------------------------------------
  182. class ImageSwitch : public Widget
  183. {
  184. public:
  185. class Callback
  186. {
  187. public:
  188. virtual ~Callback() {}
  189. virtual void imageSwitchClicked(ImageSwitch* imageButton, bool down) = 0;
  190. };
  191. explicit ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept;
  192. explicit ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept;
  193. explicit ImageSwitch(const ImageSwitch& imageSwitch) noexcept;
  194. ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept;
  195. bool isDown() const noexcept;
  196. void setDown(bool down) noexcept;
  197. void setCallback(Callback* callback) noexcept;
  198. protected:
  199. void onDisplay() override;
  200. bool onMouse(const MouseEvent&) override;
  201. private:
  202. Image fImageNormal;
  203. Image fImageDown;
  204. bool fIsDown;
  205. Callback* fCallback;
  206. DISTRHO_LEAK_DETECTOR(ImageSwitch)
  207. };
  208. // -----------------------------------------------------------------------
  209. END_NAMESPACE_DGL
  210. #endif // DGL_IMAGE_WIDGETS_HPP_INCLUDED