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.

187 lines
8.1KB

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