import { BaseEventListenerObject , Point } from "fcore/dist/index" ; import { IDisplayObjectContainerWrapper , EngineAdapter , TickerEvent } from "fgraphics/dist/index" ; import { BaseTooltip } from "./BaseTooltip" ; import { ITooltipData } from "./ITooltipData" ; export class TooltipManager extends BaseEventListenerObject { private static SHOW_DELAY : Number = 0.5 ; private _tooltipCont : IDisplayObjectContainerWrapper ; private tooltipInsideCont : IDisplayObjectContainerWrapper ; private tooltip : BaseTooltip ; private _mouseShift : Point ; private _visible : boolean ; constructor ( tooltip ) { super ( tooltip ) ; } protected construction ( tooltip ) { super . construction ( ) ; this . tooltip = tooltip ; this . mouseShift = new Point ( ) ; this . tooltipInsideCont = EngineAdapter . instance . createDisplayObjectContainerWrapper ( ) ; this . tooltipInsideCont . addChild ( this . tooltip . view ) ; this . hide ( ) ; } protected addListeners ( ) { super . addListeners ( ) ; this . eventListenerHelper . addEventListener ( EngineAdapter . instance . mainTicker , TickerEvent . TICK , this . onTick ) ; } private onTick ( ) { this . update ( ) ; } public show ( data ) { this . visible = true ; this . tooltip . data = data ; this . update ( ) ; } public hide ( ) { this . visible = false ; } /**
     * Обновление подсказки.
     */ public update ( ) { if ( ! this . visible ) { return ; } if ( ! this . tooltipCont ) { return ; } if ( ! this . tooltip ) { } let tempPos = new Point ( EngineAdapter . instance . globalMouseX , EngineAdapter . instance . globalMouseY ) ; tempPos . x += this . mouseShift . x ; tempPos . y += this . mouseShift . y ; if ( tempPos . x < 0 ) { tempPos . x = 0 ; } else if ( tempPos . x + this . tooltip . view . width > EngineAdapter . instance . rendererWidth ) { tempPos . x = EngineAdapter . instance . rendererWidth - this . tooltip . view . width ; } if ( tempPos . y < 0 ) { tempPos . y = 0 ; } else if ( tempPos . y + this . tooltip . view . height > EngineAdapter . instance . rendererHeight ) { tempPos . y = EngineAdapter . instance . rendererHeight - this . tooltip . view . height ; } tempPos = this . tooltip . view . parent . toLocal ( tempPos ) ; this . moveTooltipTo ( tempPos . x , tempPos . y ) ; } param x param y protected moveTooltipTo ( x , y ) { this . tooltip . view . x = x ; this . tooltip . view . y = y ; } public get tooltipCont ( ) : IDisplayObjectContainerWrapper { return this . _tooltipCont ; } public set tooltipCont ( value ) { if ( this . tooltipCont == value ) { return ; } this . _tooltipCont = value ; if ( this . tooltipCont ) { this . tooltipCont . addChild ( this . tooltipInsideCont ) ; } this . update ( ) ; } get mouseShift ( ) : Point { return this . _mouseShift ; } set mouseShift ( value ) { this . _mouseShift = value . clone ( ) ; this . update ( ) ; } private get visible ( ) : boolean { return this . _visible ; } private set visible ( value ) { this . _visible = value ; this . tooltipInsideCont . visible = this . visible ; } }