touchcontroller
Advanced tools
Comparing version 0.5.1 to 0.5.2
import Touch from '../Touch'; | ||
import TouchFrame from '../TouchFrame'; | ||
export default interface IListener { | ||
(element: HTMLElement, newTouch: (touch: Touch) => void): () => void; | ||
(element: HTMLElement, newTouch: (touch: Touch) => void, newHoverFrame: (frame: TouchFrame) => void): () => void; | ||
} |
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/share'; | ||
import TouchController from './TouchController'; | ||
import Touch from './Touch'; | ||
import MultiTouch from './MultiTouch'; | ||
import Vector2 from './Vector2'; | ||
export default class MultiTouchController<TElement> { | ||
private _touchController; | ||
touchController: TouchController; | ||
private _elementBinder; | ||
@@ -13,4 +12,5 @@ ongoingMultiTouches: MultiTouch<TElement | undefined>[]; | ||
private _multiTouchesObserver; | ||
constructor(_touchController: TouchController, _elementBinder: (position: Vector2) => TElement | undefined); | ||
emulateTouch(touch: Touch): void; | ||
constructor(touchController: TouchController, _elementBinder: (position: Vector2) => TElement | undefined); | ||
readonly hoveredElements: Observable<TElement | undefined>; | ||
readonly hoveredElementsChanges: Observable<[TElement | undefined, TElement | undefined]>; | ||
} |
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/share'; | ||
import Touch from './Touch'; | ||
import TouchFrame from './TouchFrame'; | ||
import IListener from './listeners/IListener'; | ||
@@ -8,3 +9,5 @@ export default class TouchController { | ||
touches: Observable<Touch>; | ||
hoveredFrames: Observable<TouchFrame>; | ||
private _touchesObserver; | ||
private _hoveredFramesObserver; | ||
constructor(element: HTMLElement, setListeners?: boolean); | ||
@@ -11,0 +14,0 @@ addListener(listener: IListener): void; |
{ | ||
"name": "touchcontroller", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Touch and mouse controller for web apps and games", | ||
@@ -5,0 +5,0 @@ "main": "./dist/touchcontroller.js", |
@@ -11,2 +11,3 @@ import IListener from './IListener'; | ||
newTouch: (touch: Touch) => void, | ||
newHoverFrame: (frame: TouchFrame)=>void | ||
) => { | ||
@@ -70,2 +71,6 @@ | ||
//} | ||
}else{ | ||
if(isNull(currentTouch)) { | ||
newHoverFrame(_createTouchFrameFromEvent(event)); | ||
} | ||
} | ||
@@ -72,0 +77,0 @@ } |
@@ -17,3 +17,4 @@ import IListener from './IListener'; | ||
return (element: HTMLElement, | ||
newTouch: (touch: Touch) => void | ||
newTouch: (touch: Touch) => void, | ||
newHoverFrame: (frame: TouchFrame)=>void | ||
) => { | ||
@@ -71,3 +72,3 @@ | ||
}); | ||
},newHoverFrame); | ||
@@ -74,0 +75,0 @@ |
@@ -10,3 +10,4 @@ import IListener from './IListener'; | ||
return (element: HTMLElement, | ||
newTouch: (touch: Touch) => void,) => { | ||
newTouch: (touch: Touch) => void, | ||
newHoverFrame: (frame: TouchFrame) => void) => { | ||
@@ -35,3 +36,3 @@ element.addEventListener( | ||
let currentTouches: {[identifier: number]: Touch} = {}; | ||
let currentTouches: { [identifier: number]: Touch } = {}; | ||
@@ -56,3 +57,3 @@ | ||
for (let i = 0, l = touches.length; i < l; i++) { | ||
const currentTouch = currentTouches[touches[i].identifier]||null; | ||
const currentTouch = currentTouches[touches[i].identifier] || null; | ||
if (!isNull(currentTouch)) { | ||
@@ -71,3 +72,3 @@ currentTouch.move( | ||
for (let i = 0, l = touches.length; i < l; i++) { | ||
const currentTouch = currentTouches[touches[i].identifier]||null; | ||
const currentTouch = currentTouches[touches[i].identifier] || null; | ||
if (!isNull(currentTouch)) { | ||
@@ -83,3 +84,3 @@ currentTouch.move( | ||
function _createTouchFrameFromEvent(event: {clientX:number; clientY:number;}) { | ||
function _createTouchFrameFromEvent(event: { clientX: number; clientY: number; }) { | ||
return new TouchFrame( | ||
@@ -86,0 +87,0 @@ new Vector2( |
import Touch from '../Touch'; | ||
import TouchFrame from '../TouchFrame'; | ||
@@ -12,4 +13,5 @@ /*export default interface IListener{ | ||
element: HTMLElement, | ||
newTouch: (touch: Touch)=>void | ||
newTouch: (touch: Touch)=>void, | ||
newHoverFrame: (frame: TouchFrame)=>void, | ||
): ()=>void; | ||
} |
@@ -5,3 +5,2 @@ import {Observable} from 'rxjs/Observable'; | ||
import TouchController from './TouchController'; | ||
import Touch from './Touch'; | ||
import MultiTouch from './MultiTouch'; | ||
@@ -12,7 +11,7 @@ import Vector2 from './Vector2'; | ||
public ongoingMultiTouches: MultiTouch<TElement | undefined>[] = []; | ||
public ongoingMultiTouches: MultiTouch<TElement | undefined>[] = [];//todo null vs. undefined | ||
public multiTouches: Observable<MultiTouch<TElement | undefined>>; | ||
private _multiTouchesObserver: Observer<MultiTouch<TElement | undefined>>; | ||
constructor(private _touchController: TouchController, | ||
constructor(public touchController: TouchController, | ||
private _elementBinder: (position: Vector2) => TElement | undefined) { | ||
@@ -24,3 +23,3 @@ | ||
this._touchController.touches.subscribe((touch) => { | ||
this.touchController.touches.subscribe((touch) => { | ||
@@ -56,6 +55,25 @@ const element = this._elementBinder(touch.firstFrame.position); | ||
emulateTouch(touch: Touch){ | ||
this._touchController.emulateTouch(touch); | ||
get hoveredElements(): Observable<TElement|undefined>{ | ||
return Observable.create((observer: Observer<TElement|undefined>) => { | ||
this.touchController.hoveredFrames.subscribe((frame) => { | ||
observer.next(this._elementBinder(frame.position)); | ||
}); | ||
}); | ||
} | ||
get hoveredElementsChanges(): Observable<[TElement|undefined,TElement|undefined]>{ | ||
return Observable.create((observer: Observer<[TElement|undefined,TElement|undefined]>) => { | ||
let lastElement: TElement|undefined; | ||
this.hoveredElements.subscribe((thisElement) => { | ||
if(lastElement!==thisElement){ | ||
observer.next([thisElement,lastElement]); | ||
lastElement = thisElement; | ||
} | ||
}); | ||
}); | ||
} | ||
//todo dispose | ||
@@ -62,0 +80,0 @@ |
@@ -5,2 +5,3 @@ import {Observable} from 'rxjs/Observable'; | ||
import Touch from './Touch'; | ||
import TouchFrame from './TouchFrame'; | ||
import IListener from './listeners/IListener'; | ||
@@ -13,5 +14,6 @@ import * as listeners from './listeners/'; | ||
public touches: Observable<Touch>; | ||
//public hover: Touch; | ||
public hoveredFrames: Observable<TouchFrame>; | ||
//private _touchesAutoIncrement: number = 0; | ||
private _touchesObserver: Observer<Touch>; | ||
private _hoveredFramesObserver: Observer<TouchFrame>; | ||
//private _ongoingTouches: Touch[] = []; | ||
@@ -35,2 +37,6 @@ | ||
this.hoveredFrames = Observable.create((observer: Observer<TouchFrame>) => { | ||
this._hoveredFramesObserver = observer; | ||
}).share(); | ||
if(setListeners){ | ||
@@ -48,3 +54,4 @@ this.addListener(listeners.createMouseListener()); | ||
this.element, | ||
(touch: Touch)=>this._touchesObserver.next(touch) | ||
(touch: Touch)=>this._touchesObserver.next(touch), | ||
(frame: TouchFrame)=>this._hoveredFramesObserver.next(frame) | ||
); | ||
@@ -51,0 +58,0 @@ //todo array of listeners disposers |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
671683
8229