import { Point } from "./point" ; import { CropperSettings } from "../cropperSettings" ; export interface IHandle { over : boolean ; drag : boolean ; position : Point ; setPosition ( x , y ) : void ; offset : Point ; radius : number ; cropperSettings : CropperSettings ; setDrag ( value ) : void ; draw ( ctx ) : void ; setOver ( over ) : void ; touchInBounds ( x , y ) : boolean ; } export class Handle implements IHandle { public over : boolean ; public drag : boolean ; private _position : Point ; public offset : Point ; public radius : number ; public cropperSettings : CropperSettings = new CropperSettings ( ) ; constructor ( x , y , radius , settings ) { this . over = false ; this . drag = false ; this . _position = new Point ( x , y ) ; this . offset = new Point ( 0 , 0 ) ; this . radius = radius ; this . cropperSettings = settings ; } public setDrag ( value ) { this . drag = value ; this . setOver ( value ) ; } public draw ( ctx ) { } public setOver ( over ) { this . over = over ; } public touchInBounds ( x , y ) { return ( x > this . position . x - this . radius + this . offset . x && x < this . position . x + this . radius + this . offset . x && y > this . position . y - this . radius + this . offset . y && y < this . position . y + this . radius + this . offset . y ) ; } public get position ( ) : Point { return this . _position ; } public setPosition ( x , y ) { this . _position . x = x ; this . _position . y = y ; } }