import { NodeScene } from "../scene" ; import { Rect , Vector2 } from "./view" ; export class MouseEvent { globalX : number ; globalY : number ; localX : number ; localY : number ; mouseButton : number ; shiftKey = false ; altKey = false ; ctrlKey = false ; private accepted = true ; public accept ( ) { this . accepted = true ; } public reject ( ) { this . accepted = false ; } public get isAccepted ( ) { return this . accepted ; } public get isRejected ( ) { return ! this . accepted ; } } export class MouseDownEvent extends MouseEvent { } export class MouseMoveEvent extends MouseEvent { deltaX : number ; deltaY : number ; } export class MouseUpEvent extends MouseEvent { } export class MouseOverEvent extends MouseEvent { } export class HoverEvent extends MouseEvent { } export class GraphicsItem { scene ! : NodeScene ; protected visible = true ; protected x = 0 ; protected y = 0 ; protected width : number ; protected height : number ; public constructor ( ) { this . width = 1 ; this . height = 1 ; } public setPos ( x , y ) { this . x = x ; this . y = y ; } public getPos ( ) { return new Vector2 ( this . x , this . y ) ; } public setSize ( w , h ) { this . width = w ; this . height = h ; } public setScene ( scene ) { this . scene = scene ; } public isPointInside ( px , py ) { if ( px >= this . x && px <= this . x + this . width && py >= this . y && py <= this . y + this . height ) return true ; return false ; } public get left ( ) { return this . x ; } public set left ( value ) { this . x = value ; } public get top ( ) { return this . y ; } public set top ( value ) { this . y = value ; } public get right ( ) { return this . x + this . width ; } public get bottom ( ) { return this . y + this . height ; } public intersectsRect ( other ) { if ( this . left > other . right ) return false ; if ( this . right < other . left ) return false ; if ( this . bottom < other . top ) return false ; if ( this . top > other . bottom ) return false ; return true ; } public intersects ( other ) { if ( this . left > other . right ) return false ; if ( this . right < other . left ) return false ; if ( this . bottom < other . top ) return false ; if ( this . top > other . bottom ) return false ; return true ; } public getRect ( ) { const rect = new Rect ( ) ; rect . x = this . x ; rect . y = this . y ; rect . width = this . width ; rect . height = this . height ; return rect ; } public setCenter ( x , y ) { this . x = x - this . width / 2 ; this . y = y - this . height / 2 ; } public centerX ( ) { return this . x + this . width / 2 ; } public centerY ( ) { return this . y + this . height / 2 ; } public getWidth ( ) { return this . width ; } public getHeight ( ) { return this . height ; } public move ( dx , dy ) { this . x += dx ; this . y += dy ; } roundRect ( ctx , x , y , w , h , r ) { if ( w < 2 * r ) r = w / 2 ; if ( h < 2 * r ) r = h / 2 ; ctx . beginPath ( ) ; ctx . moveTo ( x + r , y ) ; ctx . arcTo ( x + w , y , x + w , y + h , r ) ; ctx . arcTo ( x + w , y + h , x , y + h , r ) ; ctx . arcTo ( x , y + h , x , y , r ) ; ctx . arcTo ( x , y , x + w , y , r ) ; ctx . closePath ( ) ; } public draw ( ctx , renderData = null ) { } public mouseDown ( evt ) { } public mouseMove ( evt ) { } public mouseUp ( evt ) { } public mouseOver ( evt ) { } }