Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
MouseListener Class Reference

#include <CUMouseListener.h>

Inheritance diagram for MouseListener:

Public Member Functions

void start (int priority)
 
void start (Node *node)
 
void stop ()
 
bool isActive () const
 
bool init ()
 
bool init (EventDispatcher *dispatcher)
 

Static Public Member Functions

static MouseListenercreate ()
 
static MouseListenercreate (EventDispatcher *dispatcher)
 

Public Attributes

std::function< void(EventMouse *event, timestamp_t time)> onMouseDown
 
std::function< void(EventMouse *event, timestamp_t time)> onMouseUp
 
std::function< void(EventMouse *event, timestamp_t time)> onMouseMove
 
std::function< void(EventMouse *event, timestamp_t time)> onMouseScroll
 
CC_CONSTRUCTOR_ACCESS __pad0__: MouseListener() : _active(false) {} virtual ~MouseListener()
 

Protected Attributes

EventDispatcher * _dispatcher
 
EventListenerMouse * _mouseListener
 
bool _active
 

Detailed Description

Class provides a time senstive mouse listener.

When created, this class initializes but does not activate a mouse listener. You must use the start and stop methods to activate/deactivate the listener. Furthermore, all of the callback functions are originally undefined. They must be defined before this listener performs any useful functionality.

This class simplifies a lot of the overhead for EventListenerMouse. More importantly,it adds a timestamp to all of the callback functions so that the user can precisely time the callbacks.

This is a very expensive listener. onMouseMove is called every single animation frame, registering a mouse move regardless of whether the mouse button is held down. If you only want to register events on a button press, use a touch listener instead (which works on PCs too).

Member Function Documentation

NS_CC_BEGIN MouseListener * MouseListener::create ( )
static

Creates a new input controller for the default dispatcher.

Returns
An autoreleased mouse listener
MouseListener * MouseListener::create ( EventDispatcher *  dispatcher)
static

Creates a new input controller for the given dispatcher.

Parameters
dispatcherEvent handler for callbacks.

a reference to the event dispatcher

Returns
An autoreleased mouse listener
bool MouseListener::init ( )
inline

Initializes a new input controller for the default dispatcher.

Returns
true if the listener is initialized properly, false otherwise.
bool MouseListener::init ( EventDispatcher *  dispatcher)

Creates a new input controller for the given dispatcher.

Parameters
dispatcherEvent handler for callbacks.

a reference to the event dispatcher

Returns
true if the listener is initialized properly, false otherwise.
bool MouseListener::isActive ( ) const
inline

Returns whether this listener is active and receiving events

Returns whether this listener is active and receiving events

void MouseListener::start ( int  priority)

Starts this listener, registering it to receive events.

The listener has fixed priority.

Parameters
priorityThe input priority for the listener.
void MouseListener::start ( Node *  node)

Starts this listener, registering it to receive events.

The listener has scene priority.

Parameters
nodeThe node for scene priority.
void MouseListener::stop ( )

Stops this listener, so that it no longer receives events

Member Data Documentation

bool MouseListener::_active
protected

Whether this listener is active and receiving events

EventDispatcher* MouseListener::_dispatcher
protected

The event dispatching handling input for this controller

EventListenerMouse* MouseListener::_mouseListener
protected

Listener to process mouse events

std::function<void(EventMouse* event, timestamp_t time)> MouseListener::onMouseDown

Called when a mouse button is initially pressed

Parameters
eventthe event storing the mouse state
timethe time of the event
std::function<void(EventMouse* event, timestamp_t time)> MouseListener::onMouseMove

Called when the mouse moves

This event registers ALL THE TIME. It does not care whether the mouse button is held down or not. This makes this a very expensive listener

Parameters
eventthe event storing the mouse state
timethe time of the event
std::function<void(EventMouse* event, timestamp_t time)> MouseListener::onMouseScroll

Called when the mouse scroll wheel moves

This event only registers when the mouse button is down.

Parameters
eventthe event storing the mouse state
timethe time of the event
std::function<void(EventMouse* event, timestamp_t time)> MouseListener::onMouseUp

Called when a mouse button is released

Parameters
eventthe event storing the mouse state
timethe time of the event

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