forked from Jibo-Revival-Group/JiboOs
194 lines
5.9 KiB
JavaScript
194 lines
5.9 KiB
JavaScript
|
|
/**
|
||
|
|
* @description
|
||
|
|
* A wrapper around HammerJS to register gesture input events with the PIXI DOM Element.
|
||
|
|
* @class GestureManager
|
||
|
|
* @memberof jibo.face
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Pan gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PAN
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Panstart gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANSTART
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Panmove gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANMOVE
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Panend gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANEND
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Pancancel gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANCANCEL
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Panleft gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANLEFT
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Panright gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANRIGHT
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Panup gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANUP
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Pandown gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.PANDOWN
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Swipe gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.SWIPE
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Swipeleft gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.SWIPELEFT
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Swiperight gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.SWIPERIGHT
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Swipeup gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.SWIPEUP
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Swipedown gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.SWIPEDOWN
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Tap gesture event string.
|
||
|
|
* @type {string}
|
||
|
|
* @name jibo.face.GestureManager.TAP
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Pixi gesture.
|
||
|
|
* Instance of HammerJS.Manager
|
||
|
|
* @type {*}
|
||
|
|
* @name jibo.face.GestureManager#_hammerManager
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create the singleton instance of the GestureManager.
|
||
|
|
* @method jibo.face.GestureManager.init
|
||
|
|
* @return {jibo.face.GestureManager}
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Instantiate a HammerJS Manager object with the PIXI renderer.
|
||
|
|
* This should be called before a call to addStageGesture.
|
||
|
|
* @method jibo.face.GestureManager#init
|
||
|
|
* @param {PIXI.WebGLRenderer} renderer - The pixi renderer object.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get a reference to HammerJS,
|
||
|
|
* @method jibo.face.GestureManager#hammer
|
||
|
|
* @return {Object} The HammerJS object. See [hammer's documentation](http://hammerjs.github.io/getting-started/)
|
||
|
|
* for information on what objects are accessible through this module.
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Stop all recognizers.
|
||
|
|
* @method jibo.face.GestureManager#stop
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Add a gesture recognized by the PIXI renderer stage DOM element.
|
||
|
|
* See [hammer's documentation](http://hammerjs.github.io/getting-started/) for specifics on gesture options and hammer api objects.
|
||
|
|
* @method jibo.face.GestureManager#addStageGesture
|
||
|
|
* @param {Object} hammerType - This can be retrieved from the jibo.face.gestures.hammer reference. This is the hammer object type to be instantiated to create the gesture.
|
||
|
|
* eg. ```jibo.face.gestures.hammer.Pan```
|
||
|
|
* @param {Object} gestureOptions - This varies between each gesture. This must include an event field (which is of type string, some of which are specified as constants in this class).
|
||
|
|
* eg. ```event { GestureManager.SWIPE }```
|
||
|
|
* @param {Function(Object)} gestureCallback - Upon successful gesture recognition against the supplied displayobject, this callback will be triggered.
|
||
|
|
* It will have the event parameter supplied from the HammerJS event callback.
|
||
|
|
* @return {Object | null} The hammer object which was successfully created, or null if it was not successfully created.
|
||
|
|
* An example in calling this would be:
|
||
|
|
* ```
|
||
|
|
* GestureManager.addStageGesture(pixiDisplayObject,
|
||
|
|
* jibo.face.gestures.hammer.Swipe,
|
||
|
|
* { event: blackboard.GestureManager.SWIPELEFT},
|
||
|
|
* function(gestureEvent){
|
||
|
|
* // Got event!
|
||
|
|
* });
|
||
|
|
* ```
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Removes a gesture for Hammer Manager.
|
||
|
|
* @method jibo.face.GestureManager#removeStateGesture
|
||
|
|
* @param {any} gestureRecognizer - The gesture to remove.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Allows a gesture event to be 'spoofed', useful for testing.
|
||
|
|
* @method jibo.face.GestureManager#spoofGesture
|
||
|
|
* @param {String} [gestureEvent = tap] - Type of gesture event to spoof. Defaults to event for a tap.
|
||
|
|
* @param {Number} [xPos = 0] - The x position of input.
|
||
|
|
* @param {Number} [yPos = 0] - The y position of input.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Allows a gesture event to be 'spoofed' with options provided.
|
||
|
|
* @method jibo.face.GestureManager#spoofGestureWithOptions
|
||
|
|
* @param {String} [gestureEvent = tap] - Type of gesture event to spoof. Defaults to event for a tap.
|
||
|
|
* @param {any} options - Options that HammerJs uses to fire correct event.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Spoofs left/right pan gesture on the screen that will trigger list page swiping
|
||
|
|
* @method jibo.face.GestureManager#spoofFullPanGesture
|
||
|
|
* @param {Boolean} [panLeft = true] - Type of pan event to spoof. Defaults to left pan.
|
||
|
|
*/
|