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_MouseCursor.h 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. //==============================================================================
  21. /**
  22. Represents a mouse cursor image.
  23. This object can either be used to represent one of the standard mouse
  24. cursor shapes, or a custom one generated from an image.
  25. @tags{GUI}
  26. */
  27. class JUCE_API MouseCursor final
  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 standard 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. /** Creates a custom cursor from an image.
  83. @param image the image to use for the cursor - if this is bigger than the
  84. system can manage, it might get scaled down first, and might
  85. also have to be turned to black-and-white if it can't do colour
  86. cursors.
  87. @param hotSpot the position of the cursor's hotspot within the image
  88. */
  89. MouseCursor (const ScaledImage& image, Point<int> hotSpot);
  90. //==============================================================================
  91. /** Creates a copy of another cursor object. */
  92. MouseCursor (const MouseCursor&);
  93. /** Copies this cursor from another object. */
  94. MouseCursor& operator= (const MouseCursor&);
  95. /** Destructor. */
  96. ~MouseCursor();
  97. /** Move constructor */
  98. MouseCursor (MouseCursor&&) noexcept;
  99. /** Move assignment operator */
  100. MouseCursor& operator= (MouseCursor&&) noexcept;
  101. /** Checks whether two mouse cursors are the same.
  102. For custom cursors, two cursors created from the same image won't be
  103. recognised as the same, only MouseCursor objects that have been
  104. copied from the same object.
  105. */
  106. bool operator== (const MouseCursor&) const noexcept;
  107. /** Checks whether two mouse cursors are the same.
  108. For custom cursors, two cursors created from the same image won't be
  109. recognised as the same, only MouseCursor objects that have been
  110. copied from the same object.
  111. */
  112. bool operator!= (const MouseCursor&) const noexcept;
  113. /** Checks whether this cursor is of the standard type mentioned. */
  114. bool operator== (StandardCursorType type) const noexcept;
  115. /** Checks whether this cursor is of the standard type mentioned. */
  116. bool operator!= (StandardCursorType type) const noexcept;
  117. //==============================================================================
  118. /** Makes the system show its default 'busy' cursor.
  119. This will turn the system cursor to an hourglass or spinning beachball
  120. until the next time the mouse is moved, or hideWaitCursor() is called.
  121. This is handy if the message loop is about to block for a couple of
  122. seconds while busy and you want to give the user feedback about this.
  123. */
  124. static void showWaitCursor();
  125. /** If showWaitCursor has been called, this will return the mouse to its
  126. normal state.
  127. This will look at what component is under the mouse, and update the
  128. cursor to be the correct one for that component.
  129. @see showWaitCursor
  130. */
  131. static void hideWaitCursor();
  132. private:
  133. //==============================================================================
  134. class SharedCursorHandle;
  135. std::shared_ptr<SharedCursorHandle> cursorHandle;
  136. class PlatformSpecificHandle;
  137. friend class MouseInputSourceInternal;
  138. void showInWindow (ComponentPeer*) const;
  139. PlatformSpecificHandle* getHandle() const noexcept;
  140. JUCE_LEAK_DETECTOR (MouseCursor)
  141. };
  142. } // namespace juce