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.

155 lines
4.6KB

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