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.

104 lines
3.0KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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_KNOB_HPP_INCLUDED
  17. #define DGL_IMAGE_KNOB_HPP_INCLUDED
  18. #include "Image.hpp"
  19. #include "Widget.hpp"
  20. START_NAMESPACE_DGL
  21. // -----------------------------------------------------------------------
  22. class ImageKnob : public Widget
  23. {
  24. public:
  25. enum Orientation {
  26. Horizontal,
  27. Vertical
  28. };
  29. class Callback
  30. {
  31. public:
  32. virtual ~Callback() {}
  33. virtual void imageKnobDragStarted(ImageKnob* imageKnob) = 0;
  34. virtual void imageKnobDragFinished(ImageKnob* imageKnob) = 0;
  35. virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0;
  36. };
  37. explicit ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical) noexcept;
  38. explicit ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical) noexcept;
  39. explicit ImageKnob(const ImageKnob& imageKnob);
  40. ImageKnob& operator=(const ImageKnob& imageKnob);
  41. ~ImageKnob() override;
  42. float getValue() const noexcept;
  43. void setDefault(float def) noexcept;
  44. void setRange(float min, float max) noexcept;
  45. void setStep(float step) noexcept;
  46. void setValue(float value, bool sendCallback = false) noexcept;
  47. void setUsingLogScale(bool yesNo) noexcept;
  48. void setCallback(Callback* callback) noexcept;
  49. void setOrientation(Orientation orientation) noexcept;
  50. void setRotationAngle(int angle);
  51. protected:
  52. void onDisplay() override;
  53. bool onMouse(const MouseEvent&) override;
  54. bool onMotion(const MotionEvent&) override;
  55. bool onScroll(const ScrollEvent&) override;
  56. private:
  57. Image fImage;
  58. float fMinimum;
  59. float fMaximum;
  60. float fStep;
  61. float fValue;
  62. float fValueDef;
  63. float fValueTmp;
  64. bool fUsingDefault;
  65. bool fUsingLog;
  66. Orientation fOrientation;
  67. int fRotationAngle;
  68. bool fDragging;
  69. int fLastX;
  70. int fLastY;
  71. Callback* fCallback;
  72. bool fIsImgVertical;
  73. uint fImgLayerSize;
  74. uint fImgLayerCount;
  75. bool fIsReady;
  76. GLuint fTextureId;
  77. float _logscale(float value) const;
  78. float _invlogscale(float value) const;
  79. DISTRHO_LEAK_DETECTOR(ImageKnob)
  80. };
  81. // -----------------------------------------------------------------------
  82. END_NAMESPACE_DGL
  83. #endif // DGL_IMAGE_KNOB_HPP_INCLUDED