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_MouseInactivityDetector.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{
31 targetComp.addMouseListener (this, true);
32}
33
38
39void MouseInactivityDetector::setDelay (int newDelay) noexcept { delayMs = newDelay; }
41
42void MouseInactivityDetector::addListener (Listener* l) { listenerList.add (l); }
43void MouseInactivityDetector::removeListener (Listener* l) { listenerList.remove (l); }
44
45void MouseInactivityDetector::timerCallback()
46{
47 setActive (false);
48}
49
50void MouseInactivityDetector::wakeUp (const MouseEvent& e, bool alwaysWake)
51{
52 auto newPos = e.getEventRelativeTo (&targetComp).getPosition();
53
54 if ((! isActive) && (alwaysWake || e.source.isTouch() || newPos.getDistanceFrom (lastMousePos) > toleranceDistance))
55 setActive (true);
56
57 if (lastMousePos != newPos)
58 {
59 lastMousePos = newPos;
60 startTimer (delayMs);
61 }
62}
63
64void MouseInactivityDetector::setActive (bool b)
65{
66 if (isActive != b)
67 {
68 isActive = b;
69
70 if (isActive)
71 listenerList.call ([] (Listener& l) { l.mouseBecameActive(); });
72 else
73 listenerList.call ([] (Listener& l) { l.mouseBecameInactive(); });
74 }
75}
76
77} // namespace juce
The base class for all JUCE user-interface objects.
void addMouseListener(MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
Registers a listener to be told when mouse events occur in this component.
void removeMouseListener(MouseListener *listenerToRemove)
Deregisters a mouse listener.
Classes should implement this to receive callbacks from a MouseInactivityDetector when the mouse beco...
MouseInactivityDetector(Component &target)
Creates an inactivity watcher, attached to the given component.
void addListener(Listener *listener)
Registers a listener.
void setMouseMoveTolerance(int pixelsNeededToTrigger) noexcept
Sets the number of pixels by which the cursor is allowed to drift before it is considered to be activ...
void removeListener(Listener *listener)
Removes a previously-registered listener.
void setDelay(int newDelayMilliseconds) noexcept
Sets the time for which the mouse must be still before the callback is triggered.
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
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