| 18 | * @implements ScaledEntity |
| 19 | */ |
| 20 | export class Anchor extends ScaledEntity { |
| 21 | /** |
| 22 | * Creates an instance of Anchor. |
| 23 | * @param {object} param |
| 24 | * @param {Point} param.position |
| 25 | * @param {Point} [param.direction= {x: -1, y: -1}] |
| 26 | * @param {PositionCallback} param.callback |
| 27 | * @memberof Anchor |
| 28 | */ |
| 29 | constructor({ |
| 30 | position, |
| 31 | direction, |
| 32 | callback = () => Debugger.log('warn', this, 'Anchor missing callback') |
| 33 | } = {}) { |
| 34 | super(); |
| 35 | this.position = position || { x: 0, y: 0 }; |
| 36 | this.direction = direction || { x: -1, y: -1 }; |
| 37 | this.callback = callback; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param {object} param |
| 42 | * @param {Point} param.viewArea |
| 43 | * @return {void} @memberof Anchor |
| 44 | */ |
| 45 | onResize({ viewArea }) { |
| 46 | const halfWidth = viewArea.width * 0.5; |
| 47 | const halfHeight = viewArea.height * 0.5; |
| 48 | |
| 49 | const centerX = viewArea.x + halfWidth; |
| 50 | const centerY = viewArea.y + halfHeight; |
| 51 | |
| 52 | const x = centerX + (this.direction.x * halfWidth) + this.position.x; |
| 53 | const y = centerY + (this.direction.y * halfHeight) + this.position.y; |
| 54 | |
| 55 | this.callback({ x, y }); |
| 56 | } |
| 57 | } |
nothing calls this directly
no outgoing calls
no test coverage detected