JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::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 juce::MouseInactivityDetector:
Collaboration diagram for juce::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 () 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< intlastMousePos
 
ListenerList< ListenerlistenerList
 
size_t positionInQueue = (size_t) -1
 
ComponenttargetComp
 
int timerPeriodMs = 0
 
int toleranceDistance = 15
 

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.

@tags{GUI}

Constructor & Destructor Documentation

◆ MouseInactivityDetector()

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.

◆ ~MouseInactivityDetector()

juce::MouseInactivityDetector::~MouseInactivityDetector ( )
override

Destructor.

Member Function Documentation

◆ addListener()

void juce::MouseInactivityDetector::addListener ( Listener listener)

Registers a listener.

◆ callAfterDelay()

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

Invokes a lambda after a given number of milliseconds.

◆ callPendingTimersSynchronously()

static void juce::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 juce::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.

Referenced by juce::CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().

◆ isTimerRunning()

bool juce::Timer::isTimerRunning ( ) const
inlinenoexceptinherited

Returns true if the timer is currently running.

◆ mouseDoubleClick()

virtual void juce::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 juce::Component, juce::Slider, juce::TextEditor, juce::CodeEditorComponent, and juce::Label.

◆ mouseDown()

void juce::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 juce::MouseListener.

◆ mouseDrag()

void juce::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 juce::MouseListener.

◆ mouseEnter()

void juce::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 juce::MouseListener.

◆ mouseExit()

void juce::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 juce::MouseListener.

◆ mouseMagnify()

virtual void juce::MouseListener::mouseMagnify ( const MouseEvent event,
float  scaleFactor 
)
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.

Parameters
eventdetails about the mouse event
scaleFactora 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.

◆ mouseMove()

void juce::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 juce::MouseListener.

◆ mouseUp()

void juce::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 juce::MouseListener.

◆ mouseWheelMove()

void juce::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 juce::MouseListener.

◆ removeListener()

void juce::MouseInactivityDetector::removeListener ( Listener listener)

Removes a previously-registered listener.

◆ setActive()

void juce::MouseInactivityDetector::setActive ( bool  )
private

◆ setDelay()

void juce::MouseInactivityDetector::setDelay ( int  newDelayMilliseconds)
noexcept

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

◆ setMouseMoveTolerance()

void juce::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 juce::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 juce::StandalonePluginHolder::init(), juce::CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize(), and juce::DeviceChangeDetector::triggerAsyncDeviceChangeCallback().

◆ startTimerHz()

void juce::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 juce::AnimatedPosition< Behaviour >::endDrag(), juce::AnimatedPosition< Behaviour >::nudge(), and juce::AnimatedPosition< Behaviour >::timerCallback().

◆ stopTimer()

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

◆ timerCallback()

void juce::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 juce::Timer.

◆ wakeUp()

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

Member Data Documentation

◆ delayMs

int juce::MouseInactivityDetector::delayMs = 1500
private

◆ isActive

bool juce::MouseInactivityDetector::isActive = true
private

◆ lastMousePos

Point<int> juce::MouseInactivityDetector::lastMousePos
private

◆ listenerList

ListenerList<Listener> juce::MouseInactivityDetector::listenerList
private

◆ positionInQueue

size_t juce::Timer::positionInQueue = (size_t) -1
privateinherited

◆ targetComp

Component& juce::MouseInactivityDetector::targetComp
private

◆ timerPeriodMs

int juce::Timer::timerPeriodMs = 0
privateinherited

◆ toleranceDistance

int juce::MouseInactivityDetector::toleranceDistance = 15
private

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