Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. /**
  2. * @method rebuildInteractiveGraph
  3. * @private
  4. */
  5. PIXI.InteractionManager.prototype.rebuildInteractiveGraph = function()
  6. {
  7. this.dirty = false;
  8.  
  9. var len = this.interactiveItems.length;
  10.  
  11. for (var i = 0; i < len; i++) {
  12. this.interactiveItems[i].interactiveChildren = false;
  13. }
  14.  
  15. this.interactiveItems = [];
  16.  
  17. // Go through and collect all the objects that are interactive..
  18. this.collectInteractiveSprite(this.stage, this.stage);
  19.  
  20. if (this.stage.interactive)
  21. {
  22. this.interactiveItems.push(this.stage);
  23. }
  24. };
  25.  
  26. PIXI.InteractionData.prototype.stopped = false;
  27.  
  28. PIXI.InteractionData.prototype.stopPropagation = function() {
  29. this.stopped = true;
  30. };
  31.  
  32. /**
  33. * Is called when the mouse moves across the renderer element
  34. *
  35. * @method onMouseMove
  36. * @param event {Event} The DOM event of the mouse moving
  37. * @private
  38. */
  39. PIXI.InteractionManager.prototype.onMouseMove = function(event)
  40. {
  41. if (this.dirty)
  42. {
  43. this.rebuildInteractiveGraph();
  44. }
  45.  
  46. this.mouse.originalEvent = event;
  47.  
  48. // TODO optimize by not check EVERY TIME! maybe half as often? //
  49. var rect = this.interactionDOMElement.getBoundingClientRect();
  50.  
  51. this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width) / this.resolution;
  52. this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height) / this.resolution;
  53.  
  54. var length = this.interactiveItems.length;
  55.  
  56. for (var i = 0; i < length; i++)
  57. {
  58. var item = this.interactiveItems[i];
  59.  
  60. // Call the function!
  61. if (item.mousemove)
  62. {
  63. item.mousemove(this.mouse);
  64.  
  65. if (this.mouse.stopped) break;
  66. }
  67. }
  68. };
  69.  
  70. /**
  71. * Is called when the mouse button is pressed down on the renderer element
  72. *
  73. * @method onMouseDown
  74. * @param event {Event} The DOM event of a mouse button being pressed down
  75. * @private
  76. */
  77. PIXI.InteractionManager.prototype.onMouseDown = function(event)
  78. {
  79. if (this.dirty)
  80. {
  81. this.rebuildInteractiveGraph();
  82. }
  83.  
  84. this.mouse.originalEvent = event;
  85.  
  86. if (PIXI.AUTO_PREVENT_DEFAULT)
  87. {
  88. this.mouse.originalEvent.preventDefault();
  89. }
  90.  
  91. // loop through interaction tree...
  92. // hit test each item! ->
  93. // get interactive items under point??
  94. //stage.__i
  95. var length = this.interactiveItems.length;
  96.  
  97. var e = this.mouse.originalEvent;
  98. var isRightButton = e.button === 2 || e.which === 3;
  99. var downFunction = isRightButton ? 'rightdown' : 'mousedown';
  100. var clickFunction = isRightButton ? 'rightclick' : 'click';
  101. var buttonIsDown = isRightButton ? '__rightIsDown' : '__mouseIsDown';
  102. var isDown = isRightButton ? '__isRightDown' : '__isDown';
  103.  
  104. // while
  105. // hit test
  106. for (var i = 0; i < length; i++)
  107. {
  108. var item = this.interactiveItems[i];
  109.  
  110. if (item[downFunction] || item[clickFunction])
  111. {
  112. item[buttonIsDown] = true;
  113. item.__hit = this.hitTest(item, this.mouse);
  114.  
  115. if (item.__hit)
  116. {
  117. //call the function!
  118. if (item[downFunction])
  119. {
  120. item[downFunction](this.mouse);
  121. }
  122. item[isDown] = true;
  123.  
  124. if (this.mouse.stopped) break;
  125. }
  126. }
  127. }
  128. };
  129.  
  130. /**
  131. * Is called when the mouse is moved out of the renderer element
  132. *
  133. * @method onMouseOut
  134. * @param event {Event} The DOM event of a mouse being moved out
  135. * @private
  136. */
  137. PIXI.InteractionManager.prototype.onMouseOut = function(event)
  138. {
  139. if (this.dirty)
  140. {
  141. this.rebuildInteractiveGraph();
  142. }
  143.  
  144. this.mouse.originalEvent = event;
  145.  
  146. var length = this.interactiveItems.length;
  147.  
  148. this.interactionDOMElement.style.cursor = 'inherit';
  149.  
  150. for (var i = 0; i < length; i++)
  151. {
  152. var item = this.interactiveItems[i];
  153. if (item.__isOver)
  154. {
  155. this.mouse.target = item;
  156. if (item.mouseout)
  157. {
  158. item.mouseout(this.mouse);
  159.  
  160. if (this.mouse.stopped) break;
  161. }
  162. item.__isOver = false;
  163. }
  164. }
  165.  
  166. this.mouseOut = true;
  167.  
  168. // move the mouse to an impossible position
  169. this.mouse.global.x = -10000;
  170. this.mouse.global.y = -10000;
  171. };
  172.  
  173. /**
  174. * Is called when the mouse button is released on the renderer element
  175. *
  176. * @method onMouseUp
  177. * @param event {Event} The DOM event of a mouse button being released
  178. * @private
  179. */
  180. PIXI.InteractionManager.prototype.onMouseUp = function(event)
  181. {
  182. if (this.dirty)
  183. {
  184. this.rebuildInteractiveGraph();
  185. }
  186.  
  187. this.mouse.originalEvent = event;
  188.  
  189. var length = this.interactiveItems.length;
  190. var up = false;
  191.  
  192. var e = this.mouse.originalEvent;
  193. var isRightButton = e.button === 2 || e.which === 3;
  194.  
  195. var upFunction = isRightButton ? 'rightup' : 'mouseup';
  196. var clickFunction = isRightButton ? 'rightclick' : 'click';
  197. var upOutsideFunction = isRightButton ? 'rightupoutside' : 'mouseupoutside';
  198. var isDown = isRightButton ? '__isRightDown' : '__isDown';
  199.  
  200. for (var i = 0; i < length; i++)
  201. {
  202. var item = this.interactiveItems[i];
  203.  
  204. if (item[clickFunction] || item[upFunction] || item[upOutsideFunction])
  205. {
  206. item.__hit = this.hitTest(item, this.mouse);
  207.  
  208. if (item.__hit && !up)
  209. {
  210. //call the function!
  211. if (item[upFunction])
  212. {
  213. item[upFunction](this.mouse);
  214. }
  215. if (item[isDown])
  216. {
  217. if (item[clickFunction])
  218. {
  219. item[clickFunction](this.mouse);
  220. }
  221. }
  222.  
  223. if (!item.interactiveChildren)
  224. {
  225. up = true;
  226. }
  227. }
  228. else
  229. {
  230. if (item[isDown])
  231. {
  232. if (item[upOutsideFunction]) item[upOutsideFunction](this.mouse);
  233. }
  234. }
  235.  
  236. item[isDown] = false;
  237.  
  238. if (this.mouse.stopped) break;
  239. }
  240. }
  241. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement