-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ece646e
commit 6405f4c
Showing
10 changed files
with
213 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var Contains = function (x, y) { | ||
x -= this.x; | ||
y -= this.y; | ||
return this.geom.contains(x, y); | ||
} | ||
|
||
export default Contains; |
19 changes: 19 additions & 0 deletions
19
plugins/utils/mask/defaultmaskgraphics/methods/DrawShape.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import GetGeom from './GetGeom.js'; | ||
|
||
var DrawShape = function (width, height, padding, originX, originY) { | ||
this.geom = GetGeom(this.shapeType, width, height, padding, originX, originY, this.geom); | ||
|
||
this.clear().fillStyle(0xffffff); | ||
switch (this.shapeType) { | ||
case 1: // circle | ||
// Assume that all padding are the same value in this circle shape | ||
this.fillCircleShape(this.geom); | ||
break; | ||
|
||
default: // 0|'rectangle' | ||
this.fillRectShape(this.geom); | ||
break; | ||
} | ||
} | ||
|
||
export default DrawShape; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const RectangleGeom = Phaser.Geom.Rectangle; | ||
const CircleGemo = Phaser.Geom.Circle; | ||
|
||
var GetGeom = function (shapeType, width, height, padding, originX, originY, out) { | ||
switch (shapeType) { | ||
case 1: // circle | ||
// Assume that all padding are the same value in this circle shape | ||
padding = padding.left; | ||
var centerX = -width * (originX - 0.5); | ||
var centerY = -height * (originY - 0.5); | ||
var radius = Math.min(width, height) / 2 + padding; | ||
|
||
if ((out === undefined) || !(out instanceof (CircleGemo))) { | ||
out = new CircleGemo(); | ||
} | ||
out.setTo(centerX, centerY, radius); | ||
break; | ||
|
||
default: // 0|'rectangle' | ||
var topLeftX = -(width * originX) - padding.left; | ||
var topLeftY = -(height * originY) - padding.top; | ||
var rectWidth = width + padding.left + padding.right; | ||
var rectHeight = height + padding.top + padding.bottom; | ||
|
||
if ((out === undefined) || !(out instanceof (RectangleGeom))) { | ||
out = new RectangleGeom(); | ||
} | ||
out.setTo(topLeftX, topLeftY, rectWidth, rectHeight); | ||
break; | ||
} | ||
|
||
return out; | ||
} | ||
|
||
export default GetGeom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import SetPosition from './SetPosition.js'; | ||
import Resize from './Resize.js'; | ||
import SetOrigin from './SetOrigin.js'; | ||
import Contains from './Contains.js'; | ||
|
||
var Methods = { | ||
setPosition: SetPosition, | ||
resize: Resize, | ||
setOrigin: SetOrigin, | ||
contains: Contains, | ||
} | ||
|
||
export default Methods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import DrawShape from './DrawShape.js'; | ||
import IsKeyValueEqual from '../../../object/IsKeyValueEqual.js'; | ||
import Clone from '../../../object/Clone.js'; | ||
|
||
var Resize = function (width, height, padding) { | ||
var parent = this.parent; | ||
if (width === undefined) { | ||
width = parent.width; | ||
} | ||
if (height === undefined) { | ||
height = parent.height; | ||
} | ||
|
||
if (padding === undefined) { | ||
padding = this.padding; | ||
} else if (typeof (padding) === 'number') { | ||
padding = GetBoundsConfig(padding); | ||
} | ||
|
||
var isSizeChanged = (this.width !== width) || (this.height !== height); | ||
var isPaddingChanged = (this.padding !== padding) && !IsKeyValueEqual(this.padding, padding); | ||
if (!isSizeChanged && !isPaddingChanged) { | ||
return this; | ||
} | ||
|
||
this.width = width; | ||
this.height = height; | ||
|
||
if (isPaddingChanged) { | ||
Clone(padding, this.padding); | ||
} | ||
|
||
// Graphics does not have originX, originY properties | ||
this.originX = parent.originX; | ||
this.originY = parent.originY; | ||
|
||
DrawShape.call(this, | ||
width, height, padding, | ||
parent.originX, parent.originY | ||
); | ||
|
||
return this; | ||
} | ||
|
||
export default Resize; |
29 changes: 29 additions & 0 deletions
29
plugins/utils/mask/defaultmaskgraphics/methods/SetOrigin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import DrawShape from './DrawShape.js'; | ||
|
||
var SetOrigin = function (originX, originY) { | ||
if (originY === undefined) { | ||
originY = originX; | ||
} | ||
|
||
var parent = this.parent; | ||
if (originX === undefined) { | ||
originX = parent.originX; | ||
} | ||
if (originY === undefined) { | ||
originY = parent.originY; | ||
} | ||
if ((this.originX === originX) && (this.originY === originY)) { | ||
return this; | ||
} | ||
|
||
this.originX = originX; | ||
this.originY = originY; | ||
|
||
DrawShape.call(this, | ||
this.width, this.height, this.padding, | ||
originX, originY, | ||
); | ||
return this; | ||
} | ||
|
||
export default SetOrigin; |
Oops, something went wrong.