Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @method rebuildInteractiveGraph
- * @private
- */
- PIXI.InteractionManager.prototype.rebuildInteractiveGraph = function()
- {
- this.dirty = false;
- var len = this.interactiveItems.length;
- for (var i = 0; i < len; i++) {
- this.interactiveItems[i].interactiveChildren = false;
- }
- this.interactiveItems = [];
- // Go through and collect all the objects that are interactive..
- this.collectInteractiveSprite(this.stage, this.stage);
- if (this.stage.interactive)
- {
- this.interactiveItems.push(this.stage);
- }
- };
- PIXI.InteractionData.prototype.stopped = false;
- PIXI.InteractionData.prototype.stopPropagation = function() {
- this.stopped = true;
- };
- /**
- * Is called when the mouse moves across the renderer element
- *
- * @method onMouseMove
- * @param event {Event} The DOM event of the mouse moving
- * @private
- */
- PIXI.InteractionManager.prototype.onMouseMove = function(event)
- {
- if (this.dirty)
- {
- this.rebuildInteractiveGraph();
- }
- this.mouse.originalEvent = event;
- // TODO optimize by not check EVERY TIME! maybe half as often? //
- var rect = this.interactionDOMElement.getBoundingClientRect();
- this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width) / this.resolution;
- this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height) / this.resolution;
- var length = this.interactiveItems.length;
- for (var i = 0; i < length; i++)
- {
- var item = this.interactiveItems[i];
- // Call the function!
- if (item.mousemove)
- {
- item.mousemove(this.mouse);
- if (this.mouse.stopped) break;
- }
- }
- };
- /**
- * Is called when the mouse button is pressed down on the renderer element
- *
- * @method onMouseDown
- * @param event {Event} The DOM event of a mouse button being pressed down
- * @private
- */
- PIXI.InteractionManager.prototype.onMouseDown = function(event)
- {
- if (this.dirty)
- {
- this.rebuildInteractiveGraph();
- }
- this.mouse.originalEvent = event;
- if (PIXI.AUTO_PREVENT_DEFAULT)
- {
- this.mouse.originalEvent.preventDefault();
- }
- // loop through interaction tree...
- // hit test each item! ->
- // get interactive items under point??
- //stage.__i
- var length = this.interactiveItems.length;
- var e = this.mouse.originalEvent;
- var isRightButton = e.button === 2 || e.which === 3;
- var downFunction = isRightButton ? 'rightdown' : 'mousedown';
- var clickFunction = isRightButton ? 'rightclick' : 'click';
- var buttonIsDown = isRightButton ? '__rightIsDown' : '__mouseIsDown';
- var isDown = isRightButton ? '__isRightDown' : '__isDown';
- // while
- // hit test
- for (var i = 0; i < length; i++)
- {
- var item = this.interactiveItems[i];
- if (item[downFunction] || item[clickFunction])
- {
- item[buttonIsDown] = true;
- item.__hit = this.hitTest(item, this.mouse);
- if (item.__hit)
- {
- //call the function!
- if (item[downFunction])
- {
- item[downFunction](this.mouse);
- }
- item[isDown] = true;
- if (this.mouse.stopped) break;
- }
- }
- }
- };
- /**
- * Is called when the mouse is moved out of the renderer element
- *
- * @method onMouseOut
- * @param event {Event} The DOM event of a mouse being moved out
- * @private
- */
- PIXI.InteractionManager.prototype.onMouseOut = function(event)
- {
- if (this.dirty)
- {
- this.rebuildInteractiveGraph();
- }
- this.mouse.originalEvent = event;
- var length = this.interactiveItems.length;
- this.interactionDOMElement.style.cursor = 'inherit';
- for (var i = 0; i < length; i++)
- {
- var item = this.interactiveItems[i];
- if (item.__isOver)
- {
- this.mouse.target = item;
- if (item.mouseout)
- {
- item.mouseout(this.mouse);
- if (this.mouse.stopped) break;
- }
- item.__isOver = false;
- }
- }
- this.mouseOut = true;
- // move the mouse to an impossible position
- this.mouse.global.x = -10000;
- this.mouse.global.y = -10000;
- };
- /**
- * Is called when the mouse button is released on the renderer element
- *
- * @method onMouseUp
- * @param event {Event} The DOM event of a mouse button being released
- * @private
- */
- PIXI.InteractionManager.prototype.onMouseUp = function(event)
- {
- if (this.dirty)
- {
- this.rebuildInteractiveGraph();
- }
- this.mouse.originalEvent = event;
- var length = this.interactiveItems.length;
- var up = false;
- var e = this.mouse.originalEvent;
- var isRightButton = e.button === 2 || e.which === 3;
- var upFunction = isRightButton ? 'rightup' : 'mouseup';
- var clickFunction = isRightButton ? 'rightclick' : 'click';
- var upOutsideFunction = isRightButton ? 'rightupoutside' : 'mouseupoutside';
- var isDown = isRightButton ? '__isRightDown' : '__isDown';
- for (var i = 0; i < length; i++)
- {
- var item = this.interactiveItems[i];
- if (item[clickFunction] || item[upFunction] || item[upOutsideFunction])
- {
- item.__hit = this.hitTest(item, this.mouse);
- if (item.__hit && !up)
- {
- //call the function!
- if (item[upFunction])
- {
- item[upFunction](this.mouse);
- }
- if (item[isDown])
- {
- if (item[clickFunction])
- {
- item[clickFunction](this.mouse);
- }
- }
- if (!item.interactiveChildren)
- {
- up = true;
- }
- }
- else
- {
- if (item[isDown])
- {
- if (item[upOutsideFunction]) item[upOutsideFunction](this.mouse);
- }
- }
- item[isDown] = false;
- if (this.mouse.stopped) break;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement