refactor: forward key events

This commit is contained in:
cha0s 2019-05-23 04:56:37 -05:00
parent 5df58532dc
commit f3a82e9385

View File

@ -44,6 +44,8 @@ export class Stage extends decorate(Container) {
// Normalize input.
this.inputNormalizer = new InputNormalizer();
this.inputNormalizer.listen(this.element);
this.inputNormalizer.on('keyDown', this.onKeyDown, this);
this.inputNormalizer.on('keyUp', this.onKeyUp, this);
this.inputNormalizer.on('pointerDown', this.onPointerDown, this);
this.inputNormalizer.on('pointerMove', this.onPointerMove, this);
this.inputNormalizer.on('pointerUp', this.onPointerUp, this);
@ -86,9 +88,11 @@ export class Stage extends decorate(Container) {
if (this.parent) {
this.parent.removeChild(this.renderer.element);
}
this.inputNormalizer.off('pointerDown', this.onPointerDown, this);
this.inputNormalizer.off('pointerMove', this.onPointerMove, this);
this.inputNormalizer.off('pointerUp', this.onPointerUp, this);
this.inputNormalizer.off('keyDown', this.onKeyDown);
this.inputNormalizer.off('keyUp', this.onKeyUp);
this.inputNormalizer.off('pointerDown', this.onPointerDown);
this.inputNormalizer.off('pointerMove', this.onPointerMove);
this.inputNormalizer.off('pointerUp', this.onPointerUp);
this.inputNormalizer.destroy();
}
@ -128,6 +132,14 @@ export class Stage extends decorate(Container) {
this.element.focus();
}
onKeyDown(event) {
this.emit('keyDown', event);
}
onKeyUp(event) {
this.emit('keyUp', event);
}
onPointerDown(event) {
event.position = this.transformCanvasPosition(event.position);
this.emit('pointerDown', event);