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.

270 lines
7.5KB

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