UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

193 lines (177 loc) 5.69 kB
// Class: starling.events.TouchEvent var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../hxClasses_stub").default; var $hxEnums = require("./../../hxEnums_stub").default; var $import = require("./../../import_stub").default; var $extend = require("./../../extend_stub").default; function starling_events_Event() {return require("./../../starling/events/Event");} function openfl__$Vector_Vector_$Impl_$() {return require("./../../openfl/_Vector/Vector_Impl_");} function js_Boot() {return require("./../../js/Boot");} function starling_events_EventDispatcher() {return require("./../../starling/events/EventDispatcher");} function openfl_VectorData() {return $import(require("openfl/Vector"));} // Constructor var TouchEvent = function(type,touches,shiftKey,ctrlKey,bubbles) { if(bubbles == null) { bubbles = true; } if(ctrlKey == null) { ctrlKey = false; } if(shiftKey == null) { shiftKey = false; } (starling_events_Event().default).call(this,type,bubbles,touches); this.__shiftKey = shiftKey; this.__ctrlKey = ctrlKey; this.__visitedObjects = (openfl__$Vector_Vector_$Impl_$().default)._new(); this.updateTimestamp(touches); } // Meta TouchEvent.__name__ = "starling.events.TouchEvent"; TouchEvent.__isInterface__ = false; TouchEvent.__super__ = (starling_events_Event().default); TouchEvent.prototype = $extend((starling_events_Event().default).prototype, { resetTo: function(type,touches,shiftKey,ctrlKey,bubbles) { if(bubbles == null) { bubbles = true; } if(ctrlKey == null) { ctrlKey = false; } if(shiftKey == null) { shiftKey = false; } (starling_events_Event().default).prototype.reset.call(this,type,bubbles,touches); this.__shiftKey = shiftKey; this.__ctrlKey = ctrlKey; this.__visitedObjects.length = 0; this.updateTimestamp(touches); return this; }, updateTimestamp: function(touches) { this.__timestamp = -1.0; var numTouches = touches != null ? touches.length : 0; var _g = 0; var _g1 = numTouches; while(_g < _g1) { var i = _g++; if(touches[i].get_timestamp() > this.__timestamp) { this.__timestamp = touches[i].get_timestamp(); } } }, getTouches: function(target,phase,out) { if(out == null) { out = (openfl__$Vector_Vector_$Impl_$().default)._new(); } var allTouches = this.data; var numTouches = allTouches.length; var _g = 0; var _g1 = numTouches; while(_g < _g1) { var i = _g++; var touch = allTouches[i]; var correctTarget = touch.isTouching(target); var correctPhase = phase == null || phase == touch.get_phase(); if(correctTarget && correctPhase) { (openfl__$Vector_Vector_$Impl_$().default).set(out,out.length,touch); } } return out; }, getTouch: function(target,phase,id) { if(id == null) { id = -1; } this.getTouches(target,phase,TouchEvent.sTouches); var numTouches = TouchEvent.sTouches.length; if(numTouches > 0) { var touch = null; if(id < 0) { touch = TouchEvent.sTouches[0]; } else { var _g = 0; var _g1 = numTouches; while(_g < _g1) { var i = _g++; if(TouchEvent.sTouches[i].get_id() == id) { touch = TouchEvent.sTouches[i]; break; } } } TouchEvent.sTouches.length = 0; return touch; } else { return null; } }, interactsWith: function(target) { var result = false; this.getTouches(target,null,TouchEvent.sTouches); var i = TouchEvent.sTouches.length - 1; while(i >= 0) { if(TouchEvent.sTouches[i].get_phase() != "ended") { result = true; break; } --i; } TouchEvent.sTouches.length = 0; return result; }, dispatch: function(chain) { if(chain != null && chain.length != 0) { var chainLength = this.bubbles ? chain.length : 1; var previousTarget = this.target; this.setTarget(chain[0]); var _g = 0; var _g1 = chainLength; while(_g < _g1) { var i = _g++; if(chain[i] == null) { continue; } var chainElement = (js_Boot().default).__cast(chain[i] , (starling_events_EventDispatcher().default)); var this1 = this.__visitedObjects; if((Array.prototype.indexOf.call)(this1,chainElement,0) == -1) { var stopPropagation = chainElement.__invokeEvent(this); (openfl__$Vector_Vector_$Impl_$().default).set(this.__visitedObjects,this.__visitedObjects.length,chainElement); if(stopPropagation) { break; } } } this.setTarget(previousTarget); } }, get_timestamp: function() { return this.__timestamp; }, get_touches: function() { var touches = this.data; var a = null; if(a == null) { return (openfl_VectorData().default).ofArray((Array.prototype.concat.call)(touches)); } else { return (openfl_VectorData().default).ofArray((Array.prototype.concat.call)(touches,a)); } }, get_shiftKey: function() { return this.__shiftKey; }, get_ctrlKey: function() { return this.__ctrlKey; } }); TouchEvent.prototype.__class__ = TouchEvent.prototype.constructor = $hxClasses["starling.events.TouchEvent"] = TouchEvent; // Init Object.defineProperties(TouchEvent.prototype,{ timestamp : { get : function () { return this.get_timestamp (); }}, touches : { get : function () { return this.get_touches (); }}, shiftKey : { get : function () { return this.get_shiftKey (); }}, ctrlKey : { get : function () { return this.get_ctrlKey (); }}}); // Statics TouchEvent.TOUCH = "touch" TouchEvent.sTouches = (openfl__$Vector_Vector_$Impl_$().default)._new() // Export exports.default = TouchEvent;