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.

212 lines
6.9KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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_BASE_WIDGETS_HPP_INCLUDED
  17. #define DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED
  18. #include "EventHandlers.hpp"
  19. #include "StandaloneWindow.hpp"
  20. #include "SubWidget.hpp"
  21. START_NAMESPACE_DGL
  22. // --------------------------------------------------------------------------------------------------------------------
  23. template <class ImageType>
  24. class ImageBaseAboutWindow : public StandaloneWindow
  25. {
  26. public:
  27. explicit ImageBaseAboutWindow(Window& parentWindow, const ImageType& image = ImageType());
  28. explicit ImageBaseAboutWindow(TopLevelWidget* parentTopLevelWidget, const ImageType& image = ImageType());
  29. void setImage(const ImageType& image);
  30. protected:
  31. void onDisplay() override;
  32. bool onKeyboard(const KeyboardEvent&) override;
  33. bool onMouse(const MouseEvent&) override;
  34. private:
  35. ImageType img;
  36. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseAboutWindow)
  37. };
  38. // --------------------------------------------------------------------------------------------------------------------
  39. template <class ImageType>
  40. class ImageBaseButton : public SubWidget,
  41. public ButtonEventHandler
  42. {
  43. public:
  44. class Callback
  45. {
  46. public:
  47. virtual ~Callback() {}
  48. virtual void imageButtonClicked(ImageBaseButton* imageButton, int button) = 0;
  49. };
  50. explicit ImageBaseButton(Widget* parentWidget, const ImageType& image);
  51. explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown);
  52. explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageHover, const ImageType& imageDown);
  53. ~ImageBaseButton() 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(ImageBaseButton)
  63. };
  64. // --------------------------------------------------------------------------------------------------------------------
  65. template <class ImageType>
  66. class ImageBaseKnob : public SubWidget,
  67. public KnobEventHandler
  68. {
  69. public:
  70. class Callback
  71. {
  72. public:
  73. virtual ~Callback() {}
  74. virtual void imageKnobDragStarted(ImageBaseKnob* imageKnob) = 0;
  75. virtual void imageKnobDragFinished(ImageBaseKnob* imageKnob) = 0;
  76. virtual void imageKnobValueChanged(ImageBaseKnob* imageKnob, float value) = 0;
  77. };
  78. explicit ImageBaseKnob(Widget* parentWidget, const ImageType& image, Orientation orientation = Vertical) noexcept;
  79. explicit ImageBaseKnob(const ImageBaseKnob& imageKnob);
  80. ImageBaseKnob& operator=(const ImageBaseKnob& imageKnob);
  81. ~ImageBaseKnob() override;
  82. void setCallback(Callback* callback) noexcept;
  83. void setImageLayerCount(uint count) noexcept;
  84. void setRotationAngle(int angle);
  85. protected:
  86. void onDisplay() override;
  87. bool onMouse(const MouseEvent&) override;
  88. bool onMotion(const MotionEvent&) override;
  89. bool onScroll(const ScrollEvent&) override;
  90. private:
  91. struct PrivateData;
  92. PrivateData* const pData;
  93. DISTRHO_LEAK_DETECTOR(ImageBaseKnob)
  94. };
  95. // --------------------------------------------------------------------------------------------------------------------
  96. // note set range and step before setting the value
  97. template <class ImageType>
  98. class ImageBaseSlider : public SubWidget
  99. {
  100. public:
  101. class Callback
  102. {
  103. public:
  104. virtual ~Callback() {}
  105. virtual void imageSliderDragStarted(ImageBaseSlider* imageSlider) = 0;
  106. virtual void imageSliderDragFinished(ImageBaseSlider* imageSlider) = 0;
  107. virtual void imageSliderValueChanged(ImageBaseSlider* imageSlider, float value) = 0;
  108. };
  109. explicit ImageBaseSlider(Widget* parentWidget, const ImageType& image) noexcept;
  110. ~ImageBaseSlider() override;
  111. float getValue() const noexcept;
  112. void setValue(float value, bool sendCallback = false) noexcept;
  113. void setDefault(float def) noexcept;
  114. void setStartPos(const Point<int>& startPos) noexcept;
  115. void setStartPos(int x, int y) noexcept;
  116. void setEndPos(const Point<int>& endPos) noexcept;
  117. void setEndPos(int x, int y) noexcept;
  118. void setInverted(bool inverted) noexcept;
  119. void setRange(float min, float max) noexcept;
  120. void setStep(float step) noexcept;
  121. void setCallback(Callback* callback) noexcept;
  122. protected:
  123. void onDisplay() override;
  124. bool onMouse(const MouseEvent&) override;
  125. bool onMotion(const MotionEvent&) override;
  126. private:
  127. struct PrivateData;
  128. PrivateData* const pData;
  129. // these should not be used
  130. void setAbsoluteX(int) const noexcept {}
  131. void setAbsoluteY(int) const noexcept {}
  132. void setAbsolutePos(int, int) const noexcept {}
  133. void setAbsolutePos(const Point<int>&) const noexcept {}
  134. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseSlider)
  135. };
  136. // --------------------------------------------------------------------------------------------------------------------
  137. template <class ImageType>
  138. class ImageBaseSwitch : public SubWidget
  139. {
  140. public:
  141. class Callback
  142. {
  143. public:
  144. virtual ~Callback() {}
  145. virtual void imageSwitchClicked(ImageBaseSwitch* imageSwitch, bool down) = 0;
  146. };
  147. explicit ImageBaseSwitch(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown) noexcept;
  148. explicit ImageBaseSwitch(const ImageBaseSwitch& imageSwitch) noexcept;
  149. ImageBaseSwitch& operator=(const ImageBaseSwitch& imageSwitch) noexcept;
  150. ~ImageBaseSwitch() override;
  151. bool isDown() const noexcept;
  152. void setDown(bool down) noexcept;
  153. void setCallback(Callback* callback) noexcept;
  154. protected:
  155. void onDisplay() override;
  156. bool onMouse(const MouseEvent&) override;
  157. private:
  158. struct PrivateData;
  159. PrivateData* const pData;
  160. DISTRHO_LEAK_DETECTOR(ImageBaseSwitch)
  161. };
  162. // --------------------------------------------------------------------------------------------------------------------
  163. END_NAMESPACE_DGL
  164. #endif // DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED