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_MouseInputSourceList.h
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::detail
27{
28
30{
31public:
33 {
34 #if JUCE_ANDROID || JUCE_IOS
35 auto mainMouseInputType = MouseInputSource::InputSourceType::touch;
36 #else
37 auto mainMouseInputType = MouseInputSource::InputSourceType::mouse;
38 #endif
39
40 addSource (0, mainMouseInputType);
41 }
42
43 MouseInputSource* addSource (int index, MouseInputSource::InputSourceType type)
44 {
45 auto* s = new MouseInputSourceImpl (index, type);
46 sources.add (s);
47 sourceArray.add (MouseInputSource (s));
48
49 return &sourceArray.getReference (sourceArray.size() - 1);
50 }
51
52 MouseInputSource* getMouseSource (int index) noexcept
53 {
54 return isPositiveAndBelow (index, sourceArray.size()) ? &sourceArray.getReference (index)
55 : nullptr;
56 }
57
58 MouseInputSource* getOrCreateMouseInputSource (MouseInputSource::InputSourceType type, int touchIndex = 0)
59 {
60 if (type == MouseInputSource::InputSourceType::mouse
61 || type == MouseInputSource::InputSourceType::pen)
62 {
63 for (auto& m : sourceArray)
64 if (type == m.getType())
65 return &m;
66
67 addSource (0, type);
68 }
69 else if (type == MouseInputSource::InputSourceType::touch)
70 {
71 jassert (0 <= touchIndex && touchIndex < 100); // sanity-check on number of fingers
72
73 for (auto& m : sourceArray)
74 if (type == m.getType() && touchIndex == m.getIndex())
75 return &m;
76
77 if (canUseTouch())
78 return addSource (touchIndex, type);
79 }
80
81 return nullptr;
82 }
83
84 int getNumDraggingMouseSources() const noexcept
85 {
86 int num = 0;
87
88 for (auto* s : sources)
89 if (s->isDragging())
90 ++num;
91
92 return num;
93 }
94
95 MouseInputSource* getDraggingMouseSource (int index) noexcept
96 {
97 int num = 0;
98
99 for (auto& s : sourceArray)
100 {
101 if (s.isDragging())
102 {
103 if (index == num)
104 return &s;
105
106 ++num;
107 }
108 }
109
110 return nullptr;
111 }
112
113 void beginDragAutoRepeat (int interval)
114 {
115 if (interval > 0)
116 {
117 if (getTimerInterval() != interval)
118 startTimer (interval);
119 }
120 else
121 {
122 stopTimer();
123 }
124 }
125
126 void timerCallback() override
127 {
128 bool anyDragging = false;
129
130 for (auto* s : sources)
131 {
132 // NB: when doing auto-repeat, we need to force an update of the current position and button state,
133 // because on some OSes the queue can get overloaded with messages so that mouse-events don't get through..
135 {
136 s->lastPointerState.position = s->getRawScreenPosition();
137 s->triggerFakeMove();
138 anyDragging = true;
139 }
140 }
141
142 if (! anyDragging)
143 stopTimer();
144 }
145
147 Array<MouseInputSource> sourceArray;
148
149private:
150 bool addSource();
151 bool canUseTouch() const;
152};
153
154} // namespace juce::detail
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
static ModifierKeys getCurrentModifiersRealtime() noexcept
On desktop platforms this method will check all the mouse and key states and return a ModifierKeys ob...
bool isAnyMouseButtonDown() const noexcept
Tests for any of the mouse-button flags.
Represents a linear source of mouse events from a mouse device or individual finger in a multi-touch ...
InputSourceType
Possible mouse input sources.
An array designed for holding objects.
Makes repeated callbacks to a virtual method at a specified time interval.
Definition juce_Timer.h:52
void stopTimer() noexcept
Stops the timer.
int getTimerInterval() const noexcept
Returns the timer's interval.
Definition juce_Timer.h:116
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
void timerCallback() override
The user-defined callback routine that actually gets called periodically.
#define jassert(expression)
Platform-independent assertion macro.
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.