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.

103 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. #ifndef DOXYGEN
  16. class PointerState
  17. {
  18. auto tie() const noexcept
  19. {
  20. return std::tie (position, pressure, orientation, rotation, tiltX, tiltY);
  21. }
  22. public:
  23. PointerState() = default;
  24. bool operator== (const PointerState& other) const noexcept { return tie() == other.tie(); }
  25. bool operator!= (const PointerState& other) const noexcept { return tie() != other.tie(); }
  26. JUCE_NODISCARD PointerState withPositionOffset (Point<float> x) const noexcept { return with (&PointerState::position, position + x); }
  27. JUCE_NODISCARD PointerState withPosition (Point<float> x) const noexcept { return with (&PointerState::position, x); }
  28. JUCE_NODISCARD PointerState withPressure (float x) const noexcept { return with (&PointerState::pressure, x); }
  29. JUCE_NODISCARD PointerState withOrientation (float x) const noexcept { return with (&PointerState::orientation, x); }
  30. JUCE_NODISCARD PointerState withRotation (float x) const noexcept { return with (&PointerState::rotation, x); }
  31. JUCE_NODISCARD PointerState withTiltX (float x) const noexcept { return with (&PointerState::tiltX, x); }
  32. JUCE_NODISCARD PointerState withTiltY (float x) const noexcept { return with (&PointerState::tiltY, x); }
  33. Point<float> position;
  34. float pressure = MouseInputSource::defaultPressure;
  35. float orientation = MouseInputSource::defaultOrientation;
  36. float rotation = MouseInputSource::defaultRotation;
  37. float tiltX = MouseInputSource::defaultTiltX;
  38. float tiltY = MouseInputSource::defaultTiltY;
  39. bool isPressureValid() const noexcept { return 0.0f <= pressure && pressure <= 1.0f; }
  40. bool isOrientationValid() const noexcept { return 0.0f <= orientation && orientation <= MathConstants<float>::twoPi; }
  41. bool isRotationValid() const noexcept { return 0.0f <= rotation && rotation <= MathConstants<float>::twoPi; }
  42. bool isTiltValid (bool isX) const noexcept
  43. {
  44. return isX ? (-1.0f <= tiltX && tiltX <= 1.0f)
  45. : (-1.0f <= tiltY && tiltY <= 1.0f);
  46. }
  47. private:
  48. template <typename Value>
  49. PointerState with (Value PointerState::* member, Value item) const
  50. {
  51. auto copy = *this;
  52. copy.*member = std::move (item);
  53. return copy;
  54. }
  55. };
  56. inline auto makeMouseEvent (MouseInputSource source,
  57. const PointerState& ps,
  58. ModifierKeys modifiers,
  59. Component* eventComponent,
  60. Component* originator,
  61. Time eventTime,
  62. Point<float> mouseDownPos,
  63. Time mouseDownTime,
  64. int numberOfClicks,
  65. bool mouseWasDragged)
  66. {
  67. return MouseEvent (source,
  68. ps.position,
  69. modifiers,
  70. ps.pressure,
  71. ps.orientation,
  72. ps.rotation,
  73. ps.tiltX,
  74. ps.tiltY,
  75. eventComponent,
  76. originator,
  77. eventTime,
  78. mouseDownPos,
  79. mouseDownTime,
  80. numberOfClicks,
  81. mouseWasDragged);
  82. }
  83. #endif
  84. } // namespace juce