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.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
27{
28
29//==============================================================================
43class JUCE_API MouseInactivityDetector : private Timer,
44 private MouseListener
45{
46public:
52
54 ~MouseInactivityDetector() override;
55
59 void setDelay (int newDelayMilliseconds) noexcept;
60
64 void setMouseMoveTolerance (int pixelsNeededToTrigger) noexcept;
65
66 //==============================================================================
71 {
72 public:
73 virtual ~Listener() = default;
74
77 virtual void mouseBecameActive() = 0;
78
80 virtual void mouseBecameInactive() = 0;
81 };
82
84 void addListener (Listener* listener);
85
87 void removeListener (Listener* listener);
88
89private:
90 //==============================================================================
91 Component& targetComp;
92 ListenerList<Listener> listenerList;
93 Point<int> lastMousePos;
94 int delayMs = 1500, toleranceDistance = 15;
95 bool isActive = true;
96
97 void timerCallback() override;
98 void wakeUp (const MouseEvent&, bool alwaysWake);
99 void setActive (bool);
100
101 void mouseMove (const MouseEvent& e) override { wakeUp (e, false); }
102 void mouseEnter (const MouseEvent& e) override { wakeUp (e, false); }
103 void mouseExit (const MouseEvent& e) override { wakeUp (e, false); }
104 void mouseDown (const MouseEvent& e) override { wakeUp (e, true); }
105 void mouseDrag (const MouseEvent& e) override { wakeUp (e, true); }
106 void mouseUp (const MouseEvent& e) override { wakeUp (e, true); }
107 void mouseWheelMove (const MouseEvent& e, const MouseWheelDetails&) override { wakeUp (e, true); }
108
109 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseInactivityDetector)
110};
111
112} // namespace juce
The base class for all JUCE user-interface objects.
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Contains position and status information about a mouse event.
Classes should implement this to receive callbacks from a MouseInactivityDetector when the mouse beco...
virtual void mouseBecameInactive()=0
Called when the mouse hasn't been moved for the timeout period.
virtual void mouseBecameActive()=0
Called when the mouse is moved or clicked for the first time after a period of inactivity.
This object watches for mouse-events happening within a component, and if the mouse remains still for...
A MouseListener can be registered with a component to receive callbacks about mouse events that happe...
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Makes repeated callbacks to a virtual method at a specified time interval.
Definition juce_Timer.h:52
#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.