Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1345] Fix typing on pointer event handlers #1347

Merged
merged 4 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fixed actors being drawn when their opacity is 0 ([#875](https://github.com/excaliburjs/Excalibur/issues/875))
- Fixed iframe event handling, excalibur will respond to keyboard events from the top window ([#1294](https://github.com/excaliburjs/Excalibur/issues/1294))
- Fixed camera to be vector backed so `ex.Camera.x = ?` and `ex.Camera.pos.setTo(...)` both work as expected([#1299](https://github.com/excaliburjs/Excalibur/issues/1299))
- Fixed missing on/once/off signatures on `ex.Pointer` ([#1345](https://github.com/excaliburjs/Excalibur/issues/1345))

<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
Expand Down
32 changes: 28 additions & 4 deletions src/engine/Input/Pointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Vector } from '../Algebra';
import { Class } from '../Class';
import * as Actors from '../Util/Actors';
import { removeItemFromArray } from '../Util/Util';
import { PointerEvent } from './PointerEvents';
import { PointerMoveEvent, PointerDownEvent, PointerUpEvent, WheelEvent } from './PointerEvents';

export interface ActorsUnderPointer {
[ActorId: number]: Actor;
Expand Down Expand Up @@ -107,6 +107,30 @@ export class Pointer extends Class {
this.on('up', this._onPointerUp);
}

on(event: 'move', handler: (event: PointerMoveEvent) => void): void;
on(event: 'down', handler: (event: PointerDownEvent) => void): void;
on(event: 'up', handler: (event: PointerUpEvent) => void): void;
on(event: 'wheel', handler: (event: WheelEvent) => void): void;
on(event: string, handler: (event: any) => void): void {
super.on(event, handler);
}

once(event: 'move', handler: (event: PointerMoveEvent) => void): void;
once(event: 'down', handler: (event: PointerDownEvent) => void): void;
once(event: 'up', handler: (event: PointerUpEvent) => void): void;
once(event: 'wheel', handler: (event: WheelEvent) => void): void;
once(event: string, handler: (event: any) => void): void {
super.once(event, handler);
}

off(event: 'move', handler?: (event: PointerMoveEvent) => void): void;
off(event: 'down', handler?: (event: PointerDownEvent) => void): void;
off(event: 'up', handler?: (event: PointerUpEvent) => void): void;
off(event: 'wheel', handler?: (event: WheelEvent) => void): void;
off(event: string, handler?: (event: any) => void): void {
super.off(event, handler);
}

/**
* Update the state of current pointer, meant to be called a the end of frame
*/
Expand Down Expand Up @@ -203,20 +227,20 @@ export class Pointer extends Class {
return this._actorsUnderPointer.hasOwnProperty(actor.id.toString());
}

private _onPointerMove(ev: PointerEvent): void {
private _onPointerMove(ev: PointerMoveEvent): void {
this.lastPagePos = new Vector(ev.pagePos.x, ev.pagePos.y);
this.lastScreenPos = new Vector(ev.screenPos.x, ev.screenPos.y);
this.lastWorldPos = new Vector(ev.worldPos.x, ev.worldPos.y);
}

private _onPointerDown(ev: PointerEvent): void {
private _onPointerDown(ev: PointerDownEvent): void {
this.lastPagePos = new Vector(ev.pagePos.x, ev.pagePos.y);
this.lastScreenPos = new Vector(ev.screenPos.x, ev.screenPos.y);
this.lastWorldPos = new Vector(ev.worldPos.x, ev.worldPos.y);
this._isDown = true;
}

private _onPointerUp(): void {
private _onPointerUp(_ev: PointerUpEvent): void {
this._isDown = false;
this.dragTarget = null;
}
Expand Down