Skip to content

Commit cca955f

Browse files
committed
Updated to latest version of Pixi.
1 parent ffb413b commit cca955f

28 files changed

Lines changed: 383 additions & 183 deletions

src/pixi/InteractionData.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author Mat Groves http://matgroves.com/ @Doormat23
33
*/
4-
4+
55
/**
66
* Holds all information related to an Interaction event
77
*
@@ -18,7 +18,7 @@ PIXI.InteractionData = function()
1818
*/
1919
this.global = new PIXI.Point();
2020

21-
21+
2222
/**
2323
* The target Sprite that was interacted with
2424
*
@@ -41,9 +41,10 @@ PIXI.InteractionData = function()
4141
*
4242
* @method getLocalPosition
4343
* @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off
44+
* @param [point] {Point} A Point object in which to store the value, optional (otherwise will create a new point)
4445
* @return {Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject
4546
*/
46-
PIXI.InteractionData.prototype.getLocalPosition = function(displayObject)
47+
PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point)
4748
{
4849
var worldTransform = displayObject.worldTransform;
4950
var global = this.global;
@@ -52,10 +53,15 @@ PIXI.InteractionData.prototype.getLocalPosition = function(displayObject)
5253
var a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx,
5354
a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty,
5455
id = 1 / (a00 * a11 + a01 * -a10);
56+
57+
point = point || new PIXI.Point();
58+
59+
point.x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id;
60+
point.y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id;
61+
5562
// set the mouse coords...
56-
return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
57-
a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id);
63+
return point;
5864
};
5965

6066
// constructor
61-
PIXI.InteractionData.prototype.constructor = PIXI.InteractionData;
67+
PIXI.InteractionData.prototype.constructor = PIXI.InteractionData;

src/pixi/InteractionManager.js

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -381,22 +381,29 @@ PIXI.InteractionManager.prototype.onMouseDown = function(event)
381381
//stage.__i
382382
var length = this.interactiveItems.length;
383383

