This object watches for mouse-events happening within a component, and if the mouse remains still for long enough, triggers an event to indicate that it has become inactive. More...
#include <juce_MouseInactivityDetector.h>
Classes | |
class | Listener |
Classes should implement this to receive callbacks from a MouseInactivityDetector when the mouse becomes active or inactive. More... | |
Public Member Functions | |
MouseInactivityDetector (Component &target) | |
Creates an inactivity watcher, attached to the given component. More... | |
~MouseInactivityDetector () override | |
Destructor. More... | |
void | addListener (Listener *listener) |
Registers a listener. More... | |
void | removeListener (Listener *listener) |
Removes a previously-registered listener. More... | |
void | setDelay (int newDelayMilliseconds) noexcept |
Sets the time for which the mouse must be still before the callback is triggered. More... | |
void | setMouseMoveTolerance (int pixelsNeededToTrigger) noexcept |
Sets the number of pixels by which the cursor is allowed to drift before it is considered to be actively moved. More... | |
Private Member Functions | |
int | getTimerInterval () const noexcept |
Returns the timer's interval. More... | |
bool | isTimerRunning () const noexcept |
Returns true if the timer is currently running. More... | |
virtual void | mouseDoubleClick (const MouseEvent &event) |
Called when a mouse button has been double-clicked on a component. More... | |
void | mouseDown (const MouseEvent &e) override |
Called when a mouse button is pressed. More... | |
void | mouseDrag (const MouseEvent &e) override |
Called when the mouse is moved while a button is held down. More... | |
void | mouseEnter (const MouseEvent &e) override |
Called when the mouse first enters a component. More... | |
void | mouseExit (const MouseEvent &e) override |
Called when the mouse moves out of a component. More... | |
virtual void | mouseMagnify (const MouseEvent &event, float scaleFactor) |
Called when a pinch-to-zoom mouse-gesture is used. More... | |
void | mouseMove (const MouseEvent &e) override |
Called when the mouse moves inside a component. More... | |
void | mouseUp (const MouseEvent &e) override |
Called when a mouse button is released. More... | |
void | mouseWheelMove (const MouseEvent &e, const MouseWheelDetails &) override |
Called when the mouse-wheel is moved. More... | |
void | setActive (bool) |
void | startTimer (int intervalInMilliseconds) noexcept |
Starts the timer and sets the length of interval required. More... | |
void | startTimerHz (int timerFrequencyHz) noexcept |
Starts the timer with an interval specified in Hertz. More... | |
void | stopTimer () noexcept |
Stops the timer. More... | |
void | timerCallback () override |
The user-defined callback routine that actually gets called periodically. More... | |
void | wakeUp (const MouseEvent &, bool alwaysWake) |
Static Private Member Functions | |
static void | callAfterDelay (int milliseconds, std::function< void()> functionToCall) |
Invokes a lambda after a given number of milliseconds. More... | |
static void | callPendingTimersSynchronously () |
For internal use only: invokes any timers that need callbacks. More... | |
Private Attributes | |
int | delayMs = 1500 |
bool | isActive = true |
Point< int > | lastMousePos |
ListenerList< Listener > | listenerList |
Component & | targetComp |
int | toleranceDistance = 15 |
This object watches for mouse-events happening within a component, and if the mouse remains still for long enough, triggers an event to indicate that it has become inactive.
You'd use this for situations where e.g. you want to hide the mouse-cursor when the user's not actively using the mouse.
After creating an instance of this, use addListener to get callbacks when the activity status changes.
{GUI}
juce::MouseInactivityDetector::MouseInactivityDetector | ( | Component & | target | ) |
Creates an inactivity watcher, attached to the given component.
The target component must not be deleted while this - it will be monitored for any mouse events in it or its child components.
|
override |
Destructor.
void juce::MouseInactivityDetector::addListener | ( | Listener * | listener | ) |
Registers a listener.
|
staticinherited |
Invokes a lambda after a given number of milliseconds.
|
staticinherited |
For internal use only: invokes any timers that need callbacks.
Don't call this unless you really know what you're doing!
|
inlinenoexceptinherited |
Returns the timer's interval.
References JUCE_CALLTYPE.
Referenced by juce::CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().
|
inlinenoexceptinherited |
Returns true if the timer is currently running.
|
virtualinherited |
Called when a mouse button has been double-clicked on a component.
The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.
event | details about the position and status of the mouse event, including the source component in which it occurred |
Reimplemented in juce::Component, juce::Slider, juce::TextEditor, juce::CodeEditorComponent, and juce::Label.
|
inlineoverrideprivatevirtual |
Called when a mouse button is pressed.
The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.
Once a button is held down, the mouseDrag method will be called when the mouse moves, until the button is released.
event | details about the position and status of the mouse event, including the source component in which it occurred |
Reimplemented from juce::MouseListener.
|
inlineoverrideprivatevirtual |
Called when the mouse is moved while a button is held down.
When a mouse button is pressed inside a component, that component receives mouseDrag callbacks each time the mouse moves, even if the mouse strays outside the component's bounds.
event | details about the position and status of the mouse event, including the source component in which it occurred |
Reimplemented from juce::MouseListener.
|
inlineoverrideprivatevirtual |
Called when the mouse first enters a component.
If the mouse button isn't pressed and the mouse moves into a component, this will be called to let the component react to this.
When the mouse button is pressed and held down while being moved in or out of a component, no mouseEnter or mouseExit callbacks are made - only mouseDrag messages are sent to the component that the mouse was originally clicked on, until the button is released.
event | details about the position and status of the mouse event, including the source component in which it occurred |
Reimplemented from juce::MouseListener.
|
inlineoverrideprivatevirtual |
Called when the mouse moves out of a component.
This will be called when the mouse moves off the edge of this component.
If the mouse button was pressed, and it was then dragged off the edge of the component and released, then this callback will happen when the button is released, after the mouseUp callback.
event | details about the position and status of the mouse event, including the source component in which it occurred |
Reimplemented from juce::MouseListener.
|
virtualinherited |
Called when a pinch-to-zoom mouse-gesture is used.
If not overridden, a component will forward this message to its parent, so that parent components can collect gesture messages that are unused by child components.
event | details about the mouse event |
scaleFactor | a multiplier to indicate by how much the size of the target should be changed. A value of 1.0 would indicate no change, values greater than 1.0 mean it should be enlarged. |
Reimplemented in juce::Component.
|
inlineoverrideprivatevirtual |
Called when the mouse moves inside a component.
If the mouse button isn't pressed and the mouse moves over a component, this will be called to let the component react to this.
A component will always get a mouseEnter callback before a mouseMove.
event | details about the position and status of the mouse event, including the source component in which it occurred |
Reimplemented from juce::MouseListener.
|
inlineoverrideprivatevirtual |
Called when a mouse button is released.
A mouseUp callback is sent to the component in which a button was pressed even if the mouse is actually over a different component when the button is released.
The MouseEvent object passed in contains lots of methods for finding out which buttons were down just before they were released.
event | details about the position and status of the mouse event, including the source component in which it occurred |
Reimplemented from juce::MouseListener.
|
inlineoverrideprivatevirtual |
Called when the mouse-wheel is moved.
This callback is sent to the component that the mouse is over when the wheel is moved.
If not overridden, a component will forward this message to its parent, so that parent components can collect mouse-wheel messages that happen to child components which aren't interested in them.
event | details about the mouse event |
wheel | details about the wheel movement |
Reimplemented from juce::MouseListener.
References JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR.
void juce::MouseInactivityDetector::removeListener | ( | Listener * | listener | ) |
Removes a previously-registered listener.
|
private |
|
noexcept |
Sets the time for which the mouse must be still before the callback is triggered.
|
noexcept |
Sets the number of pixels by which the cursor is allowed to drift before it is considered to be actively moved.
|
noexceptinherited |
Starts the timer and sets the length of interval required.
If the timer is already started, this will reset it, so the time between calling this method and the next timer callback will not be less than the interval length passed in.
intervalInMilliseconds | the interval to use (any value less than 1 will be rounded up to 1) |
Referenced by juce::StandalonePluginHolder::init(), and juce::CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().
|
noexceptinherited |
Starts the timer with an interval specified in Hertz.
This is effectively the same as calling startTimer (1000 / timerFrequencyHz).
Referenced by juce::AnimatedPosition< Behaviour >::endDrag(), juce::AnimatedPosition< Behaviour >::nudge(), and juce::AnimatedPosition< Behaviour >::timerCallback().
|
noexceptinherited |
Stops the timer.
No more timer callbacks will be triggered after this method returns.
Note that if you call this from a background thread while the message-thread is already in the middle of your callback, then this method will cancel any future timer callbacks, but it will return without waiting for the current one to finish. The current callback will continue, possibly still running some of your timer code after this method has returned.
Referenced by juce::AnimatedPosition< Behaviour >::beginDrag(), juce::CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize(), juce::AnimatedPosition< Behaviour >::setPosition(), juce::AnimatedPosition< Behaviour >::timerCallback(), and juce::StandalonePluginHolder::~StandalonePluginHolder().
|
overrideprivatevirtual |
The user-defined callback routine that actually gets called periodically.
It's perfectly ok to call startTimer() or stopTimer() from within this callback to change the subsequent intervals.
Implements juce::Timer.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |