The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

130 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /**
  18. Represents the touch surface of a BLOCKS device.
  19. */
  20. class TouchSurface
  21. {
  22. public:
  23. TouchSurface (Block&);
  24. /** Destructor. */
  25. virtual ~TouchSurface();
  26. //==============================================================================
  27. struct Touch
  28. {
  29. /** A touch index, which will stay constant for each finger as it is tracked. */
  30. int index;
  31. /** The X position of this touch on the device, in logical units starting from 0 (left).
  32. See Block::getWidth() for the maximum X value on the device.
  33. */
  34. float x;
  35. /** An approximation of the velocity at which the X value is changing, measured in
  36. units/second. This is intended as a useful hint to help with gesture detection, but
  37. may be 0 if the device doesn't provide this data.
  38. */
  39. float xVelocity;
  40. /** The Y position of this touch on the device, in logical units starting from 0 (top).
  41. See Block::getHeight() to find the maximum Y on the device.
  42. */
  43. float y;
  44. /** An approximation of the velocity at which the Y value is changing, measured in
  45. units/second. This is intended as a useful hint to help with gesture detection, but
  46. may be 0 if the device doesn't provide this data.
  47. */
  48. float yVelocity;
  49. /** The current pressure of this touch, in the range 0.0 (no pressure) to 1.o (very hard). */
  50. float z;
  51. /** The rate at which pressure is currently changing, measured in units/second. This is
  52. intended as a useful hint to help with gesture detection, but may be 0 if the device
  53. doesn't provide this data.
  54. */
  55. float zVelocity;
  56. /** The timestamp of this event, in milliseconds since the device was booted. */
  57. Block::Timestamp eventTimestamp;
  58. /** True if this is the first event for this finger/index. */
  59. bool isTouchStart;
  60. /** True if this is the final event as this finger/index is lifted off. */
  61. bool isTouchEnd;
  62. /** The ID of the block that generated this touch. */
  63. Block::UID blockUID;
  64. /** The initial X position of the touchStart event corresponding to this finger/index. */
  65. float startX;
  66. /** The initial Y position of the touchStart event corresponding to this finger/index. */
  67. float startY;
  68. };
  69. //==============================================================================
  70. /** Forces a touch-off message for all active touches. */
  71. virtual void cancelAllActiveTouches() noexcept = 0;
  72. //==============================================================================
  73. /** Receives callbacks when a touch moves or changes pressure. */
  74. struct Listener
  75. {
  76. virtual ~Listener();
  77. virtual void touchChanged (TouchSurface&, const Touch&) = 0;
  78. };
  79. /** Testing feature: this allows you to inject touches onto a touch surface. */
  80. void callListenersTouchChanged (const TouchSurface::Touch& t)
  81. {
  82. listeners.call (&Listener::touchChanged, *this, t);
  83. }
  84. /** Adds a listener to be called when the surface is touched. */
  85. void addListener (Listener*);
  86. /** Removes a previously-registered listener. */
  87. void removeListener (Listener*);
  88. //==============================================================================
  89. /** The block that owns this touch surface. */
  90. Block& block;
  91. protected:
  92. //==============================================================================
  93. juce::ListenerList<Listener> listeners;
  94. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TouchSurface)
  95. };