384+
var e = this.mouse.originalEvent;
385+
var isRightButton = e.button === 2 || e.which === 3;
386+
var downFunction = isRightButton ? 'rightdown' : 'mousedown';
387+
var clickFunction = isRightButton ? 'rightclick' : 'click';
388+
var buttonIsDown = isRightButton ? '__rightIsDown' : '__mouseIsDown';
389+
var isDown = isRightButton ? '__isRightDown' : '__isDown';
390+
384391
// while
385392
// hit test
386393
for (var i = 0; i < length; i++)
387394
{
388395
var item = this.interactiveItems[i];
389396

390-
if(item.mousedown || item.click)
397+
if(item[downFunction] || item[clickFunction])
391398
{
392-
item.__mouseIsDown = true;
399+
item[buttonIsDown] = true;
393400
item.__hit = this.hitTest(item, this.mouse);
394401

395402
if(item.__hit)
396403
{
397404
//call the function!
398-
if(item.mousedown)item.mousedown(this.mouse);
399-
item.__isDown = true;
405+
if(item[downFunction])item[downFunction](this.mouse);
406+
item[isDown] = true;
400407

401408
// just the one!
402409
if(!item.interactiveChildren)break;
@@ -412,13 +419,15 @@ PIXI.InteractionManager.prototype.onMouseDown = function(event)
412419
* @param event {Event} The DOM event of a mouse button being moved out
413420
* @private
414421
*/
415-
PIXI.InteractionManager.prototype.onMouseOut = function()
422+
PIXI.InteractionManager.prototype.onMouseOut = function(event)
416423
{
417424
if(this.dirty)
418425
{
419426
this.rebuildInteractiveGraph();
420427
}
421428

429+
this.mouse.originalEvent = event || window.event; //IE uses window.event
430+
422431
var length = this.interactiveItems.length;
423432

424433
this.interactionDOMElement.style.cursor = 'inherit';
@@ -460,36 +469,46 @@ PIXI.InteractionManager.prototype.onMouseUp = function(event)
460469
var length = this.interactiveItems.length;
461470
var up = false;
462471

472+
var e = this.mouse.originalEvent;
473+
var isRightButton = e.button === 2 || e.which === 3;
474+
475+
var upFunction = isRightButton ? 'rightup' : 'mouseup';
476+
var clickFunction = isRightButton ? 'rightclick' : 'click';
477+
var upOutsideFunction = isRightButton ? 'rightupoutside' : 'mouseupoutside';
478+
var isDown = isRightButton ? '__isRightDown' : '__isDown';
479+
463480
for (var i = 0; i < length; i++)
464481
{
465482
var item = this.interactiveItems[i];
466483

467-
item.__hit = this.hitTest(item, this.mouse);
468-
469-
if(item.__hit && !up)
484+
if(item[clickFunction] || item[upFunction] || item[upOutsideFunction])
470485
{
471-
//call the function!
472-
if(item.mouseup)
486+
item.__hit = this.hitTest(item, this.mouse);
487+
488+
if(item.__hit && !up)
473489
{
474-
item.mouseup(this.mouse);
490+
//call the function!
491+
if(item[upFunction])
492+
{
493+
item[upFunction](this.mouse);
494+
}
495+
if(item[isDown])
496+
{
497+
if(item[clickFunction])item[clickFunction](this.mouse);
498+
}
499+
500+
if(!item.interactiveChildren)up = true;
475501
}
476-
if(item.__isDown)
502+
else
477503
{
478-
if(item.click)item.click(this.mouse);
504+
if(item[isDown])
505+
{
506+
if(item[upOutsideFunction])item[upOutsideFunction](this.mouse);
507+
}
479508
}
480509

481-
if(!item.interactiveChildren)up = true;
510+
item[isDown] = false;
482511
}
483-
else
484-
{
485-
if(item.__isDown)
486-
{
487-
if(item.mouseupoutside)item.mouseupoutside(this.mouse);
488-
}
489-
}
490-
491-
item.__isDown = false;
492-
//}
493512
}
494513
};
495514

@@ -596,7 +615,8 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event)
596615
// update the touch position
597616
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
598617
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
599-
if(navigator.isCocoonJS) {
618+
if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
619+
//Support for CocoonJS fullscreen scale modes
600620
touchData.global.x = touchEvent.clientX;
601621
touchData.global.y = touchEvent.clientY;
602622
}
@@ -640,7 +660,8 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
640660
this.touchs[touchEvent.identifier] = touchData;
641661
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
642662
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
643-
if(navigator.isCocoonJS) {
663+
if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
664+
//Support for CocoonJS fullscreen scale modes
644665
touchData.global.x = touchEvent.clientX;
645666
touchData.global.y = touchEvent.clientY;
646667
}
@@ -695,7 +716,8 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event)
695716
var up = false;
696717
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
697718
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
698-
if(navigator.isCocoonJS) {
719+
if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
720+
//Support for CocoonJS fullscreen scale modes
699721
touchData.global.x = touchEvent.clientX;
700722
touchData.global.y = touchEvent.clientY;
701723
}

src/pixi/core/Circle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ PIXI.Circle.prototype.contains = function(x, y)
7777
*/
7878
PIXI.Circle.prototype.getBounds = function()
7979
{
80-
return new PIXI.Rectangle(this.x - this.radius, this.y - this.radius, this.width, this.height);
80+
return new PIXI.Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
8181
};
8282

8383
// constructor

src/pixi/core/Matrix.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,45 @@ PIXI.Matrix.prototype.toArray = function(transpose)
7878
return array;
7979
};
8080

81+
/**
82+
* Get a new position with the current transormation applied.
83+
* Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
84+
*
85+
* @method apply
86+
* @param pos {Point} The origin
87+
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
88+
* @return {Point} The new point, transformed trough this matrix
89+
*/
90+
PIXI.Matrix.prototype.apply = function(pos, newPos)
91+
{
92+
newPos = newPos || new PIXI.Point();
93+
94+
newPos.x = this.a * pos.x + this.b * pos.y + this.tx;
95+
newPos.y = this.c * pos.x + this.d * pos.y + this.ty;
96+
97+
return newPos;
98+
};
99+
100+
/**
101+
* Get a new position with the inverse of the current transormation applied.
102+
* Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
103+
*
104+
* @method apply
105+
* @param pos {Point} The origin
106+
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
107+
* @return {Point} The new point, inverse-transformed trough this matrix
108+
*/
109+
PIXI.Matrix.prototype.applyInverse = function(pos, newPos)
110+
{
111+
newPos = newPos || new PIXI.Point();
112+
113+
var id = 1 / (this.a * this.d + this.b * -this.c);
114+
newPos.x = this.d * id * pos.x - this.b * id * pos.y + (this.ty * this.b - this.tx * this.d) * id;
115+
newPos.y = this.a * id * pos.y - this.c * id * pos.x + (this.tx * this.c - this.ty * this.a) * id;
116+
117+
return newPos;
118+
};
119+
81120
PIXI.identityMatrix = new PIXI.Matrix();
82121

83122
PIXI.determineMatrixArrayType = function() {

0 commit comments

Comments
 (0)