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.

juce_PointerState.h 4.4KB

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