import { CanvasEngine } from "../CanvasEngine" ; import { Rectangle } from "../geometry/Rectangle" ; import { BaseEvent , BaseListener , BaseObject } from "@projectstorm/react-core" ; export interface DimensionTrackerListener extends BaseListener < DimensionTracker > { updated ( event ) ; } export class DimensionTracker extends BaseObject < DimensionTrackerListener > { realDimensions : Rectangle ; enableTracking : boolean ; constructor ( ) { super ( ) ; this . enableTracking = true ; this . realDimensions = new Rectangle ( ) ; } recompute ( canvasEngine , clientRect ) { this . realDimensions . updateDimensions ( clientRect . left , clientRect . top , clientRect . width , clientRect . height ) ; } updateDimensions ( canvasEngine , ClientRect ) { if ( ! this . enableTracking ) { return false ; } this . recompute ( canvasEngine , ClientRect ) ; this . iterateListeners ( "dimensions updated" , ( listener , event ) => { if ( listener . updated ) { listener . updated ( event ) ; } } ) ; } }