1. Event EventCustom
All event classes inherit Event.
Event enumeration defines the type of event:
enum class the Type { TOUCH, // touch KEYBOARD, // keyboard ACCELERATION, // accelerator MOUSE, // mouse the FOCUS, // GAME_CONTROLLER, // gamepad the CUSTOM // User defined };
Event member variables:
Type _type; // event type BOOL _isStopped; // event suspend the Node * _currentTarget; // action node
Event constructor:
Event::Event(Type type) : _type(type) , _isStopped(false) , _currentTarget(nullptr)
{}
EventCustom is a custom event. Event than extra member variables:
void * _userData; /// <the User the Data std :: String _eventName; // custom event name
EventCustom constructor event type Type is set to CUSTOM. Set _eventName.
EventCustom::EventCustom(const std::string& eventName) : Event(Type::CUSTOM) , _userData(nullptr) , _eventName(eventName) { }
3. EventListener
Listeners have their own type of ID, ID is to monitor this type of event. The event will only be distributed to the same listener ID are processed.
In addition to custom monitors, touch monitors, other listeners ID and event type correspondence. Custom listeners ID is custom event event name. The touch type is one of two kinds corresponding to the listener.
Listener class has the enumeration definition monitor type of event, and Event touch compared to split into single-touch and multi-touch:
enum class the Type { UNKNOWN, TOUCH_ONE_BY_ONE, // single touch TOUCH_ALL_AT_ONCE, // multi-touch KEYBOARD, MOUSE, ACCELERATION, the FOCUS, GAME_CONTROLLER, the CUSTOM };
Listener member variables:
:: function std < void (Event *)> _onEvent; /// processing incoming event callback function callback function Event Type _type; /// type of event listener of the type Event listenerID _listenerID; /// listener listener ID Event ID BOOL _isRegistered; /// registered at the listener has been added model types within to the Dispatcher. int _fixedPriority; // priority listener, the greater the value the higher the priority the Node * _node; // the Node Graph based SCENE priority listener associated BOOL _paused; // pause listener listener iS paused at The model types within BOOL _isEnabled; // 是否启用 Whether the listener is enabled
init method listener to member variables are initialized.
FIG listener scene priority is fixed at 0, add the automatic setting process. Custom priority listener priority must not be 0.
Listeners pause or not only for the scene graph priority listener. Custom-priority pause sign listener has been false. When the custom priority listeners need to "pause" and does not receive events, call setEnabled (false) can be.
4. EventListenerCustom
Custom event listeners have members:
std::function<void(EventCustom*)> _onCustomEvent;
When you create a create method to listen for the event name as a listener ID. The callback function as _onCustomEvent. When init, _onEvent is set to anonymous function:
auto listener = [this](Event* event){ if (_onCustomEvent != nullptr) { _onCustomEvent(static_cast<EventCustom*>(event)); } };
The anonymous callback function is a callback function _onCustomEvent packaging we set, converts the type of event to EventCustom.