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.

258 lines
8.7KB

  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. /**
  24. DGL Image About Window class.
  25. This is a Window attached (transient) to another Window that simply shows an Image as its content.
  26. It is typically used for "about this project" style pop-up Windows.
  27. Pressing 'Esc' or clicking anywhere on the window will automatically close it.
  28. @see CairoImageAboutWindow, OpenGLImageAboutWindow, Window::runAsModal(bool)
  29. */
  30. template <class ImageType>
  31. class ImageBaseAboutWindow : public StandaloneWindow
  32. {
  33. public:
  34. /**
  35. Constructor taking an existing Window as the parent transient window and an optional image.
  36. If @a image is valid, the about window size will match the image size.
  37. */
  38. explicit ImageBaseAboutWindow(Window& transientParentWindow, const ImageType& image = ImageType());
  39. /**
  40. Constructor taking a top-level-widget's Window as the parent transient window and an optional image.
  41. If @a image is valid, the about window size will match the image size.
  42. */
  43. explicit ImageBaseAboutWindow(TopLevelWidget* topLevelWidget, const ImageType& image = ImageType());
  44. /**
  45. Set a new image to use as background for this window.
  46. Window size will adjust to match the image size.
  47. */
  48. void setImage(const ImageType& image);
  49. protected:
  50. void onDisplay() override;
  51. bool onKeyboard(const KeyboardEvent&) override;
  52. bool onMouse(const MouseEvent&) override;
  53. private:
  54. ImageType img;
  55. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseAboutWindow)
  56. };
  57. // --------------------------------------------------------------------------------------------------------------------
  58. /**
  59. DGL Image Button class.
  60. This is a typical button, where the drawing comes from a pregenerated set of images.
  61. The button can be under "normal", "hover" and "down" states, with one separate image possible for each.
  62. The event logic for this button comes from the ButtonEventHandler class.
  63. @see CairoImageButton, OpenGLImageButton
  64. */
  65. template <class ImageType>
  66. class ImageBaseButton : public SubWidget,
  67. public ButtonEventHandler
  68. {
  69. public:
  70. class Callback
  71. {
  72. public:
  73. virtual ~Callback() {}
  74. virtual void imageButtonClicked(ImageBaseButton* imageButton, int button) = 0;
  75. };
  76. explicit ImageBaseButton(Widget* parentWidget, const ImageType& image);
  77. explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown);
  78. explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageHover, const ImageType& imageDown);
  79. ~ImageBaseButton() override;
  80. void setCallback(Callback* callback) noexcept;
  81. protected:
  82. void onDisplay() override;
  83. bool onMouse(const MouseEvent&) override;
  84. bool onMotion(const MotionEvent&) override;
  85. private:
  86. struct PrivateData;
  87. PrivateData* const pData;
  88. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseButton)
  89. };
  90. // --------------------------------------------------------------------------------------------------------------------
  91. /**
  92. DGL Image Knob class.
  93. This is a typical knob/dial, where the drawing comes from a pregenerated image "filmstrip".
  94. The knob's "filmstrip" image can be either horizontal or vertical,
  95. with the number of steps automatically based on the largest value (ie, horizontal if width>height, vertical if height>width).
  96. There are no different images for "hover" or "down" states.
  97. The event logic for this knob comes from the KnobEventHandler class.
  98. @see CairoImageKnob, OpenGLImageKnob
  99. */
  100. template <class ImageType>
  101. class ImageBaseKnob : public SubWidget,
  102. public KnobEventHandler
  103. {
  104. public:
  105. class Callback
  106. {
  107. public:
  108. virtual ~Callback() {}
  109. virtual void imageKnobDragStarted(ImageBaseKnob* imageKnob) = 0;
  110. virtual void imageKnobDragFinished(ImageBaseKnob* imageKnob) = 0;
  111. virtual void imageKnobValueChanged(ImageBaseKnob* imageKnob, float value) = 0;
  112. };
  113. explicit ImageBaseKnob(Widget* parentWidget, const ImageType& image, Orientation orientation = Vertical) noexcept;
  114. explicit ImageBaseKnob(const ImageBaseKnob& imageKnob);
  115. ImageBaseKnob& operator=(const ImageBaseKnob& imageKnob);
  116. ~ImageBaseKnob() override;
  117. void setCallback(Callback* callback) noexcept;
  118. void setImageLayerCount(uint count) noexcept;
  119. void setRotationAngle(int angle);
  120. bool setValue(float value, bool sendCallback = false) noexcept override;
  121. protected:
  122. void onDisplay() override;
  123. bool onMouse(const MouseEvent&) override;
  124. bool onMotion(const MotionEvent&) override;
  125. bool onScroll(const ScrollEvent&) override;
  126. private:
  127. struct PrivateData;
  128. PrivateData* const pData;
  129. DISTRHO_LEAK_DETECTOR(ImageBaseKnob)
  130. };
  131. // --------------------------------------------------------------------------------------------------------------------
  132. // note set range and step before setting the value
  133. template <class ImageType>
  134. class ImageBaseSlider : public SubWidget
  135. {
  136. public:
  137. class Callback
  138. {
  139. public:
  140. virtual ~Callback() {}
  141. virtual void imageSliderDragStarted(ImageBaseSlider* imageSlider) = 0;
  142. virtual void imageSliderDragFinished(ImageBaseSlider* imageSlider) = 0;
  143. virtual void imageSliderValueChanged(ImageBaseSlider* imageSlider, float value) = 0;
  144. };
  145. explicit ImageBaseSlider(Widget* parentWidget, const ImageType& image) noexcept;
  146. ~ImageBaseSlider() override;
  147. float getValue() const noexcept;
  148. void setValue(float value, bool sendCallback = false) noexcept;
  149. void setDefault(float def) noexcept;
  150. void setStartPos(const Point<int>& startPos) noexcept;
  151. void setStartPos(int x, int y) noexcept;
  152. void setEndPos(const Point<int>& endPos) noexcept;
  153. void setEndPos(int x, int y) noexcept;
  154. void setInverted(bool inverted) noexcept;
  155. void setRange(float min, float max) noexcept;
  156. void setStep(float step) noexcept;
  157. void setCallback(Callback* callback) noexcept;
  158. protected:
  159. void onDisplay() override;
  160. bool onMouse(const MouseEvent&) override;
  161. bool onMotion(const MotionEvent&) override;
  162. private:
  163. struct PrivateData;
  164. PrivateData* const pData;
  165. // these should not be used
  166. void setAbsoluteX(int) const noexcept {}
  167. void setAbsoluteY(int) const noexcept {}
  168. void setAbsolutePos(int, int) const noexcept {}
  169. void setAbsolutePos(const Point<int>&) const noexcept {}
  170. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseSlider)
  171. };
  172. // --------------------------------------------------------------------------------------------------------------------
  173. template <class ImageType>
  174. class ImageBaseSwitch : public SubWidget
  175. {
  176. public:
  177. class Callback
  178. {
  179. public:
  180. virtual ~Callback() {}
  181. virtual void imageSwitchClicked(ImageBaseSwitch* imageSwitch, bool down) = 0;
  182. };
  183. explicit ImageBaseSwitch(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown) noexcept;
  184. explicit ImageBaseSwitch(const ImageBaseSwitch& imageSwitch) noexcept;
  185. ImageBaseSwitch& operator=(const ImageBaseSwitch& imageSwitch) noexcept;
  186. ~ImageBaseSwitch() override;
  187. bool isDown() const noexcept;
  188. void setDown(bool down) noexcept;
  189. void setCallback(Callback* callback) noexcept;
  190. protected:
  191. void onDisplay() override;
  192. bool onMouse(const MouseEvent&) override;
  193. private:
  194. struct PrivateData;
  195. PrivateData* const pData;
  196. DISTRHO_LEAK_DETECTOR(ImageBaseSwitch)
  197. };
  198. // --------------------------------------------------------------------------------------------------------------------
  199. END_NAMESPACE_DGL
  200. #endif // DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED