JUCE  v5.1.1-3-g1a0b28c73
JUCE API
MouseInactivityDetector Class Reference

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>

Inheritance diagram for MouseInactivityDetector:
Collaboration diagram for MouseInactivityDetector:

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 ()
 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...
 
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
 
bool isActive
 
Point< intlastMousePos
 
ListenerList< ListenerlistenerList
 
ComponenttargetComp
 
int toleranceDistance
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MouseInactivityDetector()

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.

◆ ~MouseInactivityDetector()

MouseInactivityDetector::~MouseInactivityDetector ( )

Destructor.

Member Function Documentation

◆ addListener()

void MouseInactivityDetector::addListener ( Listener listener)

Registers a listener.

◆ callAfterDelay()

static void Timer::callAfterDelay ( int  milliseconds,
std::function< void()>  functionToCall 
)
staticinherited

Invokes a lambda after a given number of milliseconds.

◆ callPendingTimersSynchronously()

static void Timer::callPendingTimersSynchronously ( )
staticinherited

For internal use only: invokes any timers that need callbacks.

Don't call this unless you really know what you're doing!

◆ getTimerInterval()

int Timer::getTimerInterval ( ) const
inlinenoexceptinherited

Returns the timer's interval.

Returns
the timer's interval in milliseconds if it's running, or 0 if it's not.

References JUCE_CALLTYPE.

Referenced by CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().

◆ isTimerRunning()

bool Timer::isTimerRunning ( ) const
inlinenoexceptinherited

Returns true if the timer is currently running.

◆ mouseDoubleClick()

virtual void MouseListener::mouseDoubleClick ( const MouseEvent event)
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.

Parameters
eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseUp

Reimplemented in Component, Slider, TextEditor, CodeEditorComponent, and Label.

Referenced by Component::getComponentEffect().

◆ mouseDown()

void MouseInactivityDetector::mouseDown ( const MouseEvent event)
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.

Parameters
eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseUp, mouseDrag, mouseDoubleClick, contains

Reimplemented from MouseListener.

◆ mouseDrag()

void MouseInactivityDetector::mouseDrag ( const MouseEvent event)
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.

Parameters
eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseUp, mouseMove, contains, setDragRepeatInterval

Reimplemented from MouseListener.

◆ mouseEnter()

void MouseInactivityDetector::mouseEnter ( const MouseEvent event)
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.

Parameters
eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseExit, mouseDrag, mouseMove, contains

Reimplemented from MouseListener.

◆ mouseExit()

void MouseInactivityDetector::mouseExit ( const MouseEvent event)
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.

Parameters
eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseEnter, mouseDrag, mouseMove, contains

Reimplemented from MouseListener.

◆ mouseMove()

void MouseInactivityDetector::mouseMove ( const MouseEvent event)
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.

Parameters
eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseEnter, mouseExit, mouseDrag, contains

Reimplemented from MouseListener.

◆ mouseUp()

void MouseInactivityDetector::mouseUp ( const MouseEvent event)
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.

Parameters
eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseDrag, mouseDoubleClick, contains

Reimplemented from MouseListener.

◆ mouseWheelMove()

void MouseInactivityDetector::mouseWheelMove ( const MouseEvent event,
const MouseWheelDetails wheel 
)
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.

Parameters
eventdetails about the mouse event
wheeldetails about the wheel movement

Reimplemented from MouseListener.

References JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR.

◆ removeListener()

void MouseInactivityDetector::removeListener ( Listener listener)

Removes a previously-registered listener.

◆ setActive()

void MouseInactivityDetector::setActive ( bool  )
private

◆ setDelay()

void MouseInactivityDetector::setDelay ( int  newDelayMilliseconds)
noexcept

Sets the time for which the mouse must be still before the callback is triggered.

◆ setMouseMoveTolerance()

void MouseInactivityDetector::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.

◆ startTimer()

void Timer::startTimer ( int  intervalInMilliseconds)
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.

Parameters
intervalInMillisecondsthe interval to use (any value less than 1 will be rounded up to 1)

Referenced by FakeMouseMoveGenerator::FakeMouseMoveGenerator(), StandalonePluginHolder::init(), and CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().

◆ startTimerHz()

void Timer::startTimerHz ( int  timerFrequencyHz)
noexceptinherited

Starts the timer with an interval specified in Hertz.

This is effectively the same as calling startTimer (1000 / timerFrequencyHz).

Referenced by AnimatedPosition< Behaviour >::endDrag(), AnimatedPosition< Behaviour >::nudge(), and AnimatedPosition< Behaviour >::timerCallback().

◆ stopTimer()

void Timer::stopTimer ( )
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 AnimatedPosition< Behaviour >::beginDrag(), CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize(), AnimatedPosition< Behaviour >::setPosition(), AnimatedPosition< Behaviour >::timerCallback(), and StandalonePluginHolder::~StandalonePluginHolder().

◆ timerCallback()

void MouseInactivityDetector::timerCallback ( )
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 Timer.

◆ wakeUp()

void MouseInactivityDetector::wakeUp ( const MouseEvent ,
bool  alwaysWake 
)
private

Member Data Documentation

◆ delayMs

int MouseInactivityDetector::delayMs
private

◆ isActive

bool MouseInactivityDetector::isActive
private

◆ lastMousePos

Point<int> MouseInactivityDetector::lastMousePos
private

◆ listenerList

ListenerList<Listener> MouseInactivityDetector::listenerList
private

◆ targetComp

Component& MouseInactivityDetector::targetComp
private

◆ toleranceDistance

int MouseInactivityDetector::toleranceDistance
private

The documentation for this class was generated from the following file: