package com.oxylusflash.book { import flash.display.BlendMode; import flash.display.Sprite; import flash.filters.BlurFilter; import flash.geom.Point; import flash.text.TextField; import flash.text.TextFieldAutoSize; import caurina.transitions.Tweener; public class Tooltip extends Sprite { public var bgMc:TooltipBackground; public var lblTxt:TextField; public var tipMc:Sprite; protected static const VISIBLE:int = 1; protected static const INVISIBLE:int = 0; protected var state:int = INVISIBLE; protected var blurFilter:BlurFilter = new BlurFilter(DropMenu.BLUR, DropMenu.BLUR, 3); /** * Main tooltip used for the buttons ate the bottom of the screen. */ public function Tooltip() { this.alpha = 0; this.mouseEnabled = false; this.mouseChildren = false; this.blendMode = BlendMode.LAYER; lblTxt.autoSize = TextFieldAutoSize.LEFT; lblTxt.multiline = false; lblTxt.wordWrap = false; lblTxt.condenseWhite = true; lblTxt.styleSheet = Global.styleSheet; lblTxt.text = ""; tipMc.x = 0; } /** * Show / hide tooltip. */ public function show():void { if (state == INVISIBLE) { state = VISIBLE; Tweener.addTween(this, { alpha: 1, base: Global.baseTween }); } } public function hide():void { if (state == VISIBLE) { state = INVISIBLE; Tweener.addTween(this, { alpha: 0, base: Global.baseTween }); } } /** * Tooltip string. */ public function set tip(value:String):void { lblTxt.htmlText = value; bgMc.width = Math.round(lblTxt.width); var xPos:Number = -Math.round(bgMc.width * 0.5); var pt:Point = this.localToGlobal(new Point(xPos, 0)); pt = Global.optBar.globalToLocal(pt); if (pt.x < 0) { xPos += -pt.x; } else if (pt.x + bgMc.width > Global.optBar.width) { xPos -= pt.x + bgMc.width - Global.optBar.width; } bgMc.x = lblTxt.x = xPos; } public function get tip():String { return lblTxt.htmlText; } /** * Overrides. */ override public function get alpha():Number { return super.alpha; } override public function set alpha(value:Number):void { super.alpha = value; this.visible = value > 0; blurFilter.blurX = blurFilter.blurY = (1 - value) * DropMenu.BLUR; this.filters = this.visible ? [blurFilter] : []; } override public function get width():Number { return bgMc.width; } override public function set width(value:Number):void { } override public function get height():Number { return bgMc.height; } override public function set height(value:Number):void { } } }