1 /**
  2  * The Render Engine
  3  * KeyboardInputComponent
  4  *
  5  * @fileoverview An extension of the input component to handle touch inputs from
  6  *               devices which support them.
  7  *
  8  * @author: Brett Fattori (brettf@renderengine.com)
  9  * @author: $Author: bfattori $
 10  * @version: $Revision: 1555 $
 11  *
 12  * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com)
 13  *
 14  * Permission is hereby granted, free of charge, to any person obtaining a copy
 15  * of this software and associated documentation files (the "Software"), to deal
 16  * in the Software without restriction, including without limitation the rights
 17  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 18  * copies of the Software, and to permit persons to whom the Software is
 19  * furnished to do so, subject to the following conditions:
 20  *
 21  * The above copyright notice and this permission notice shall be included in
 22  * all copies or substantial portions of the Software.
 23  *
 24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 27  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 29  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 30  * THE SOFTWARE.
 31  *
 32  */
 33 
 34 // The class this file defines and its required classes
 35 R.Engine.define({
 36     "class":"R.struct.Touch",
 37     "requires":[
 38         "R.math.Point2D"
 39     ]
 40 });
 41 
 42 /**
 43  * @class A data object which represents a touch event generated by {@link R.components.TouchInput}.
 44  *        Since touches are handled differently across platforms, this class aims to
 45  *        normalize what is returned and allow a game to handle the input without concern
 46  *        for platform.
 47  *
 48  * @param touch {Event} The touch from the event object
 49  * @constructor
 50  * @description A touch data object.
 51  */
 52 R.struct.Touch = Base.extend(/** @scope R.struct.Touch.prototype */{
 53 
 54     touchX:null,
 55     touchY:null,
 56 
 57     /**
 58      * @private
 59      */
 60     constructor:function (touch) {
 61         this.touchX = touch.pageX;
 62         this.touchY = touch.pageY;
 63     },
 64 
 65     /**
 66      * Get the X coordinate of the touch
 67      * @return {Number} The X coordinate of the touch
 68      */
 69     getX:function () {
 70         return this.touchX;
 71     },
 72 
 73     /**
 74      * Get the Y coordinate of the touch
 75      * @return {Number} The Y coordinate of the touch
 76      */
 77     getY:function () {
 78         return this.touchY;
 79     },
 80 
 81     /**
 82      * Get a {@link R.math.Point2D} which represents the location of the touch
 83      * @return {R.math.Point2D} The coordinates of the touch
 84      */
 85     get:function () {
 86         return R.math.Point2D.create(this.touchX, this.touchY);
 87     }
 88 
 89 }, /** @scope R.struct.Touch.prototype */{
 90     /**
 91      * Get the class name of this object
 92      *
 93      * @return {String} "R.struct.Touch"
 94      */
 95     getClassName:function () {
 96         return "R.struct.Touch";
 97     }
 98 });
 99