Leap Motion C++ API Reference  0.8.0
Leap::Listener Class Reference

The Listener class defines a set of callback functions that you can override in a subclass to respond to events dispatched by the Controller object. More...

Public Member Functions

 Listener ()
 Constructs a Listener object.
 
virtual void onConnect (const Controller &)
 Called when the Controller object connects to the Leap Motion software, or when this Listener object is added to a Controller that is already connected.
 
virtual void onDisconnect (const Controller &)
 Called when the Controller object disconnects from the Leap Motion software.
 
virtual void onExit (const Controller &)
 Called when this Listener object is removed from the Controller or the Controller instance is destroyed.
 
virtual void onFocusGained (const Controller &)
 Called when this application becomes the foreground application.
 
virtual void onFocusLost (const Controller &)
 Called when this application loses the foreground focus.
 
virtual void onFrame (const Controller &)
 Called when a new frame of hand and finger tracking data is available.
 
virtual void onInit (const Controller &)
 Called once, when this Listener object is newly added to a Controller.
 
virtual ~Listener ()
 Destructs this Listener object.
 

Detailed Description

The Listener class defines a set of callback functions that you can override in a subclass to respond to events dispatched by the Controller object.

To handle Leap Motion events, create an instance of a Listener subclass and assign it to the Controller instance. The Controller calls the relevant Listener callback function when an event occurs, passing in a reference to itself. You do not have to implement callbacks for events you do not want to handle.

The Controller object calls these Listener functions from a thread created by the Leap Motion library, not the thread used to create or set the Listener instance.

Constructor & Destructor Documentation

Leap::Listener::Listener ( )
inline

Constructs a Listener object.

virtual Leap::Listener::~Listener ( )
inlinevirtual

Destructs this Listener object.

Member Function Documentation

virtual void Leap::Listener::onConnect ( const Controller )
inlinevirtual

Called when the Controller object connects to the Leap Motion software, or when this Listener object is added to a Controller that is already connected.

void SampleListener::onConnect(const Controller& controller) {
std::cout << "Connected" << std::endl;
}
Parameters
controllerThe Controller object invoking this callback function.
virtual void Leap::Listener::onDisconnect ( const Controller )
inlinevirtual

Called when the Controller object disconnects from the Leap Motion software.

The controller can disconnect when the Leap Motion device is unplugged, the user shuts the Leap Motion software down, or the Leap Motion software encounters an unrecoverable error.

void SampleListener::onDisconnect(const Controller& controller) {
std::cout << "Disconnected" << std::endl;
}

Note: When you launch a Leap-enabled application in a debugger, the Leap Motion library does not disconnect from the application. This is to allow you to step through code without losing the connection because of time outs.

Parameters
controllerThe Controller object invoking this callback function.
virtual void Leap::Listener::onExit ( const Controller )
inlinevirtual

Called when this Listener object is removed from the Controller or the Controller instance is destroyed.

void SampleListener::onExit(const Controller& controller) {
std::cout << "Exited" << std::endl;
}
Parameters
controllerThe Controller object invoking this callback function.
virtual void Leap::Listener::onFocusGained ( const Controller )
inlinevirtual

Called when this application becomes the foreground application.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

void SampleListener::onFocusGained(const Controller& controller) {
std::cout << "Focus gained " << std::endl;
}
Parameters
controllerThe Controller object invoking this callback function.
virtual void Leap::Listener::onFocusLost ( const Controller )
inlinevirtual

Called when this application loses the foreground focus.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

void SampleListener::onFocusLost(const Controller& controller) {
std::cout << "Focus lost " << std::endl;
}
Parameters
controllerThe Controller object invoking this callback function.
virtual void Leap::Listener::onFrame ( const Controller )
inlinevirtual

Called when a new frame of hand and finger tracking data is available.

Access the new frame data using the Controller::frame() function.

void SampleListener::onFrame(const Controller& controller) {
std::cout << "New frame " << std::endl;
}

Note, the Controller skips any pending onFrame events while your onFrame handler executes. If your implementation takes too long to return, one or more frames can be skipped. The Controller still inserts the skipped frames into the frame history. You can access recent frames by setting the history parameter when calling the Controller::frame() function. You can determine if any pending onFrame events were skipped by comparing the ID of the most recent frame with the ID of the last received frame.

Parameters
controllerThe Controller object invoking this callback function.
virtual void Leap::Listener::onInit ( const Controller )
inlinevirtual

Called once, when this Listener object is newly added to a Controller.

void SampleListener::onInit(const Controller& controller) {
std::cout << "Initialized" << std::endl;
}
Parameters
controllerThe Controller object invoking this callback function.