123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- /****************************************************************************
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- /**
- * Base class of all kinds of events.
- * @class
- * @extends cc.Class
- */
- cc.Event = cc.Class.extend(/** @lends cc.Event# */{
- _type: 0, // Event type
- _isStopped: false, //< whether the event has been stopped.
- _currentTarget: null, //< Current target
- _setCurrentTarget: function (target) {
- this._currentTarget = target;
- },
- ctor: function (type) {
- this._type = type;
- },
- /**
- * Gets the event type
- * @function
- * @returns {Number}
- */
- getType: function () {
- return this._type;
- },
- /**
- * Stops propagation for current event
- * @function
- */
- stopPropagation: function () {
- this._isStopped = true;
- },
- /**
- * Checks whether the event has been stopped
- * @function
- * @returns {boolean}
- */
- isStopped: function () {
- return this._isStopped;
- },
- /**
- * <p>
- * Gets current target of the event <br/>
- * note: It only be available when the event listener is associated with node. <br/>
- * It returns 0 when the listener is associated with fixed priority.
- * </p>
- * @function
- * @returns {cc.Node} The target with which the event associates.
- */
- getCurrentTarget: function () {
- return this._currentTarget;
- }
- });
- //event type
- /**
- * The type code of Touch event.
- * @constant
- * @type {number}
- */
- cc.Event.TOUCH = 0;
- /**
- * The type code of Keyboard event.
- * @constant
- * @type {number}
- */
- cc.Event.KEYBOARD = 1;
- /**
- * The type code of Acceleration event.
- * @constant
- * @type {number}
- */
- cc.Event.ACCELERATION = 2;
- /**
- * The type code of Mouse event.
- * @constant
- * @type {number}
- */
- cc.Event.MOUSE = 3;
- /**
- * The type code of Custom event.
- * @constant
- * @type {number}
- */
- cc.Event.CUSTOM = 4;
- /**
- * The Custom event
- * @class
- * @extends cc.Event
- */
- cc.EventCustom = cc.Event.extend(/** @lends cc.EventCustom# */{
- _eventName: null,
- _userData: null, // User data
- ctor: function (eventName) {
- cc.Event.prototype.ctor.call(this, cc.Event.CUSTOM);
- this._eventName = eventName;
- },
- /**
- * Sets user data
- * @param {*} data
- */
- setUserData: function (data) {
- this._userData = data;
- },
- /**
- * Gets user data
- * @returns {*}
- */
- getUserData: function () {
- return this._userData;
- },
- /**
- * Gets event name
- * @returns {String}
- */
- getEventName: function () {
- return this._eventName;
- }
- });
- /**
- * The mouse event
- * @class
- * @extends cc.Event
- */
- cc.EventMouse = cc.Event.extend(/** @lends cc.EventMouse# */{
- _eventType: 0,
- _button: 0,
- _x: 0,
- _y: 0,
- _prevX: 0,
- _prevY: 0,
- _scrollX: 0,
- _scrollY: 0,
- ctor: function (eventType) {
- cc.Event.prototype.ctor.call(this, cc.Event.MOUSE);
- this._eventType = eventType;
- },
- /**
- * Sets scroll data
- * @param {number} scrollX
- * @param {number} scrollY
- */
- setScrollData: function (scrollX, scrollY) {
- this._scrollX = scrollX;
- this._scrollY = scrollY;
- },
- /**
- * Returns the x axis scroll value
- * @returns {number}
- */
- getScrollX: function () {
- return this._scrollX;
- },
- /**
- * Returns the y axis scroll value
- * @returns {number}
- */
- getScrollY: function () {
- return this._scrollY;
- },
- /**
- * Sets cursor location
- * @param {number} x
- * @param {number} y
- */
- setLocation: function (x, y) {
- this._x = x;
- this._y = y;
- },
- /**
- * Returns cursor location
- * @return {cc.Point} location
- */
- getLocation: function () {
- return {x: this._x, y: this._y};
- },
- /**
- * Returns the current cursor location in screen coordinates
- * @return {cc.Point}
- */
- getLocationInView: function() {
- return {x: this._x, y: cc.view._designResolutionSize.height - this._y};
- },
- _setPrevCursor: function (x, y) {
- this._prevX = x;
- this._prevY = y;
- },
- /**
- * Returns the delta distance from the previous location to current location
- * @return {cc.Point}
- */
- getDelta: function () {
- return {x: this._x - this._prevX, y: this._y - this._prevY};
- },
- /**
- * Returns the X axis delta distance from the previous location to current location
- * @return {Number}
- */
- getDeltaX: function () {
- return this._x - this._prevX;
- },
- /**
- * Returns the Y axis delta distance from the previous location to current location
- * @return {Number}
- */
- getDeltaY: function () {
- return this._y - this._prevY;
- },
- /**
- * Sets mouse button
- * @param {number} button
- */
- setButton: function (button) {
- this._button = button;
- },
- /**
- * Returns mouse button
- * @returns {number}
- */
- getButton: function () {
- return this._button;
- },
- /**
- * Returns location X axis data
- * @returns {number}
- */
- getLocationX: function () {
- return this._x;
- },
- /**
- * Returns location Y axis data
- * @returns {number}
- */
- getLocationY: function () {
- return this._y;
- }
- });
- //Different types of MouseEvent
- /**
- * The none event code of mouse event.
- * @constant
- * @type {number}
- */
- cc.EventMouse.NONE = 0;
- /**
- * The event type code of mouse down event.
- * @constant
- * @type {number}
- */
- cc.EventMouse.DOWN = 1;
- /**
- * The event type code of mouse up event.
- * @constant
- * @type {number}
- */
- cc.EventMouse.UP = 2;
- /**
- * The event type code of mouse move event.
- * @constant
- * @type {number}
- */
- cc.EventMouse.MOVE = 3;
- /**
- * The event type code of mouse scroll event.
- * @constant
- * @type {number}
- */
- cc.EventMouse.SCROLL = 4;
- /**
- * The tag of Mouse left button
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_LEFT = 0;
- /**
- * The tag of Mouse right button (The right button number is 2 on browser)
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_RIGHT = 2;
- /**
- * The tag of Mouse middle button (The right button number is 1 on browser)
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_MIDDLE = 1;
- /**
- * The tag of Mouse button 4
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_4 = 3;
- /**
- * The tag of Mouse button 5
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_5 = 4;
- /**
- * The tag of Mouse button 6
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_6 = 5;
- /**
- * The tag of Mouse button 7
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_7 = 6;
- /**
- * The tag of Mouse button 8
- * @constant
- * @type {Number}
- */
- cc.EventMouse.BUTTON_8 = 7;
- /**
- * The touch event
- * @class
- * @extends cc.Event
- */
- cc.EventTouch = cc.Event.extend(/** @lends cc.EventTouch# */{
- _eventCode: 0,
- _touches: null,
- ctor: function (arr) {
- cc.Event.prototype.ctor.call(this, cc.Event.TOUCH);
- this._touches = arr || [];
- },
- /**
- * Returns event code
- * @returns {number}
- */
- getEventCode: function () {
- return this._eventCode;
- },
- /**
- * Returns touches of event
- * @returns {Array}
- */
- getTouches: function () {
- return this._touches;
- },
- _setEventCode: function (eventCode) {
- this._eventCode = eventCode;
- },
- _setTouches: function (touches) {
- this._touches = touches;
- }
- });
- /**
- * The maximum touch numbers
- * @constant
- * @type {Number}
- */
- cc.EventTouch.MAX_TOUCHES = 5;
- cc.EventTouch.EventCode = {BEGAN: 0, MOVED: 1, ENDED: 2, CANCELLED: 3};
|