Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUMouseListener.h>
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 MouseListener * | create () |
static MouseListener * | create (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 |
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).
|
static |
Creates a new input controller for the default dispatcher.
|
static |
Creates a new input controller for the given dispatcher.
dispatcher | Event handler for callbacks. |
a reference to the event dispatcher
|
inline |
Initializes a new input controller for the default dispatcher.
bool MouseListener::init | ( | EventDispatcher * | dispatcher | ) |
Creates a new input controller for the given dispatcher.
dispatcher | Event handler for callbacks. |
a reference to the event dispatcher
|
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.
priority | The input priority for the listener. |
void MouseListener::start | ( | Node * | node | ) |
Starts this listener, registering it to receive events.
The listener has scene priority.
node | The node for scene priority. |
void MouseListener::stop | ( | ) |
Stops this listener, so that it no longer receives events
|
protected |
Whether this listener is active and receiving events
|
protected |
The event dispatching handling input for this controller
|
protected |
Listener to process mouse events
std::function<void(EventMouse* event, timestamp_t time)> MouseListener::onMouseDown |
Called when a mouse button is initially pressed
event | the event storing the mouse state |
time | the 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
event | the event storing the mouse state |
time | the 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.
event | the event storing the mouse state |
time | the time of the event |
std::function<void(EventMouse* event, timestamp_t time)> MouseListener::onMouseUp |
Called when a mouse button is released
event | the event storing the mouse state |
time | the time of the event |