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.

175 lines
5.2KB

  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_EVENT_HANDLERS_HPP_INCLUDED
  17. #define DGL_EVENT_HANDLERS_HPP_INCLUDED
  18. #include "Widget.hpp"
  19. START_NAMESPACE_DGL
  20. /* NOTE none of these classes get assigned to a widget automatically
  21. Manual plugging into Widget events is needed, like so:
  22. ```
  23. bool onMouse(const MouseEvent& ev) override
  24. {
  25. return ButtonEventHandler::mouseEvent(ev);
  26. }
  27. ```
  28. */
  29. // --------------------------------------------------------------------------------------------------------------------
  30. class ButtonEventHandler
  31. {
  32. public:
  33. enum State {
  34. kButtonStateDefault = 0x0,
  35. kButtonStateHover = 0x1,
  36. kButtonStateActive = 0x2,
  37. kButtonStateActiveHover = kButtonStateActive|kButtonStateHover
  38. };
  39. class Callback
  40. {
  41. public:
  42. virtual ~Callback() {}
  43. virtual void buttonClicked(SubWidget* widget, int button) = 0;
  44. };
  45. explicit ButtonEventHandler(SubWidget* self);
  46. virtual ~ButtonEventHandler();
  47. bool isActive() noexcept;
  48. void setActive(bool active, bool sendCallback) noexcept;
  49. bool isChecked() const noexcept;
  50. void setChecked(bool checked, bool sendCallback) noexcept;
  51. bool isCheckable() const noexcept;
  52. void setCheckable(bool checkable) noexcept;
  53. Point<double> getLastClickPosition() const noexcept;
  54. Point<double> getLastMotionPosition() const noexcept;
  55. void setCallback(Callback* callback) noexcept;
  56. bool mouseEvent(const Widget::MouseEvent& ev);
  57. bool motionEvent(const Widget::MotionEvent& ev);
  58. protected:
  59. State getState() const noexcept;
  60. void clearState() noexcept;
  61. virtual void stateChanged(State state, State oldState);
  62. void setInternalCallback(Callback* callback) noexcept;
  63. void triggerUserCallback(SubWidget* widget, int button);
  64. private:
  65. struct PrivateData;
  66. PrivateData* const pData;
  67. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ButtonEventHandler)
  68. };
  69. // --------------------------------------------------------------------------------------------------------------------
  70. class KnobEventHandler
  71. {
  72. public:
  73. enum Orientation {
  74. Horizontal,
  75. Vertical
  76. };
  77. // NOTE hover not implemented yet
  78. enum State {
  79. kKnobStateDefault = 0x0,
  80. kKnobStateHover = 0x1,
  81. kKnobStateDragging = 0x2,
  82. kKnobStateDraggingHover = kKnobStateDragging|kKnobStateHover
  83. };
  84. class Callback
  85. {
  86. public:
  87. virtual ~Callback() {}
  88. virtual void knobDragStarted(SubWidget* widget) = 0;
  89. virtual void knobDragFinished(SubWidget* widget) = 0;
  90. virtual void knobValueChanged(SubWidget* widget, float value) = 0;
  91. };
  92. explicit KnobEventHandler(SubWidget* self);
  93. explicit KnobEventHandler(SubWidget* self, const KnobEventHandler& other);
  94. KnobEventHandler& operator=(const KnobEventHandler& other);
  95. virtual ~KnobEventHandler();
  96. // returns raw value, is assumed to be scaled if using log
  97. float getValue() const noexcept;
  98. // NOTE: value is assumed to be scaled if using log
  99. virtual bool setValue(float value, bool sendCallback = false) noexcept;
  100. // returns 0-1 ranged value, already with log scale as needed
  101. float getNormalizedValue() const noexcept;
  102. // NOTE: value is assumed to be scaled if using log
  103. void setDefault(float def) noexcept;
  104. // NOTE: value is assumed to be scaled if using log
  105. void setRange(float min, float max) noexcept;
  106. void setStep(float step) noexcept;
  107. void setUsingLogScale(bool yesNo) noexcept;
  108. Orientation getOrientation() const noexcept;
  109. void setOrientation(const Orientation orientation) noexcept;
  110. void setCallback(Callback* callback) noexcept;
  111. bool mouseEvent(const Widget::MouseEvent& ev);
  112. bool motionEvent(const Widget::MotionEvent& ev);
  113. bool scrollEvent(const Widget::ScrollEvent& ev);
  114. protected:
  115. State getState() const noexcept;
  116. private:
  117. struct PrivateData;
  118. PrivateData* const pData;
  119. /* not for use */
  120. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  121. KnobEventHandler(KnobEventHandler& other) = delete;
  122. KnobEventHandler(const KnobEventHandler& other) = delete;
  123. #else
  124. KnobEventHandler(KnobEventHandler& other);
  125. KnobEventHandler(const KnobEventHandler& other);
  126. #endif
  127. DISTRHO_LEAK_DETECTOR(KnobEventHandler)
  128. };
  129. // --------------------------------------------------------------------------------------------------------------------
  130. END_NAMESPACE_DGL
  131. #endif // DGL_EVENT_HANDLERS_HPP_INCLUDED