1 /** 2 * The Render Engine 3 * MouseInfo 4 * 5 * @fileoverview Data object which holds mouse information. 6 * 7 * @author: Brett Fattori (brettf@renderengine.com) 8 * 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.MouseInfo", 37 "requires":[ 38 "R.engine.PooledObject", 39 "R.math.Point2D", 40 "R.math.Vector2D", 41 "R.engine.Events" 42 ] 43 }); 44 45 /** 46 * @class An object which contains information about the mouse in relation to 47 * a rendering context. 48 * 49 * @extends R.engine.PooledObject 50 * @constructor 51 * @description Creates a mouse data structure. 52 */ 53 R.struct.MouseInfo = function () { 54 return R.engine.PooledObject.extend(/** @scope R.struct.MouseInfo.prototype */{ 55 56 /** 57 * The current mouse position 58 * @type {R.math.Point2D} 59 */ 60 position:null, 61 62 /** 63 * The last mouse position 64 * @type {R.math.Point2D} 65 */ 66 lastPosition:null, 67 68 /** 69 * The position at which a mouse button was pressed 70 * @type {R.math.Point2D} 71 */ 72 downPosition:null, 73 74 /** 75 * The currently pressed mouse button. See {@link R.engine.Events} 76 * @type {Number} 77 */ 78 button:-1, 79 80 /** 81 * A vector indicating the direction and amount of mouse movement. 82 * @type {R.math.Vector2D} 83 */ 84 moveVec:null, 85 86 /** 87 * A normalized vector indicating the direction of mouse movement after a 88 * button was pressed and held. 89 * @type {R.math.Vector2D} 90 */ 91 dragVec:null, 92 93 /** 94 * The game object the mouse is currently over 95 * @type {R.engine.GameObject} 96 */ 97 lastOver:null, 98 99 /** @private */ 100 moveTimer:null, 101 102 /** @private */ 103 constructor:function () { 104 this.position = R.math.Point2D.create(0, 0); 105 this.lastPosition = R.math.Point2D.create(0, 0); 106 this.downPosition = R.math.Point2D.create(0, 0); 107 this.button = R.engine.Events.MOUSE_NO_BUTTON; 108 this.moveVec = R.math.Vector2D.create(0, 0); 109 this.dragVec = R.math.Vector2D.create(0, 0); 110 this.lastOver = null; 111 this.moveTimer = null; 112 this.base(arguments[0] || "MouseInfo"); 113 }, 114 115 /** 116 * Destroy the collision data object. 117 */ 118 destroy:function () { 119 this.position.destroy(); 120 this.lastPosition.destroy(); 121 this.downPosition.destroy(); 122 this.moveVec.destroy(); 123 this.dragVec.destroy(); 124 this.base(); 125 }, 126 127 /** 128 * Release the collision data object back into the pool for reuse. 129 */ 130 release:function () { 131 this.base(); 132 this.position = null; 133 this.lastPosition = null; 134 this.downPosition = null; 135 this.button = -1 136 this.moveVec = null; 137 this.dragVec = null; 138 this.lastOver = null; 139 this.moveTimer = null; 140 } 141 142 }, { 143 getClassName:function () { 144 return "R.struct.MouseInfo"; 145 } 146 }); 147 }; 148 149