Prettified all files.
This commit is contained in:
+86
-58
@@ -9,30 +9,32 @@ import { InteractionMapper } from '../interaction.js'
|
||||
* on the same level.
|
||||
*/
|
||||
export class ScatterContainer extends PIXI.Graphics {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {PIXI.Renderer} renderer - PIXI renderer, needed for hit testing
|
||||
* @param {Bool} stopEvents - Whether events should be stopped or propagated
|
||||
* @param {Bool} claimEvents - Whether events should be marked as claimed
|
||||
* if findTarget return as non-null value.
|
||||
* @param {PIXI.Container} container - A container for the scatter
|
||||
* @param {Bool} showBounds - Show bounds for debugging purposes.
|
||||
* @param {Bool} showTouches - Show touches and pointer for debugging purposes.
|
||||
* @param {Color} backgroundColor - Set background color if specified.
|
||||
* @param {PIXIApp} app - Needed if showBounds is true to register
|
||||
* update handler.
|
||||
*/
|
||||
constructor(renderer, {
|
||||
stopEvents = true,
|
||||
claimEvents = true,
|
||||
container = null,
|
||||
showBounds = false,
|
||||
showPolygon = false,
|
||||
showTouches = false,
|
||||
backgroundColor = null,
|
||||
app = window.app
|
||||
} = {}) {
|
||||
* @constructor
|
||||
* @param {PIXI.Renderer} renderer - PIXI renderer, needed for hit testing
|
||||
* @param {Bool} stopEvents - Whether events should be stopped or propagated
|
||||
* @param {Bool} claimEvents - Whether events should be marked as claimed
|
||||
* if findTarget return as non-null value.
|
||||
* @param {PIXI.Container} container - A container for the scatter
|
||||
* @param {Bool} showBounds - Show bounds for debugging purposes.
|
||||
* @param {Bool} showTouches - Show touches and pointer for debugging purposes.
|
||||
* @param {Color} backgroundColor - Set background color if specified.
|
||||
* @param {PIXIApp} app - Needed if showBounds is true to register
|
||||
* update handler.
|
||||
*/
|
||||
constructor(
|
||||
renderer,
|
||||
{
|
||||
stopEvents = true,
|
||||
claimEvents = true,
|
||||
container = null,
|
||||
showBounds = false,
|
||||
showPolygon = false,
|
||||
showTouches = false,
|
||||
backgroundColor = null,
|
||||
app = window.app
|
||||
} = {}
|
||||
) {
|
||||
super()
|
||||
this.container = container
|
||||
if (this.container)
|
||||
@@ -53,7 +55,7 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
this.backgroundColor = backgroundColor
|
||||
if (showBounds || showTouches || showPolygon) {
|
||||
//console.log("Show TOUCHES!!!")
|
||||
this.app.ticker.add((delta) => this.update(delta), this)
|
||||
this.app.ticker.add(delta => this.update(delta), this)
|
||||
}
|
||||
if (backgroundColor) {
|
||||
this.updateBackground()
|
||||
@@ -77,8 +79,12 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
let y = 0
|
||||
// @container: We need to call the constant values, as the container
|
||||
// gets resized, when a child moves outside the original boundaries.
|
||||
let w = (this.container) ? this.containerDimensions.x : (this.backgroundWidth || this.app.width)
|
||||
let h = (this.container) ? this.containerDimensions.y : (this.backgroundHeight || this.app.height)
|
||||
let w = this.container
|
||||
? this.containerDimensions.x
|
||||
: this.backgroundWidth || this.app.width
|
||||
let h = this.container
|
||||
? this.containerDimensions.y
|
||||
: this.backgroundHeight || this.app.height
|
||||
|
||||
if (this.app.fullscreen && this.app.monkeyPatchMapping) {
|
||||
let fixed = this.mapPositionToPoint({ x: w, y: 0 })
|
||||
@@ -113,7 +119,7 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
|
||||
update(dt) {
|
||||
this.clear()
|
||||
this.lineStyle(1, 0x0000FF)
|
||||
this.lineStyle(1, 0x0000ff)
|
||||
if (this.showBounds) {
|
||||
for (let child of this.children) {
|
||||
if (child.scatter) {
|
||||
@@ -125,11 +131,11 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
this.drawCircle(child.scatter.x, child.scatter.y, 4)
|
||||
}
|
||||
}
|
||||
this.lineStyle(2, 0x0000FF)
|
||||
this.lineStyle(2, 0x0000ff)
|
||||
this.drawShape(this.bounds)
|
||||
}
|
||||
if (this.showPolygon) {
|
||||
this.lineStyle(2, 0xFF0000)
|
||||
this.lineStyle(2, 0xff0000)
|
||||
for (let child of this.children) {
|
||||
if (child.scatter) {
|
||||
let polygon = child.scatter.polygon
|
||||
@@ -149,8 +155,7 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
}
|
||||
|
||||
capture(event) {
|
||||
if (this.stopEvents)
|
||||
Events.stop(event)
|
||||
if (this.stopEvents) Events.stop(event)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -162,8 +167,14 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
// if (hit) {
|
||||
// console.log("findHitScatter", displayObject)
|
||||
// }
|
||||
if (hit && this.hitScatter === null && typeof (displayObject) != undefined) {
|
||||
this.hitScatter = (displayObject.scatter) ? displayObject.scatter : null
|
||||
if (
|
||||
hit &&
|
||||
this.hitScatter === null &&
|
||||
typeof displayObject != undefined
|
||||
) {
|
||||
this.hitScatter = displayObject.scatter
|
||||
? displayObject.scatter
|
||||
: null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +184,10 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
let local = new PIXI.Point()
|
||||
let interactionManager = this.renderer.plugins.interaction
|
||||
interactionManager.mapPositionToPoint(local, point.x, point.y)
|
||||
if (element instanceof DisplayObjectScatter && element.displayObject.parent != null) {
|
||||
if (
|
||||
element instanceof DisplayObjectScatter &&
|
||||
element.displayObject.parent != null
|
||||
) {
|
||||
return element.displayObject.parent.toLocal(local)
|
||||
}
|
||||
return local
|
||||
@@ -190,11 +204,13 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
this.hitScatter = null
|
||||
let interactionManager = this.renderer.plugins.interaction
|
||||
let fakeEvent = this.fakeInteractionEvent(local)
|
||||
interactionManager.processInteractive(fakeEvent,
|
||||
interactionManager.processInteractive(
|
||||
fakeEvent,
|
||||
this,
|
||||
this.findHitScatter.bind(this), true)
|
||||
if (this.claimEvents)
|
||||
event.claimedByScatter = this.hitScatter
|
||||
this.findHitScatter.bind(this),
|
||||
true
|
||||
)
|
||||
if (this.claimEvents) event.claimedByScatter = this.hitScatter
|
||||
return this.hitScatter
|
||||
}
|
||||
|
||||
@@ -209,19 +225,13 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
let displayObject = interactionManager.hitTest(local, this)
|
||||
if (displayObject != null && displayObject.scatter != null)
|
||||
this.hitScatter = displayObject.scatter
|
||||
if (this.claimEvents)
|
||||
event.claimedByScatter = this.hitScatter
|
||||
if (this.claimEvents) event.claimedByScatter = this.hitScatter
|
||||
return this.hitScatter
|
||||
}
|
||||
|
||||
onStart(event, interaction) {}
|
||||
|
||||
onStart(event, interaction) {
|
||||
|
||||
}
|
||||
|
||||
onMove(event, interaction) {
|
||||
|
||||
}
|
||||
onMove(event, interaction) {}
|
||||
|
||||
onEnd(event, interaction) {
|
||||
for (let key of interaction.ended.keys()) {
|
||||
@@ -253,7 +263,6 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
if (this.backgroundColor) {
|
||||
this.updateBackground()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,14 +271,20 @@ export class ScatterContainer extends PIXI.Graphics {
|
||||
* PIXI.DisplayObject can be wrapped.
|
||||
*/
|
||||
export class DisplayObjectScatter extends AbstractScatter {
|
||||
|
||||
constructor(displayObject, renderer,
|
||||
{ x = null, y = null,
|
||||
constructor(
|
||||
displayObject,
|
||||
renderer,
|
||||
{
|
||||
x = null,
|
||||
y = null,
|
||||
minScale = 0.1,
|
||||
maxScale = 1.0,
|
||||
startScale = 1.0,
|
||||
autoBringToFront = true,
|
||||
translatable = true, scalable = true, rotatable = true, resizable = false,
|
||||
translatable = true,
|
||||
scalable = true,
|
||||
rotatable = true,
|
||||
resizable = false,
|
||||
movableX = true,
|
||||
movableY = true,
|
||||
throwVisibility = 44,
|
||||
@@ -279,19 +294,29 @@ export class DisplayObjectScatter extends AbstractScatter {
|
||||
rotation = null,
|
||||
overdoScaling = 1.5,
|
||||
onTransform = null,
|
||||
onThrowFinished = null } = {}) {
|
||||
onThrowFinished = null
|
||||
} = {}
|
||||
) {
|
||||
// For the simulation of named parameters,
|
||||
// see: http://exploringjs.com/es6/ch_parameter-handling.html
|
||||
super({
|
||||
overdoScaling,
|
||||
minScale, maxScale,
|
||||
minScale,
|
||||
maxScale,
|
||||
startScale,
|
||||
autoBringToFront,
|
||||
translatable, scalable, rotatable, resizable,
|
||||
movableX, movableY, throwVisibility, throwDamping,
|
||||
translatable,
|
||||
scalable,
|
||||
rotatable,
|
||||
resizable,
|
||||
movableX,
|
||||
movableY,
|
||||
throwVisibility,
|
||||
throwDamping,
|
||||
autoThrow,
|
||||
onThrowFinished,
|
||||
rotationDegrees, rotation,
|
||||
rotationDegrees,
|
||||
rotation,
|
||||
onTransform
|
||||
})
|
||||
this.displayObject = displayObject
|
||||
@@ -458,7 +483,10 @@ export class DisplayObjectScatter extends AbstractScatter {
|
||||
if (this.displayObject.parent instanceof ScatterContainer) {
|
||||
let scatterContainer = this.displayObject.parent
|
||||
scatterContainer.bringToFront(this.displayObject)
|
||||
} else if (this.displayObject.parent != null && this.displayObject.parent.scatter) {
|
||||
} else if (
|
||||
this.displayObject.parent != null &&
|
||||
this.displayObject.parent.scatter
|
||||
) {
|
||||
this.displayObject.parent.scatter.toFront(this.displayObject)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user