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.

183 lines
7.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. Represents a mouse cursor image.
  24. This object can either be used to represent one of the standard mouse
  25. cursor shapes, or a custom one generated from an image.
  26. */
  27. class JUCE_API MouseCursor
  28. {
  29. public:
  30. //==============================================================================
  31. /** The set of available standard mouse cursors. */
  32. enum StandardCursorType
  33. {
  34. ParentCursor = 0, /**< Indicates that the component's parent's cursor should be used. */
  35. NoCursor, /**< An invisible cursor. */
  36. NormalCursor, /**< The stardard arrow cursor. */
  37. WaitCursor, /**< The normal hourglass or spinning-beachball 'busy' cursor. */
  38. IBeamCursor, /**< A vertical I-beam for positioning within text. */
  39. CrosshairCursor, /**< A pair of crosshairs. */
  40. CopyingCursor, /**< The normal arrow cursor, but with a "+" on it to indicate
  41. that you're dragging a copy of something. */
  42. PointingHandCursor, /**< A hand with a pointing finger, for clicking on web-links. */
  43. DraggingHandCursor, /**< An open flat hand for dragging heavy objects around. */
  44. LeftRightResizeCursor, /**< An arrow pointing left and right. */
  45. UpDownResizeCursor, /**< an arrow pointing up and down. */
  46. UpDownLeftRightResizeCursor, /**< An arrow pointing up, down, left and right. */
  47. TopEdgeResizeCursor, /**< A platform-specific cursor for resizing the top-edge of a window. */
  48. BottomEdgeResizeCursor, /**< A platform-specific cursor for resizing the bottom-edge of a window. */
  49. LeftEdgeResizeCursor, /**< A platform-specific cursor for resizing the left-edge of a window. */
  50. RightEdgeResizeCursor, /**< A platform-specific cursor for resizing the right-edge of a window. */
  51. TopLeftCornerResizeCursor, /**< A platform-specific cursor for resizing the top-left-corner of a window. */
  52. TopRightCornerResizeCursor, /**< A platform-specific cursor for resizing the top-right-corner of a window. */
  53. BottomLeftCornerResizeCursor, /**< A platform-specific cursor for resizing the bottom-left-corner of a window. */
  54. BottomRightCornerResizeCursor, /**< A platform-specific cursor for resizing the bottom-right-corner of a window. */
  55. NumStandardCursorTypes
  56. };
  57. //==============================================================================
  58. /** Creates the standard arrow cursor. */
  59. MouseCursor() noexcept;
  60. /** Creates one of the standard mouse cursor */
  61. MouseCursor (StandardCursorType);
  62. /** Creates a custom cursor from an image.
  63. @param image the image to use for the cursor - if this is bigger than the
  64. system can manage, it might get scaled down first, and might
  65. also have to be turned to black-and-white if it can't do colour
  66. cursors.
  67. @param hotSpotX the x position of the cursor's hotspot within the image
  68. @param hotSpotY the y position of the cursor's hotspot within the image
  69. */
  70. MouseCursor (const Image& image, int hotSpotX, int hotSpotY);
  71. /** Creates a custom cursor from an image.
  72. @param image the image to use for the cursor - if this is bigger than the
  73. system can manage, it might get scaled down first, and might
  74. also have to be turned to black-and-white if it can't do colour
  75. cursors.
  76. @param hotSpotX the x position of the cursor's hotspot within the image
  77. @param hotSpotY the y position of the cursor's hotspot within the image
  78. @param scaleFactor the factor by which this image is larger than the target
  79. screen size of the cursor.
  80. */
  81. MouseCursor (const Image& image, int hotSpotX, int hotSpotY, float scaleFactor);
  82. //==============================================================================
  83. /** Creates a copy of another cursor object. */
  84. MouseCursor (const MouseCursor&);
  85. /** Copies this cursor from another object. */
  86. MouseCursor& operator= (const MouseCursor&);
  87. /** Destructor. */
  88. ~MouseCursor();
  89. /** Move constructor */
  90. MouseCursor (MouseCursor&&) noexcept;
  91. /** Move assignment operator */
  92. MouseCursor& operator= (MouseCursor&&) noexcept;
  93. /** Checks whether two mouse cursors are the same.
  94. For custom cursors, two cursors created from the same image won't be
  95. recognised as the same, only MouseCursor objects that have been
  96. copied from the same object.
  97. */
  98. bool operator== (const MouseCursor&) const noexcept;
  99. /** Checks whether two mouse cursors are the same.
  100. For custom cursors, two cursors created from the same image won't be
  101. recognised as the same, only MouseCursor objects that have been
  102. copied from the same object.
  103. */
  104. bool operator!= (const MouseCursor&) const noexcept;
  105. /** Checks whether this cursor is of the standard type mentioned. */
  106. bool operator== (StandardCursorType type) const noexcept;
  107. /** Checks whether this cursor is of the standard type mentioned. */
  108. bool operator!= (StandardCursorType type) const noexcept;
  109. //==============================================================================
  110. /** Makes the system show its default 'busy' cursor.
  111. This will turn the system cursor to an hourglass or spinning beachball
  112. until the next time the mouse is moved, or hideWaitCursor() is called.
  113. This is handy if the message loop is about to block for a couple of
  114. seconds while busy and you want to give the user feedback about this.
  115. */
  116. static void showWaitCursor();
  117. /** If showWaitCursor has been called, this will return the mouse to its
  118. normal state.
  119. This will look at what component is under the mouse, and update the
  120. cursor to be the correct one for that component.
  121. @see showWaitCursor
  122. */
  123. static void hideWaitCursor();
  124. private:
  125. //==============================================================================
  126. class SharedCursorHandle;
  127. friend class SharedCursorHandle;
  128. SharedCursorHandle* cursorHandle;
  129. friend class MouseInputSourceInternal;
  130. void showInWindow (ComponentPeer* window) const;
  131. void showInAllWindows() const;
  132. void* getHandle() const noexcept;
  133. static void* createStandardMouseCursor (MouseCursor::StandardCursorType type);
  134. static void deleteMouseCursor (void* cursorHandle, bool isStandard);
  135. JUCE_LEAK_DETECTOR (MouseCursor)
  136. };
  137. } // namespace juce