JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_MouseCursor.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30{
31public:
33 : handle (type),
34 standardType (type),
35 standard (true)
36 {
37 }
38
40 : info { image, hotSpot },
41 handle (info),
42 standardType (MouseCursor::NormalCursor),
43 standard (false)
44 {
45 // your hotspot needs to be within the bounds of the image!
46 jassert (image.getScaledBounds().toNearestInt().contains (hotSpot));
47 }
48
50 {
51 if (! isPositiveAndBelow (type, MouseCursor::NumStandardCursorTypes))
52 return nullptr;
53
54 static SpinLock mutex;
55 static std::array<std::weak_ptr<SharedCursorHandle>, MouseCursor::NumStandardCursorTypes> cursors;
56
57 const SpinLock::ScopedLockType sl (mutex);
58
59 auto& weak = cursors[type];
60
61 if (auto strong = weak.lock())
62 return strong;
63
64 auto strong = std::make_shared<SharedCursorHandle> (type);
65 weak = strong;
66 return strong;
67 }
68
69 bool isStandardType (MouseCursor::StandardCursorType type) const noexcept
70 {
71 return type == standardType && standard;
72 }
73
74 PlatformSpecificHandle* getHandle() noexcept { return &handle; }
75 MouseCursor::StandardCursorType getType() const noexcept { return standardType; }
76
77private:
80 const MouseCursor::StandardCursorType standardType;
81 const bool standard;
82
84};
85
86//==============================================================================
88
90 : cursorHandle (type != MouseCursor::NormalCursor ? SharedCursorHandle::createStandard (type) : nullptr)
91{
92}
93
96{
97}
98
99MouseCursor::MouseCursor (const Image& image, int hotSpotX, int hotSpotY, float scaleFactor)
100 : MouseCursor (ScaledImage (image, scaleFactor), { hotSpotX, hotSpotY })
101{
102}
103
105 : cursorHandle (std::make_shared<SharedCursorHandle> (image, hotSpot))
106{
107}
108
109MouseCursor::MouseCursor (const MouseCursor&) = default;
110
111MouseCursor::~MouseCursor() = default;
112
114
116
118
120{
121 return getHandle() == other.getHandle();
122}
123
125{
126 return cursorHandle != nullptr ? cursorHandle->isStandardType (type)
127 : (type == NormalCursor);
128}
129
130bool MouseCursor::operator!= (const MouseCursor& other) const noexcept { return ! operator== (other); }
131bool MouseCursor::operator!= (StandardCursorType type) const noexcept { return ! operator== (type); }
132
137
142
143MouseCursor::PlatformSpecificHandle* MouseCursor::getHandle() const noexcept
144{
145 return cursorHandle != nullptr ? cursorHandle->getHandle() : nullptr;
146}
147
148void MouseCursor::showInWindow (ComponentPeer* peer) const
149{
150 PlatformSpecificHandle::showInWindow (getHandle(), peer);
151}
152
153} // namespace juce
MouseInputSource getMainMouseSource() const noexcept
Returns the main mouse input device that the system is using.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
Automatically locks and unlocks a mutex object.
Holds a fixed-size bitmap.
Definition juce_Image.h:58
Represents a mouse cursor image.
bool operator!=(const MouseCursor &) const noexcept
Checks whether two mouse cursors are the same.
static void hideWaitCursor()
If showWaitCursor has been called, this will return the mouse to its normal state.
bool operator==(const MouseCursor &) const noexcept
Checks whether two mouse cursors are the same.
~MouseCursor()
Destructor.
static void showWaitCursor()
Makes the system show its default 'busy' cursor.
MouseCursor() noexcept
Creates the standard arrow cursor.
StandardCursorType
The set of available standard mouse cursors.
@ NormalCursor
The standard arrow cursor.
@ WaitCursor
The normal hourglass or spinning-beachball 'busy' cursor.
MouseCursor & operator=(const MouseCursor &)
Copies this cursor from another object.
void revealCursor()
Un-hides the mouse cursor if it was hidden by hideCursor().
void showMouseCursor(const MouseCursor &cursor)
Changes the mouse cursor, (if there is one).
A pair of (x, y) coordinates.
Definition juce_Point.h:42
An image that will be resampled before it is drawn.
A simple spin-lock class that can be used as a simple, low-overhead mutex for uncontended situations.
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.