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.

ImageWidgets.hpp 8.1KB

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