/** * com.sekati.ui.FauxView * @version 1.3.0 * @author jason m horwitz | sekati.com | tendercreative.com * Copyright (C) 2007 jason m horwitz, Sekat LLC. All Rights Reserved. * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php */ import com.sekati.core.App; import com.sekati.core.CoreObject; import com.sekati.core.FWDepth; import com.sekati.draw.Rectangle; import com.sekati.display.StageDisplay; import com.sekati.events.Broadcaster; import com.sekati.events.Dispatcher; import com.sekati.geom.Point; import com.sekati.utils.ClassUtils; import com.sekati.utils.Delegate; /** * FauxView singleton creates a set of {@link com.sekati.display.BaseClip} rectangles on stage for use in tracking and broadcast * a 16:9 content viewport scaled proportionally to the Stage. * * This wraps and simplifies the {@link com.sekati.display.StageDisplay} dispatched events and * pushes them thru {@link com.sekati.events.Broadcaster} using the {@code onPropcast} event after * updating the tracking clip so that the information may be used in liquid layouts that require * positional relationships. */ class com.sekati.ui.FauxView extends CoreObject { private static var _instance:FauxView; private static var onFauxViewUpdateEVENT:String = "onFauxViewUpdate"; private static var _proportionW:Number = 16; private static var _proportionH:Number = 9; private static var RATIO:Number = (_proportionH / _proportionW); private var _this:FauxView; private var _viewport:MovieClip; private var _tbox:MovieClip; private var _bbox:MovieClip; /** * Singleton Constructor - create a tracker clip, set to proper ratio and listen for stage events. */ private function FauxView() { super( ); App.log.status(_instance, "*** - FauxView Initialized ..." ); _this = this; var target:MovieClip = ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, _root, "fauxView", {_x:0, _y:0, _depth:FWDepth.FauxView} ); _viewport = ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, target, "__viewport_center_area__", {_x:0, _y:0, _visible:false} ); Rectangle.draw( _viewport, new Point( 0, 0 ), new Point( _proportionW, _proportionH ), 0xFFFF00, 25, 0 ); _tbox = ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, target, "__viewport_top_letterbox__", {_x:0, _y:0, _visible:true} ); Rectangle.draw( _tbox, new Point( 0, 0 ), new Point( _proportionW, _proportionH ), 0x000000, 100, 0 ); _bbox = ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, target, "__viewport_bot_letterbox__", {_x:0, _y:0, _visible:true} ); Rectangle.draw( _bbox, new Point( 0, 0 ), new Point( _proportionW, _proportionH ), 0x000000, 100, 0 ); Dispatcher.$.addEventListener( StageDisplay.onStageResizeEVENT, Delegate.create( _this, update ) ); Dispatcher.$.addEventListener( StageDisplay.onStageResizeCompleteEVENT, Delegate.create( _this, update ) ); Dispatcher.$.addEventListener( StageDisplay.onStageFullScreenEVENT, Delegate.create( _this, update ) ); update( ); } /** * Singleton Accessor * @return Proportioncaster */ public static function getInstance():FauxView { if (!_instance) { _instance = new FauxView( ); } return _instance; } /** * shorthand singleton accessor getter */ public static function get $():FauxView { return FauxView.getInstance( ); } /** * Set a new proportion to scale by. * @param w (Number) * @param h (Number) * @return Void */ public function setProp(w:Number, h:Number):Void { _proportionW = w; _proportionH = h; update( ); } /** * Proportionally scale the tracker to fit Stage. * @return Void */ private function update():Void { var w:Number = Stage.width; var h:Number = int( w * RATIO ); var y:Number = int( Stage.height / 2 - h / 2 ); var bh:Number = (int( Stage.height - h - y ) < 23) ? 23 : int( Stage.height - h - y ); // place positions _viewport._width = _tbox._width = _bbox._width = w; _viewport._height = h; _viewport._y = y; _tbox._height = y; _bbox._height = bh; _bbox._y = Stage.height - bh; Broadcaster.$.broadcast( onFauxViewUpdateEVENT, p ); } public function get panoramic_height():Number { return int( Stage.width * RATIO ); } /** * _x getter * @return Number */ public function get x():Number { return _viewport._x; } public function get _x():Number { return _viewport._x; } /** * _y getter * @return Number */ public function get y():Number { return _viewport._y; } public function get _y():Number { return _viewport._y; } /** * _width getter * @return Number */ public function get w():Number { return _viewport._width; } public function get _width():Number { return _viewport._width; } /** * _height getter * @return Number */ public function get h():Number { return _viewport._height; } public function get _height():Number { return _viewport._height; } /** * center x * @return Number */ public function get cx():Number { return (w / 2); } /** * center y * @return Number */ public function get cy():Number { return (h / 2) + y; } /** * return bottom of "viewport" * @return Number */ public function get bottom():Number { return y + h; } /** * return the tracker object * @return MovieClip */ public function get shape():MovieClip { return _viewport; } /** * return the top letter box object * @return MovieClip */ public function get topShape():MovieClip { return _tbox; } /** * return the bottom letterbox object * @return MovieClip */ public function get botShape():MovieClip { return _bbox; } /** * proportion getter * @return Object */ public function get p():Object { return {x:x, y:y, w:w, h:h, b:bottom}; } }