LMMS
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:
38
40 : info { image, hotSpot },
41 handle (info),
44 {
45 // your hotspot needs to be within the bounds of the image!
46 jassert (image.getScaledBounds().toNearestInt().contains (hotSpot));
47 }
48
49 static std::shared_ptr<SharedCursorHandle> createStandard (const MouseCursor::StandardCursorType type)
50 {
52 return nullptr;
53
54 static SpinLock mutex;
55 static std::array<std::weak_ptr<SharedCursorHandle>, MouseCursor::NumStandardCursorTypes> cursors;
56
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
70 {
71 return type == standardType && standard;
72 }
73
76
77private:
81 const bool standard;
82
84};
85
86//==============================================================================
88
93
94MouseCursor::MouseCursor (const Image& image, int hotSpotX, int hotSpotY)
95 : MouseCursor (ScaledImage (image), { hotSpotX, hotSpotY })
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
113MouseCursor& MouseCursor::operator= (const MouseCursor&) = default;
114
116
117MouseCursor& MouseCursor::operator= (MouseCursor&&) noexcept = default;
118
119bool MouseCursor::operator== (const MouseCursor& other) const noexcept
120{
121 return getHandle() == other.getHandle();
122}
123
124bool MouseCursor::operator== (StandardCursorType type) const noexcept
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
134{
135 Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
136}
137
139{
140 Desktop::getInstance().getMainMouseSource().revealCursor();
141}
142
144{
145 return cursorHandle != nullptr ? cursorHandle->getHandle() : nullptr;
146}
147
152
153} // namespace juce
pthread_mutex_t mutex
Definition Controller.C:6
#define noexcept
Definition DistrhoDefines.h:72
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Definition juce_ComponentPeer.h:44
static Desktop &JUCE_CALLTYPE getInstance()
Definition juce_Desktop.cpp:50
Definition juce_Image.h:58
Definition juce_linux_Windowing.cpp:707
static void showInWindow(PlatformSpecificHandle *handle, ComponentPeer *peer)
Definition juce_linux_Windowing.cpp:721
Definition juce_MouseCursor.cpp:30
bool isStandardType(MouseCursor::StandardCursorType type) const noexcept
Definition juce_MouseCursor.cpp:69
PlatformSpecificHandle handle
Definition juce_MouseCursor.cpp:79
const MouseCursor::StandardCursorType standardType
Definition juce_MouseCursor.cpp:80
SharedCursorHandle(const MouseCursor::StandardCursorType type)
Definition juce_MouseCursor.cpp:32
CustomMouseCursorInfo info
Definition juce_MouseCursor.cpp:78
static std::shared_ptr< SharedCursorHandle > createStandard(const MouseCursor::StandardCursorType type)
Definition juce_MouseCursor.cpp:49
SharedCursorHandle(const ScaledImage &image, Point< int > hotSpot)
Definition juce_MouseCursor.cpp:39
MouseCursor::StandardCursorType getType() const noexcept
Definition juce_MouseCursor.cpp:75
PlatformSpecificHandle * getHandle() noexcept
Definition juce_MouseCursor.cpp:74
const bool standard
Definition juce_MouseCursor.cpp:81
Definition juce_MouseCursor.h:39
void showInWindow(ComponentPeer *) const
Definition juce_MouseCursor.cpp:148
static void hideWaitCursor()
Definition juce_MouseCursor.cpp:138
std::shared_ptr< SharedCursorHandle > cursorHandle
Definition juce_MouseCursor.h:179
static void showWaitCursor()
Definition juce_MouseCursor.cpp:133
MouseCursor() noexcept
StandardCursorType
Definition juce_MouseCursor.h:44
@ NumStandardCursorTypes
Definition juce_MouseCursor.h:72
@ NormalCursor
Definition juce_MouseCursor.h:48
@ WaitCursor
Definition juce_MouseCursor.h:50
PlatformSpecificHandle * getHandle() const noexcept
Definition juce_MouseCursor.cpp:143
Definition juce_Point.h:42
Definition juce_ScaledImage.h:45
Definition juce_SpinLock.h:42
GenericScopedLock< SpinLock > ScopedLockType
Definition juce_SpinLock.h:73
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition carla_juce.cpp:31
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
@ image
Definition juce_AccessibilityRole.h:42
Definition juce_Uuid.h:141
#define true
Definition ordinals.h:82
#define false
Definition ordinals.h:83
Definition juce_gui_basics.cpp:128
#define const
Definition zconf.h:137