diff --git a/README.md b/README.md index f06dc1f..751c987 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # CustomTimer -A Flash Module for custom timers in Dota 2 +A Panorama Module for custom timers in Dota 2 +The Scaleform Module has been depreciated and can be found [here](https://github.com/ynohtna92/CustomTimer/releases/tag/Scaleform)

@@ -9,23 +10,25 @@ A Flash Module for custom timers in Dota 2 Usage ----- -Places the flash3 and script files in the correct location in your custom game directory. +Places the panorama and script files in the correct location in your custom game directory. In lua use ````lua -FireGameEvent('cgm_timer_display', { timerMsg = "Remaining", timerSeconds = 10, timerWarning = 10, timerEnd = false, timerPosition = 0}) +CustomGameEventManager:Send_ServerToAllClients("display_timer", {msg="hi", duration=10, mode=0, endfade=false, position=0, warning=5, paused=false, sound=true} ) ```` **Where:** -- timerMsg (String) = Your Message -- timerSeconds (Integer) = Duration in seconds -- timerEnd (Boolean) = When true the timer will not disappear when it hits 0 -- timerPosition (Integer) = 0 (Display Center), 1 (Display Left), 2 (Display Right), 4 (Display Center - offset) -- timerWarning (Integer) = -1 (Disable, Will default to '0' Red) - Changes the timer color to red when the timer is low - +- msg (String) = Your Message +- duration (Integer) = Duration in seconds +- endfade (Boolean) = When true the timer will not disappear when it hits 0 +- position (Integer) = 0 (Display Center), 1 (Display Left), 2 (Display Right), 4 (Display Center - offset) +- warning (Integer) = -1 (Disable, Will default to '0' Red) - Changes the timer color to red when the timer is low +- paused (Boolean) = true (Pause), false (Unpause) +- sound (Boolean) = true (Warning Sound On), false (Warning Sound Off) + You may also call this lua function to pause the timer. ```lua -FireGameEvent('cgm_timer_pause', { timePaused = true}) +CustomGameEventManager:Send_ServerToAllClients("pause_timer", {pause=true} ) ``` **Where:** -- timePaused (Boolean) = true (Pause), false (Unpause) +- paused (Boolean) = true (Pause), false (Unpause) diff --git a/src/timer.png b/panorama/images/custom_game/custom_timer_bg.png similarity index 100% rename from src/timer.png rename to panorama/images/custom_game/custom_timer_bg.png diff --git a/panorama/layout/custom_game/custom_timer.xml b/panorama/layout/custom_game/custom_timer.xml new file mode 100644 index 0000000..57c1318 --- /dev/null +++ b/panorama/layout/custom_game/custom_timer.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/panorama/layout/custom_game/custom_ui_manifest.xml b/panorama/layout/custom_game/custom_ui_manifest.xml new file mode 100644 index 0000000..baf252a --- /dev/null +++ b/panorama/layout/custom_game/custom_ui_manifest.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/panorama/scripts/custom_game/custom_timer.js b/panorama/scripts/custom_game/custom_timer.js new file mode 100644 index 0000000..0ec7921 --- /dev/null +++ b/panorama/scripts/custom_game/custom_timer.js @@ -0,0 +1,104 @@ +var COLOUR_NORMAL = "#FFFFFF"; +var COLOUR_WARNING = "#DF161F"; +var TIMER_INTERVAL = 0.05; +var FADE_INTERVAL = 0.025; + +var startTime = -1; +var timerDuration = 0; +var timerMode = 0; // Countdown = 0, Countup = 1 +var timerMessage = "Remaining"; +var timerEnd = false; // When true, hide on timer end +var timerPosition = 0; +var timerPaused = false; +var timerSound = false; +var timer = null; +var timerWarning = -1; // Second to start warning at from end (-1 Disabled) +var timerLast = 0; + +var timer = $( "#TimerBox" ); +var hideMarginTop = -78; +var initMarginTop = 22; +var curtMarginTop = hideMarginTop; + +function UpdateTimer() { + if (timerPaused) + startTime += 0.05; + + var timerTextRemain = $( "#TimerRemaining" ); + var time = Game.GetGameTime() - startTime; + var remaining = Math.ceil(timerDuration - time); + + if (remaining <= timerWarning && timerWarning != -1) { + if (remaining != timerLast && timerSound) { + timerLast = remaining; + $.Msg('Beep'); + Game.EmitSound("BUTTON_CLICK_MINOR"); + } + timerTextRemain.style['color'] = COLOUR_WARNING; + } + else + timerTextRemain.style['color'] = COLOUR_NORMAL; + if (remaining >= 0) { + if (timerMode == 0) + timerTextRemain.text = FormatTime(remaining); + else + timerTextRemain.text = FormatTime(time); + } + if (time < timerDuration) + $.Schedule(TIMER_INTERVAL, function(){UpdateTimer();}); + else + timer.RemoveClass("FadeIn"); +} + +function FadeIn() { + curtMarginTop += 10; + timer.style["margin-top"] = curtMarginTop + "px"; + $.Msg(curtMarginTop); + if (curtMarginTop != initMarginTop) + $.Schedule(FADE_INTERVAL, function(){FadeIn();}); +} + +function DisplayTimer( table ) { + timerMessage = table.msg || "Remaining"; + timerDuration = table.duration; + timerMode = table.mode; + timerEnd = table.endfade; + timerPosition = table.position; + timerWarning = table.warning; + timerPaused = table.paused; + timerSound = table.sound; + startTime = Game.GetGameTime(); + var timerTextMsg = $( "#TimerMsg" ); + timerTextMsg.text = $.Localize(timerMessage); + UpdateTimer(); + //curtMarginTop = hideMarginTop; + //timer.style["margin-top"] = curtMarginTop + "px"; + //FadeIn(); + timer.AddClass("FadeIn"); +} + +function PauseTimer( bool ) { + timerPaused = bool.pause; +} + +function FormatTime( seconds ) { + var hours = Math.floor(seconds / 3600); + var remainder = seconds % 3600; + var minutes = Math.floor(remainder / 60); + var seconds = Math.floor(remainder % 60); + var s = ""; + var m = ""; + var h = ""; + if (seconds < 10) + s = "0"; + if (minutes < 10) + m = "0"; + if (hours < 10) + h = "0"; + return h + hours + ":" + m + minutes + ":" + s + seconds; +} + +(function () { + GameEvents.Subscribe( "display_timer", DisplayTimer ); + GameEvents.Subscribe( "pause_timer", PauseTimer ); +})(); \ No newline at end of file diff --git a/panorama/styles/custom_game/custom_timer.css b/panorama/styles/custom_game/custom_timer.css new file mode 100644 index 0000000..3c6003f --- /dev/null +++ b/panorama/styles/custom_game/custom_timer.css @@ -0,0 +1,58 @@ +.BaseHud +{ + width: 100%; + height: 100%; + flow-children: down; +} + +.Clip +{ + clip: rect(44px, 300px, 110px,0px); + horizontal-align: right; + width: 300px; + height: 110px; +} + +.TimerBox +{ + width: 261px; + height: 80px; + background-image: url("file://{resources}/images/custom_game/custom_timer_bg.png"); + background-size: 100%; + horizontal-align: right; + margin-top: -78px; + margin-right: 15px; + z-index: -10; + transition-property: transform; + transition-duration: 0.25s; + transition-timing-function: linear; +} + +.TimerBox Label +{ + color: #FFFFFF; + font-size: 21px; + font-weight: bold; + +} + +#TimerMsg +{ + margin-top: 34px; + margin-left: 20px; + text-align: center; + width: 130px; +} + +#TimerRemaining +{ + margin-top: 34px; + margin-left: 144px; + text-align: center; + width: 100px; +} + +.FadeIn +{ + transform: translateY(100px); +} diff --git a/resource/flash3/CustomUI_Timer.swf b/resource/flash3/CustomUI_Timer.swf deleted file mode 100644 index 81ec8a1..0000000 Binary files a/resource/flash3/CustomUI_Timer.swf and /dev/null differ diff --git a/resource/flash3/custom_ui.txt b/resource/flash3/custom_ui.txt deleted file mode 100644 index f687174..0000000 --- a/resource/flash3/custom_ui.txt +++ /dev/null @@ -1,75 +0,0 @@ -"CustomUI" -{ - "1" - { - "File" "CustomUI_Timer" - "Depth" "40" - } -} - - -// ============================================= -// Depths of base Dota UI elements -// ============================================= -// hud_chat: 8, - -// error_msg: 10, - -// voicechat: 11, -// shop: 12, -// tutorial: 13, -// herodisplay: 14, -// actionpanel: 15, -// inventory: 16, -// channelbar: 17, - -// gameend: 19, -// chat_wheel: 20, -// survey: 21, -// quests: 22, -// questlog: 23, - -// ti_onstage_side: 30, - -// last_hit_challenge: 35, -// waitingforplayers: 36, -// highlight_reel: 37, -// stats_dropdown: 38, -// halloween: 39, -// killcam: 40, // and inspect -// scoreboard: 41, -// quickstats: 42, -// shared_units: 43, -// shared_content: 44, - -// holdout: 50, - -// spectator_items: 145, -// spectator_graph: 146, -// spectator_harvest: 147, -// spectator_player: 148, -// spectator_fantasy: 149, - -// heroselection: 250, -// spectate_heroselection: 251, -// shared_heroselectorandloadout : 252, - -// broadcaster: 364, - -// spectate: 365, -// coach: 366, - -// combat_log: 367, - -// guide_panel: 368, - -// loadgame: 380, - -// report_dialogue : 381, -// popups : 382, -// matchmaking_ready : 383, - -// ti_onstage_pods: 500, - -// overlay: 1000 -// ============================================= \ No newline at end of file diff --git a/scripts/custom_events.txt b/scripts/custom_events.txt deleted file mode 100644 index c5cdfd7..0000000 --- a/scripts/custom_events.txt +++ /dev/null @@ -1,35 +0,0 @@ -// No spaces in event names, max length 32 -// All strings are case sensitive -// -// valid data key types are: -// string : a zero terminated string -// bool : unsigned int, 1 bit -// byte : unsigned int, 8 bit -// short : signed int, 16 bit -// long : signed int, 32 bit -// float : float, 32 bit -// uint64 : unsigned int 64 bit -// local : any data, but not networked to clients -// -// following key names are reserved: -// local : if set to 1, event is not networked to clients -// unreliable : networked, but unreliable -// suppress : never fire this event -// time : firing server time -// eventid : holds the event ID - -"CustomEvents" -{ - "cgm_timer_display" - { - "timerMsg" "string" - "timerSeconds" "string" - "timerEnd" "bool" - "timerPosition" "byte" - "timerWarning" "long" - } - "cgm_timer_pause" - { - "timePaused" "bool" - } -} \ No newline at end of file diff --git a/src/CG_Timer.as b/src/CG_Timer.as deleted file mode 100644 index 132679d..0000000 --- a/src/CG_Timer.as +++ /dev/null @@ -1,235 +0,0 @@ -package { - - import flash.utils.Timer; - import flash.events.TimerEvent; - import flash.display.MovieClip; - import flash.events.MouseEvent; - import flash.utils.getDefinitionByName; - import scaleform.clik.events.*; - - //import some stuff from the valve lib - import ValveLib.Globals; - import ValveLib.ResizeManager; - - import fl.transitions.Tween; - import fl.transitions.easing.*; - - //copied from VotingPanel.as source - import flash.display.*; - import flash.filters.*; - import flash.text.*; - import scaleform.clik.events.*; - import vcomponents.*; - - public class CG_Timer extends MovieClip { - - public var gameAPI:Object; - public var globals:Object; - - public var startTime:Number = -1; - public var timerDuration:int; - public var timerMessage:String; - public var timerEnd:Boolean = false; - public var timerPosition:int = 0; - public var timerPaused:Boolean = false; - public var timer:Timer = null; - public var timerWarning:Number = -1; - - public var xTemp:int; - public var yTemp:int; - public var stageWTemp:int; - - public function CG_Timer() { - // constructor code - } - - //set initialise this instance's gameAPI - public function setup(api:Object, globals:Object) { - this.gameAPI = api; - this.globals = globals; - - // default: play btn is visible, stop button is not - trace("##Called Timer Setup!"); - this.visible = false; - - this.timeMessage.text = Globals.instance.GameInterface.Translate("#TimerTitle"); - - this.gameAPI.SubscribeToGameEvent("cgm_timer_display", this.onTimerUpdate); - this.gameAPI.SubscribeToGameEvent("cgm_timer_pause", this.onTimerPaused); - - trace("## Called Timer Setup Completed!"); - } - - //On UI unload, we need to kill the timer - public function kill() : void { - trace("Timer: Killing timer"); - if ( this.timer != null) { - this.timer.stop(); - this.timer = null; - trace("Timer: Timer Killed!"); - } - } - - //onScreenResize - public function screenResize(stageW:int, stageH:int, xScale:Number, yScale:Number, wide:Boolean){ - - trace("Stage Size: ",stageW,stageH); - - this.x = (stageW/2 + 180)*yScale*0.8; - this.y = 95*yScale*0.8; - - this.xTemp = this.x; - this.yTemp = this.y; - this.stageWTemp = stageW; - - trace("#Result Resize: ",this.x,this.y,yScale); - - this.width = this.width*yScale; - this.height = this.height*yScale; - - //Now we just set the scale of this element, because these parameters are already the inverse ratios - this.scaleX = xScale*0.8; - this.scaleY = yScale*0.8; - - trace("#ScoreBoard Panel Resize"); - } - - public function updateCounter(e:TimerEvent) :void{ - // Check if object still exist in ui. - if ( this.timeRemaining == null ) { - kill() - return; - } - - if (Globals.instance.Loader_overlay.movieClip.dota_paused.visible || this.timerPaused) - this.startTime += .1; - - var time:Number = Globals.instance.Game.Time() - this.startTime; - var remaining:Number = Math.ceil(this.timerDuration - time); - - if (remaining <= (this.timerWarning) && this.timerWarning != -1) - this.timeRemaining.textColor = 0xDF161F; - else - this.timeRemaining.textColor = 0xFFFFFF; - - if (remaining >= 0) - this.timeRemaining.text = getTime(remaining); - - if (time >= this.timerDuration){ - this.timer.stop(); - this.timer = null; - if (!this.timerEnd){ - var t:Timer = new Timer(1000,1); - t.addEventListener(TimerEvent.TIMER, fadeOut); - t.start(); - } - } - } - - public function fadeIn():void{ - this.y -= 100; - var t:Timer = new Timer(25,10); - t.addEventListener(TimerEvent.TIMER, incrementFadeIn); - t.start(); - } - - public function incrementFadeIn(e:TimerEvent) :void{ - this.y += 10; - } - - public function fadeOut():void{ - var t:Timer = new Timer(25,10); - t.addEventListener(TimerEvent.TIMER, incrementFadeOut); - t.start(); - } - - public function incrementFadeOut(e:TimerEvent) :void{ - this.y -= 10; - if (this.y < 20){ - this.visible = false; - this.y += 100; - } - } - - public function getTime(seconds:int) : String{ - var timeString:String; - var seconds:int; - var s:String = ""; - var minutes:int; - var m:String = ""; - var hours:int; - var h:String = ""; - hours = seconds / 3600; - var remainder:int = seconds % 3600; - minutes = remainder / 60; - seconds = remainder % 60; - if (seconds < 10){ - s = "0"; - } - if (minutes < 10){ - m = "0"; - } - if (hours < 10){ - h = "0"; - } - timeString = h + hours + ":" + m + minutes + ":" + s + seconds; - return timeString; - } - - //onTimerPaused - public function onTimerPaused(args:Object) : void{ - if (args.timePaused != null) - this.timerPaused = args.timePaused; - } - - //onTimerUpdate - public function onTimerUpdate(args:Object) : void{ - if (args.timerMsg != "") { - this.timeMessage.htmlText = Globals.instance.GameInterface.Translate(args.timerMsg); - this.timerMessage = args.timerMsg; - } - this.timeRemaining.text = getTime(args.timerSeconds); - this.timerDuration = args.timerSeconds; - if (args.timerEnd != null) - this.timerEnd = args.timerEnd; - if (args.timerWarning != null) - this.timerWarning = args.timerWarning; - if (args.timerSeconds <= args.timerWarning && args.timerWarning != -1) - this.timeRemaining.textColor = 0xDF161F; - else - this.timeRemaining.textColor = 0xFFFFFF; - if (args.timerPosition != null) { - this.timerPosition = args.timerPosition; - if (this.timerPosition == 0) { - this.x = this.xTemp; - this.y = this.yTemp; - } - if (this.timerPosition == 1) { - this.x = 20 + this.width/2; - this.y = this.yTemp - 15; - } - if (this.timerPosition == 2) { - this.x = this.stageWTemp - this.width/2 - 15; - this.y = this.yTemp - 15; - } - if (this.timerPosition == 4) { - this.x = this.xTemp; - this.y = this.yTemp - 15; - } - } - if (!this.visible){ - fadeIn(); - } - - if ( this.timer != null) { - this.timer.stop(); - this.timer = null; - } - this.startTime = Globals.instance.Game.Time(); - this.timer = new Timer(100); - this.timer.addEventListener(TimerEvent.TIMER, updateCounter); - this.timer.start(); - this.visible = true; - } - } -} diff --git a/src/CustomTimerPreview.PNG b/src/CustomTimerPreview.PNG deleted file mode 100644 index e0d6db5..0000000 Binary files a/src/CustomTimerPreview.PNG and /dev/null differ diff --git a/src/CustomUI_Timer.fla b/src/CustomUI_Timer.fla deleted file mode 100644 index 6cd1f0c..0000000 Binary files a/src/CustomUI_Timer.fla and /dev/null differ diff --git a/src/Timer_Module.as b/src/Timer_Module.as deleted file mode 100644 index 89ed0e3..0000000 --- a/src/Timer_Module.as +++ /dev/null @@ -1,75 +0,0 @@ -// Credits to Noya for a lot of this Flash code, from his mod Courier Madness. -// Also Credits to Perry for abundant Flash info. - -package { - import flash.display.MovieClip; - import flash.events.MouseEvent; - import flash.utils.getDefinitionByName; - import scaleform.clik.events.*; - - //import some stuff from the valve lib - import ValveLib.Globals; - import ValveLib.ResizeManager; - - import fl.transitions.Tween; - import fl.transitions.easing.*; - - //copied from VotingPanel.as source - import flash.display.*; - import flash.filters.*; - import flash.text.*; - import scaleform.clik.events.*; - import vcomponents.*; - - public class Timer_Module extends MovieClip{ - - //these three variables are required by the engine - public var gameAPI:Object; - public var globals:Object; - public var elementName:String; - - private var ScreenWidth:int; - private var ScreenHeight:int; - public var scaleRatioY:Number; - - //constructor, you usually will use onLoaded() instead - public function Timer_Module() : void { - - } - - //this function is called when the UI is loaded - public function onLoaded() : void { - //make this UI visible - visible = true; - - //let the client rescale the UI - Globals.instance.resizeManager.AddListener(this); - - this.timer.setup(this.gameAPI, this.globals); - this.gameAPI.OnUnload = OnUnload; - - trace("## Custom UI loaded!"); - } - - //this function is called when the UI is unloaded - public function OnUnload() : Boolean { - this.timer.kill(); - trace("## Custom UI unloaded!"); - return true; - } - - public function onResize(re:ResizeManager) : * { - - // calculate by what ratio the stage is scaling - scaleRatioY = re.ScreenHeight/1080; - - trace("##### RESIZE #########"); - - ScreenWidth = re.ScreenWidth; - ScreenHeight = re.ScreenHeight; - - //pass the resize event to our module, we pass the width and height of the screen, as well as the INVERSE of the stage scaling ratios. - this.timer.screenResize(re.ScreenWidth, re.ScreenHeight, scaleRatioY, scaleRatioY, re.IsWidescreen()); - } - } -} \ No newline at end of file diff --git a/src/ValveLib/Controls/InputBox.as b/src/ValveLib/Controls/InputBox.as deleted file mode 100644 index 44ae458..0000000 --- a/src/ValveLib/Controls/InputBox.as +++ /dev/null @@ -1,116 +0,0 @@ -package ValveLib.Controls -{ - import scaleform.clik.controls.TextInput; - import scaleform.clik.controls.ScrollingList; - import scaleform.clik.events.InputEvent; - import scaleform.clik.interfaces.IDataProvider; - import scaleform.clik.events.ButtonEvent; - import scaleform.gfx.MouseEventEx; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.constants.InputValue; - import flash.ui.Keyboard; - import flash.events.Event; - import ValveLib.Events.InputBoxEvent; - import scaleform.clik.managers.FocusHandler; - import frota; - - public class InputBox extends TextInput - { - - public function InputBox() { - super(); - } - - private var _autoCompleteListValue:Object; - - protected var _autoCompleteList:ScrollingList; - - override public function handleInput(param1:InputEvent) : void { - var _loc6_:IDataProvider = null; - var _loc7_:ButtonEvent = null; - var _loc8_:ButtonEvent = null; - var _loc2_:MouseEventEx = param1 as MouseEventEx; - var _loc3_:uint = _loc2_ == null?0:_loc2_.mouseIdx; - var _loc4_:uint = _loc2_ == null?0:_loc2_.buttonIdx; - if(param1.handled) - { - return; - } - var _loc5_:InputDetails = param1.details; - if(_loc5_.value == InputValue.KEY_UP) - { - return; - } - if(!(this._autoCompleteList == null) && (this._autoCompleteList.visible)) - { - if(_loc5_.code == Keyboard.UP) - { - this._autoCompleteList.selectedIndex = Math.max(0,this._autoCompleteList.selectedIndex-1); - return; - } - if(_loc5_.code == Keyboard.DOWN) - { - _loc6_ = Object(this._autoCompleteList)._dataProvider as IDataProvider; - if(_loc6_ != null) - { - this._autoCompleteList.selectedIndex = Math.min(_loc6_.length-1,this._autoCompleteList.selectedIndex + 1); - } - return; - } - if(_loc5_.code == Keyboard.ENTER) - { - _loc6_ = Object(this._autoCompleteList)._dataProvider as IDataProvider; - if(_loc6_ != null) - { - text = _loc6_.requestItemAt(this._autoCompleteList.selectedIndex)["label"]; - dispatchEvent(new Event(Event.CHANGE)); - return; - } - } - } - if(_loc5_.code == Keyboard.ENTER) - { - trace(" enter pressed - dispatching InputBoxEvent"); - dispatchEvent(new InputBoxEvent(InputBoxEvent.TEXT_SUBMITTED)); - _loc7_ = new ButtonEvent(ButtonEvent.CLICK,true,false,_loc3_,_loc4_,false); - dispatchEvent(_loc7_); - } - else - { - if(_loc5_.code == Keyboard.TAB) - { - trace(" tab pressed - dispatching InputBoxEvent"); - dispatchEvent(new InputBoxEvent(InputBoxEvent.TAB_PRESSED)); - _loc8_ = new ButtonEvent(ButtonEvent.CLICK,true,false,_loc3_,_loc4_,false); - dispatchEvent(_loc8_); - } - } - trace("handleInput code = " + _loc5_.code + " this = " + this.name + " stage.focus = " + stage.focus + " getFocus = " + FocusHandler.getInstance().getFocus(0)); - super.handleInput(param1); - } - - override protected function configUI() : void { - super.configUI(); - this.findAutoCompleteList(); - } - - public function get autoCompleteList() : Object { - return this._autoCompleteListValue; - } - - public function set autoCompleteList(param1:Object) : void { - this._autoCompleteListValue = param1; - } - - protected function findAutoCompleteList() : * { - var _loc1_:ScrollingList = null; - if(this._autoCompleteListValue is String) - { - if(parent != null) - { - this._autoCompleteList = parent.getChildByName(this._autoCompleteListValue.toString()) as ScrollingList; - } - } - } - } -} diff --git a/src/ValveLib/Controls/ScrollView.as b/src/ValveLib/Controls/ScrollView.as deleted file mode 100644 index 5b7f818..0000000 --- a/src/ValveLib/Controls/ScrollView.as +++ /dev/null @@ -1,230 +0,0 @@ -package ValveLib.Controls -{ - import scaleform.clik.core.UIComponent; - import scaleform.clik.interfaces.IScrollBar; - import flash.display.MovieClip; - import scaleform.clik.constants.InvalidationType; - import flash.events.Event; - import flash.events.MouseEvent; - import scaleform.clik.controls.ScrollIndicator; - import scaleform.clik.controls.ScrollBar; - - public class ScrollView extends UIComponent - { - - public function ScrollView() { - super(); - } - - private var _scrollBarValue:Object; - - private var autoScrollBar:Boolean = false; - - protected var _scrollBar:IScrollBar; - - private var _scrollPosition:Number = 0; - - public var contentMask:MovieClip; - - public var content:MovieClip; - - public var _debug:Boolean = false; - - public var overrideMax:int = -1; - - public var scrollStep:int = 15; - - public function get scrollPosition() : Number { - return this._scrollPosition; - } - - public function set scrollPosition(param1:Number) : void { - var _loc2_:Object = this.content.getBounds(this.content); - var _loc3_:Number = this.content.height - this.contentMask.height; - _loc3_ = _loc3_ + _loc2_.top / scaleY; - if(this.overrideMax != -1) - { - _loc3_ = this.overrideMax; - } - var param1:Number = Math.max(0,Math.min(_loc3_,Math.round(param1))); - this._scrollPosition = param1; - invalidateData(); - } - - public function get scrollBar() : Object { - return this._scrollBar; - } - - public function set scrollBar(param1:Object) : void { - this._scrollBarValue = param1; - if(this._debug) - { - trace("scrollBar set, setting _scrollBarValue to " + this._scrollBarValue); - } - invalidate(InvalidationType.SCROLL_BAR); - } - - protected function createScrollBar() : void { - var _loc1_:IScrollBar = null; - if(this._debug) - { - trace("createScrollBar _scrollBarValue = " + this._scrollBarValue); - } - if(this._scrollBar) - { - this._scrollBar.removeEventListener(Event.SCROLL,this.handleScroll); - this._scrollBar.removeEventListener(Event.CHANGE,this.handleScroll); - this._scrollBar.focusTarget = null; - this._scrollBar = null; - } - if(!this._scrollBarValue || this._scrollBarValue == "") - { - if(this._debug) - { - trace("ScrolView warning: no scrollbar name specified"); - } - return; - } - if(this._scrollBarValue is String) - { - if(parent != null) - { - _loc1_ = parent.getChildByName(this._scrollBarValue.toString()) as IScrollBar; - } - if(_loc1_ == null) - { - trace("ScrollView warning, couldn\'t find scrollbar called: " + this._scrollBarValue.toString()); - } - else - { - if(this._debug) - { - trace("found a scrollbar by name = " + _loc1_); - } - } - } - else - { - _loc1_ = this._scrollBarValue as IScrollBar; - } - this._scrollBar = _loc1_; - invalidateSize(); - if(this._scrollBar == null) - { - return; - } - this._scrollBar.addEventListener(Event.SCROLL,this.handleScroll,false,0,true); - this._scrollBar.addEventListener(Event.CHANGE,this.handleScroll,false,0,true); - this._scrollBar.focusTarget = this; - this._scrollBar.tabEnabled = false; - } - - public function availableWidth() : Number { - return this.autoScrollBar?width - this._scrollBar.width:width; - } - - override protected function configUI() : void { - super.configUI(); - if(!(this._scrollBarValue == "") && !(this._scrollBarValue == null)) - { - this.scrollBar = this._scrollBarValue; - } - addEventListener(MouseEvent.MOUSE_WHEEL,this.handleMouseWheel,false,0,true); - } - - override protected function draw() : void { - if(isInvalid(InvalidationType.SCROLL_BAR)) - { - this.createScrollBar(); - } - this.drawScrollBar(); - this.updateScrollBar(); - super.draw(); - } - - private function drawScrollBar() : void { - var _loc1_:* = NaN; - _loc1_ = 0; - if(!this.autoScrollBar) - { - return; - } - this._scrollBar.x = width - this._scrollBar.width - _loc1_; - this._scrollBar.y = _loc1_; - this._scrollBar.height = height - _loc1_ * 2; - } - - protected function handleScroll(param1:Event) : void { - this.scrollPosition = this._scrollBar.position; - this.content.y = -this.scrollPosition; - } - - public function updateScrollBar() : void { - var _loc3_:ScrollIndicator = null; - var _loc4_:ScrollBar = null; - if(this.content == null) - { - if(this._debug) - { - trace("content is null"); - } - return; - } - if(this.contentMask == null) - { - if(this._debug) - { - trace("contentMask is null"); - } - return; - } - if(this._scrollBar == null) - { - if(this._debug) - { - trace("_scrollBar is null"); - } - return; - } - var _loc1_:Object = this.content.getBounds(this.content); - var _loc2_:Number = this.content.height - this.contentMask.height; - if(this._debug) - { - trace("contentBounds.top = " + _loc1_.top + " scaleY = " + scaleY); - } - _loc2_ = _loc2_ + _loc1_.top / scaleY; - if(this.overrideMax != -1) - { - _loc2_ = this.overrideMax; - } - if(this._scrollBar != null) - { - _loc3_ = this._scrollBar as ScrollIndicator; - if(_loc3_ != null) - { - _loc3_.setScrollProperties(this.contentMask.height,0,_loc2_,this.scrollStep); - } - _loc4_ = this._scrollBar as ScrollBar; - if(_loc4_ != null) - { - _loc4_.trackScrollPageSize = Math.max(1,this.contentMask.height - this.scrollStep); - } - this.scrollPosition = this._scrollPosition; - this._scrollBar.position = this._scrollPosition; - this._scrollBar.validateNow(); - } - if(this._debug) - { - trace("parent = " + parent + " updateScrollBar content height = " + this.content.height + " contentMask height = " + this.contentMask.height + " max = " + _loc2_ + " _scrollPosition = " + this._scrollPosition + " content.y = " + this.content.y); - } - } - - protected function handleMouseWheel(param1:MouseEvent) : void { - this.scrollList((param1.delta > 0?1:-1) * this.scrollStep); - } - - protected function scrollList(param1:int) : void { - this.scrollPosition = this.scrollPosition - param1; - } - } -} diff --git a/src/ValveLib/ElementLoader.as b/src/ValveLib/ElementLoader.as deleted file mode 100644 index 76f5286..0000000 --- a/src/ValveLib/ElementLoader.as +++ /dev/null @@ -1,109 +0,0 @@ -package ValveLib -{ - import flash.display.Loader; - import flash.display.MovieClip; - import flash.events.ProgressEvent; - import flash.events.Event; - import flash.events.IOErrorEvent; - import flash.net.URLRequest; - import flash.display.DisplayObjectContainer; - - public class ElementLoader extends Object - { - - public function ElementLoader() { - super(); - } - - public var gameAPI:Object; - - public var level:Number; - - public var loader:Loader; - - public var elementName:String; - - public var slot:Number; - - public var channel:Number; - - public var movieClip:MovieClip; - - public function Init(param1:MovieClip, param2:Object, param3:Number, param4:String) : * { - var _loc6_:* = NaN; - var _loc7_:* = NaN; - var _loc8_:* = NaN; - var _loc9_:Loader = null; - var _loc5_:* = param4 + ".swf"; - if(this.loader == null) - { - this.loader = new Loader(); - this.loader.name = param4 + "_loader"; - this.loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,this.OnLoadProgress); - this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoadingComplete); - this.loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onIOError); - _loc6_ = -1; - this.loader.tabIndex = param3; - _loc7_ = param1.numChildren; - _loc8_ = 0; - while(_loc8_ < _loc7_) - { - if(param1.getChildAt(_loc8_) is Loader) - { - _loc9_ = param1.getChildAt(_loc8_) as Loader; - if(_loc9_.tabIndex > param3) - { - _loc6_ = _loc8_; - break; - } - } - _loc8_++; - } - param1.addChild(this.loader); - this.loader.visible = false; - if(_loc6_ != -1) - { - param1.setChildIndex(this.loader,_loc6_); - } - this.gameAPI = param2; - this.elementName = param4; - } - this.loader.load(new URLRequest(_loc5_)); - } - - public function onLoadingComplete(param1:Event) : * { - trace("onLoadingComplete " + this.elementName + " this = " + this); - this.loader.visible = true; - this.movieClip = this.loader.content as MovieClip; - this.movieClip["gameAPI"] = this.gameAPI; - this.movieClip["elementName"] = this.elementName; - this.gameAPI.OnLoadFinished(this.movieClip,Globals.instance.UISlot); - this.movieClip.onLoaded(); - } - - public function OnLoadProgress(param1:ProgressEvent) : * { - trace("OnLoadProgress " + this.elementName + " " + param1.bytesLoaded + " / " + param1.bytesTotal); - this.gameAPI.OnLoadProgress(this.loader.content,param1.bytesLoaded,param1.bytesTotal); - } - - public function onIOError(param1:IOErrorEvent) : * { - trace("onIOError " + this.elementName); - this.gameAPI.OnLoadError(this.loader.content,0); - } - - public function Unload() : * { - var _loc1_:DisplayObjectContainer = this.loader.parent; - Globals.instance.resizeManager.RemoveListener(this.movieClip); - if(this.loader.contentLoaderInfo != null) - { - this.loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,this.OnLoadProgress); - this.loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,this.onLoadingComplete); - this.loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,this.onIOError); - } - _loc1_.removeChild(this.loader); - this.movieClip = null; - this.loader.unload(); - this.loader = null; - } - } -} diff --git a/src/ValveLib/Events/InputBoxEvent.as b/src/ValveLib/Events/InputBoxEvent.as deleted file mode 100644 index 4292d4c..0000000 --- a/src/ValveLib/Events/InputBoxEvent.as +++ /dev/null @@ -1,24 +0,0 @@ -package ValveLib.Events -{ - import flash.events.Event; - - public class InputBoxEvent extends Event - { - - public function InputBoxEvent(param1:String, param2:Boolean=true, param3:Boolean=false) { - super(param1,param2,param3); - } - - public static const TEXT_SUBMITTED:String = "textSubmitted"; - - public static const TAB_PRESSED:String = "tabPressed"; - - override public function clone() : Event { - return new InputBoxEvent(type,bubbles,cancelable); - } - - override public function toString() : String { - return formatToString("ButtonEvent","type","bubbles","cancelable"); - } - } -} diff --git a/src/ValveLib/Events/ShopEvent.as b/src/ValveLib/Events/ShopEvent.as deleted file mode 100644 index d5e5786..0000000 --- a/src/ValveLib/Events/ShopEvent.as +++ /dev/null @@ -1,54 +0,0 @@ -package ValveLib.Events -{ - import flash.events.Event; - - public class ShopEvent extends Event - { - - public function ShopEvent(param1:String, param2:Boolean=true, param3:Boolean=false) { - super(param1,param2,param3); - } - - public static const SHOP_ANIMATED_OPEN:String = "shopAnimatedOpen"; - - public static const SELECT_ITEM:String = "selectItem"; - - public static const PURCHASE_ITEM:String = "purchaseItem"; - - public static const SET_QUICK_BUY_ITEM:String = "setQuickBuyItem"; - - public static const PLAYER_SHOP_CHANGED:String = "playerShopChanged"; - - public static const PLAYER_GOLD_CHANGED:String = "playerGoldChanged"; - - public static const UPDATE_SHOP_ITEM:String = "updateShopItem"; - - public static const UPGRADE_ITEM:String = "upgradeItem"; - - public static const SHOW_TOOLTIP:String = "showTooltip"; - - public static const HIDE_TOOLTIP:String = "hideTooltip"; - - public function get gold() : Number { - return this._gold; - } - - public function set gold(param1:Number) : void { - this._gold = param1; - } - - private var _gold:Number; - - public var itemName:String; - - public var tooltipObject:Object; - - override public function clone() : Event { - return new ShopEvent(type,bubbles,cancelable); - } - - override public function toString() : String { - return formatToString("ButtonEvent","type","bubbles","cancelable"); - } - } -} diff --git a/src/ValveLib/Globals.as b/src/ValveLib/Globals.as deleted file mode 100644 index 2b6c479..0000000 --- a/src/ValveLib/Globals.as +++ /dev/null @@ -1,512 +0,0 @@ -package ValveLib -{ - import flash.display.MovieClip; - import scaleform.clik.managers.InputDelegate; - import flash.display.StageScaleMode; - import flash.display.StageAlign; - import flash.events.Event; - import scaleform.clik.core.UIComponent; - import flash.display.DisplayObject; - import flash.display.DisplayObjectContainer; - import flash.display.Loader; - import flash.display.Bitmap; - import flash.net.URLRequest; - import flash.display.Scene; - - public dynamic class Globals extends Object - { - - public function Globals() { - this.cachedImageData = {}; - super(); - } - - public static var instance:Globals = null; - - public static function Create(param1:MovieClip) : * { - if(instance == null) - { - instance = new Globals(); - instance.Init(param1); - } - return instance; - } - - public var UISlot:Number = 0; - - public var noInvisibleAdvance:Boolean = true; - - public var Level0:MovieClip = null; - - public var ElementDepths; - - public var GameInterface:Object = null; - - public var PlatformCode:Number; - - public var resizeManager:ResizeManager = null; - - public var cachedImageData:Object; - - public function Init(param1:MovieClip) : * { - InputDelegate.getInstance().externalInputHandler = this.customInputHandler; - this.Level0 = param1; - param1.stage.scaleMode = StageScaleMode.NO_SCALE; - param1.stage.align = StageAlign.TOP_LEFT; - if(this.resizeManager == null) - { - this.resizeManager = new ResizeManager(); - this.resizeManager.AuthoredWidth = param1.stage.stageWidth; - this.resizeManager.AuthoredHeight = param1.stage.stageHeight; - trace("Globals.Init() w = " + param1.stage.stageWidth + " h = " + param1.stage.stageHeight); - this.resizeManager.OnStageResize(); - param1.stage.addEventListener(Event.RESIZE,this.onStageResize); - } - if(UIComponent.sdkVersion != "4.2.23") - { - trace("Warning: UI file compiled with incorrect SDK version"); - } - } - - public function onStageResize(param1:Event) : * { - trace("onStageResize"); - if(this.resizeManager) - { - this.resizeManager.OnStageResize(); - } - } - - public function debugPrintChildren(param1:*, param2:Boolean=true, param3:Number=0) : * { - var _loc4_:* = NaN; - var _loc5_:DisplayObject = null; - if(param1 == null) - { - return; - } - _loc4_ = 0; - while(_loc4_ < param1.numChildren) - { - _loc5_ = param1.getChildAt(_loc4_); - trace(this.debugTabs(param3),_loc5_.name,_loc5_); - if((param2) && _loc5_ is DisplayObjectContainer) - { - this.debugPrintChildren(_loc5_,true,param3 + 1); - } - _loc4_++; - } - } - - public function debugPrintParent(param1:*) : * { - if(param1 == null) - { - return; - } - var _loc2_:* = 0; - while(param1 != null) - { - trace(this.debugTabs(_loc2_),param1.name,param1 + " (width,height " + param1.width + ", " + param1.height + " - (scale " + param1.scaleX + ", " + param1.scaleY + ")"); - param1 = param1.parent; - _loc2_++; - } - } - - public function debugTabs(param1:Number) : String { - var _loc3_:* = NaN; - var _loc2_:* = ""; - _loc3_ = 0; - while(_loc3_ < param1) - { - _loc2_ = _loc2_ + " "; - _loc3_++; - } - return _loc2_; - } - - public function RequestElement(param1:String, param2:Object) : * { - var _loc3_:ElementLoader = null; - trace("RequestElement " + param1 + " gameAPI = " + param2); - if((this.ElementDepths) && (this.ElementDepths[param1])) - { - trace("RequestElement " + param1 + " depth = " + this.ElementDepths[param1]); - _loc3_ = this["Loader_" + param1] as ElementLoader; - if(_loc3_ == null) - { - _loc3_ = new ElementLoader(); - this["Loader_" + param1] = _loc3_; - trace("saved loader as: Loader_" + param1); - } - _loc3_.Init(this.Level0,param2,this.ElementDepths[param1],param1); - } - } - - public function RemoveElement(param1:MovieClip) : * { - var _loc2_:String = null; - var _loc3_:ElementLoader = null; - if(param1 == null) - { - trace("RemoveElement: mc is null"); - return; - } - trace("RemoveElement " + param1 + " ID = " + param1["elementName"]); - if(param1["gameAPI"].OnUnload(param1)) - { - _loc2_ = "Loader_" + param1["elementName"]; - trace(" Looking up element loader: " + _loc2_); - _loc3_ = this[_loc2_] as ElementLoader; - if(_loc3_ != null) - { - _loc3_.Unload(); - this[_loc2_] = null; - _loc3_ = null; - } - } - } - - public function SetConvars(param1:Object) : * { - var _loc2_:String = null; - var _loc3_:* = undefined; - for (_loc2_ in param1) - { - _loc3_ = param1[_loc2_]; - if(_loc3_ != undefined) - { - switch(typeof _loc3_) - { - case "string": - case "number": - case "boolean": - this.GameInterface.SetConvar(_loc2_,_loc3_); - continue; - default: - continue; - } - - } - else - { - continue; - } - } - } - - public function TraceObject(param1:Object, param2:String) : * { - var _loc4_:* = NaN; - var _loc5_:* = NaN; - var _loc6_:String = null; - if(!param2) - { - param2 = ""; - } - var _loc3_:* = param2 + " "; - if(typeof param1 == "object") - { - if(param1 is Array) - { - trace(param2 + "["); - _loc4_ = 0; - _loc5_ = param1.length; - while(_loc4_ < _loc5_) - { - this.TraceObject(param1[_loc4_],_loc3_); - _loc4_ = _loc4_ + 1; - } - trace(param2 + "]"); - } - else - { - trace(param2 + "{"); - for (_loc6_ in param1) - { - trace(_loc3_ + _loc6_ + "="); - this.TraceObject(param1[_loc6_],_loc3_); - } - trace(param2 + "}"); - } - } - else - { - trace(param2 + " " + param1.toString()); - } - } - - public function IsPC() : Boolean { - return this.PlatformCode == 0; - } - - public function IsXbox() : Boolean { - return this.PlatformCode == 1; - } - - public function IsPS3() : Boolean { - return this.PlatformCode == 2; - } - - public function LoadMiniHeroImage(param1:String, param2:MovieClip) : * { - if(param1 == null || param1.length == 0) - { - return; - } - trace("load mini hero",param1,param2,param2.name); - this.LoadImage("images/miniheroes/" + param1 + ".png",param2,false); - } - - public function LoadHeroImage(param1:String, param2:MovieClip) : * { - var _loc3_:* = 0; - _loc3_ = param2.numChildren-1; - while(_loc3_ >= 0) - { - param2.removeChildAt(_loc3_); - _loc3_--; - } - if(param1 == null || param1.length == 0) - { - return; - } - this.LoadImage("images/heroes/" + param1 + ".png",param2,false); - } - - public function LoadItemImage(param1:String, param2:MovieClip) : * { - var _loc3_:* = 0; - _loc3_ = param2.numChildren-1; - while(_loc3_ >= 0) - { - param2.removeChildAt(_loc3_); - _loc3_--; - } - if(param1 == null || param1.length == 0) - { - return; - } - this.LoadImage("images/items/" + param1 + ".png",param2,false); - } - - public function LoadHeroModelImage(param1:String, param2:MovieClip) : * { - var _loc3_:* = 0; - _loc3_ = param2.numChildren-1; - while(_loc3_ >= 0) - { - param2.removeChildAt(_loc3_); - _loc3_--; - } - if(param1 == null || param1.length == 0) - { - return; - } - this.LoadImage("images/heroes_full/" + param1 + ".png",param2,false); - } - - public var NumAvatars = 11; - - public function LoadAvatarImage(param1:Number, param2:MovieClip) : * { - var _loc3_:* = 0; - _loc3_ = param2.numChildren-1; - while(_loc3_ >= 0) - { - param2.removeChildAt(_loc3_); - _loc3_--; - } - var _loc4_:* = "images/dashboard/avatars/avatar_puck.png"; - switch(param1) - { - case 0: - _loc4_ = "images/dashboard/avatars/avatar_creep.png"; - break; - case 1: - _loc4_ = "images/dashboard/avatars/avatar_crystal_maiden.png"; - break; - case 2: - _loc4_ = "images/dashboard/avatars/avatar_kunkka.png"; - break; - case 3: - _loc4_ = "images/dashboard/avatars/avatar_faceless_void.png"; - break; - case 4: - _loc4_ = "images/dashboard/avatars/avatar_furion.png"; - break; - case 5: - _loc4_ = "images/dashboard/avatars/avatar_juggernaut.png"; - break; - case 6: - _loc4_ = "images/dashboard/avatars/avatar_bloodseeker.png"; - break; - case 7: - _loc4_ = "images/dashboard/avatars/avatar_lich.png"; - break; - case 8: - _loc4_ = "images/dashboard/avatars/avatar_axe.png"; - break; - case 9: - _loc4_ = "images/dashboard/avatars/avatar_pudge.png"; - break; - case 10: - _loc4_ = "images/dashboard/avatars/avatar_puck.png"; - break; - } - - this.LoadImage(_loc4_,param2,false); - } - - public function LoadAbilityImage(param1:String, param2:MovieClip) : * { - var _loc3_:* = 0; - _loc3_ = param2.numChildren-1; - while(_loc3_ >= 0) - { - param2.removeChildAt(_loc3_); - _loc3_--; - } - if(param1 == null || param1.length == 0) - { - return; - } - this.LoadImage("images/spellicons/" + param1 + ".png",param2,false); - } - - public function LoadTeamLogo(param1:String, param2:MovieClip) : * { - var _loc3_:* = 0; - if(param1 == null || param1.length == 0) - { - param1 = "team_radiant"; - } - _loc3_ = param2.numChildren-1; - while(_loc3_ >= 0) - { - param2.removeChildAt(_loc3_); - _loc3_--; - } - this.LoadImage("images/teams/" + param1 + ".png",param2,false); - } - - public function LoadTournamentPlayerImage(param1:String, param2:MovieClip) : * { - var _loc3_:* = 0; - _loc3_ = param2.numChildren-1; - while(_loc3_ >= 0) - { - param2.removeChildAt(_loc3_); - _loc3_--; - } - if(param1 == null || param1.length == 0) - { - return; - } - this.LoadImage("images/players/" + param1 + ".png",param2,false); - } - - public function LoadImage(param1:String, param2:MovieClip, param3:Boolean) : * { - this.LoadImageWithCallback(param1,param2,param3,null); - } - - public function RemoveImageFromCache(param1:String) : * { - if(this.cachedImageData[param1] != null) - { - this.cachedImageData[param1] = null; - } - } - - public function LoadImageWithCallback(param1:String, param2:MovieClip, param3:Boolean, param4:Function) : * { - var _loc5_:* = 0; - var _loc6_:Loader = null; - var _loc7_:Bitmap = null; - if((param3) && param2["originalWidth"] == null) - { - param2["originalWidth"] = param2.width / param2.scaleX; - param2["originalHeight"] = param2.height / param2.scaleY; - } - _loc5_ = param2.numChildren-1; - while(_loc5_ >= 0) - { - param2.removeChildAt(_loc5_); - _loc5_--; - } - if(param1 == null || param1.length == 0) - { - return; - } - if(this.cachedImageData[param1] == null) - { - _loc6_ = new Loader(); - _loc6_["imageName"] = param1; - _loc6_["resize"] = param3; - _loc6_["callbackfunc"] = param4; - _loc6_.load(new URLRequest(param1)); - _loc6_.visible = false; - param2.addChild(_loc6_); - _loc6_.contentLoaderInfo.addEventListener(Event.COMPLETE,this.imageLoadComplete); - } - else - { - _loc7_ = new Bitmap(this.cachedImageData[param1],"auto",true); - _loc7_.smoothing = true; - param2.addChild(_loc7_); - if(param3) - { - _loc7_.width = param2["originalWidth"]; - _loc7_.height = param2["originalHeight"]; - } - if(param4 != null) - { - param4(_loc7_); - } - } - } - - public function PrecacheImage(param1:String) : * { - if(param1 == null || param1.length == 0) - { - return; - } - if(this.cachedImageData[param1] != null) - { - return; - } - var _loc2_:Loader = new Loader(); - _loc2_["imageName"] = param1; - _loc2_.load(new URLRequest(param1)); - _loc2_.contentLoaderInfo.addEventListener(Event.COMPLETE,this.precacheImageComplete); - } - - public function precacheImageComplete(param1:Event) : * { - param1.target.removeEventListener(Event.COMPLETE,this.precacheImageComplete); - var _loc2_:Bitmap = param1.target.content as Bitmap; - this.cachedImageData[param1.target.loader["imageName"]] = _loc2_.bitmapData; - } - - public function imageLoadComplete(param1:Event) : * { - var _loc3_:Function = null; - param1.target.removeEventListener(Event.COMPLETE,this.imageLoadComplete); - var _loc2_:Bitmap = param1.target.content as Bitmap; - this.cachedImageData[param1.target.loader["imageName"]] = _loc2_.bitmapData; - _loc2_.smoothing = true; - if(param1.target.loader["resize"]) - { - if(!(param1.target.loader.parent == null) && !(param1.target.content == null)) - { - param1.target.content.width = param1.target.loader.parent["originalWidth"]; - param1.target.content.height = param1.target.loader.parent["originalHeight"]; - } - } - param1.target.loader.visible = true; - if(param1.target.loader["callbackfunc"]) - { - _loc3_ = param1.target.loader["callbackfunc"]; - _loc3_(param1.target.content); - } - } - - public function customInputHandler(param1:String, param2:Number, param3:*=null) : * { - } - - public function getFrameNumberFromLabel(param1:MovieClip, param2:String) : int { - var _loc3_:Scene = param1.currentScene; - var _loc4_:* = 0; - while(_loc4_ < _loc3_.labels.length) - { - if(_loc3_.labels[_loc4_].name == param2) - { - return _loc3_.labels[_loc4_].frame; - } - _loc4_++; - } - return -1; - } - } -} diff --git a/src/ValveLib/Managers/DragManager.as b/src/ValveLib/Managers/DragManager.as deleted file mode 100644 index dd2a30d..0000000 --- a/src/ValveLib/Managers/DragManager.as +++ /dev/null @@ -1,115 +0,0 @@ -package ValveLib.Managers -{ - import flash.display.Stage; - import flash.display.Sprite; - import scaleform.clik.interfaces.IDragSlot; - import scaleform.clik.events.DragEvent; - import flash.geom.Point; - import flash.events.MouseEvent; - import flash.display.MovieClip; - import flash.events.Event; - import flash.display.DisplayObject; - - public class DragManager extends Object - { - - public function DragManager() { - super(); - } - - protected static var _stage:Stage; - - protected static var _dragCanvas:Sprite; - - protected static var _initialized:Boolean = false; - - protected static var _inDrag:Boolean = false; - - protected static var _dragData:Object; - - protected static var _dragTarget:Sprite; - - protected static var _origDragSlot:IDragSlot; - - protected static var _dragOffsetX:int; - - protected static var _dragOffsetY:int; - - public static function init(param1:Stage) : void { - if(_initialized) - { - return; - } - _initialized = true; - DragManager._stage = param1; - _dragCanvas = new Sprite(); - _dragCanvas.mouseEnabled = _dragCanvas.mouseChildren = false; - _stage.addChild(_dragCanvas); - _stage.addEventListener(DragEvent.DRAG_START,DragManager.handleStartDragEvent,false,0,true); - } - - public static function inDrag() : Boolean { - return _inDrag; - } - - public static function setDragOffset(param1:int, param2:int) : void { - _dragOffsetX = param1; - _dragOffsetY = param2; - } - - public static function handleStartDragEvent(param1:DragEvent) : void { - if(param1.dragTarget == null || param1.dragSprite == null) - { - return; - } - _dragTarget = param1.dragSprite; - _dragData = param1.dragData; - _origDragSlot = param1.dragTarget; - var _loc2_:Point = new Point(_dragTarget.x,_dragTarget.y); - var _loc3_:Point = _dragTarget.localToGlobal(_loc2_); - _dragCanvas.addChild(_dragTarget); - _dragTarget.x = _dragCanvas.mouseX + _dragOffsetX; - _dragTarget.y = _dragCanvas.mouseY + _dragOffsetY; - _dragOffsetX = _dragOffsetY = 0; - _inDrag = true; - _stage.addEventListener(MouseEvent.MOUSE_UP,handleEndDragEvent,false,0,true); - var _loc4_:MovieClip = _dragTarget as MovieClip; - _loc4_.startDrag(); - _loc4_.mouseEnabled = _loc4_.mouseChildren = false; - _loc4_.trackAsMenu = true; - } - - public static function handleEndDragEvent(param1:MouseEvent) : void { - var _loc5_:DragEvent = null; - _stage.removeEventListener(MouseEvent.MOUSE_UP,handleEndDragEvent,false); - _inDrag = false; - var _loc2_:* = false; - var _loc3_:IDragSlot = findSpriteAncestorOf(_dragTarget.dropTarget) as IDragSlot; - if(!(_loc3_ == null) && _loc3_ is IDragSlot && !(_loc3_ == _origDragSlot)) - { - _loc5_ = new DragEvent(DragEvent.DROP,_dragData,_origDragSlot,_loc3_,_dragTarget); - _loc2_ = _loc3_.handleDropEvent(_loc5_); - } - _dragTarget.stopDrag(); - _dragTarget.mouseEnabled = _dragTarget.mouseChildren = true; - (_dragTarget as MovieClip).trackAsMenu = false; - _dragCanvas.removeChild(_dragTarget); - var _loc4_:DragEvent = new DragEvent(DragEvent.DRAG_END,_dragData,_origDragSlot,_loc3_,_dragTarget); - _origDragSlot.handleDragEndEvent(_loc4_,_loc2_); - _origDragSlot.dispatchEvent(_loc4_); - _dragTarget = null; - _origDragSlot = null; - } - - protected static function handleStageAddedEvent(param1:Event) : void { - } - - protected static function findSpriteAncestorOf(param1:DisplayObject) : IDragSlot { - while((param1) && !(param1 is IDragSlot)) - { - param1 = param1.parent; - } - return param1 as IDragSlot; - } - } -} diff --git a/src/ValveLib/ResizeManager.as b/src/ValveLib/ResizeManager.as deleted file mode 100644 index d1d32f0..0000000 --- a/src/ValveLib/ResizeManager.as +++ /dev/null @@ -1,308 +0,0 @@ -package ValveLib -{ - import flash.display.MovieClip; - import flash.geom.Point; - - public class ResizeManager extends Object - { - - public function ResizeManager() { - this.ScalingFactors = new Array(); - this.ReferencePositions = new Array(); - this.Listeners = new Array(); - super(); - var _loc1_:* = 0; - while(_loc1_ <= SCALE_USING_HORIZONTAL) - { - this.ScalingFactors.push(1); - _loc1_++; - } - var _loc2_:* = 0; - while(_loc2_ <= REFERENCE_CENTER_Y) - { - this.ReferencePositions.push(0); - _loc2_++; - } - } - - public static var ALIGN_NONE:Number = 0; - - public static var ALIGN_LEFT:Number = 0; - - public static var ALIGN_RIGHT:Number = 1; - - public static var ALIGN_TOP:Number = 0; - - public static var ALIGN_BOTTOM:Number = 1; - - public static var ALIGN_CENTER:Number = 0.5; - - public static var POSITION_LEFT:Number = 0; - - public static var POSITION_SAFE_LEFT:Number = 0.075; - - public static var POSITION_RIGHT:Number = 1; - - public static var POSITION_SAFE_RIGHT:Number = 0.925; - - public static var POSITION_TOP:Number = 0; - - public static var POSITION_SAFE_TOP:Number = 0.075; - - public static var POSITION_BOTTOM:Number = 1; - - public static var POSITION_SAFE_BOTTOM:Number = 0.925; - - public static var POSITION_CENTER:Number = 0.5; - - public static var REFERENCE_LEFT:Number = 0; - - public static var REFERENCE_TOP:Number = 1; - - public static var REFERENCE_SAFE_LEFT:Number = 2; - - public static var REFERENCE_SAFE_TOP:Number = 3; - - public static var REFERENCE_RIGHT:Number = 4; - - public static var REFERENCE_BOTTOM:Number = 5; - - public static var REFERENCE_SAFE_RIGHT:Number = 6; - - public static var REFERENCE_SAFE_BOTTOM:Number = 7; - - public static var REFERENCE_CENTER_X:Number = 8; - - public static var REFERENCE_CENTER_Y:Number = 9; - - public static var SCALE_NONE:Number = 0; - - public static var SCALE_BIGGEST:Number = 1; - - public static var SCALE_SMALLEST:Number = 2; - - public static var SCALE_USING_VERTICAL:Number = 3; - - public static var SCALE_USING_HORIZONTAL:Number = 4; - - public static var PC_BORDER_SIZE:Number = 10; - - public var ScalingFactors:Array; - - public var ReferencePositions:Array; - - public var ScreenWidth:Number = -1; - - public var ScreenHeight:Number = -1; - - public var ScreenX:Number = -1; - - public var ScreenY:Number = -1; - - public var AuthoredWidth:Number; - - public var AuthoredHeight:Number; - - public var Hidden:Boolean; - - public var Listeners:Array; - - public function UpdateReferencePositions() : * { - this.ReferencePositions[REFERENCE_LEFT] = this.ScreenX; - this.ReferencePositions[REFERENCE_RIGHT] = this.ScreenX + this.ScreenWidth; - this.ReferencePositions[REFERENCE_TOP] = this.ScreenY; - this.ReferencePositions[REFERENCE_BOTTOM] = this.ScreenY + this.ScreenHeight; - this.ReferencePositions[REFERENCE_CENTER_X] = Math.floor((this.ReferencePositions[REFERENCE_LEFT] + this.ReferencePositions[REFERENCE_RIGHT]) / 2); - this.ReferencePositions[REFERENCE_CENTER_Y] = Math.floor((this.ReferencePositions[REFERENCE_TOP] + this.ReferencePositions[REFERENCE_BOTTOM]) / 2); - if(Globals.instance.IsPC()) - { - this.ReferencePositions[REFERENCE_SAFE_LEFT] = this.ReferencePositions[REFERENCE_LEFT] + PC_BORDER_SIZE; - this.ReferencePositions[REFERENCE_SAFE_TOP] = this.ReferencePositions[REFERENCE_TOP] + PC_BORDER_SIZE; - this.ReferencePositions[REFERENCE_SAFE_RIGHT] = this.ReferencePositions[REFERENCE_RIGHT] - PC_BORDER_SIZE; - this.ReferencePositions[REFERENCE_SAFE_BOTTOM] = this.ReferencePositions[REFERENCE_BOTTOM] - PC_BORDER_SIZE; - } - else - { - this.ReferencePositions[REFERENCE_SAFE_LEFT] = this.ScreenX + Math.ceil(POSITION_SAFE_LEFT * this.ScreenWidth); - this.ReferencePositions[REFERENCE_SAFE_TOP] = this.ScreenY + Math.ceil(POSITION_SAFE_TOP * this.ScreenHeight); - this.ReferencePositions[REFERENCE_SAFE_RIGHT] = this.ScreenX + Math.floor(POSITION_SAFE_RIGHT * this.ScreenWidth); - this.ReferencePositions[REFERENCE_SAFE_BOTTOM] = this.ScreenY + Math.floor(POSITION_SAFE_BOTTOM * this.ScreenHeight); - } - } - - public function SetScaling(param1:MovieClip, param2:Number) : * { - if(param1["originalXScale"] == null) - { - param1["originalXScale"] = param1.scaleX; - param1["originalYScale"] = param1.scaleY; - } - var param2:Number = this.ScalingFactors[param2]; - param1.scaleX = param1.originalXScale * param2; - param1.scaleY = param1.originalYScale * param2; - trace(" SetScaling " + param2 + " originalXscale = " + param1["originalXScale"] + " originalYScale = " + param1["originalYScale"] + " obj.scaleX = " + param1.scaleX + " obj.scaleY = " + param1.scaleY); - } - - public function GetPctPosition(param1:Number, param2:Number, param3:Number, param4:Number) : Number { - return Math.floor(param4 * param1 - param3 * param2); - } - - public function ResetPosition(param1:MovieClip, param2:Number, param3:Number, param4:Number, param5:Number, param6:Number) : * { - this.SetScaling(param1,param2); - var _loc7_:Number = this.GetPctPosition(param4,param6,param1.width,this.ScreenWidth); - var _loc8_:Number = this.GetPctPosition(param3,param5,param1.height,this.ScreenHeight); - param1.x = this.ScreenX + _loc7_; - param1.y = this.ScreenY + _loc8_; - } - - public function GetPixelPosition(param1:Number, param2:Number, param3:Number, param4:Number) : * { - return Math.floor(this.ReferencePositions[param1] + param2 - param4 * param3); - } - - public function ResetPositionByPixel(param1:MovieClip, param2:Number, param3:Number, param4:Number, param5:Number, param6:Number, param7:Number, param8:Number) : * { - this.SetScaling(param1,param2); - param1.x = this.GetPixelPosition(param3,param4 * this.ScalingFactors[param2],param5,param1.width); - param1.y = this.GetPixelPosition(param6,param7 * this.ScalingFactors[param2],param8,param1.height); - } - - public function ResetPositionByPercentage(param1:MovieClip, param2:Number, param3:Number, param4:Number, param5:Number, param6:Number, param7:Number, param8:Number) : * { - this.SetScaling(param1,param2); - param1.x = this.GetPixelPosition(param3,param4 * this.ScreenWidth,param5,param1.width); - param1.y = this.GetPixelPosition(param6,param7 * this.ScreenHeight,param8,param1.height); - } - - public function PositionDashboardPage(param1:MovieClip) : * { - trace("new PositionDashboardPage"); - this.SetScaling(param1,SCALE_USING_VERTICAL); - var _loc2_:Number = this.ScreenWidth * 0.5; - if(this.Is16by9()) - { - param1.x = _loc2_ - 625 * this.ScalingFactors[SCALE_USING_VERTICAL]; - } - else - { - if(this.Is16by10()) - { - param1.x = _loc2_ - 540 * this.ScalingFactors[SCALE_USING_VERTICAL]; - } - else - { - param1.x = _loc2_ - 484 * this.ScalingFactors[SCALE_USING_VERTICAL]; - } - } - param1.y = 96 * this.ScalingFactors[SCALE_USING_VERTICAL]; - } - - public function IsWidescreen() : Boolean { - return this.ScreenWidth / this.ScreenHeight > 1.5; - } - - public function Is16by9() : Boolean { - return this.ScreenWidth / this.ScreenHeight > 1.7; - } - - public function Is16by10() : Boolean { - return this.ScreenWidth / this.ScreenHeight < 1.7 && this.ScreenWidth / this.ScreenHeight > 1.5; - } - - public function OnStageResize() : * { - var _loc6_:Object = null; - var _loc1_:Number = Globals.instance.Level0.stage.stageWidth; - var _loc2_:Number = Globals.instance.Level0.stage.stageHeight; - Globals.instance.Level0.transform.perspectiveProjection.projectionCenter = new Point(_loc1_ * 0.5,_loc2_ * 0.5); - this.ScreenX = 0; - this.ScreenY = 0; - trace("ResizeManager onResize w = " + _loc1_ + " h = " + _loc2_ + " AuthoredWidth = " + this.AuthoredWidth + " AuthoredHeight = " + this.AuthoredHeight); - if(this.ScreenWidth == _loc1_ && this.ScreenHeight == _loc2_) - { - return; - } - this.ScreenWidth = _loc1_; - this.ScreenHeight = _loc2_; - var _loc3_:Number = this.ScreenWidth / this.AuthoredWidth; - var _loc4_:Number = this.ScreenHeight / this.AuthoredHeight; - if(_loc1_ == 1280 && _loc2_ == 1024) - { - _loc4_ = 960 / this.AuthoredHeight; - } - if(_loc3_ >= _loc4_) - { - this.ScalingFactors[SCALE_BIGGEST] = _loc3_; - this.ScalingFactors[SCALE_SMALLEST] = _loc4_; - } - else - { - this.ScalingFactors[SCALE_BIGGEST] = _loc4_; - this.ScalingFactors[SCALE_SMALLEST] = _loc3_; - } - this.ScalingFactors[SCALE_USING_VERTICAL] = _loc4_; - this.ScalingFactors[SCALE_USING_HORIZONTAL] = _loc3_; - trace(" ScalingFactors[SCALE_USING_VERTICAL] = " + this.ScalingFactors[SCALE_USING_VERTICAL] + " scalex = " + _loc3_ + " scaley = " + _loc4_); - this.UpdateReferencePositions(); - var _loc5_:Number = this.Listeners.length; - var _loc7_:* = 0; - while(_loc7_ < _loc5_) - { - _loc6_ = this.Listeners[_loc7_]; - if(_loc6_["onResize"] != undefined) - { - this.Listeners[_loc7_].onResize(this); - } - _loc7_ = _loc7_ + 1; - } - } - - public function GetListenerIndex(param1:Object, param2:Number) : Number { - var _loc3_:Number = 0; - if(param2 == -1) - { - param2 = this.Listeners.length-1; - } - while(_loc3_ <= param2) - { - if(this.Listeners[_loc3_] == param1) - { - return _loc3_; - } - _loc3_++; - } - return -1; - } - - public function AddListener(param1:Object) : * { - if(this.GetListenerIndex(param1,-1) == -1) - { - this.Listeners.push(param1); - param1.onResize(this); - } - } - - public function RemoveListener(param1:Object) : * { - var _loc2_:Number = this.Listeners.length-1; - var _loc3_:Number = this.GetListenerIndex(param1,_loc2_); - if(_loc3_ == -1) - { - return; - } - if(_loc3_ == _loc2_) - { - this.Listeners.length = _loc2_; - } - else - { - if(_loc3_ == 0) - { - this.Listeners.shift(); - } - else - { - this.Listeners = this.Listeners.slice(0,_loc3_).concat(this.Listeners.slice(_loc3_ + 1,_loc2_ + 1)); - } - } - } - - private function Remove() : * { - this.Listeners.length = 0; - Globals.instance.resizeManager = null; - } - } -} diff --git a/src/scaleform/clik/constants/ConstrainMode.as b/src/scaleform/clik/constants/ConstrainMode.as deleted file mode 100644 index c1215f7..0000000 --- a/src/scaleform/clik/constants/ConstrainMode.as +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Defintions for the available constrain modes for use with Constraints. These determine how the Constraints will scale its elements. The default mode is COUNTER_SCALE. - */ - -/************************************************************************** - -Filename : ConstrainMode.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - - public class ConstrainMode - { - // Constants: - public static const COUNTER_SCALE:String = "counterScale"; - public static const REFLOW:String = "reflow"; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/ControllerType.as b/src/scaleform/clik/constants/ControllerType.as deleted file mode 100644 index e6083be..0000000 --- a/src/scaleform/clik/constants/ControllerType.as +++ /dev/null @@ -1,27 +0,0 @@ -/** - * An enumeration of controller types. - */ - -/************************************************************************** - -Filename : ControllerType.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - - public class ControllerType - { - public static const MOUSE:uint = 0; - public static const KEYBOARD:uint = 1; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/DirectionMode.as b/src/scaleform/clik/constants/DirectionMode.as deleted file mode 100644 index 13c4243..0000000 --- a/src/scaleform/clik/constants/DirectionMode.as +++ /dev/null @@ -1,23 +0,0 @@ -/************************************************************************** - -Filename : DirectionMode.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - public class DirectionMode - { - // Constants: - public static const HORIZONTAL:String = "horizontal"; - public static const VERTICAL:String = "vertical"; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/FocusMode.as b/src/scaleform/clik/constants/FocusMode.as deleted file mode 100644 index 3a555c4..0000000 --- a/src/scaleform/clik/constants/FocusMode.as +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Definitions for the available "focus modes" that FocusHandler should use when moving focus. - */ - -/************************************************************************** - -Filename : FocusMode.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - public class FocusMode - { - // Constants: - /** If LOOP is used, FocusHandler will search for avaiable focus targets in the target direction until it reaches the end of the document. If no valid target is found before the end of the document, it will begin a new search from the opposite side of the document and repeat the process. */ - public static const LOOP:String = "loop"; - /** If DEFAULT is used, FocusHandler will search for available focus targets in the target direction until it reaches the end of the document. If no valid target is found before the end of the document, the search will end there. */ - public static const DEFAULT:String = "default"; - public static const VERTICAL:String = "focusModeVertical"; - public static const HORIZONTAL:String = "focusModeHorizontal"; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/InputValue.as b/src/scaleform/clik/constants/InputValue.as deleted file mode 100644 index f23c27d..0000000 --- a/src/scaleform/clik/constants/InputValue.as +++ /dev/null @@ -1,29 +0,0 @@ -/** - * An enumeration of key input 'states' or 'values'. - */ - -/************************************************************************** - -Filename : InputValue.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - - public class InputValue - { - // Constants: - public static const KEY_DOWN:String = "keyDown"; - public static const KEY_UP:String = "keyUp"; - public static const KEY_HOLD:String = "keyHold"; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/InvalidationType.as b/src/scaleform/clik/constants/InvalidationType.as deleted file mode 100644 index 3b1fe9b..0000000 --- a/src/scaleform/clik/constants/InvalidationType.as +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Definitions for the component invalidation types. These types are used to segment parts of invalidation (which primarily occurs draw()) to minimize unnecessary updates. - */ - -/************************************************************************** - -Filename : InvalidationType.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - - public class InvalidationType - { - public static const ALL:String = "all"; - public static const SIZE:String = "size"; - public static const STATE:String = "state"; - public static const DATA:String = "data"; - public static const SETTINGS:String = "settings"; - public static const RENDERERS:String = "renderers"; - public static const SCROLL_BAR:String = "scrollBar"; - public static const SELECTED_INDEX:String = "selectedIndex"; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/LayoutMode.as b/src/scaleform/clik/constants/LayoutMode.as deleted file mode 100644 index 113511a..0000000 --- a/src/scaleform/clik/constants/LayoutMode.as +++ /dev/null @@ -1,27 +0,0 @@ -/************************************************************************** - -Filename : LayoutMode.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - - public class LayoutMode - { - // Constants: - public static const ALIGN_NONE:String = "none"; - public static const ALIGN_LEFT:String = "left"; - public static const ALIGN_RIGHT:String = "right"; - public static const ALIGN_CENTER:String = "center"; - public static const ALIGN_TOP:String = "top"; - public static const ALIGN_BOTTOM:String = "bottom"; - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/NavigationCode.as b/src/scaleform/clik/constants/NavigationCode.as deleted file mode 100644 index abf51b8..0000000 --- a/src/scaleform/clik/constants/NavigationCode.as +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************** - -Filename : NavigationCode.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - /** - * An enumeration of common navigation equivalents. - */ - public class NavigationCode - { - // Constants - public static var UP:String = "up"; - public static var DOWN:String = "down"; - public static var LEFT:String = "left"; - public static var RIGHT:String = "right"; - - public static var START:String = "start"; - public static var BACK:String = "back"; - - /** Constants representing the typical gamepad keys. */ - public static var GAMEPAD_A:String = "enter-gamepad_A"; - public static var GAMEPAD_B:String = "escape-gamepad_B"; - public static var GAMEPAD_X:String = "gamepad_X"; - public static var GAMEPAD_Y:String = "gamepad_Y"; - public static var GAMEPAD_L1:String = "gamepad_L1"; - public static var GAMEPAD_L2:String = "gamepad_L2"; - public static var GAMEPAD_L3:String = "gamepad_L3"; - public static var GAMEPAD_R1:String = "gamepad_R1"; - public static var GAMEPAD_R2:String = "gamepad_R2"; - public static var GAMEPAD_R3:String = "gamepad_R3"; - public static var GAMEPAD_START:String = "start"; - public static var GAMEPAD_BACK:String = "back"; - - public static var ENTER:String = "enter-gamepad_A"; - public static var ESCAPE:String = "escape-gamepad_B"; - public static var END:String = "end"; - public static var HOME:String = "home"; - - public static var PAGE_DOWN:String = "pageDown"; - public static var PAGE_UP:String = "pageUp"; - - public static var TAB:String = "tab"; - public static var SHIFT_TAB:String = "shifttab"; // lowercase to match GFx - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/ScrollBarDirection.as b/src/scaleform/clik/constants/ScrollBarDirection.as deleted file mode 100644 index d541baf..0000000 --- a/src/scaleform/clik/constants/ScrollBarDirection.as +++ /dev/null @@ -1,28 +0,0 @@ -/************************************************************************** - -Filename : ScrollBarDirection.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - /** - * Definitions for the track directions to be used by ScrollBar. - */ - public class ScrollBarDirection - { - // Constants: - /** If HORIZONTAL is used, the ScrollBar will scroll horizontally. */ - public static const HORIZONTAL:String = "horizontal"; - /** If VERTICAL is used, the ScrollBar will scroll vertically. */ - public static const VERTICAL:String = "vertical"; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/ScrollBarTrackMode.as b/src/scaleform/clik/constants/ScrollBarTrackMode.as deleted file mode 100644 index 8d5b2f4..0000000 --- a/src/scaleform/clik/constants/ScrollBarTrackMode.as +++ /dev/null @@ -1,28 +0,0 @@ -/************************************************************************** - -Filename : ScrollBarTrackMode.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.constants -{ - /** - * Definitions for the available "track modes" for use with ScrollBar. - */ - public class ScrollBarTrackMode - { - // Constants: - /** If SCROLL_PAGE is used, when the track is clicked, the scroll bar will be scrolled by one page. */ - public static const SCROLL_PAGE:String = "scrollPage"; - /** If SCROLL_TO_CURSOR is used, when the track is clicked, the scroll bar will be scrolled to the location of the click. */ - public static const SCROLL_TO_CURSOR:String = "scrollToCursor"; - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/constants/WrappingMode.as b/src/scaleform/clik/constants/WrappingMode.as deleted file mode 100644 index 4094040..0000000 --- a/src/scaleform/clik/constants/WrappingMode.as +++ /dev/null @@ -1,28 +0,0 @@ -/************************************************************************** - -Filename : WrappingMode.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ -package scaleform.clik.constants -{ - /** - * Definitions for the available wrapping modes which affect list input. - */ - public class WrappingMode - { - // Constants: - /** Focus can leave the component from all edges of the component using arrow keys. */ - public static const NORMAL:String = "normal"; - /** Focus wil be unable to leave the component from all edges of the component using arrow keys. */ - public static const STICK:String = "stick"; - /** When selection reaches the last item in row/column, the next move will cause it to wrap to the beginning. Focus will remain in the component. */ - public static const WRAP:String = "wrap"; - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/Button.as b/src/scaleform/clik/controls/Button.as deleted file mode 100644 index a2da40c..0000000 --- a/src/scaleform/clik/controls/Button.as +++ /dev/null @@ -1,839 +0,0 @@ -/** - *

Buttons are the foundation component of the CLIK framework and are used anywhere a clickable interface control is required. The default Button class (scaleform.clik.controls.Button) supports a textField to display a label, and states to visually indicate user interaction. Buttons can be used on their own, or as part of a composite component, such as ScrollBar arrows or the Slider thumb. Most interactive components that are click-activated compose or extend Button.

- *

The CLIK Button is a general purpose button component, which supports mouse interaction, keyboard interaction, states and other functionality that allow it to be used in a multitude of user interfaces. It also supports toggle capability as well as animated states. The ToggleButton, AnimatedButton and AnimatedToggleButton provided in the Button.fla component source file all use the same base component class.

- * - *

Inspectable Properties

- *

- * The inspectable properties of the Button component are: - *

- *

- * - *

States

- *

- * The CLIK Button component supports different states based on user interaction. These states include - *

- *

- * - * These states are represented as keyframes in the Flash timeline, and are the minimal set of keyframes required for the Button component to operate correctly. There are other states that extend the capabilities of the component to support complex user interactions and animated transitions, and this information is provided in the Getting Started with CLIK Buttons document. - * - *

Events

- *

- * All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.

- * - * The events generated by the Button component are listed below. The properties listed next to the event are provided in addition to the common properties. - * - *

- */ - -/************************************************************************** - -Filename : Button.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ -package scaleform.clik.controls { - - import flash.display.DisplayObject; - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.events.TimerEvent; - import flash.text.TextField; - import flash.text.TextFieldAutoSize; - import flash.text.TextFormat; - import flash.utils.getTimer; - import flash.utils.Timer; - - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.constants.ControllerType; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.utils.Constraints; - import scaleform.clik.utils.ConstrainedElement; - - import scaleform.gfx.FocusEventEx; - import scaleform.gfx.MouseEventEx; - - [Event(name="SHOW", type="scaleform.clik.events.ComponentEvent")] - [Event(name="HIDE", type="scaleform.clik.events.ComponentEvent")] - [Event(name="FOCUS_IN", type="scaleform.clik.events.FocusHandlerEvent")] - [Event(name="FOCUS_OUT", type="scaleform.clik.events.FocusHandlerEvent")] - [Event(name="SELECT", type="flash.events.Event")] - [Event(name="STATE_CHANGE", type="scaleform.clik.events.ComponentEvent")] - [Event(name="PRESS", type="scaleform.clik.events.ButtonEvent")] - [Event(name="CLICK", type="scaleform.clik.events.ButtonEvent")] - [Event(name="DRAG_OVER", type="scaleform.clik.events.ButtonEvent")] - [Event(name="DRAG_OUT", type="scaleform.clik.events.ButtonEvent")] - [Event(name="RELEASE_OUTSIDE", type="scaleform.clik.events.ButtonEvent")] - - public class Button extends UIComponent { - - // Constants: - - // Public Properties: - /** Locks drag over and drag out state changes. Useful for scrollbar and slider thumbs. */ - public var lockDragStateChange:Boolean = false; - /** The delay (milliseconds) before the initial repeat event is fired. */ - public var repeatDelay:Number = 500; - /** The delay (milliseconds) between subsequent repeat events. */ - public var repeatInterval:Number = 200; - /** True if constraints are disabled for the component. Setting the disableConstraints property to true will remove constraints from the textfield. This is useful for components with timeline based textfield size tweens, since constraints break them due to a Flash quirk. */ - public var constraintsDisabled:Boolean = false; - /** True if the Button can be deselected when already selected and clicked again. False for RadioButtons by default.*/ - public var allowDeselect:Boolean = true; - /** True if the Button should not autosize itself when the state changes. False otherwise-- by default. Note that the autoSize property will not work if preventAutosizing is set to true. */ - public var preventAutosizing:Boolean = false; - - // Protected Properties: - /** @private */ - protected var _toggle:Boolean = false; - /** @private */ - protected var _label:String; - /** @private */ - protected var _state:String; - /** @private */ - protected var _group:ButtonGroup; - /** @private */ - protected var _groupName:String; - /** @private */ - protected var _selected:Boolean = false; - /** @private */ - protected var _data:Object; - /** @private */ - protected var _autoRepeat:Boolean = false; - /** @private */ - protected var _autoSize:String = TextFieldAutoSize.NONE; - /** @private */ - protected var _pressedByKeyboard:Boolean = false; - /** @private */ - protected var _isRepeating:Boolean = false; - /** Reference to the UIComponent that generated this Button, if applicatable (eg. ButtonGroup). @private */ - protected var _owner:UIComponent = null; - /** A list of frames that apply to a given state. The frames will be called in order, and the last existing frame will be displayed. @private */ - protected var _stateMap:Object = { - up:["up"], - over:["over"], - down:["down"], - release: ["release", "over"], - out:["out","up"], - disabled:["disabled"], - selecting: ["selecting", "over"], - toggle: ["toggle", "up"], - kb_selecting: ["kb_selecting", "up"], - kb_release: ["kb_release", "out", "up"], - kb_down: ["kb_down", "down"] - } - /** @private */ - protected var _newFrame:String; - /** @private */ - protected var _newFocusIndicatorFrame:String; - /** @private */ - protected var _repeatTimer:Timer; - /** @private */ - protected var _mouseDown:int = 0; // Determines if the mouse is in a press for each controller. - /** @private */ - protected var _focusIndicatorLabelHash:Object; - /** @private */ - protected var _autoRepeatEvent:ButtonEvent; - - // UI Elements: - /** A reference to the textField in the component. The textField is an optional element. Note that when state changes are made, the textField instance may change, so changes made to it externally may be lost. */ - public var textField:TextField; - public var defaultTextFormat:TextFormat; - - /** @private */ - protected var _focusIndicator:MovieClip; - - // Initialization: - public function Button() { - super(); - buttonMode = true; - } - - /** @private */ - override protected function preInitialize():void { - if (!constraintsDisabled) { - constraints = new Constraints(this, ConstrainMode.COUNTER_SCALE); - } - } - - /** @private */ - override protected function initialize():void { - super.initialize(); - - // Set tabEnabled to true in ctor so that it's true for configUI(). This allows user to change tabEnabled - // before configUI() occurs and ensures that Button is tabEnabled == true; by default. - tabEnabled = true; - } - - // Public getter / setters: - /** Data related to the button. This property is particularly helpful when using butons in a ButtonGroup. */ - [Inspectable(type = "string", defaultValue = "")] - public function get data():Object { return _data; } - public function set data(value:Object):void { - _data = value; - } - - /** Determines if the button dispatches "click" events when pressed down and held. */ - [Inspectable(defaultValue = "false")] - public function get autoRepeat():Boolean { return _autoRepeat; } - public function set autoRepeat(value:Boolean):void { - _autoRepeat = value; - } - - /** - * Enable/disable this component. Focus (along with keyboard events) and mouse events will be suppressed if disabled. - */ - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - super.enabled = value; - mouseChildren = false; // Keep mouseChildren false for Button and its subclasses. - - var state:String; - if (super.enabled) { - state = (_focusIndicator == null && (_displayFocus || _focused)) ? "over" : "up"; - } else { - state = "disabled"; - } - setState(state); - } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * false will remove support for tab key, direction key and mouse - * button based focus changes. - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - super.focusable = value; - } - - /** A button with a toggle value of true will change its selected state when the button is "clicked". */ - [Inspectable(defaultValue="false")] - public function get toggle():Boolean { return _toggle; } - public function set toggle(value:Boolean):void { - _toggle = value; - } - - /** Reference to the owner of this Button (generally, a subclass of CoreList). */ - public function get owner():UIComponent { return _owner; } - public function set owner(value:UIComponent):void { _owner = value; } - - /** Retrieve the current state of the Button. */ - public function get state():String { return _state; } - - /** - * Set the selected state of the Button. Buttons can have two sets of mouse states, a selected and unselected. - * When a Button's toggle property is true the selected state will be changed when the button - * is clicked, however the selected state can be set using ActionScript even if the toggle property is false. - */ - [Inspectable(defaultValue="false")] - public function get selected():Boolean { return _selected; } - public function set selected(value:Boolean):void { - if (_selected == value) { return; } - _selected = value; - - //#state This will do a change in state. - // 1. If the component is not focused, and the selected property is changed via code, it will do a hard frame change unless it is part of a button group. - // 2. If the component was pressed with the mouse, and is changing its selected state (toggle), it plays the "switch" animation. - // 2b. If the component was pressed with the keyboard, but has no focusMovie, the "switch" animation plays. - // 3. If the component was pressed with the keyboard (and is focused), it plays the kb_switch animation. - // 4. EDGE CASE The component will not be able to be do a up->focused_selected_up when a focused clip changes its selected state via code. - if (enabled) { - if (!_focused) { - setState("toggle"); - } - else if (_pressedByKeyboard && _focusIndicator != null) { - // Pressed with keyboard + focusIndicator (down->selected_up, selected_down->up) - setState("kb_selecting"); - } - else { - // Pressed with mouse or keyboard and no focusIndicator (down->selected_over, selected_down->over) - setState("selecting"); - } - - if (owner) { - // Use temp bool rather than _displayFocus to avoid redudancy check in set displayFocus(). - var df:Boolean = (_selected && owner != null && checkOwnerFocused()); - // If we have a focusIndicator and our owner is focused, use the "toggle" state. Otherwise, use "selecting". - setState( (df && _focusIndicator == null) ? "selecting" : "toggle" ); - displayFocus = df - } - } - else { - setState("disabled"); - } - - validateNow(); - - // The event is dispatched after the frame change so that listening objects can override the behavior. - dispatchEventAndSound(new Event(Event.SELECT)); - } - - /** - * A reference to the ButtonGroup instance that the button belongs to. The group is usually created - * in the parent clip of the button, so buttons in the same MovieClip scope with the same name can behave as - * a group. ButtonGroups will only be created in the parent scope when automatically created. - * @see ButtonGroup - */ - public function get group():ButtonGroup { return _group; } - public function set group(value:ButtonGroup):void { - if (_group != null) { - _group.removeButton(this); - removeEventListener(Event.REMOVED_FROM_STAGE, removeFromButtonGroup); - } - _group = value; - if (_group != null) { - _group.addButton(this); - addEventListener(Event.REMOVED_FROM_STAGE, removeFromButtonGroup, false, 0, true); - } - } - - /** - * The name of the group that the button belongs to. If the group does not exist, it is created in the parent of the button so that other buttons with the same group name can belong to the same group. - * @see #group - * @see ButtonGroup - */ - public function get groupName():String { return _groupName; } - public function set groupName(value:String):void { - if (_inspector && value == "") { return; } - if (_groupName == value) { return; } - if (value != null) { - addEventListener(Event.ADDED, addToAutoGroup, false, 0, true); - addEventListener(Event.REMOVED, addToAutoGroup, false, 0, true); - } else { - removeEventListener(Event.ADDED, addToAutoGroup, false); - removeEventListener(Event.REMOVED, addToAutoGroup, false); - } - _groupName = value; - addToAutoGroup(null); - } - - /** - * The ActionScript-only label parameter that sets the text directly, and assumes localization - * has been handled externally. - */ - [Inspectable(defaultValue="")] - public function get label():String { return _label; } - public function set label(value:String):void { - if (_label == value) { return; } - _label = value; - invalidateData(); - } - - /** - * Determines if the button will scale to fit the text that it contains. Setting the autoSize - * property to TextFieldAutoSize.NONE ("none") will leave its current size unchanged. - */ - [Inspectable(defaultValue="none", enumeration="none,left,right,center")] - public function get autoSize():String { return _autoSize; } - public function set autoSize(value:String):void { - if (value == _autoSize) { return; } - _autoSize = value; - invalidateData(); - } - - /** A reference to a MovieClip that is used to denote focus. It can either have one frame (which will cause the Button to show/hide this focus movie by toggling its visibility), or have two named frames: show and hide, which will be played appropriately.*/ - public function get focusIndicator():MovieClip { return _focusIndicator; } - public function set focusIndicator(value:MovieClip):void { - _focusIndicatorLabelHash = null; - _focusIndicator = value; - _focusIndicatorLabelHash = UIComponent.generateLabelHash(_focusIndicator); - } - - // Public Methods: - /** @private */ - override public function handleInput(event:InputEvent):void { - if (event.isDefaultPrevented()) { return; } - var details:InputDetails = event.details; - var index:uint = details.controllerIndex; - - switch (details.navEquivalent) { - case NavigationCode.ENTER: - if (details.value == InputValue.KEY_DOWN) { - handlePress(index); - event.handled = true; - } - else if (details.value == InputValue.KEY_UP) { - if (_pressedByKeyboard) { - handleRelease(index); - event.handled = true; - } - } - break; - } - } - - /** @private */ - override public function toString():String { - return "[CLIK Button " + name + "]"; - } - - // Protected Methods: - /** @private */ - override protected function configUI():void { - if (!constraintsDisabled) { - constraints.addElement("textField", textField, Constraints.ALL); - } - - super.configUI(); - tabEnabled = (_focusable && enabled && tabEnabled); - mouseChildren = tabChildren = false; - - addEventListener(MouseEvent.ROLL_OVER, handleMouseRollOver, false, 0, true); - addEventListener(MouseEvent.ROLL_OUT, handleMouseRollOut, false, 0, true); - addEventListener(MouseEvent.MOUSE_DOWN, handleMousePress, false, 0, true); - addEventListener(MouseEvent.CLICK, handleMouseRelease, false, 0, true); - addEventListener(MouseEvent.DOUBLE_CLICK, handleMouseRelease, false, 0, true); - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - - //LM: Consider moving to showFocus() or something similar. - if (_focusIndicator != null && !_focused && _focusIndicator.totalFrames == 1) { focusIndicator.visible = false; } - } - - /** @private */ - override protected function draw():void { - // State is invalid, and has been set (is not the default) - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - - if (_newFocusIndicatorFrame) { - focusIndicator.gotoAndPlay(_newFocusIndicatorFrame); - _newFocusIndicatorFrame = null; - } - - updateAfterStateChange(); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.STATE_CHANGE)); - // NFM: Should size be invalidated here by default? It can cause problems with timeline animations, - // especially with focusIndictators that extend beyond the size of the original MovieClip. Instead, - // perhaps let subclasses call invalidate(InvalidationType.SIZE) as necessary instead. - invalidate(InvalidationType.DATA, InvalidationType.SIZE); - } - - // Data is invalid when label or autoSize changes. - if (isInvalid(InvalidationType.DATA)) { - updateText(); - if (autoSize != TextFieldAutoSize.NONE) { - invalidateSize(); - } - } - - // Resize and update constraints - if (isInvalid(InvalidationType.SIZE) ) { - if (!preventAutosizing) { - alignForAutoSize(); - setActualSize(_width, _height); - } - if (!constraintsDisabled) { - constraints.update(_width, _height); - } - } - } - - /** @private */ - protected function addToAutoGroup(event:Event):void { - if (parent == null) { - group = null; - return; - } - var g:ButtonGroup = ButtonGroup.getGroup(_groupName, parent); - if (g == group) { return; } - group = g; - } - - /** @private */ - protected function removeFromButtonGroup(event:Event):void { - group = null; - } - - /** @private */ - protected function checkOwnerFocused():Boolean { - var ownerFocused:Boolean = false; - if (owner != null) { - ownerFocused = (_owner.focused != 0); // Is owner focused? - - // If the owner wasn't focused, check its .focusTarget (eg. ScrollingList in a DropDownMenu). - if (ownerFocused == 0) { - var ownerFocusTarget:Object = _owner.focusTarget; - if (ownerFocusTarget != null) { - ownerFocused = (ownerFocusTarget != 0) - } - } - } - - return ownerFocused; - } - - /** @private */ - protected function calculateWidth():Number { - var w:Number = actualWidth; - if (!constraintsDisabled) { - var element:ConstrainedElement = constraints.getElement("textField"); - w = Math.ceil(textField.textWidth + element.left + element.right + 5); // We add 5 pixels to accommodate Flash's poor measurement of anti-aliased fonts. - } - - return w; - } - - /** @private */ - protected function alignForAutoSize():void { - if (!initialized || _autoSize == TextFieldAutoSize.NONE || textField == null) { return; } - - var oldWidth:Number = _width; - var newWidth:Number = _width = calculateWidth(); - - switch (_autoSize) { - case TextFieldAutoSize.RIGHT: - var oldRight:Number = x + oldWidth; - x = oldRight - newWidth; - break; - case TextFieldAutoSize.CENTER: - var oldCenter:Number = x + oldWidth * 0.5; - x = oldCenter - newWidth * 0.5; - break; - } - } - - /** @private */ - protected function updateText():void { - if (_label != null && textField != null) { - textField.text = _label; - } - } - - /** @private */ - override protected function changeFocus():void { - if (!enabled) { return; } - if (_focusIndicator == null) { - setState((_focused || _displayFocus) ? "over" : "out"); - if (_pressedByKeyboard && !_focused) { - _pressedByKeyboard = false; - } - } else { - if (_focusIndicator.totalframes == 1) { - _focusIndicator.visible = _focused > 0; // Do a simple show/hide on single-frame focus indicators. - } else { - // Check if the focus state exists first, and use it. Otherwise use default behaviour. - var focusFrame:String = "state" + _focused; - if (_focusIndicatorLabelHash[focusFrame]) { - _newFocusIndicatorFrame = "state" + _focused; - } else { - _newFocusIndicatorFrame = (_focused || _displayFocus) ? "show" : "hide"; - } - invalidateState(); - } - // If focus is moved on keyboard press, the button needs to reset since it will not recieve a key up event. - if (_pressedByKeyboard && !_focused) { - setState("kb_release"); - _pressedByKeyboard = false; - } - } - } - - // Mouse-only input - /** @private */ - protected function handleMouseRollOver(event:MouseEvent):void { - var sfEvent:MouseEventEx = event as MouseEventEx; - var mouseIdx:uint = (sfEvent == null) ? 0 : sfEvent.mouseIdx; - - // DRAG_OVER - if (event.buttonDown) { - dispatchEventAndSound(new ButtonEvent(ButtonEvent.DRAG_OVER)); - - if (!enabled) { return; } - if (lockDragStateChange && Boolean(_mouseDown << mouseIdx & 1)) { return; } - if (_focused || _displayFocus) { - setState(focusIndicator == null ? "down" : "kb_down"); // The user has dragged out first, so do a up->down transition. - } else { - setState("over"); - } - } - - // MOUSE_OVER - else { - if (!enabled) { return; } - if (_focused || _displayFocus) { - if (_focusIndicator != null) { setState("over"); } - } else { - setState("over"); - } - } - - } - - /** @private */ - protected function handleMouseRollOut(event:MouseEvent):void { - var sfEvent:MouseEventEx = event as MouseEventEx; - var index:uint = (sfEvent == null) ? 0 : sfEvent.mouseIdx; - - // DRAG_OUT - if (event.buttonDown) { - dispatchEventAndSound(new ButtonEvent(ButtonEvent.DRAG_OUT)); - if (Boolean(_mouseDown & 1 << index)) { - if (stage != null) { // Button may have just been removed from stage, firing a MouseRollOut. Stage will be null in this case. - stage.addEventListener(MouseEvent.MOUSE_UP, handleReleaseOutside, false, 0, true); - } - } - - if (lockDragStateChange || !enabled) { return; } - if (_focused || _displayFocus) { - setState(_focusIndicator == null ? "release" : "kb_release"); // The user has pressed and dragged out of the component. Do a down->up transition. - } else { - setState("out"); - } - } - - // ROLL_OUT - else { - if (!enabled) { return; } - if (_focused || _displayFocus) { - if (_focusIndicator != null) { setState("out"); } - } - else { - setState("out"); - } - } - } - - /** @private */ - protected function handleMousePress(event:MouseEvent):void { - var sfEvent:MouseEventEx = event as MouseEventEx; - var mouseIdx:uint = (sfEvent == null) ? 0 : sfEvent.mouseIdx; // index of Mouse that generated event. - var btnIdx:uint = (sfEvent == null) ? 0 : sfEvent.buttonIdx; // index of Button of Mouse that generated event. - if (btnIdx != 0) { return; } - - _mouseDown |= 1 << mouseIdx; - - if (enabled) { - setState("down"); - - // Uses single controller like AS2. - if (autoRepeat && _repeatTimer == null) { - _autoRepeatEvent = new ButtonEvent(ButtonEvent.CLICK, true, false, mouseIdx, btnIdx, false, true); - _repeatTimer = new Timer(repeatDelay, 1); - _repeatTimer.addEventListener(TimerEvent.TIMER_COMPLETE, beginRepeat, false, 0, true); - _repeatTimer.start(); - } - - var sfButtonEvent:ButtonEvent = new ButtonEvent(ButtonEvent.PRESS, true, false, mouseIdx, btnIdx, false, false); - dispatchEventAndSound(sfButtonEvent); - } - } - - /** @private */ - protected function handleMouseRelease(event:MouseEvent):void { - _autoRepeatEvent = null; - if (!enabled) { return; } - var sfEvent:MouseEventEx = event as MouseEventEx; - var mouseIdx:uint = (sfEvent == null) ? 0 : sfEvent.mouseIdx; - var btnIdx:uint = (sfEvent == null) ? 0 : sfEvent.buttonIdx; // index of Button of Mouse that generated event. - if (btnIdx != 0) { return; } - - _mouseDown ^= 1 << mouseIdx; - - // Always remove timer, in case autoRepeat was turned off during press. - if (_mouseDown == 0 && _repeatTimer) { - _repeatTimer.stop(); _repeatTimer.reset(); - _repeatTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, beginRepeat); - _repeatTimer.removeEventListener(TimerEvent.TIMER, handleRepeat); - _repeatTimer = null; //LM: Consider leaving in memory. - } - - setState("release"); - handleClick(mouseIdx); - - if (!_isRepeating) { - var sfButtonEvent:ButtonEvent = new ButtonEvent(ButtonEvent.CLICK, true, false, mouseIdx, btnIdx, false, false); - dispatchEventAndSound(sfButtonEvent); - } - - _isRepeating = false; - } - - /** @private */ - protected function handleReleaseOutside(event:MouseEvent):void { - _autoRepeatEvent = null; - if (contains(event.target as DisplayObject)) { return; } - - var sfEvent:MouseEventEx = event as MouseEventEx; - var mouseIdx:uint = (sfEvent == null) ? 0 : sfEvent.mouseIdx; - var btnIdx:uint = (sfEvent == null) ? 0 : sfEvent.buttonIdx; // index of Button of Mouse that generated event. - if (btnIdx != 0) { return; } - - if (stage) stage.removeEventListener(MouseEvent.MOUSE_UP, handleReleaseOutside, false); - - _mouseDown ^= 1 << mouseIdx; - dispatchEventAndSound(new ButtonEvent(ButtonEvent.RELEASE_OUTSIDE)); - if (!enabled) { return; } - - if (lockDragStateChange) { - if (_focused || _displayFocus) { - setState(focusIndicator == null ? "release" : "kb_release"); // See handleDragOut(). - } else { - setState("kb_release"); // * button is not focused and released outside (down->up). - } - } - } - - // Controller input - /** @private */ - protected function handlePress(controllerIndex:uint = 0):void { - if (!enabled) { return; } - _pressedByKeyboard = true; - setState(_focusIndicator == null ? "down" : "kb_down"); - - // Uses single controller like AS2. - if (autoRepeat && _repeatTimer == null) { - _autoRepeatEvent = new ButtonEvent(ButtonEvent.CLICK, true, false, controllerIndex, 0, true, true); - _repeatTimer = new Timer(repeatDelay, 1); - _repeatTimer.addEventListener(TimerEvent.TIMER_COMPLETE, beginRepeat, false, 0, true); - _repeatTimer.start(); - } - - var sfEvent:ButtonEvent = new ButtonEvent(ButtonEvent.PRESS, true, false, controllerIndex, 0, true, false); - dispatchEventAndSound(sfEvent); - - } - - /** @private */ - protected function handleRelease(controllerIndex:uint = 0):void { - if (!enabled) { return; } - setState(focusIndicator == null ? "release" : "kb_release"); - - // Always remove timer, in case autoRepeat was turned off during press. - if (_repeatTimer) { - _repeatTimer.stop(); _repeatTimer.reset(); - _repeatTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, beginRepeat); - _repeatTimer.removeEventListener(TimerEvent.TIMER, handleRepeat); - _repeatTimer = null; //LM: Consider leaving in memory. - } - - handleClick(controllerIndex); - _pressedByKeyboard = false; - - if (!_isRepeating) { - var sfEvent:ButtonEvent = new ButtonEvent(ButtonEvent.CLICK, true, false, controllerIndex, 0, true, false); - dispatchEventAndSound(sfEvent); - } - - _isRepeating = false; - } - - /** @private */ - protected function handleClick(controllerIndex:uint = 0):void { - if (toggle && (!selected || allowDeselect)) { selected = !selected; } - } - - /** @private */ - protected function beginRepeat(event:TimerEvent):void { - _repeatTimer.delay = repeatInterval; - _repeatTimer.repeatCount = 0; - _repeatTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, beginRepeat); - _repeatTimer.addEventListener(TimerEvent.TIMER, handleRepeat, false, 0, true); - _repeatTimer.reset(); - _repeatTimer.start(); - } - - /** @private */ - protected function handleRepeat(event:TimerEvent):void { - // Always remove timer, in case autoRepeat was turned off during press. - if (_mouseDown == 0 && !_pressedByKeyboard) { - _repeatTimer.stop(); _repeatTimer.reset(); - _repeatTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, beginRepeat); - _repeatTimer.removeEventListener(TimerEvent.TIMER, handleRepeat); - _repeatTimer = null; //LM: Consider leaving in memory. - } - - if (_autoRepeatEvent) { // In theory, mousePressEvent should never be null here. - _isRepeating = true; - dispatchEventAndSound(_autoRepeatEvent); - } - } - - /** @private */ - protected function setState(state:String):void { - _state = state; - var prefixes:Vector. = getStatePrefixes(); - var states:Array = _stateMap[state]; - if (states == null || states.length == 0) { return; } - var l:uint = prefixes.length; - for (var i:uint=0; i = Vector.([""]); - /** @private */ - protected var statesSelected:Vector. = Vector.(["selected_", ""]); - /** @private */ - protected function getStatePrefixes():Vector. { - return _selected ? statesSelected : statesDefault; - } - - /** This happens any time the state changes. @private */ - protected function updateAfterStateChange():void { - if (!initialized) { return; } - if (constraints != null && !constraintsDisabled && textField != null) { - constraints.updateElement("textField", textField); // Update references in Constraints - } - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/ButtonBar.as b/src/scaleform/clik/controls/ButtonBar.as deleted file mode 100644 index 24055a3..0000000 --- a/src/scaleform/clik/controls/ButtonBar.as +++ /dev/null @@ -1,572 +0,0 @@ -/** - * The ButtonBar is similar to the ButtonGroup although it has a visual representation. It is also able to create Button instances on the fly based on a DataProvider. The ButtonBar is useful for creating dynamic tab-bar like UI elements. - * - *

Inspectable Properties

- *

- * The inspectable properties of the Button component are: - *

    - *
  • autoSize: Determines if the ButtonBar's Buttons will scale to fit the text that it contains and which direction to align the resized Button. Setting the autoSize property to TextFieldAutoSize.NONE ("none") will leave the child Buttons' size unchanged.
  • - *
  • buttonWidth: Sets a common width to all Button instances. If autoSize is set to true this property is ignored.
  • - *
  • direction: Button placement. Horizontal will place the Button instances side-by-side, while vertical will stack them on top of each other.
  • - *
  • enabled: Disables the button if set to true.
  • - *
  • focusable: By default the ButtonBar can receive focus for user interactions. Setting this property to false will disable focus acquisition.
  • - *
  • itemRenderer: Linkage ID of the Button component symbol. This symbol will be instantiated as needed based on the data assigned to the ButtonBar.
  • - *
  • spacing: The spacing between the Button instances. Affects only the current direction (see direction property).
  • - *
  • visible: Hides the component if set to false.
  • - *
- *

- * - *

States

- *

- * The CLIK ButtonBar does not have any visual states because its managed Button components are used to display the group state. - *

- * - *

Events

- *

- * All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.

    - *
  • type: The event type.
  • - *
  • target: The target that generated the event.
- * - * The events generated by the Button component are listed below. The properties listed next to the event are provided in addition to the common properties. - *
    - *
  • ComponentEvent.SHOW: The visible property has been set to true at runtime.
  • - *
  • ComponentEvent.HIDE: The visible property has been set to false at runtime.
  • - *
  • FocusHandlerEvent.FOCUS_IN: The component has received focus.
  • - *
  • FocusHandlerEvent.FOCUS_OUT: The component has lost focus.
  • - *
  • ButtonBar.BUTTON_SELECT: The selected property has changed.
  • - *
  • IndexEvent.INDEX_CHANGE,: The button has been pressed.
  • - *
- *

- */ - -/************************************************************************** - -Filename : ButtonBar.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.events.Event; - import flash.text.TextFieldAutoSize; - import flash.system.ApplicationDomain; - - import scaleform.clik.controls.Button; - import scaleform.clik.controls.ButtonGroup; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.constants.InputValue; - import scaleform.clik.core.UIComponent; - import scaleform.clik.data.DataProvider; - import scaleform.clik.events.IndexEvent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ButtonBarEvent; - import scaleform.clik.interfaces.IDataProvider; - import scaleform.clik.ui.InputDetails; - - public class ButtonBar extends UIComponent - { - // Constants: - public static const DIRECTION_HORIZONTAL:String = "horizontal"; - public static const DIRECTION_VERTICAL:String = "vertical"; - - // Public Properties: - - // Protected Properties: - /** @private */ - protected var _autoSize:String = "none"; - /** @private */ - protected var _buttonWidth:Number = 0; - /** @private */ - protected var _dataProvider:IDataProvider; - /** @private */ - protected var _direction:String = DIRECTION_HORIZONTAL; - /** @private */ - protected var _group:ButtonGroup; - /** @private */ - protected var _itemRenderer:String = "Button"; - /** @private */ - protected var _itemRendererClass:Class; - /** @private */ - protected var _labelField:String = "label"; - /** @private */ - protected var _labelFunction:Function; - /** @private */ - protected var _renderers:Array; - /** @private */ - protected var _spacing:Number = 0; - /** @private */ - protected var _selectedIndex:Number = -1; - - // UI Elements: - public var container:MovieClip; - - // Initialization: - public function ButtonBar() { - super(); - } - - /** @private */ - override protected function initialize():void { - super.initialize(); - dataProvider = new DataProvider(); // Default Data. - _renderers = []; - } - - // Public Getter / Setters: - /** - * Enable/disable this component. Focus (along with keyboard events) and mouse events will be suppressed if disabled. - */ - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - if (enabled == value) { return; } - super.enabled = value; - for (var i:Number = 0; i < _renderers.length; i++) { - if (_itemRendererClass) { - (_renderers[i] as _itemRendererClass).enabled = value; - } else { - (_renderers[i] as UIComponent).enabled = value; - } - - } - } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * false will remove support for tab key, direction key and mouse - * button based focus changes. - * @see focusable - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - super.focusable = value; - } - - /** - * The data model displayed in the component. The dataProvider must implement the - * IDataProvider interface. When a new DataProvider is set, the selectedIndex - * property will be reset to 0. - * @see DataProvider - * @see IDataProvider - */ - public function get dataProvider():IDataProvider { return _dataProvider; } - public function set dataProvider(value:IDataProvider):void { - if (_dataProvider == value) { return; } - if (_dataProvider != null) { - _dataProvider.removeEventListener(Event.CHANGE, handleDataChange, false); - } - _dataProvider = value; - if (_dataProvider == null) { return; } - _dataProvider.addEventListener(Event.CHANGE, handleDataChange, false, 0, true); - invalidateData(); - } - - /** - * The linkage ID for the renderer used to display each item in the list. The list components only support - * a single itemRenderer for all items. - */ - [Inspectable(name="itemRenderer", defaultValue="Button")] - public function set itemRendererName(value:String):void { - if ((_inspector && value == "Button") || value == "") { return; } - - // Need a try/catch in case the specified class cannot be found: - try { - var domain:ApplicationDomain = ApplicationDomain.currentDomain; - if (loaderInfo != null && loaderInfo.applicationDomain != null) domain = loaderInfo.applicationDomain; - var classRef:Class = domain.getDefinition(value) as Class; - } catch (error:*) { - throw new Error("The class " + value + " cannot be found in your library. Please ensure it exists."); - } - - if (classRef != null) { - _itemRendererClass = classRef; - invalidate(); - } - } - - /** - * The spacing between each item in pixels. Spacing can be set to a negative value to overlap items. - */ - [Inspectable(defaultValue="0")] - public function get spacing():Number { return _spacing; } - public function set spacing(value:Number):void { - _spacing = value; - invalidateSettings(); - } - - /** - * The direction the buttons draw. When the direction is set to "horizontal", the buttons will draw on the same y-coordinate, with the spaceing between each instance. When the direction is set to "vertical", the buttons will draw with the same x-coordinate, with the spacing between each instance. - * @see #spacing - */ - [Inspectable(defaultValue="horizontal", type="list", enumeration="horizontal,vertical")] - public function get direction():String { return _direction; } - public function set direction(value:String):void { - _direction = value; - invalidateSettings(); - } - - /** - * Determines if the buttons auto-size to fit their label. This parameter will only be applied if the itemRenderer supports it. - */ - [Inspectable(type="String", enumeration="none,left,center,right", defaultValue="none")] - public function get autoSize():String { return _autoSize; } - public function set autoSize(value:String):void { - if (value == _autoSize) { return; } - _autoSize = value; - for (var i:Number=0; i < _renderers.length; i++) { - (_renderers[i] as _itemRendererClass).autoSize = _autoSize; - } - invalidateSettings(); - } - - /** - * The width of each button. Overrides the {@code autoSize} property when set. Set to 0 to let the component auto-size. - */ - [Inspectable(defaultValue="0")] - public function get buttonWidth():Number { return _buttonWidth; } - public function set buttonWidth(value:Number):void { - _buttonWidth = value; - invalidate(); - } - - /** - * The index of the item that is selected in a single-selection list. - */ - public function get selectedIndex():int { return _selectedIndex; } - public function set selectedIndex(value:int):void { - if (value == _selectedIndex) { return; } - var oldSelectedIndex:int = _selectedIndex; - - var renderer:Button = _renderers[oldSelectedIndex] as Button; - if (renderer) { - renderer.selected = false; - } - - _selectedIndex = value; - - renderer = _renderers[_selectedIndex] as Button; - if (renderer) { - renderer.selected = true; - } - - dispatchEventAndSound( new IndexEvent(IndexEvent.INDEX_CHANGE, true, true, _selectedIndex, oldSelectedIndex, _dataProvider[_selectedIndex]) ); - } - - /** - * The item at the selectedIndex in the DataProvider. - */ - public function get selectedItem():Object { return _dataProvider.requestItemAt(_selectedIndex); } - - /** - * The {@code data} property of the selectedItem. - * @see Button#data - */ - public function get data():Object { return selectedItem.data; } - - /** - * The name of the field in the {@code dataProvider} model to be displayed as the label for itemRenderers. A labelFunction will be used over a labelField if it is defined. - */ - public function get labelField():String { return _labelField; } - public function set labelField(value:String):void { - _labelField = value; - invalidateData(); - } - - /** - * The function used to determine the label for itemRenderers. A labelFunction will override a labelField if it is defined. - */ - public function get labelFunction():Function { return _labelFunction; } - public function set labelFunction(value:Function):void { - _labelFunction = value; - invalidateData(); - } - - // Public Methods: - /** Mark the settings of this component invalid and schedule a draw() on next Stage.INVALIDATE event. */ - public function invalidateSettings():void { - invalidate(InvalidationType.SETTINGS); - } - - /** - * Convert an item to a label string using the labelField and labelFunction. If the item is not an object, then it will be converted to a string, and returned. - * @param item The item to convert to a label. - * @returns The converted label string. - * @see #labelField - * @see #labelFunction - */ - public function itemToLabel(item:Object):String { - if (item == null) { return ""; } - if (_labelFunction != null) { - return _labelFunction(item); - } else if (item is String) { - return item as String; - } else if (_labelField != null && item[_labelField] != null) { - return item[_labelField]; - } - return item.toString(); - } - - /** Retrieve a reference to one of the ButtonBar's Buttons. */ - public function getButtonAt(index:int):Button { - if (index >= 0 && index < _renderers.length) { - return _renderers[index]; - } else { - return null; - } - } - - /** @private */ - override public function handleInput(event:InputEvent):void { - if (event.handled) { return; } // Already handled. - - // Pass on to selected renderer first - var renderer:Button = _renderers[_selectedIndex] as Button; - if (renderer != null) { - renderer.handleInput(event); // Since we are just passing on the event, it won't bubble, and should properly stopPropagation. - if (event.handled) { return; } - } - - // Only allow actions on key down, but still set handled=true when it would otherwise be handled. - var details:InputDetails = event.details; - var keyPress:Boolean = (details.value == InputValue.KEY_DOWN || details.value == InputValue.KEY_HOLD); - if (!keyPress) { return; } - - var indexChanged:Boolean = false; - var newIndex:Number; - - switch(details.navEquivalent) { - case NavigationCode.LEFT: - if (_direction == DIRECTION_HORIZONTAL) { - newIndex = _selectedIndex - 1; - indexChanged = true; - } - break; - case NavigationCode.RIGHT: - if (_direction == DIRECTION_HORIZONTAL) { - newIndex = _selectedIndex + 1; - indexChanged = true; - } - break; - case NavigationCode.UP: - if (_direction == DIRECTION_VERTICAL) { - newIndex = _selectedIndex - 1; - indexChanged = true; - } - break; - case NavigationCode.DOWN: - if (_direction == DIRECTION_VERTICAL) { - newIndex = _selectedIndex + 1; - indexChanged = true; - } - break; - default: - break; - } - - if (indexChanged) { - newIndex = Math.max(0, Math.min(_dataProvider.length - 1, newIndex)); - if (newIndex != _selectedIndex) { - selectedIndex = newIndex; - event.handled = true; - } - } - } - - /** @private */ - override public function toString():String { - return "[CLIK ButtonBar " + name + "]"; - } - - // Protected Methods: - /** @private */ - override protected function configUI():void { - super.configUI(); - - tabEnabled = (_focusable && enabled); - - if (_group == null) { - _group = new ButtonGroup(name + "Group", this); - } - _group.addEventListener(ButtonEvent.CLICK, handleButtonGroupChange, false, 0, true); - - if (container == null) { - container = new MovieClip(); - addChild(container); - } - - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - } - - /** @private */ - override protected function draw():void { - if (isInvalid(InvalidationType.RENDERERS) || isInvalid(InvalidationType.DATA) || - isInvalid(InvalidationType.SETTINGS) || isInvalid(InvalidationType.SIZE)) { - - removeChild(container); - setActualSize(_width, _height); - container.scaleX = 1 / scaleX; - container.scaleY = 1 / scaleY; - addChild(container); - - updateRenderers(); - } - } - - /** @private */ - protected function refreshData():void { - selectedIndex = Math.min(_dataProvider.length - 1, _selectedIndex); - if (_dataProvider) { - _dataProvider.requestItemRange(0, _dataProvider.length-1, populateData); - } - } - - /** @private */ - protected function updateRenderers():void { - var w:Number = 0; - var h:Number = 0; - var overflowIndex:int = -1; - - // If the rendererClass the same as the previous rendererClass, remove them properly. - if (_renderers[0] is _itemRendererClass) { - while (_renderers.length > _dataProvider.length) { - var c:int = _renderers.length - 1; - if (container.contains( _renderers[c] )) { - container.removeChild( _renderers[c] ); - } - _renderers.splice(c--, 1); - } - } - else { - while (container.numChildren > 0) { - container.removeChildAt(0); - } - _renderers.length = 0; - } - - // Create any new renderers we may need without overflowing. - for (var i:uint = 0; i < _dataProvider.length && overflowIndex == -1; i++) { - var renderer:Button; - var isNew:Boolean = false; - - if ( i < _renderers.length ) { - renderer = _renderers[i]; - } - else { - renderer = new _itemRendererClass(); - setupRenderer(renderer, i); - isNew = true; - } - - // NFM: Consider tracking changes to renderer and then deciding on whether invalidation is necessary. - populateRendererData(renderer, i); - if (_autoSize == TextFieldAutoSize.NONE && _buttonWidth > 0) { - renderer.width = _buttonWidth; // Manually size the renderer - } - else if (_autoSize != TextFieldAutoSize.NONE) { - renderer.autoSize = _autoSize; - } - - renderer.validateNow(); - - if (_direction == DIRECTION_HORIZONTAL) { - if ( _width > (renderer.width + _spacing + w)) { - renderer.y = 0; - renderer.x = w; - w += renderer.width + _spacing; - } else { - // If the ButtonBar is not large enough to support the renderer, do not create it. - overflowIndex = i; - renderer = null; - } - } else { - if ( _height > (renderer.height + _spacing + h)) { - renderer.x = 0; - renderer.y = h; - h += renderer.height + _spacing; - } else { - // If the ButtonBar is not large enough to support the renderer, do not create it. - overflowIndex = i; - renderer = null; - } - } - - if (isNew && renderer != null) { // Renderer will be null if it was overflow. - renderer.group = _group; // Don't set renderer.group beforehand or it will be added to group's array. - container.addChild(renderer); - _renderers.push(renderer); - } - } - - // Clean up the renderers now that the overflowIndex has been set. - if (overflowIndex > - 1) { - for (var j:int = _renderers.length - 1; j >= overflowIndex; j--) { - var rend:Button = _renderers[j] - if (rend) { - if (container.contains(rend)) { - container.removeChild(rend); - } - _renderers.splice(j, 1); - } - } - } - - selectedIndex = Math.min(_dataProvider.length - 1, _selectedIndex); - } - - /** @private */ - protected function populateData(data:Array):void { - for (var i:uint = 0; i < _renderers.length; i++) { - var renderer:Button = _renderers[i] as Button; - populateRendererData( renderer, i ); - renderer.validateNow(); - } - } - - /** @private */ - protected function populateRendererData(renderer:Button, index:uint):void { - renderer.label = itemToLabel( _dataProvider.requestItemAt(index) ); - renderer.data = _dataProvider.requestItemAt(index); - renderer.selected = (index == selectedIndex); - } - - /** @private */ - protected function setupRenderer(renderer:Button, index:uint):void { - renderer.owner = this; - renderer.focusable = false; - renderer.focusTarget = this; - renderer.toggle = true; - renderer.allowDeselect = false; - } - - /** @private */ - protected function handleButtonGroupChange(event:Event):void { - if (_group.selectedIndex != selectedIndex) { - selectedIndex = _group.selectedIndex; - dispatchEventAndSound(new ButtonBarEvent(ButtonBarEvent.BUTTON_SELECT, false, true, _selectedIndex, event.target as Button)); - } - } - - /** @private */ - protected function handleDataChange(event:Event):void { - invalidate(InvalidationType.DATA); - } - - /** @private */ - override protected function changeFocus():void { - var renderer:Button = _renderers[_selectedIndex] as Button; - if (renderer == null) { return; } - renderer.displayFocus = (_focused > 0); - } - } -} diff --git a/src/scaleform/clik/controls/ButtonGroup.as b/src/scaleform/clik/controls/ButtonGroup.as deleted file mode 100644 index edb2366..0000000 --- a/src/scaleform/clik/controls/ButtonGroup.as +++ /dev/null @@ -1,253 +0,0 @@ -/** - * The CLIK ButtonGroup component is used to manage sets of buttons. It allows one button in the set to be selected, and ensures that the rest are unselected. If the user selects another button in the set, then the currently selected button will be unselected. Any component that derives from the CLIK Button component such as CheckBox and RadioButton) can be assigned a ButtonGroup instance. - * - *

Inspectable Properties

- *

- * The ButtonGroup does not have a visual representation on the Stage. Therefore no inspectable properties are available. - *

- * - *

States

- * - *

- * The ButtonGroup does not have a visual representation on the Stage. Therefore no states are associated with it. - *

- * - *

Events

- *

- * All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.

    - *
  • type: The event type.
  • - *
  • target: The target that generated the event.
- * - * The events generated by the Button component are listed below. The properties listed next to the event are provided in addition to the common properties. - *
    - *
  • Event.CHANGE: The selected button of the ButtonGroup has changed.
  • - *
  • ButtonEvent.BUTTON_CLICK: A button in the group has been clicked.
  • - *
- *

-*/ - -/************************************************************************** - -Filename : ButtonGroup.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.DisplayObjectContainer; - import flash.display.Sprite; - import flash.events.Event; - import flash.events.EventDispatcher; - import flash.events.MouseEvent; - import flash.utils.Dictionary; - - import scaleform.clik.controls.Button; - import scaleform.clik.events.ButtonEvent; - - [Event(name="BUTTON_CLICK", type="flash.events.ButtonEvent")] - [Event(name="CHANGE", type="flash.events.Event")] - - public class ButtonGroup extends EventDispatcher - { - // Constants: - public static var groups:Dictionary = new Dictionary(true); - public static function getGroup(name:String, scope:DisplayObjectContainer):ButtonGroup { - var list:Object = groups[scope]; - if (list == null) { list = groups[scope] = new Object(); } - var group:ButtonGroup = list[name.toLowerCase()]; - if (group == null) { group = list[name.toLowerCase()] = new ButtonGroup(name, scope); } - return group; - } - - // Public Properties: - /** - * The name of the ButtonGroup, specified by the {@code groupName} property on the subscribing Buttons. - * @see Button#groupName - */ - public var name:String; - /** The MovieClip container in which this ButtonGroup belongs. @private */ - protected var weakScope:Dictionary; - /** The current Button that is selected. Only a single Button can be selected at one time. */ - public var selectedButton:Button; - - // Protected Properties: - /** @private */ - protected var _children:Array; - - // Initialization: - public function ButtonGroup(name:String, scope:DisplayObjectContainer) { - this.name = name; - - // We do this to avoid creating a strong reference to the scope. A strong reference - // may interfere with unloading content. A Dictionary is used to provide weak reference - // support. - this.weakScope = new Dictionary(true); - this.weakScope[scope] = null; - - _children = []; - } - - // Public getter / setters: - /** - * The number of buttons in the group. - */ - public function get length():uint { return _children.length; } - /** - * The data for the selected Button. - */ - public function get data():Object { return selectedButton.data; } - /** - * The index of the Button in the ButtonGroup's children array. - */ - public function get selectedIndex():int { - return _children.indexOf(selectedButton); - } - - public function get scope():DisplayObjectContainer { - var doc:DisplayObjectContainer = null; - for (var a:String in scope) { - doc = a as DisplayObjectContainer; - break; - } - return doc; - } - - // Public Methods: - /** - * Add a Button to group. A Button can only be added once to a ButtonGroup, and can only exist in - * a single group at a time. Buttons will change the selection of a ButtonGroup by dispatching "select" - * and "click" events. - * @param button The Button instance to add to this group - */ - public function addButton(button:Button):void { - removeButton(button); - _children.push(button); - - if (button.selected) { - updateSelectedButton(button, true); - } - - button.addEventListener(Event.SELECT, handleSelect, false, 0, true); - button.addEventListener(ButtonEvent.CLICK, handleClick, false, 0, true); - button.addEventListener(Event.REMOVED, handleRemoved, false, 0, true); - } - - /** - * Remove a button from the group. If it the last button in the group, the button should clean up - * and destroy the ButtonGroup. - * @param button The Button instance to be removed from group. - */ - public function removeButton(button:Button):void { - var index:int = _children.indexOf(button); - if (index == -1) { return; } - - _children.splice(index, 1); - - button.removeEventListener(Event.SELECT, handleSelect, false); - button.removeEventListener(ButtonEvent.CLICK, handleClick, false); - } - - /** - * Find a button at a specified index in the ButtonGroup. Buttons are indexed in the order that they are added. - * @param index Index in the ButtonGroup of the Button. - * @returns The button at the specified index. null if there is no button at that index. - */ - public function getButtonAt( index:int ):Button { return _children[index] as Button; } - - public function setSelectedButtonByIndex( index:uint, selected:Boolean = true ):Boolean { - var success:Boolean = false; - var btn:Button = _children[index] as Button; - if (btn != null) { - btn.selected = selected; - success = true; - } - return success; - } - - /** Clear the currently selected button, effectively deselecting the group. */ - public function clearSelectedButton():void - { - updateSelectedButton(null); - } - - /** Returns true if the Button provided is part of the ButtonGroup. */ - public function hasButton(button:Button):Boolean { - return _children.indexOf(button) > -1; - } - - /** @private */ - override public function toString():String { - return "[CLIK ButtonGroup " + name + " (" + _children.length + ")]"; - } - - // Protected Methods: - /** - * The "selected" state of one of the buttons in the group has changed. If the button is selected, - * it will become the new {@code selectedButton}. If it is not, the selectedButton in the group will be - * set to {@code null}. - * @private - */ - protected function handleSelect(event:Event):void { - var button:Button = event.target as Button; - if (button.selected) { - updateSelectedButton(button, true); - } else { - updateSelectedButton(button, false); - } - } - - /** - * Sets the specified button to the {@code selectedButton}. The selected property of the previous selected - * Button will be set to {@code false}. If {@code null} is passed to this method, the current selected Button - * will be deselected, and the {@code selectedButton} property set to {@code null}. - * @param button The button instance to select. - * @see #selectedButton - * @private - */ - protected function updateSelectedButton(button:Button, selected:Boolean = true):void { - if (selected && button == selectedButton) { return; } - - // Determine if this is just a "turn off currently selected" action. - var turnOffOnly:Boolean = (!selected && button == selectedButton && button.allowDeselect); - - // Set the selectedButton early, because subsquent deselection of the current button will fire this method - // again. - var oldButton:Button = selectedButton; - if (selected) { selectedButton = button; } - - if (selected && oldButton != null) { - oldButton.selected = false; - } - - if (turnOffOnly) { - selectedButton = null; - } else if (!selected) { - return; - } - - dispatchEvent(new Event(Event.CHANGE)); - } - - /** - * A button in the group has been clicked. The button will be set to the {@code selectedButton}. - * @private - */ - protected function handleClick(event:ButtonEvent):void { - dispatchEvent(event); - } - - /** - * @private - */ - protected function handleRemoved(event:Event):void { - removeButton(event.target as Button); - } - } - -} diff --git a/src/scaleform/clik/controls/CheckBox.as b/src/scaleform/clik/controls/CheckBox.as deleted file mode 100644 index cb429e5..0000000 --- a/src/scaleform/clik/controls/CheckBox.as +++ /dev/null @@ -1,116 +0,0 @@ -/** - * The CheckBox is a Button component that is set to toggle the selected state when clicked. CheckBoxes are used to display and change a true/false (Boolean) value. It is functionally equivalent to the ToggleButton, but sets the toggle property implicitly. - * - *

Inspectable Properties

- *

- * Since it derives from the Button control, the CheckBox contains the same inspectable properties as the Button - * with the omission of the toggle and disableFocus properties. - *

    - *
  • autoSize: Determines if the button will scale to fit the text that it contains and which direction to align the resized button. Setting the autoSize property to TextFieldAutoSize.NONE ("none") will leave its current size unchanged.
  • - *
  • data: Custom string that can be attached to the component as seperate data than the CheckBox's label.
  • - *
  • enabled: Disables the component if set to false.
  • - *
  • focusable: By default buttons receive focus for user interactions. Setting this property to false will disable focus acquisition.
  • - *
  • label: Sets the label of the Button.
  • - *
  • selected: Checks (or selects) the CheckBox when set to true.
  • - *
  • visible: Hides the button if set to false.
  • - *
- *

- * - *

States

- *

- * Due to its toggle property, the CheckBox requires another set of keyframes to denote the selected state. These - * states include - *

    - *
  • an up or default state.
  • - *
  • an over state when the mouse cursor is over the component, or when it is focused.
  • - *
  • a down state when the button is pressed.
  • - *
  • a disabled state.
  • - *
  • a selected_up or default state.
  • - *
  • a selected_over state when the mouse cursor is over the component, or when it is focused.
  • - *
  • a selected_down state when the button is pressed.
  • - *
  • a selected_disabled state.
  • - *
- *

- * - * These are the minimal set of keyframes that should be in a CheckBox. The extended set of states and keyframes supported by the Button component, and consequently the CheckBox component, are described in the Getting Started with CLIK Buttons document. - * - *

Events

- *

- * All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.

    - *
  • type: The event type.
  • - *
  • target: The target that generated the event.
- * - * The events generated by the Button component are listed below. The properties listed next to the event are provided in addition to the common properties. - *
    - *
  • ComponentEvent.SHOW: The visible property has been set to true at runtime.
  • - *
  • ComponentEvent.HIDE: The visible property has been set to false at runtime.
  • - *
  • FocusHandlerEvent.FOCUS_IN: The button has received focus.
  • - *
  • FocusHandlerEvent.FOCUS_OUT: The button has lost focus.
  • - *
  • Event.SELECT: The selected property has changed.
  • - *
  • ComponentEvent.STATE_CHANGE: The button's state has changed.
  • - *
  • ButtonEvent.PRESS: The button has been pressed.
  • - *
  • ButtonEvent.CLICK: The button has been clicked.
  • - *
  • ButtonEvent.DRAG_OVER: The mouse cursor has been dragged over the button (while the left mouse button is pressed).
  • - *
  • ButtonEvent.DRAG_OUT: The mouse cursor has been dragged out of the button (while the left mouse button is pressed).
  • - *
  • ButtonEvent.RELEASE_OUTSIDE: The mouse cursor has been dragged out of the button and the left mouse button has been released.
  • - *
- *

- */ - -/************************************************************************** - -Filename : CheckBox.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import scaleform.clik.controls.Button; - - public class CheckBox extends Button - { - // Constants: - - // Public Properties: - - // Protected Properties: - - // Initialization: - public function CheckBox() { - super(); - } - - /** @private */ - override protected function initialize():void { - super.initialize(); - _toggle = true; - } - - // Public Getter / Setters: - // Override inspectables from base class - /** @private */ - override public function get autoRepeat():Boolean { return false; } - /** @private */ - override public function set autoRepeat(value:Boolean):void { } - /** @private */ - override public function get toggle():Boolean { return true; } - /** @private */ - override public function set toggle(value:Boolean):void {} - - // Public Methods: - /** @private */ - override public function toString():String { - return "[CLIK CheckBox " + name + "]"; - } - - // Protected Methods: - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/CoreList.as b/src/scaleform/clik/controls/CoreList.as deleted file mode 100644 index cb3f7f0..0000000 --- a/src/scaleform/clik/controls/CoreList.as +++ /dev/null @@ -1,542 +0,0 @@ -/** - * An abstract class used to display a list of data, and set a selectedIndex (or indices). This class only manages data, and instantiating itemRenderers, but the sub-class must request the renderers and arrange them. It is sub-classed by the ScrollingList and TileList components. - */ - -/************************************************************************** - -Filename : CoreList.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.DisplayObject; - import flash.display.Sprite; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.geom.Rectangle; - import flash.system.ApplicationDomain; - - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.core.UIComponent; - import scaleform.clik.data.DataProvider; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ListEvent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.interfaces.IDataProvider; - import scaleform.clik.interfaces.IListItemRenderer; - - import scaleform.gfx.MouseEventEx; - - public class CoreList extends UIComponent - { - // Constants: - - // Public Properties: - - // Protected Properties: - /** The current selectedIndex being displayed. */ - protected var _selectedIndex:int = -1; - /** The latest internal selectedIndex. Will be pushed to _selectedIndex next time updateSelectedIndex() is called. */ - protected var _newSelectedIndex:int = -1; - /** The dataProvider for the List. */ - protected var _dataProvider:IDataProvider; - /** The property name of the Objects within the DataPRovider that holds the label for the ListItemRenderers. */ - protected var _labelField:String = "label"; - /** The function to use to evaluate the label for the ListItemRenderer. */ - protected var _labelFunction:Function; - - /** A reference to the class for the item renderers, used whenenever a new renderer is created. */ - protected var _itemRenderer:Class; - /** The name of the Class for the ListItemRenderer. */ - protected var _itemRendererName:String = "DefaultListItemRenderer"; - /** List of the current renderers. */ - protected var _renderers:Vector.; - /** true if the List is using external renderers; false if it generating them at runtime. */ - protected var _usingExternalRenderers:Boolean = false; - /** The number of usable renderers. */ - protected var _totalRenderers:uint = 0; - - /** The current state of the component being displayed. */ - protected var _state:String = "default"; - /** The latest internal state of the component. Pushed to _state and displayed in draw(). */ - protected var _newFrame:String; - - // UI Elements: - // The container MovieClip which the auto-generated ScrollBar will be added to. - public var container:Sprite; - - // Initialization: - public function CoreList() { - super(); - } - - /** @private */ - override protected function initialize():void { - dataProvider = new DataProvider(); // Default Data. - super.initialize(); - } - - // Public Getter / Setters: - /** - * Enable/disable focus management for the component. Setting the focusable property to - * {@code focusable=false} will remove support for tab key, direction key and mouse - * button based focus changes. - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - super.focusable = value; - } - - /** - * The linkage ID for the renderer used to display each item in the list. The list components only support - * a single itemRenderer for all items. - */ - [Inspectable(name = "itemRenderer", defaultValue = "DefaultListItemRenderer")] - public function get itemRendererName():String { return _itemRendererName; } - public function set itemRendererName(value:String):void { - if ((_inspector && value == "") || value == "") { return; } - - var domain:ApplicationDomain = ApplicationDomain.currentDomain; - if (loaderInfo != null && loaderInfo.applicationDomain != null) domain = loaderInfo.applicationDomain; - var classRef:Class = domain.getDefinition(value) as Class; - - if (classRef != null) { - itemRenderer = classRef; - } else { - trace("Error: " + this + ", The class " + value + " cannot be found in your library. Please ensure it is there."); - } - } - - /** Set the itemRenderer class. */ - public function get itemRenderer():Class { return _itemRenderer; } - public function set itemRenderer(value:Class):void { - _itemRenderer = value; - invalidateRenderers(); - } - - /** - * The name of data renderers to be used in this list instance. The names are a string followed by - * consecutive numbers incrementing from 0 or 1. For instance "renderer1, renderer2, renderer3, etc". - * The renderers must be in the parent timeline of the list instance in order to be used. If a specific - * numbered clip is missing, then only the renderers up to that point will be used. - */ - [Inspectable(defaultValue="")] - public function set itemRendererInstanceName(value:String):void { - - if (value == null || value == "" || parent == null) { return; } - var i:uint = 0; - var newRenderers:Vector. = new Vector.(); - while (++i) { - var clip:IListItemRenderer = parent.getChildByName(value + i) as IListItemRenderer; - if (clip == null) { // No more in list. This allows renderers to start with 1 or 0 - if (i == 0) { continue; } - break; - } - newRenderers.push(clip); - } - - if (newRenderers.length == 0) { - if (componentInspectorSetting) { return; } - newRenderers = null; // Reverts to internal renderers. - } - itemRendererList = newRenderers; - } - - /** - * Set a list of external MovieClips to use as renderers, instead of auto-generating the renderers at run-time. - * The rendererInstance property uses this method to set the renderer list. - */ - public function set itemRendererList(value:Vector.):void { - var l:uint, i:uint; - if (_usingExternalRenderers) { - l = _renderers.length; - for (i=0; i= _renderers.length) { return null; } - return _renderers[newIndex] as IListItemRenderer; - } - - /** Mark the item renderers as invalid and schedule a draw() on next Stage.INVALIDATE event. */ - public function invalidateRenderers():void { - invalidate(InvalidationType.RENDERERS); - } - - /** Mark the selectedIndex as invalid and schedule a draw() on next Stage.INVALIDATE event. */ - public function invalidateSelectedIndex():void { - invalidate(InvalidationType.SELECTED_INDEX); - } - - /** @private */ - override public function toString():String { - return "[CLIK CoreList "+ name +"]"; - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - - if (container == null) { - container = new Sprite(); - addChild(container); - //LM: We can't apply a grid this way like we could in AS2. Revisit if we have scaling issues. - //container.scale9Grid = new Rectangle(0,0,0,0); - } - - tabEnabled = (_focusable && enabled); - tabChildren = false; - - addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel, false, 0, true); - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - } - - override protected function draw():void { - if (isInvalid(InvalidationType.SELECTED_INDEX)) { - updateSelectedIndex(); - } - - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - } - - var i:uint, l:uint, renderer:IListItemRenderer, displayObject:DisplayObject; - // Remove old internal renderers - if (!_usingExternalRenderers && isInvalid(InvalidationType.RENDERERS)) { - if (_renderers != null) { - l = _renderers.length; - for (i=0; i(); - invalidateData(); - } - - // Counter-scale to ensure base component is the right size. - if (!_usingExternalRenderers && isInvalid(InvalidationType.SIZE)) { - removeChild(container); - setActualSize(_width, _height); - container.scaleX = 1 / scaleX; - container.scaleY = 1 / scaleY; - _totalRenderers = calculateRendererTotal(availableWidth, availableHeight); - - addChild(container); - invalidateData(); - } - - // Create/Destroy renderers - if (!_usingExternalRenderers && isInvalid(InvalidationType.RENDERERS, InvalidationType.SIZE)) { - drawRenderers(_totalRenderers); // Update renderer count - - //TODO: For variable height, we would skip this until we had populated the data and measured it. - drawLayout(); - } - - if (isInvalid(InvalidationType.DATA)) { - refreshData(); // Renderers get invalidated here. - //TODO: For variable-height, we would reflow at this point. - } - } - - /** @private */ - override protected function changeFocus():void { - if (_focused || _displayFocus) { - setState("focused", "default"); - } else { - setState("default"); - } - } - - protected function refreshData():void { } - protected function updateSelectedIndex():void { } - - protected function calculateRendererTotal(width:Number, height:Number):uint { - return height / 20 >> 0; - } - - protected function drawLayout():void { } - - protected function drawRenderers(total:Number):void { - if (_itemRenderer == null) { - trace("Renderer class not defined."); return; - } - - var i:int, l:int, renderer:IListItemRenderer, displayObject:DisplayObject; - for (i = _renderers.length; i < _totalRenderers; i++) { - renderer = createRenderer(i); - if (renderer == null) { break; } - _renderers.push(renderer); - container.addChild(renderer as DisplayObject); - } - l = _renderers.length; - for (i=l-1; i>=_totalRenderers; i--) { - renderer = getRendererAt(i); - if (renderer != null) { - cleanUpRenderer(renderer); - displayObject = renderer as DisplayObject; - if (container.contains(displayObject)) { container.removeChild(displayObject); } - } - _renderers.splice(i, 1); - } - } - - protected function createRenderer(index:uint):IListItemRenderer { - var renderer:IListItemRenderer = new _itemRenderer() as IListItemRenderer; - if (renderer == null) { - trace("Renderer class could not be created."); return null; - } - // NFM: Future optimization - createRenderer(index, setup=true), don't setupRenderer() if !setup. Use createRenderer(0, false) when finding rendererHeight. - setupRenderer(renderer); - return renderer; - } - - protected function setupRenderer(renderer:IListItemRenderer):void { - renderer.owner = this; - renderer.focusTarget = this; - renderer.tabEnabled = false; // Children can still be tabEnabled, or the renderer could re-enable this. //LM: There is an issue with this. Setting disabled could automatically re-enable. Consider alternatives. - renderer.doubleClickEnabled = true; - - renderer.addEventListener(ButtonEvent.PRESS, dispatchItemEvent, false, 0, true); - renderer.addEventListener(ButtonEvent.CLICK, handleItemClick, false, 0, true); - renderer.addEventListener(MouseEvent.DOUBLE_CLICK, dispatchItemEvent, false, 0, true); - renderer.addEventListener(MouseEvent.ROLL_OVER, dispatchItemEvent, false, 0, true); - renderer.addEventListener(MouseEvent.ROLL_OUT, dispatchItemEvent, false, 0, true); - - if (_usingExternalRenderers) { - renderer.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel, false, 0, true); - } - } - - protected function cleanUpRenderer(renderer:IListItemRenderer):void { - renderer.owner = null; - renderer.focusTarget = null; - // renderer.tabEnabled = true; - renderer.doubleClickEnabled = false; //LM: Could have unwanted behaviour when using external renderers. - renderer.removeEventListener(ButtonEvent.PRESS, dispatchItemEvent); - renderer.removeEventListener(ButtonEvent.CLICK, handleItemClick); - renderer.removeEventListener(MouseEvent.DOUBLE_CLICK, dispatchItemEvent); - renderer.removeEventListener(MouseEvent.ROLL_OVER, dispatchItemEvent); - renderer.removeEventListener(MouseEvent.ROLL_OUT, dispatchItemEvent); - renderer.removeEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel); - } - - protected function dispatchItemEvent(event:Event):Boolean { - var type:String; - switch (event.type) { - case ButtonEvent.PRESS: - type = ListEvent.ITEM_PRESS; - break; - case ButtonEvent.CLICK: - type = ListEvent.ITEM_CLICK; - break; - case MouseEvent.ROLL_OVER: - type = ListEvent.ITEM_ROLL_OVER; - break; - case MouseEvent.ROLL_OUT: - type = ListEvent.ITEM_ROLL_OUT; - break; - case MouseEvent.DOUBLE_CLICK: - type = ListEvent.ITEM_DOUBLE_CLICK; - break; - default: - return true; - } - - var renderer:IListItemRenderer = event.currentTarget as IListItemRenderer; - - // Propogate the controller / mouse index. - var controllerIdx:uint = 0; - if (event is ButtonEvent) { controllerIdx = (event as ButtonEvent).controllerIdx; } - else if (event is MouseEventEx) { controllerIdx = (event as MouseEventEx).mouseIdx; } - - var buttonIdx:uint = 0; - if (event is ButtonEvent) { buttonIdx = (event as ButtonEvent).buttonIdx; } - else if (event is MouseEventEx) { buttonIdx = (event as MouseEventEx).buttonIdx; } - - // Propogate whether the keyboard / gamepad generated this event. - var isKeyboard:Boolean = false; - if (event is ButtonEvent) { isKeyboard = (event as ButtonEvent).isKeyboard; } - - var newEvent:ListEvent = new ListEvent(type, false, true, renderer.index, 0, renderer.index, renderer, dataProvider[renderer.index], controllerIdx, buttonIdx, isKeyboard); - return dispatchEventAndSound(newEvent); - } - - protected function handleDataChange(event:Event):void { - invalidate(InvalidationType.DATA); - } - - protected function handleItemClick(event:ButtonEvent):void { - var index:Number = (event.currentTarget as IListItemRenderer).index; - if (isNaN(index)) { return; } // If the data has not been populated, but the listItemRenderer is clicked, it will have no index. - if (dispatchItemEvent(event)) { - selectedIndex = index; - } - } - - protected function handleMouseWheel(event:MouseEvent):void { - scrollList(event.delta > 0 ? 1 : -1); - } - - protected function scrollList(delta:int):void {} - - protected function setState(...states:Array):void { - if (states.length == 1) { - var onlyState:String = states[0].toString(); - if (_state != onlyState && _labelHash[onlyState]) { - _state = _newFrame = onlyState; - invalidateState(); - } - return; - } - var l:uint = states.length; - for (var i:uint=0; iInspectable Properties

- * The inspectable properties of the DragSlot component are: - *
    - *
  • enabled: Disables the component if set to false.
  • - *
  • visible: Hides the component if set to false.
  • - *
- * - *

States

- *

- * The CLIK DragSlot component supports different states based on user interaction. These states include - *

    - *
  • an up or default state.
  • - *
  • an over state when the mouse cursor is over the component
  • - *
  • a down state when the DragSlot is pressed.
  • - *
  • a disabled state.
  • - *
- * - * These states are represented as keyframes in the Flash timeline, and are the minimal set of keyframes required for the DragSlot component to operate correctly. There are other states that extend the capabilities of the component to support complex user interactions and animated transitions, and this information is provided in the Getting Started with CLIK Buttons document. - *

- * - *

Events

- *

- * All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.

    - *
  • type: The event type.
  • - *
  • target: The target that generated the event.
- * - * The events generated by the DragSlot component are listed below. The properties listed next to the event are provided in addition to the common properties. - *
    - *
  • ComponentEvent.SHOW: The visible property has been set to true at runtime.
  • - *
  • ComponentEvent.HIDE: The visible property has been set to false at runtime.
  • - *
  • DragEvent.DRAG_START: A drag has been initiated from this DragSlot.
  • - *
  • DragEvent.DRAG_END: A drag that was initiated from this DragSlot has ended.
  • - *
  • ButtonEvent.CLICK: The DragSlot has been clicked.
  • - *
- *

- */ - -/************************************************************************** - -Filename : DragSlot.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.display.Stage; - import flash.events.Event; - import flash.events.MouseEvent; - - import scaleform.gfx.FocusEventEx; - import scaleform.gfx.MouseEventEx; - - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.DragEvent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.events.DragEvent; - import scaleform.clik.interfaces.IDragSlot; - import scaleform.clik.interfaces.IDataProvider; - import scaleform.clik.managers.DragManager; - - public class DragSlot extends UIComponent implements IDragSlot - { - // Constants: - - // Public Properties: - - // Protected Properties: - /** The x-coordinate of the original MOUSE_DOWN event. Used to discern when the mouse has traveled enough to trigger a DragEvent. */ - protected var _mouseDownX:Number; - /** The y-coordinate of the original MOUSE_DOWN event. Used to discern when the mouse has traveled enough to trigger a DragEvent. */ - protected var _mouseDownY:Number; - /** Reference to the content Sprite that will be dragged about the Stage. */ - protected var _content:Sprite; - /** Unique numeric value that represents the data held by this DragSlot. */ - protected var _data:Object; // NFM: Consider for removal here. Move into a subclass. - protected var _stageRef:Stage = null; - protected var _newFrame:String; - protected var _stateMap:Object = { - up:["up"], - over:["over"], - down:["down"], - release: ["release", "over"], - out:["out","up"], - disabled:["disabled"], - selecting: ["selecting", "over"] - } - protected var _state:String; - - // UI Elements: - /** Reference to the canvas which the content Sprite will be attached to. */ - public var contentCanvas:Sprite; - - // Initialization: - public function DragSlot() { - super(); - - if (!contentCanvas) { - contentCanvas = new Sprite(); - addChild(contentCanvas); - } - - if (stage) { - DragManager.init(stage); - } - - trackAsMenu = true; - } - - // Public Getter / Setters: - /** - * Data related to the DragSlot. This may be include information about the slot itself or the content to be dragged. - */ - public function get data():Object { return _data; } - public function set data(value:Object):void { - _data = value; - invalidateData(); - } - - /** - * A reference to the Sprite or MovieClip that will be dragged from the DragSlot. This will generally be a Sprite containing a Bitmap. - */ - public function get content():Sprite { return _content; } - public function set content(value:Sprite):void { - if (value != _content) { - if (_content) { - // If we're still the parent of our old _content, removeChild it. Could be overriden by subclass. - if (contentCanvas.contains(_content)) { - contentCanvas.removeChild(_content); - } - } - - _content = value; - if (_content == null) { return; } - - // Reparent the icon for the data at 0,0 on the contentCanvas. - if (_content != this) { - contentCanvas.addChild(_content); // NFM: This should come from the data Object. Maybe set data() creates a Sprite? - _content.x = 0; - _content.y = 0; - _content.mouseChildren = false; - } - } - } - - // Public Methods: - /** Sets the DragSlot's stage reference, required for dragging functionality, in the case that the DragSlot does not exist on the stage already . */ - public function setStage(value:Stage):void { - if (_stageRef == null && value != null) { - _stageRef = value; - DragManager.init(value); - } - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - - addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver, true, 0, true); - addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown, false, 0, true); - addEventListener(MouseEvent.ROLL_OVER, handleMouseRollOver, false, 0, true); - addEventListener(MouseEvent.ROLL_OUT, handleMouseRollOut, false, 0, true); - } - - override protected function draw():void { - super.draw(); - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - } - } - - /** @exclude */ - override public function toString():String { - return "[CLIK DragSlot " + name + "]"; - } - - protected function handleMouseOver(e:MouseEvent):void { - if (DragManager.inDrag()) { - // Subclass should define behavior. - // Example: Ask C++ whether or not we should display a "OK to Drop Here!" state. - } - else if (content != null) { - // Subclass should define behavior. - // Example: If we're not inDrag() and we have some data, show the user some state() that shows the item can be picked up. - } - } - - protected function handleMouseDown(e:MouseEvent):void { - // Don't start a dragEvent if we're accepting one via a MouseDown. - if (DragManager.inDrag() || !enabled) { return; } - if (_content != null) { - stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp, false, 0, true); - stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove, false, 0, true); - - _mouseDownX = mouseX; - _mouseDownY = mouseY; - } - } - - protected function handleMouseRollOver(event:MouseEvent):void { - if (!enabled) { return; } - setState("over"); - } - - protected function handleMouseRollOut(event:MouseEvent):void { - if (!enabled) { return; } - setState("out"); - } - - protected function cleanupDragListeners():void { - // Clean up the original mouse listeners since we've started a DragEvent. - stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp, false); - stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove, false); - - _mouseDownX = undefined; - _mouseDownY = undefined; - } - - protected function handleMouseMove(e:MouseEvent):void { - // NFM: This should be moved into a subclass. - // Require the user to add at least 3 pixels of mouse movement to start an official drag. - if (mouseX > _mouseDownX + 3 || mouseX < _mouseDownX - 3 || - mouseY > _mouseDownY + 3 || mouseY < _mouseDownY - 3) { - cleanupDragListeners() - - // Dispatch the DragEvent to be caught by the DragManager. - var dragStartEvent:DragEvent = new DragEvent(DragEvent.DRAG_START, _data, this, null, _content) - dispatchEventAndSound(dragStartEvent); - handleDragStartEvent(dragStartEvent); - } - } - - protected function handleMouseUp(e:MouseEvent):void { - // Clean up the original mouse listeners since the user has "clicked". - cleanupDragListeners() - - _content.x = 0; - _content.y = 0; - - // Dispatch a generic CLIK ButtonEvent.CLICK to be caught by whomever may be listening. - dispatchEventAndSound(new ButtonEvent(ButtonEvent.CLICK)); - } - - public function handleDragStartEvent(e:DragEvent):void { - // Base functionality will be to hide the _content. Could be gray-scaled. Can be subclassed. - } - - public function handleDropEvent(e:DragEvent):Boolean { - // Ask C++ what we're going to do with the data. If we want it, return true. - var acceptDrop:Boolean = true; // Ask C++ - if (acceptDrop) { - // For right now, just transfer the Sprite over to our ownership. - content = e.dragSprite; - } - - return acceptDrop; - } - - public function handleDragEndEvent(e:DragEvent, wasValidDrop:Boolean):void { - // If it landed in a valid drop... - if (wasValidDrop) { - // Ask C++ if we should hang on to it (backpack to backpack? backpack to action bar?) - content = null; // For now, just dump our data. - } - else { - // If the drop was invalid, ask C++ what to do (reparent? destroy? etc...). - contentCanvas.addChild(e.dragSprite); - e.dragSprite.x = 0; - e.dragSprite.y = 0; - } - } - - protected function setState(state:String):void { - _state = state; - var states:Array = _stateMap[state]; - if (states == null || states.length == 0) { return; } - var sl:uint = states.length; - for (var j:uint=0; jdropdownMenu.dataProvider = ["item1", "item2", "item3", "item4"]; - * - *

Inspectable Properties

- *

- * The inspectable properties of the DropdownMenu component are:

    - *
  • autoSize: Determines if the button will scale to fit the text that it contains and which direction to align the resized button. Setting the autoSize property to {@code autoSize="none"} will leave its current size unchanged.
  • - *
  • dropdown: Symbol name of the list component (ScrollingList or TileList) to use with the DropdownMenu component.
  • - *
  • enabled: Disables the button if set to false.
  • - *
  • focusable: By default buttons receive focus for user interactions. Setting this property to false will disable focus acquisition.
  • - *
  • menuDirection:The list open direction. Valid values are "up" and "down".
  • - *
  • menuMargin: The margin between the boundary of the list component and the list items created internally. This margin also affects the automatically generated scrollbar.
  • - *
  • menuOffset: Horizontal and vertical offsets of the dropdown list from the dropdown button position. A positive horizontal value moves the list to the right of the dropdown button horizontal position. A positive vertical value moves the list away from the button.
  • - *
  • menuPadding: Extra padding at the top, bottom, left, and right for the list items. Does not affect the automatically generated scrollbar.
  • - *
  • menuRowCount: The number of rows that the list should display.
  • - *
  • menuWidth: If set, this number will be enforced as the width of the menu.
  • - *
  • thumbOffset: Scrollbar thumb top and bottom offsets. This property has no effect if the list does not automatically create a scrollbar instance.
  • - *
  • scrollBar: Symbol name of the dropdown list’s scroll bar. Created by the dropdown list instance. If value is empty, then the dropdown list will have no scroll bar.
  • - *
  • visible: Hides the component if set to false.
  • - *

    - * - *

    States

    - *

    - * The DropdownMenu is toggled when opened, and therefore needs the same states as a ToggleButton or CheckBox that denote the selected state. These states include

      - *
    • an up or default state.
    • - *
    • an over state when the mouse cursor is over the component, or when it is focused.
    • - *
    • a down state when the button is pressed.
    • - *
    • a disabled state.
    • - *
    • a selected_up or default state.
    • - *
    • a selected_over state when the mouse cursor is over the component, or when it is focused.
    • - *
    • a selected_down state when the button is pressed.
    • - *
    • a selected_disabled state.
    - *

    - * - *

    Events

    - *

    - * All event callbacks receive a single Object parameter that contains relevant information about the event. The following properties are common to all events.

      - *
    • type: The event type.
    • - *
    • target: The target that generated the event.
    - * - *
      - *
    • ComponentEvent.SHOW: The visible property has been set to true at runtime.
    • - *
    • ComponentEvent.HIDE: The visible property has been set to false at runtime.
    • - *
    • FocusHandlerEvent.FOCUS_IN: The component has received focus.
    • - *
    • FocusHandlerEvent.FOCUS_OUT: The component has lost focus.
    • - *
    • Event.SELECT: The selected property has changed.
    • - *
    • ButtonEvent.PRESS: The button has been pressed.
    • - *
    • ButtonEvent.CLICK: The button has been clicked.
    • - *
    • ButtonEvent.DRAG_OVER: The mouse cursor has been dragged over the button (while the left mouse button is pressed).
    • - *
    • ButtonEvent.DRAG_OUT: The mouse cursor has been dragged out of the button (while the left mouse button is pressed).
    • - *
    • ButtonEvent.RELEASE_OUTSIDE: The mouse cursor has been dragged out of the button and the left mouse button has been released.
    • - *
    • ListEvent.INDEX_CHANGE: The selected index has changed.
    • - *
    - *

    -*/ - -/************************************************************************** - -Filename : DropdownMenu.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.MovieClip; - import flash.display.DisplayObject; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.system.ApplicationDomain; - - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.constants.WrappingMode - import scaleform.clik.controls.Button; - import scaleform.clik.data.DataProvider; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ListEvent; - import scaleform.clik.interfaces.IDataProvider; - import scaleform.clik.managers.PopUpManager; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.utils.Padding; - - [Event(name="change", type="flash.events.Event")] - - public class DropdownMenu extends Button - { - // Constants: - - // Public Properties: - /** Symbol name of the list component (ScrollingList or TileList) to use with the DropdownMenu component. */ - [Inspectable(type="String", defaultValue="CLIKScrollingList")] - public var dropdown:Object = "CLIKScrollingList"; - [Inspectable(type="String", defaultValue="CLIKListItemRenderer")] - public var itemRenderer:Object = "CLIKListItemRenderer"; - /** Symbol name of the dropdown list’s scroll bar. Created by the dropdown list instance. If value is empty, then the dropdown list will have no scroll bar. */ - [Inspectable(type="String")] - public var scrollBar:Object; - - /** - * Determines how focus "wraps" when the end or beginning of the component is reached. -
      -
    • WrappingMode.NORMAL: The focus will leave the component when it reaches the end of the data
    • -
    • WrappingMode.WRAP: The selection will wrap to the beginning or end.
    • -
    • WrappingMode.STICK: The selection will stop when it reaches the end of the data.
    • -
    - */ - [Inspectable(enumeration="normal,stick,wrap", defaultValue="normal")] - public var menuWrapping:String = WrappingMode.NORMAL; - /** Direction the list opens. Valid values are "up" and "down". **/ - [Inspectable(enumeration="up,down", defaultValue="down")] - public var menuDirection:String = "down"; - [Inspectable(defaultValue = "-1")] - public var menuWidth:Number = -1; - [Inspectable(defaultValue = "1")] - public var menuMargin:Number = 1; - [Inspectable(defaultValue = "5")] - public var menuRowCount:Number = 5; - [Inspectable(defaultFixedLength = "true")] - public var menuRowsFixed:Boolean = true; - // Inspectable menuPadding is handled by inspectableMenuPadding setter - public var menuPadding:Padding; - // Inspectable menuOffset is handled by inspectableMenuOffset setter - public var menuOffset:Padding; - // Inspectable thumbOffset is handled by inspectableThumbOffset setter - public var thumbOffsetTop:Number; - public var thumbOffsetBottom:Number; - - // Protected Properties: - protected var _selectedIndex:int = -1; - protected var _dataProvider:IDataProvider; - protected var _labelField:String = "label"; - protected var _labelFunction:Function; - protected var _popup:MovieClip; - - // UI Elements - protected var _dropdownRef:MovieClip = null; - - // Initialization: - /** - * The constructor is called when a DropdownMenu or a sub-class of DropdownMenu is instantiated on stage or by using {@code attachMovie()} in ActionScript. This component can not be instantiated using {@code new} syntax. When creating new components that extend DropdownMenu, ensure that a {@code super()} call is made first in the constructor. - */ - public function DropdownMenu() { - super(); - } - - override protected function initialize():void { - dataProvider = new DataProvider(); // Default Data. - menuOffset = new Padding(0, 0, 0, 0); - menuPadding = new Padding(0, 0, 0, 0); - super.initialize(); - } - - // Public Methods: - // ** Override inspectables from base class - override public function get autoRepeat():Boolean { return false; } - override public function set autoRepeat(value:Boolean):void { } - override public function get data():Object { return null; } - override public function set data(value:Object):void { } - override public function get label():String { return ""; } - override public function set label(value:String):void { } - - // These overrides must be valid - override public function get selected():Boolean { return super.selected; } - override public function set selected(value:Boolean):void { super.selected = value; } - override public function get toggle():Boolean { return super.toggle; } - override public function set toggle(value:Boolean):void { super.toggle = value; } - - /** - * Extra padding at the top, bottom, left, and right for the list items. Does not affect the automatically generated ScrollBar. - */ - [Inspectable(name="menuPadding", defaultValue="top:0,right:0,bottom:0,left:0")] - public function set inspectableMenuPadding(value:Object):void { - if (!componentInspectorSetting) { return; } - menuPadding = new Padding(value.top, value.right, value.bottom, value.left); - } - - /** - * Offsets for the dropdown list from the dropdown button position. Does not affect the automatically generated ScrollBar. - */ - [Inspectable(name="menuOffset", defaultValue="top:0,right:0,bottom:0,left:0")] - public function set inspectableMenuOffset(value:Object):void { - if (!componentInspectorSetting) { return; } - menuOffset = new Padding(value.top, value.right, value.bottom, value.left); - } - - /** - * Scrollbar thumb top and bottom offsets. This property has no effect if the list does not automatically create a scrollbar instance. - */ - [Inspectable(name="thumbOffset", defaultValue="top:0,bottom:0")] - public function set inspectableThumbOffset(value:Object):void { - if (!componentInspectorSetting) { return; } - thumbOffsetTop = Number(value.top); - thumbOffsetBottom = Number(value.bottom); - } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * {@code focusable=false} will remove support for tab key, direction key and mouse - * button based focus changes. - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - super.focusable = value; - } - - /** - * The index of the item that is selected in a single-selection list. The DropdownMenu will always have - * a {@code selectedIndex} of 0 or greater, unless there is no data. - */ - public function get selectedIndex():int { return _selectedIndex; } - public function set selectedIndex(value:int):void { - if (_selectedIndex == value) { return; } - _selectedIndex = value; - invalidateSelectedIndex(); - if (_dropdownRef != null) { - var dd:CoreList = _dropdownRef as CoreList; - var offset:uint = (dd is ScrollingList) ? (dd as ScrollingList).scrollPosition : 0; - dispatchEventAndSound(new ListEvent(ListEvent.INDEX_CHANGE, true, false, _selectedIndex, - -1, -1, dd.getRendererAt(_selectedIndex, offset), _dataProvider[_selectedIndex])); - } - } - - /** - * The data model displayed in the component. The dataProvider can be an Array or any object exposing the - * appropriate API, defined in the {@code IDataProvider} interface. If an Array is set as the - * {@code dataProvider}, functionality will be mixed into it by the {@code DataProvider.initialize} method. - * When a new DataProvider is set, the {@code selectedIndex} property will be reset to 0. - * @see DataProvider - * @see IDataProvider - */ - public function get dataProvider():IDataProvider { return _dataProvider; } - public function set dataProvider(value:IDataProvider):void { - if (_dataProvider == value) { return; } - if (_dataProvider != null) { - _dataProvider.removeEventListener(Event.CHANGE, handleDataChange, false); - } - _dataProvider = value; - var len:int = _dataProvider.length; - if (!menuRowsFixed && len > 0 && len < menuRowCount) - menuRowCount = len; - if (_dataProvider == null) { return; } - _dataProvider.addEventListener(Event.CHANGE, handleDataChange, false, 0, true); - invalidateData(); - } - - /** - * The name of the field in the {@code dataProvider} to be displayed as the label for the TextInput field. - * A {@code labelFunction} will be used over a {@code labelField} if it is defined. - * @see #itemToLabel() - */ - public function get labelField():String { return _labelField; } - public function set labelField(value:String):void { - _labelField = value; - invalidateData(); - } - - /** - * The function used to determine the label for an item. A {@code labelFunction} will override a - * {@code labelField} if it is defined. - * @see #itemToLabel() - */ - public function get labelFunction():Function { return _labelFunction; } - public function set labelFunction(value:Function):void { - _labelFunction = value; - invalidateData(); - } - - /** - * Convert an item to a label string using the {@code labelField} and {@code labelFunction}. - * @param item The item to convert to a label. - * @returns The converted label string. - * @see #labelField - * @see #labelFunction - */ - public function itemToLabel(item:Object):String { - if (item == null) { return ""; } - if (_labelFunction != null) { - return _labelFunction(item); - } else if ( item is String ) { - return item.toString(); - } - else if (_labelField != null && item[_labelField] != null) { - return item[_labelField]; - } - return item.toString(); - } - - /** - * Open the dropdown list. The {@code selected} and {@code isOpen} properties of the DropdownMenu are - * set to {@code true} when open. Input will be passed to the dropdown when it is open before it is - * handled by the DropdownMenu. - */ - public function open():void { - selected = true; - stage.addEventListener(MouseEvent.MOUSE_DOWN, handleStageClick, false, 0, true); - - showDropdown(); - } - - /** - * Close the dropdown list. The list is not destroyed, the {@code visible} property is set to {@code false}. - * The {@code selected} property of the DropdownMenu is set to {@code false} when closed. - */ - public function close():void { - selected = false; - stage.removeEventListener(MouseEvent.MOUSE_DOWN, handleStageClick, false); - - hideDropdown(); - } - - /** - * Returns {@code true} if the dropdown list is open, {@code false} if not. - */ - public function isOpen():Boolean { - return (_dropdownRef != null); - } - - /** Mark the selectedIndex as invalid and schedule a draw() on next Stage.INVALIDATE event. */ - public function invalidateSelectedIndex():void { - invalidate(InvalidationType.SELECTED_INDEX); - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - if (event.handled) { return; } - - if (_dropdownRef != null && selected) { - _dropdownRef.handleInput(event); - if (event.handled) { return; } - } - - super.handleInput(event); - - var details:InputDetails = event.details; - var keyPress:Boolean = details.value == InputValue.KEY_DOWN; - switch (details.navEquivalent) { - case NavigationCode.ESCAPE: - if (selected) { - if (keyPress) { close(); } - event.handled = true; - } - default: - break; - } - } - - /** @exclude */ - override public function toString():String { - return "[CLIK DropdownMenu " + name + "]"; - } - - // Protected Methods: - override protected function draw():void { - if (isInvalid(InvalidationType.SELECTED_INDEX) || isInvalid(InvalidationType.DATA)) { - _dataProvider.requestItemAt(_selectedIndex, populateText); - invalidateData(); // Button will update label only when data is invalid - } - - // We call super.draw later so the base can update the label if it was changed during selectedIndex or data invalidation - super.draw(); - } - - override protected function changeFocus():void { - super.changeFocus(); - - // If open, close the menu - if (_selected && _dropdownRef) { close(); } - } - - override protected function handleClick(controllerIndex:uint = 0):void { - !_selected ? open() : close(); - super.handleClick(); - } - - protected function handleDataChange(event:Event):void { - invalidate(InvalidationType.DATA); - } - - - protected function populateText(item:Object):void { - updateLabel(item); - dispatchEventAndSound(new Event(Event.CHANGE)); - } - - protected function updateLabel(item:Object):void { - _label = itemToLabel(item); - } - - protected function handleStageClick(event:MouseEvent):void { - if (this.contains(event.target as DisplayObject)) { return; } - if (this._dropdownRef.contains(event.target as DisplayObject)) { return; } - close(); - } - - protected function showDropdown():void { - if (dropdown == null) { return; } - - var domain:ApplicationDomain = ApplicationDomain.currentDomain; - if (loaderInfo != null && loaderInfo.applicationDomain != null) domain = loaderInfo.applicationDomain; - - var dd:MovieClip; - if (dropdown is String && dropdown != "") { - var classRef:Class = domain.getDefinition(dropdown.toString()) as Class; - - if (classRef != null) { dd = new classRef() as CoreList; } - } - - if (dd) { - if (itemRenderer is String && itemRenderer != "") { dd.itemRenderer = domain.getDefinition(itemRenderer.toString()) as Class; } - else if (itemRenderer is Class) { dd.itemRenderer = itemRenderer as Class; } - - if (scrollBar is String && scrollBar != "") { dd.scrollBar = domain.getDefinition(scrollBar.toString()) as Class; } - else if (scrollBar is Class) { dd.scrollBar = scrollBar as Class; } - - dd.selectedIndex = _selectedIndex; - dd.width = (menuWidth == -1) ? (width + menuOffset.left + menuOffset.right) : menuWidth; - dd.dataProvider = _dataProvider; - dd.padding = menuPadding; - dd.wrapping = menuWrapping; - dd.margin = menuMargin; - dd.thumbOffset = { top:thumbOffsetTop, bottom:thumbOffsetBottom }; - dd.focusTarget = this; - dd.rowCount = (menuRowCount < 1) ? 5 : menuRowCount; - dd.labelField = _labelField; - dd.labelFunction = _labelFunction; - dd.addEventListener(ListEvent.ITEM_CLICK, handleMenuItemClick, false, 0, true); - - _dropdownRef = dd; - PopUpManager.show(dd, x + menuOffset.left, - (menuDirection == "down") ? y + height + menuOffset.top : y - _dropdownRef.height + menuOffset.bottom, - parent); - } - } - - protected function hideDropdown():void { - if (_dropdownRef) { - _dropdownRef.parent.removeChild(_dropdownRef); - _dropdownRef = null; - } - } - - protected function handleMenuItemClick(e:ListEvent):void { - selectedIndex = e.index; - close(); - } - } -} diff --git a/src/scaleform/clik/controls/Label.as b/src/scaleform/clik/controls/Label.as deleted file mode 100644 index c01cd53..0000000 --- a/src/scaleform/clik/controls/Label.as +++ /dev/null @@ -1,312 +0,0 @@ -/** - * The CLIK Label component is a noneditable standard textField wrapped by a MovieClip symbol, with a few additional convenient features. Internally, the Label supports the same properties and behaviors as the standard textField, however only a handful of commonly used features are exposed by the component itself. Access to the Label’s actual textField is provided if the user needs to change its properties directly. In certain cases, such as those described below, developers may use the standard textField instead of the Label component. - * - * Since the Label is a MovieClip symbol, it can be embellished with graphical elements, which is not possible with the standard textField. As a symbol, it does not need to be configured per instance like textField instances. The Label also provides a disabled state that can be defined in the timeline. Whereas, complex AS2 code is required to mimic such behavior with the standard textField. - * - * The Label component uses constraints by default, which means resizing a Label instance on the stage will have no visible effect at runtime. If resizing textFields is required, developers should use the standard textField instead of the Label in most cases. In general, if consistent reusability is not a requirement for the text element, the standard textField is a lighter weight alternative than the Label component. - * - *

    Inspectable Properties

    - *

    - * The inspectable properties of the Label component are: - *

      - *
    • autoSize: Determines if the Label will scale to fit the text that it contains and which direction to align the resized button. Setting the autoSize property to {@code autoSize="none"} will leave its current size unchanged.
    • - *
    • enabled: Disables the Label if set to false.
    • - *
    • text: Sets the text of the Label.
    • - *
    • visible: Hides the Label if set to false.
    • - *
    - *

    - * - *

    States

    - *

    - * The CLIK Label component supports two states based on the disabled property. - *

      - *
    • A default or enabled state.
    • - *
    • a disabled state.
    • - *
    - *

    - * - *

    Events

    - *

    - * All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.

      - *
    • type: The event type.
    • - *
    • target: The target that generated the event.
    - * - * The events generated by the component are listed below. The properties listed next to the event are provided in addition to the common properties. - *
      - *
    • ComponentEvent.SHOW: The visible property has been set to true at runtime.
    • - *
    • ComponentEvent.HIDE: The visible property has been set to false at runtime.
    • - *
    • ComponentEvent.STATE_CHANGE: The Label's state has changed.
    • - *
    - *

    - */ - -/************************************************************************** - -Filename : Label.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.DisplayObject; - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.text.TextField; - import flash.text.TextFieldAutoSize; - - import scaleform.gfx.FocusEventEx; - import scaleform.gfx.MouseEventEx; - - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.data.DataProvider; - import scaleform.clik.interfaces.IDataProvider; - import scaleform.clik.constants.ControllerType; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.utils.ConstrainedElement; - import scaleform.clik.utils.Constraints; - - [Event(name = "change", type = "flash.events.Event")] - - public class Label extends UIComponent { - - // Constants: - - // Public Properties: - /** True if constraints are disabled for the component. Setting the disableConstraintsproperty to {@code disableConstraints=true} will remove constraints from the textfield. This is useful for components with timeline based textfield size tweens, since constraints break them due to a Flash quirk. */ - public var constraintsDisabled:Boolean = false; - - // Protected Properties: - protected var _text:String; - protected var _autoSize:String = TextFieldAutoSize.NONE; - protected var isHtml:Boolean; - - protected var state:String = "default"; - protected var _newFrame:String; - - // UI Elements: - /** A reference to the textField instance used to display the selected item's label. Note that when state changes are made, the textField instance may change, so changes made to it externally may be lost. */ - public var textField:TextField; - - // Initialization: - public function Label() { - super(); - } - - override protected function preInitialize():void { - if (!constraintsDisabled) { - constraints = new Constraints(this, ConstrainMode.COUNTER_SCALE); - } - } - - override protected function initialize():void { - super.initialize(); - } - - // Public getter / setters: - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - if (value == super.enabled) { return; } - super.enabled = value; - mouseEnabled = mouseChildren = value; - setState(defaultState); - } - - /** - * The text to be displayed by the Label component. This property assumes that localization has been - * handled externally. - * @see #htmlText For formatted text, use the {@code htmlText} property. - */ - [Inspectable(name="text")] - public function get text():String { return _text; } - public function set text(value:String):void { - if (value == null) { - value == ""; - } - isHtml = false; - _text = value; - invalidateData(); - } - - /** - * The html text to be displayed by the label component. This property assumes that localization has - * been handled externally. - * @see #text For plain text use {@code text} property. - */ - public function get htmlText():String { return _text; } - public function set htmlText(value:String):void { - if (value == null) { - value == ""; - } - isHtml = true; - _text = value; - invalidateData(); - } - - /** - * Determines if the component will scale to fit the text that it contains. Setting the {@code autoSize} - * property to TextFieldAutoSize.NONE ("none") will leave its current size unchanged. - */ - [Inspectable(defaultValue="none", enumeration="none,left,right,center")] - public function get autoSize():String { return _autoSize; } - public function set autoSize(value:String):void { - if (value == _autoSize) { return; } - _autoSize = value; - invalidateData(); - } - - public function get length():uint { return textField.length; } - public function get defaultState():String { - return (!enabled ? "disabled" : (focused ? "focused" : "default")); - } - - // Public Methods: - /** Append a String to the existing text within the Label. */ - public function appendText(value:String):void { - _text += value; - isHtml = false; - invalidateData(); - } - - /** - * Append an HTML-formatted String to the existing text within the Label. Note that the Label will be - * automatically set to display HTML text. - */ - public function appendHtml(value:String):void { - _text += value; - isHtml = true; - invalidateData(); - } - - /** @exclude */ - override public function toString():String { - return "[CLIK Label " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - if (!constraintsDisabled) { - constraints.addElement("textField", textField, Constraints.ALL); - } - - focusable = false; - // setState(defaultState, "default"); // NFM: Not sure if this is required for a Label. - } - - protected function calculateWidth():Number { - if (constraints == null || textField == null) { - return actualWidth; - } - - if (!constraintsDisabled) { - var element:ConstrainedElement = constraints.getElement("textField"); - } - - var w:Number = Math.ceil(textField.textWidth + element.left + element.right + 5); // We add 5 pixels to accommodate Flash's poor measurement of anti-aliased fonts. - return w; - } - - protected function alignForAutoSize():void { - if (!initialized || _autoSize == TextFieldAutoSize.NONE || textField == null) { return; } - - var oldWidth:Number = _width; - var newWidth:Number = _width = calculateWidth(); - - switch (_autoSize) { - case TextFieldAutoSize.RIGHT: - var oldRight:Number = x + oldWidth; - x = oldRight - newWidth; - break; - case TextFieldAutoSize.CENTER: - var oldCenter:Number = x + oldWidth * 0.5; - x = oldCenter - newWidth * 0.5; - break; - } - } - - override protected function draw():void { - // State is invalid, and has been set (is not the default) - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - - updateAfterStateChange(); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.STATE_CHANGE)); - invalidate(InvalidationType.SIZE); - } - if (isInvalid(InvalidationType.DATA)) { - updateText(); - if (autoSize != TextFieldAutoSize.NONE) { - alignForAutoSize(); - invalidateSize(); - } - } - - // Resize and update constraints - if (isInvalid(InvalidationType.SIZE)) { - setActualSize(_width, _height); - if (!constraintsDisabled) { - constraints.update(_width, _height); - } - } - } - - protected function updateText():void { - if (_text != null && textField != null) { - if (isHtml) { - textField.htmlText = _text; - } else { - textField.text = _text; - } - } - } - - protected function updateAfterStateChange():void { - if (!initialized) { return; } - if (constraints != null && !constraintsDisabled) { - constraints.updateElement("textField", textField); // Update references in Constraints - } - - updateText(); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.STATE_CHANGE)); - } - - protected function setState(...states:Array):void { - if (states.length == 1) { - var onlyState:String = states[0].toString(); - if (state != onlyState && _labelHash[onlyState]) { - state = _newFrame = onlyState; - invalidateState(); - } - return; - } - - var l:uint = states.length; - for (var i:uint=0; iInspectable Properties

    - *

    - * Since the ListItemRenderer’s are controlled by a container component and never configured manually by a user, they contain only a small subset of the inspectable properties of the Button. - *

      - *
    • label: Sets the label of the ListItemRenderer.
    • - *
    • visible: Hides the button if set to false.
    • - *
    • enabled: Disables the button if set to true.
    • - *
    - *

    - * - *

    States

    - *

    - * Since it can be selected inside a container component, the ListItemRenderer requires the selected set of keyframes to denote its selected state. This component’s states include - *

      - *
    • an up or default state.
    • - *
    • an over state when the mouse cursor is over the component, or when it is focused.
    • - *
    • a down state when the button is pressed.
    • - *
    • a disabled state.
    • - *
    • a selected_up or default state.
    • - *
    • a selected_over state when the mouse cursor is over the component, or when it is focused.
    • - *
    • a selected_down state when the button is pressed.
    • - *
    • a selected_disabled state.
    • - *
    - *

    - * - * These are the minimal set of keyframes that should be in a ListItemRenderer. The extended set of states and keyframes supported by the Button component, and consequently the ListItemRenderer component, are described in the Getting Started with CLIK Buttons document. - * - *

    Events

    - * All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events. - *
      - *
    • type: The event type.
    • - *
    • target: The target that generated the event.
    • - *
    - * - *

    - * The events generated by the ListItemRenderer component are the same as the Button component. The properties listed next to the event are provided in addition to the common properties. - *

    - * - *

    - * Generally, rather than listening for the events dispatched by ListItemRenderer’s, users should add an event listener to the List itself. - * Lists will dispatch ListEvents including ITEM_PRESS and ITEM_CLICK when interaction with one of its child ListItemRenderers occurs. - * This allows users to add one EventListener to a List for a mouse click event (ListEvent.ITEM_CLICK), rather than one EventListener on each ListItemRenderer within said List. - *

      - *
    • ComponentEvent.SHOW: The visible property has been set to true at runtime.
    • - *
    • ComponentEvent.HIDE: The visible property has been set to false at runtime.
    • - *
    • ComponentEvent.STATE_CHANGE: The component's state has changed.
    • - *
    • FocusHandlerEvent.FOCUS_IN: The component has received focus.
    • - *
    • FocusHandlerEvent.FOCUS_OUT: The component has lost focus.
    • - *
    • Event.SELECT: The selected property has changed.
    • - *
    • ButtonEvent.PRESS: The button has been pressed.
    • - *
    • ButtonEvent.CLICK: The button has been clicked.
    • - *
    • ButtonEvent.DRAG_OVER: The mouse cursor has been dragged over the button (while the left mouse button is pressed).
    • - *
    • ButtonEvent.DRAG_OUT: The mouse cursor has been dragged out of the button (while the left mouse button is pressed).
    • - *
    • ButtonEvent.RELEASE_OUTSIDE: The mouse cursor has been dragged out of the button and the left mouse button has been released.
    • - *
    - *

    - */ - -/************************************************************************** - -Filename : ListItemRenderer.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.events.FocusEvent; - - import scaleform.clik.core.UIComponent; - import scaleform.clik.data.ListData; - import scaleform.clik.interfaces.IListItemRenderer; - - public class ListItemRenderer extends Button implements IListItemRenderer - { - // Constants: - - // Public Properties: - - // Protected Properties: - protected var _index:uint = 0; // Index of the ListItemRenderer - protected var _selectable:Boolean = true; - - // UI Elements: - - // Initialization: - public function ListItemRenderer() { - super(); - } - - // Public Getter / Setters: - // Override for focusable since ListItemRenderers should never acquire focus. - /** @exclude */ - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { } - - /** The index of this ListItemRenderer relative to its owner (generally, a subclass of CoreList). */ - public function get index():uint { return _index; } - public function set index(value:uint):void { _index = value; } - - /** UNIMPLEMENTED! true if this ListItemRenderer can be selected in the List; false otherwise. */ - public function get selectable():Boolean { return _selectable; } - public function set selectable(value:Boolean):void { _selectable = value; } - - // Public Methods: - /** - * Set the list data relevant to the ListItemRenderer. Each time the item changes, or is redrawn by the {@code owner}, the ListItemRenderer is updated using this method. - * @param listData An object which contains information for this ListItemRenderer relative to the List (index, selected state, label). - */ - public function setListData(listData:ListData):void { - index = listData.index; - selected = listData.selected; // Maybe this should be .selected and then skip the setState below (since we set displayFocus). - label = listData.label || ""; - // setState( "up" ); // Refresh the component, including the timeline state. - } - - /** - * Sets data from the {@code dataProvider} to the renderer. - * @param data The data associated with this ListItemRenderer. - */ - public function setData(data:Object):void { - this.data = data; - } - - /** @exclude */ - override public function toString():String { - return "[CLIK ListItemRenderer " + index + ", " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - focusTarget = owner; // The component sets the focusTarget to its owner instead of vice-versa. This allows sub-classes to override this behaviour. - _focusable = tabEnabled = tabChildren = mouseChildren = false; - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/NumericStepper.as b/src/scaleform/clik/controls/NumericStepper.as deleted file mode 100644 index bb0466e..0000000 --- a/src/scaleform/clik/controls/NumericStepper.as +++ /dev/null @@ -1,357 +0,0 @@ -/** - * The NumericStepper component displays a single number in the range assigned to it, and supports the ability to increment and decrement the value based on an arbitrary step size. - - Inspectable Properties - A NumericStepper component will have the following inspectable properties:
      -
    • enabled: Disables the component if set to false.
    • -
    • focusable: By default, NumericStepper can receive focus for user interactions. Setting this property to false will disable focus acquisition.
    • -
    • minimum: The minimum value of the NumericStepper’s range.
    • -
    • maximum: The maximum value of the NumericStepper’s range.
    • -
    • value: The numeric value displayed by the NumericStepper.
    • -
    • visible: Hides the component if set to false.
    • - - States - The NumericStepper component supports three states based on its focused and disabled properties.
        -
      • default or enabled state.
      • -
      • focused state, that highlights the textField area.
      • -
      • disabled state.
      - - Events - All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.
        -
      • type: The event type.
      • -
      • target: The target that generated the event.
      - - The events generated by the NumericStepper component are listed below. The properties listed next to the event are provided in addition to the common properties. -
        -
      • ComponentEvent.SHOW: The visible property has been set to true at runtime.
      • -
      • ComponentEvent.HIDE: The visible property has been set to false at runtime.
      • -
      • ComponentEvent.STATE_CHANGE: The NumericStepper's state has changed.
      • -
      • FocusHandlerEvent.FOCUS_IN: The NumericStepper has received focus.
      • -
      • FocusHandlerEvent.FOCUS_OUT: The NumericStepper has lost focus.
      • -
      • IndexEvent.INDEX_CHANGE: The NumericStepper's value has changed.
      • -
      • ButtonEvent.CLICK: The next or previous Button of the NumericStepper has been clicked.
      • -
      - */ - -/************************************************************************** - -Filename : NumericStepper.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.DisplayObject; - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.text.TextField; - - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.events.IndexEvent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.constants.ControllerType; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.utils.Constraints; - import scaleform.clik.utils.ConstrainedElement; - - public class NumericStepper extends UIComponent { - - // Constants: - - // Public Properties: - /** The amount the value is incremented or decremented. */ - [Inspectable(defaultValue="1")] - public var stepSize:Number = 1; - /** True if constraints are disabled for the component. Setting the disableConstraintsproperty to {@code disableConstraints=true} will remove constraints from the textfield. This is useful for components with timeline based textfield size tweens, since constraints break them due to a Flash quirk. */ - public var constraintsDisabled:Boolean = false; - - // Protected Properties: - protected var _maximum:Number = 10; - protected var _minimum:Number = 0; - protected var _stepSize:Number; - protected var _value:Number = 0; - protected var _labelFunction:Function; - protected var state:String = "default"; - protected var _newFrame:String; - - // UI Elements: - /** A reference to the textField instance used to display the selected item's label. Note that when state changes are made, the textField instance may change, so changes made to it externally may be lost. */ - public var textField:TextField; - /** A reference to the next button instance used to increment the {@code selectedIndex}. */ - public var nextBtn:Button; - /** A reference to the previous button instance used to decrement the {@code selectedIndex}. */ - public var prevBtn:Button; - - public var container:MovieClip; - - // Initialization: - public function NumericStepper() { - super(); - } - - override protected function preInitialize():void { - if (!constraintsDisabled) { - constraints = new Constraints(this, ConstrainMode.COUNTER_SCALE); - } - } - - override protected function initialize():void { - super.initialize(); - } - - // Public getter / setters: - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - if (value == super.enabled) { return; } - super.enabled = value; - - mouseEnabled = tabEnabled = value; - gotoAndPlay( value ? ((_focused > 0) ? "focused" : "default") : "disabled" ); - if (!initialized) { return; } - - updateAfterStateChange(); - prevBtn.enabled = nextBtn.enabled = value; - } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * {@code focusable=false} will remove support for tab key, direction key and mouse - * button based focus changes. - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - super.focusable = value; - } - - /** - * The maximum allowed value. The {@code value} property will always be less than or equal to the {@code maximum}. - */ - [Inspectable(defaultValue="10")] - public function get maximum():Number { return _maximum; } - public function set maximum(value:Number):void { - _maximum = value; - value = _value; - } - - /** - * The minimum allowed value. The {@code value} property will always be greater than or equal to the {@code minimum}. - */ - [Inspectable(defaultValue="0")] - public function get minimum():Number { return _minimum; } - public function set minimum(value:Number):void { - _minimum = value; - value = _value; - } - - /** - * The value of the numeric stepper. The {@code value} property will always be kept between the {@code mimimum} and {@code maximum}. - * @see #minimum - * @see #maximum - */ - [Inspectable(name="value", defaultValue="0")] - public function get value():Number { return _value; } - public function set value(v:Number):void { - v = lockValue(v); - if (v == _value) { return; } - var previousValue:Number = _value; - _value = v; - if (initialized) { - dispatchEventAndSound(new IndexEvent(IndexEvent.INDEX_CHANGE, true, false, value, previousValue, null)); - } - invalidate(); - } - - /** - * The function used to determine the label. - */ - public function get labelFunction():Function { return _labelFunction; } - public function set labelFunction(value:Function):void { - _labelFunction = value; - updateLabel(); - } - - // Public Methods: - /** Increment the {@code value} of the NumericStepper, using the {@code stepSize}. */ - public function increment():void { onNext(null); } - - /** Decrement the {@code value} of the NumericStepper, using the {@code stepSize}. */ - public function decrement():void { onPrev(null); } - - override public function handleInput(event:InputEvent):void { - if (event.isDefaultPrevented()) { return; } - var details:InputDetails = event.details; - var index:uint = details.controllerIndex; - - var keyPress:Boolean = (details.value == InputValue.KEY_DOWN || details.value == InputValue.KEY_HOLD); - switch (details.navEquivalent) { - case NavigationCode.RIGHT: - if (_value < _maximum) { - if (keyPress) { onNext(null); } - event.handled = true; - } - break; - case NavigationCode.LEFT: - if (_value > _minimum) { - if (keyPress) { onPrev(null); } - event.handled = true; - } - break; - case NavigationCode.HOME: - if (!keyPress) { value = _minimum } - event.handled = true; - break; - case NavigationCode.END: - if (!keyPress) { value = _maximum; } - event.handled = true; - break; - } - } - - override public function toString():String { - return "[CLIK NumericStepper " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - if (!constraintsDisabled) { - constraints.addElement("textField", textField, Constraints.LEFT | Constraints.RIGHT); - } - - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - nextBtn.addEventListener(ButtonEvent.CLICK, onNext, false, 0, true); - prevBtn.addEventListener(ButtonEvent.CLICK, onPrev, false, 0, true); - - tabEnabled = _focusable; - tabChildren = false; - - // Prevent internal components from preventing mouse focus moves to the component. - if (textField != null) { - textField.tabEnabled = textField.mouseEnabled = false; - } - if (container != null) { - container.tabEnabled = container.mouseEnabled = false; - } - - prevBtn.enabled = nextBtn.enabled = enabled; - prevBtn.autoRepeat = nextBtn.autoRepeat = true; - prevBtn.focusable = nextBtn.focusable = false; - prevBtn.focusTarget = nextBtn.focusTarget = this; - prevBtn.tabEnabled = nextBtn.tabEnabled = false; - prevBtn.mouseEnabled = nextBtn.mouseEnabled = true; - } - - override protected function draw():void { - // State is invalid, and has been set (is not the default) - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - - updateAfterStateChange(); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.STATE_CHANGE)); - } - - if (isInvalid(InvalidationType.DATA)) { - updateLabel(); - } - - // Resize and update constraints - if (isInvalid(InvalidationType.SIZE)) { - setActualSize(_width, _height); - if (!constraintsDisabled) { - constraints.update(_width, _height); - } - } - } - - override protected function changeFocus():void { - if (_focused || _displayFocus) { - setState("focused", "default"); - } else { - setState("default"); - } - - updateAfterStateChange(); - prevBtn.displayFocus = nextBtn.displayFocus = (_focused > 0); - } - - protected function handleDataChange(event:Event):void { - invalidate(InvalidationType.DATA); - } - - protected function updateAfterStateChange():void { - invalidateSize(); - updateLabel(); - - // Update the children's mouseEnabled/tabEnabled settings in case new instances have been created. - if (textField != null) { - textField.tabEnabled = textField.mouseEnabled = false; - } - if (container != null) { - container.tabEnabled = container.mouseEnabled = false; - } - - if (constraints != null && !constraintsDisabled) { - constraints.updateElement("textField", textField); // Update references in Constraints - } - } - - protected function updateLabel():void { - var label:String = _value.toString(); - if (_labelFunction != null) { - label = _labelFunction(_value); - } - textField.text = label; - } - - protected function onNext( event:ButtonEvent ):void { - value = _value + stepSize; - } - - protected function onPrev( event:ButtonEvent ):void { - value = _value - stepSize; - } - - protected function setState(...states:Array):void { - if (states.length == 1) { - var onlyState:String = states[0].toString(); - if (state != onlyState && _labelHash[onlyState]) { - state = _newFrame = onlyState; - invalidateState(); - } - return; - } - var l:uint = states.length; - for (var i:uint=0; ioptionStepper.dataProvider = [“item1”, “item2”, “item3”, “item4”, “item5”]; - - Inspectable Properties - A MovieClip that derives from the OptionStepper component will have the following inspectable properties: -
        -
      • enabled: Disables the component if set to false.
      • -
      • focusable: By default buttons receive focus for user interactions. Setting this property to false will disable focus acquisition.
      • -
      • visible: Hides the component if set to false.
      • -
      - - States - The OptionStepper component supports three states based on its focused and disabled properties. -
        -
      • default or enabled state.
      • -
      • focused state, that highlights the textField area.
      • -
      • disabled state.
      • -
      - - Events - All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.
        -
      • type: The event type.
      • -
      • target: The target that generated the event.
      - - The events generated by the OptionStepper component are listed below. The properties listed next to the event are provided in addition to the common properties. -
        -
      • ComponentEvent.SHOW: The visible property has been set to true at runtime.
      • -
      • ComponentEvent.HIDE: The visible property has been set to false at runtime.
      • -
      • ComponentEvent.STATE_CHANGE: The component's state has changed.
      • -
      • FocusHandlerEvent.FOCUS_IN: The component has received focus.
      • -
      • FocusHandlerEvent.FOCUS_OUT: The component has lost focus.
      • -
      • IndexEvent.INDEX_CHANGE: The OptionStepper's value has changed.
      • -
      - */ - -/************************************************************************** - -Filename : OptionStepper.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.DisplayObject; - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.FocusEvent; - import flash.events.MouseEvent; - import flash.text.TextField; - - import scaleform.gfx.FocusEventEx; - import scaleform.gfx.MouseEventEx; - - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.ControllerType; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.core.UIComponent; - import scaleform.clik.data.DataProvider; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.events.IndexEvent; - import scaleform.clik.interfaces.IDataProvider; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.utils.Constraints; - import scaleform.clik.utils.ConstrainedElement; - - [Event(name = "change", type = "flash.events.Event")] - - public class OptionStepper extends UIComponent { - - // Constants: - - // Public Properties: - /** A reference to the currently selected item in the dataProvider. */ - public var selectedItem:Object; - - // Protected Properties: - protected var _dataProvider:IDataProvider; - protected var _selectedIndex:Number = 0; - protected var _newSelectedIndex:int = 0; - protected var _labelField:String = "label"; - protected var _labelFunction:Function; - - protected var _state:String = "default"; - protected var _newFrame:String; - - // Disables Constraints for this component. Must be set in the constructor or before super.preInitialize() is called. - protected var _constraintsDisabled:Boolean = false; - - // UI Elements: - /** A reference to the textField instance used to display the selected item's label. Note that when state changes are made, the textField instance may change, so changes made to it externally may be lost. */ - public var textField:TextField; - /** A reference to the next button instance used to increment the {@code selectedIndex}. */ - public var nextBtn:Button; - /** A reference to the previous button instance used to decrement the {@code selectedIndex}. */ - public var prevBtn:Button; - - // Initialization: - public function OptionStepper() { - super(); - } - - override protected function preInitialize():void { - if (!_constraintsDisabled) { - constraints = new Constraints(this, ConstrainMode.COUNTER_SCALE); - } - } - - override protected function initialize():void { - dataProvider = new DataProvider(); // Default data. - super.initialize(); - } - - // Public Getter / Setters: - /** - * Enable/disable this component. Focus (along with keyboard events) and mouse events will be suppressed if disabled. - */ - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - if (value == super.enabled) { return; } - super.enabled = value; - mouseEnabled = enabled; - tabEnabled = (_focusable && enabled); - - gotoAndPlay( value ? ((_focused > 0) ? "focused" : "default") : "disabled" ); - if (!initialized) { return; } - updateAfterStateChange(); - prevBtn.enabled = nextBtn.enabled = value; - } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * {@code focusable=false} will remove support for tab key, direction key and mouse - * button based focus changes. - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - super.focusable = value; - } - - /** - * The data model displayed in the component. The dataProvider can be an Array or any object exposing the - * appropriate API, defined in the {@code IDataProvider} interface. If an Array is set as the dataProvider, - * functionality will be mixed into it by the {@code DataProvider.initialize} method. When a new DataProvider - * is set, the {@code selectedIndex} property will be reset to 0. - * @see DataProvider#initialize - * @see IDataProvider - */ - public function get dataProvider():IDataProvider { return _dataProvider; } - public function set dataProvider(value:IDataProvider):void { - if (_dataProvider != value) { - if (_dataProvider != null) { - _dataProvider.removeEventListener(Event.CHANGE, handleDataChange); - } - - _dataProvider = value; - selectedItem = null; - - if (_dataProvider == null) { return; } - _dataProvider.addEventListener(Event.CHANGE, handleDataChange); - } - - invalidateData(); - updateSelectedItem(); - } - - /** - * The index of the item in the {@code dataProvider} that is selected in a single-selection list. - */ - public function get selectedIndex():int { return _selectedIndex; } - public function set selectedIndex(value:int):void { - var newIndex:Number = Math.max(0, Math.min(_dataProvider.length-1, value)); - if (newIndex == _selectedIndex || newIndex == _newSelectedIndex) { return; } - _newSelectedIndex = newIndex; - invalidateSelectedIndex(); - } - - /** - * The name of the field in the {@code dataProvider} model to be displayed as the label in the TextInput - * field. A {@code labelFunction} will be used over a {@code labelField} if it is defined. - * @see #itemToLabel - */ - public function get labelField():String { return _labelField; } - public function set labelField(value:String):void { - _labelField = value; - updateLabel(); - } - - /** - * The function used to determine the label for an item. A {@code labelFunction} will override a - * {@code labelField} if it is defined. - * @see #itemToLabel - */ - public function get labelFunction():Function { return _labelFunction; } - public function set labelFunction(value:Function):void { - _labelFunction = value; - updateLabel(); - } - - // Public Methods: - /** - * Convert an item to a label string using the {@code labelField} and {@code labelFunction}. - * @param item The item to convert to a label. - * @returns The converted label string. - * @see #labelField - * @see #labelFunction - */ - public function itemToLabel(item:Object):String { - if (item == null) { return ""; } - if (_labelFunction != null) { - return _labelFunction(item); - } else if (_labelField != null && _labelField in item && item[_labelField] != null) { - return item[_labelField]; - } - return item.toString(); - } - - /** Mark the selectedIndex as invalid and schedule a draw() on next Stage.INVALIDATE event. */ - public function invalidateSelectedIndex():void { - invalidate(InvalidationType.SELECTED_INDEX); - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - if (event.isDefaultPrevented()) { return; } - var details:InputDetails = event.details; - var index:uint = details.controllerIndex; - - var keyPress:Boolean = (details.value == InputValue.KEY_DOWN || details.value == InputValue.KEY_HOLD); - switch (details.navEquivalent) { - case NavigationCode.RIGHT: - if (_selectedIndex < _dataProvider.length - 1) { - if (keyPress) { onNext(null); } - event.handled = true; - } - break; - case NavigationCode.LEFT: - if (_selectedIndex > 0) { - if (keyPress) { onPrev(null); } - event.handled = true; - } - break; - - case NavigationCode.HOME: - if (!keyPress) { selectedIndex = 0; } - event.handled = true; - break; - case NavigationCode.END: - if (!keyPress) { selectedIndex = _dataProvider.length -1; } - event.handled = true; - break; - } - } - - /** @exclude */ - override public function toString():String { - return "[CLIK OptionStepper " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - if (!_constraintsDisabled) { - constraints.addElement("textField", textField, Constraints.ALL); - } - - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - nextBtn.addEventListener(ButtonEvent.CLICK, onNext, false, 0, true); - prevBtn.addEventListener(ButtonEvent.CLICK, onPrev, false, 0, true); - - tabEnabled = _focusable; - tabChildren = false; - - // Prevent internal components from preventing mouse focus moves to the component. - textField.tabEnabled = textField.mouseEnabled = false; - - prevBtn.enabled = nextBtn.enabled = enabled; - prevBtn.autoRepeat = nextBtn.autoRepeat = true; - prevBtn.focusable = nextBtn.focusable = false; - prevBtn.focusTarget = nextBtn.focusTarget = this; - prevBtn.tabEnabled = nextBtn.tabEnabled = false; - prevBtn.mouseEnabled = nextBtn.mouseEnabled = true; - } - - override protected function draw():void { - if (isInvalid(InvalidationType.SELECTED_INDEX)) { - updateSelectedIndex(); - } - - // State is invalid, and has been set (is not the default) - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - - updateAfterStateChange(); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.STATE_CHANGE)); - invalidate(InvalidationType.DATA); - } - - if (isInvalid(InvalidationType.DATA)) { - refreshData(); - } - - // Resize and update constraints - if (isInvalid(InvalidationType.SIZE)) { - setActualSize(_width, _height); - if (!_constraintsDisabled) { - constraints.update(_width, _height); - } - } - } - - override protected function changeFocus():void { - if (_focused || _displayFocus) { - setState("focused", "default"); - } else { - setState("default"); - } - - // updateAfterStateChange(); // AS2 - prevBtn.displayFocus = nextBtn.displayFocus = (_focused > 0); - } - - protected function updateSelectedIndex():void { - if (_selectedIndex == _newSelectedIndex) { return; } - var lastIndex:int = _selectedIndex; - _selectedIndex = _newSelectedIndex; - dispatchEventAndSound(new IndexEvent(IndexEvent.INDEX_CHANGE, true, false, _selectedIndex, lastIndex, dataProvider[_selectedIndex])); - updateSelectedItem(); - } - - protected function refreshData():void { - _dataProvider.requestItemAt(_selectedIndex, populateText); - } - - protected function handleDataChange(event:Event):void { - invalidate(InvalidationType.DATA); - } - - protected function updateAfterStateChange():void { - invalidateSize(); - updateLabel(); - - // Update the children's mouseEnabled/tabEnabled settings in case new instances have been created. - textField.tabEnabled = textField.mouseEnabled = false; - - if (constraints != null && !_constraintsDisabled) { - constraints.updateElement("textField", textField); // Update references in Constraints - } - } - - protected function updateLabel():void { - if (selectedItem == null) { return; } - if (textField != null) { textField.text = itemToLabel(selectedItem); } - } - - protected function updateSelectedItem():void { - invalidateData(); - } - - protected function populateText( item:Object ):void { - selectedItem = item; - updateLabel(); - dispatchEventAndSound(new Event(Event.CHANGE)); - } - - protected function onNext( event:Object ):void { - selectedIndex += 1 - invalidateSelectedIndex(); - } - - protected function onPrev( event:Object ):void { - selectedIndex -= 1; - invalidateSelectedIndex(); - } - - protected function setState(...states:Array):void { - if (states.length == 1) { - var onlyState:String = states[0].toString(); - if (_state != onlyState && _labelHash[onlyState]) { - _state = _newFrame = onlyState; - invalidateState(); - } - return; - } - - var l:uint = states.length; - for (var i:uint=0; iInspectable Properties - Since it derives from the Button control, the RadioButton contains the same inspectable properties as the Button with the omission of the toggle and disableFocus properties. -
        -
      • autoRepeat: Determines if the button dispatches "click" events when pressed down and held.
      • -
      • autoSize: Determines if the button will scale to fit the text that it contains and which direction to align the resized button. Setting the autoSize property to {@code autoSize="none"} will leave its current size unchanged.
      • -
      • data: Data related to the button. This property is particularly helpful when using butons in a ButtonGroup.
      • -
      • enabled: Disables the button if set to false.
      • -
      • focusable: By default buttons receive focus for user interactions. Setting this property to false will disable focus acquisition.
      • -
      • label: Sets the label of the Button.
      • -
      • selected: Set the selected state of the Button. Buttons can have two sets of mouse states, a selected and unselected. When a Button's {@code toggle} property is {@code true} the selected state will be changed when the button is clicked, however the selected state can be set using ActionScript even if the toggle property is false.
      • -
      • toggle: Sets the toggle property of the Button. If set to true, the Button will act as a toggle button.
      • -
      • visible: Hides the button if set to false.
      • -
      - - States - Since the RadioButton is able to toggle between selected and unselected states, it, similar the CheckBox, requires at least the following states: -
        -
      • an up or default state.
      • -
      • an over state when the mouse cursor is over the component, or when it is focused.
      • -
      • a down state when the button is pressed.
      • -
      • a disabled state.
      • -
      • a selected_up or default state.
      • -
      • a selected_over state when the mouse cursor is over the component, or when it is focused.
      • -
      • a selected_down state when the button is pressed.
      • -
      • a selected_disabled state.
      • -
      - - These are the minimal set of keyframes that should be in a RadioButton. The extended set of states and keyframes supported by the Button component, and consequently the RadioButton component, are described in the Getting Started with CLIK Buttons document. - - Events - All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.
        -
      • type: The event type.
      • -
      • target: The target that generated the event.
      - - The events generated by the RadioButton component are listed below. The properties listed next to the event are provided in addition to the common properties.
        -
          -
        • ComponentEvent.SHOW: The visible property has been set to true at runtime.
        • -
        • ComponentEvent.HIDE: The visible property has been set to false at runtime.
        • -
        • ComponentEvent.STATE_CHANGE: The button's state has changed.
        • -
        • FocusHandlerEvent.FOCUS_IN: The button has received focus.
        • -
        • FocusHandlerEvent.FOCUS_OUT: The button has lost focus.
        • -
        • Event.SELECT: The selected property has changed.
        • -
        • ButtonEvent.PRESS: The button has been pressed.
        • -
        • ButtonEvent.CLICK: The button has been clicked.
        • -
        • ButtonEvent.DRAG_OVER: The mouse cursor has been dragged over the button (while the left mouse button is pressed).
        • -
        • ButtonEvent.DRAG_OUT: The mouse cursor has been dragged out of the button (while the left mouse button is pressed).
        • -
        • ButtonEvent.RELEASE_OUTSIDE: The mouse cursor has been dragged out of the button and the left mouse button has been released.
        • -
        -*/ - -/************************************************************************** - -Filename : RadioButton.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import scaleform.clik.controls.Button; - - import flash.events.MouseEvent; - - public class RadioButton extends Button { - - // Constants: - public static const DEFAULT_GROUPNAME:String = "default"; - - // Public Properties: - - // Protected Properties: - - // Initialization: - public function RadioButton() { - super(); - } - - override protected function initialize():void { - super.initialize(); - toggle = true; - allowDeselect = false; - if (_group == null) { - groupName = DEFAULT_GROUPNAME; - } - } - - // Public getter / setters: - // ** Override inspectables from base class - override public function get autoRepeat():Boolean { return false; } - override public function set autoRepeat(value:Boolean):void { } - override public function get toggle():Boolean { return true; } - override public function set toggle(value:Boolean):void { } - - // ** Expose groupName as inspectable - [Inspectable(defaultValue="")] - override public function get groupName():String { return super.groupName; } - override public function set groupName(value:String):void { - super.groupName = value; - } - - // Public Methods: - /** @exclude */ - override public function toString():String { - return "[CLIK RadioButton " + name + "]"; - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/ScrollBar.as b/src/scaleform/clik/controls/ScrollBar.as deleted file mode 100644 index 538b2cb..0000000 --- a/src/scaleform/clik/controls/ScrollBar.as +++ /dev/null @@ -1,339 +0,0 @@ -/** - * The CLIK ScrollBar displays and controls the scroll position of another component. It adds interactivity to the ScrollIndicator with a draggable thumb button, as well as optional “up” and “down” arrow buttons, and a clickable track. - - Inspectable Properties - The inspectable properties of the ScrollBar are similar to ScrollIndicator with one addition: -
          -
        • enabled: Disables the component if set to false.
        • -
        • offsetTop: Thumb offset at the top. A positive value moves the thumb's top-most position higher.
        • -
        • offsetBottom: Thumb offset at the bottom. A positive value moves the thumb's bottom-most position lower.
        • -
        • trackMode: When the user clicks on the track with the cursor, the scrollPage setting will cause the thumb to continuously scroll by a page until the cursor is released. The scrollToCursor setting will cause the thumb to immediately jump to the cursor and will also transition the thumb into a dragging mode until the cursor is released.
        • -
        • scrollTarget: Set a TextArea or normal multiline textField as the scroll target to automatically respond to scroll events. Non-text field types have to manually update the ScrollIndicator properties.
        • -
        • visible: Hides the component if set to false.
        • -
        - - States - The ScrollBar, similar to the ScrollIndicator, does not have explicit states. It uses the states of its child elements, the thumb, up, down and track Button components. - - - Events - All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.
          -
        • type: The event type.
        • -
        • target: The target that generated the event.
        - - The events generated by the ScrollBar component are listed below. The properties listed next to the event are provided in addition to the common properties. -
          -
        • ComponentEvent.SHOW: The visible property has been set to true at runtime.
        • -
        • ComponentEvent.HIDE: The visible property has been set to false at runtime.
        • -
        • Event.SCROLL: The scroll position has changed.
        • -
        -*/ - -/************************************************************************** - -Filename : ScrollBar.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.geom.Point; - import flash.text.TextField; - - import scaleform.clik.constants.ScrollBarTrackMode - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.core.UIComponent; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.ButtonEvent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.utils.Constraints; - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.constants.ScrollBarDirection; - - public class ScrollBar extends ScrollIndicator { - - // Constants: - - // Public Properties: - public var trackScrollPageSize:Number = 1; //LM: Should we use _pageSize instead? - - // Protected Properties: - protected var _dragOffset:Point; - protected var _trackMode:String = ScrollBarTrackMode.SCROLL_PAGE; - protected var _trackScrollPosition:Number = -1; - protected var _trackDragMouseIndex:Number = -1; - - // UI Elements: - /** A reference to the up arrow symbol in the ScrollBar, used to decrement the scroll position. */ - public var upArrow:Button; - /** A reference to the down arrow symbol in the ScrollBar, used to increment the scroll position. */ - public var downArrow:Button; - - // Initialization: - public function ScrollBar() { - super(); - } - - override protected function initialize():void { - super.initialize(); - - var r:Number = rotation; - rotation = 0; - - // The upArrow doesn't need a constraints, since it sticks to top left. - if (downArrow) { - constraints.addElement("downArrow", downArrow, Constraints.BOTTOM); - } - constraints.addElement("track", track, Constraints.TOP | Constraints.BOTTOM); - rotation = r; - } - - override protected function preInitialize():void { - constraints = new Constraints(this, ConstrainMode.REFLOW); - } - - // Public Getter / Setters: - /** - * Enable / disable this component. Focus (along with keyboard events) and mouse events will be suppressed if disabled. - */ - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - if (enabled == value) { return; } - super.enabled = value; - - gotoAndPlay(enabled ? "default" : "disabled"); // setState? - invalidate(InvalidationType.STATE); - } - - /** - * Set the scroll position to a number between the minimum and maximum. - */ - override public function get position():Number { return _position; } - override public function set position(value:Number):void { - value = Math.round(value); // The value is rounded so that the scrolling represents the position properly. Particularly for TextFields. - if (value == position) { return; } - super.position = value; - updateScrollTarget(); - } - - /** - * Set the behavior when clicking on the track. The scrollPage value will move the grip by a page in the direction of the click. The scrollToCursor value will move the grip to the exact position that was clicked and become instantly draggable. - */ - [Inspectable(type="String", enumeration="scrollPage,scrollToCursor", defaultValue="scrollPage")] - public function get trackMode():String { return _trackMode; } - public function set trackMode(value:String):void { - if (value == _trackMode) { return; } - _trackMode = value; - if (initialized) { - track.autoRepeat = (trackMode == ScrollBarTrackMode.SCROLL_PAGE); - } - } - - // Public Methods: - /** @exclude */ - override public function get availableHeight():Number { - return track.height - thumb.height + offsetBottom + offsetTop; - } - - /** @exclude */ - override public function toString():String { - return "[CLIK ScrollBar " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - mouseEnabled = mouseChildren = enabled; - tabEnabled = tabChildren = _focusable; - - addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel, false, 0, true); - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - - if (upArrow) { - upArrow.addEventListener(ButtonEvent.CLICK, handleUpArrowClick, false, 0, true); - upArrow.addEventListener(ButtonEvent.PRESS, handleUpArrowPress, false, 0, true); - upArrow.focusTarget = this; - upArrow.autoRepeat = true; - } - if (downArrow) { - downArrow.addEventListener(ButtonEvent.CLICK, handleDownArrowClick, false, 0, true); - downArrow.addEventListener(ButtonEvent.PRESS, handleDownArrowPress, false, 0, true); - downArrow.focusTarget = this; - downArrow.autoRepeat = true; - } - - thumb.addEventListener(MouseEvent.MOUSE_DOWN, handleThumbPress, false, 0, true); - thumb.focusTarget = this; - thumb.lockDragStateChange = true; - - track.addEventListener(MouseEvent.MOUSE_DOWN, handleTrackPress, false, 0, true); - track.addEventListener(ButtonEvent.CLICK, handleTrackClick, false, 0, true); - - if (track is UIComponent) { (track as UIComponent).focusTarget = this; } - // Uses tabChildren instead of setting tabEnabled on buttons. - track.autoRepeat = (trackMode == ScrollBarTrackMode.SCROLL_PAGE); - } - - protected function scrollUp():void { - position -= _pageScrollSize; - } - - protected function scrollDown():void { - position += _pageScrollSize; - } - - override protected function drawLayout():void { - // NFM: Reset the y position of the thumb so that the _height is valid when the constraints are updated. - thumb.y = track.y - offsetTop; - - if (isHorizontal) { - constraints.update(_height, _width); - } else { - constraints.update(_width, _height); - } - - // This is a fix for a bug in Flash Player/Scaleform where setting the width/height of a rotated DisplayObject - // will cause errors in its width/height. These width/height changes can exponentially? impact one another - // depending on the current rotation when and order in which they are applied. - // There are actually a few different bugs at play, but the short version for ScrollBar is that the - // DisplayObject.width will be screwed up when we change the size/scale of the ScrollBar in setActualSize and - // remain incorrect when constraints.update() is called, regardless of explicit calls to set super.width in UIComponent. - // Once all of these changes have been made, we can work around the problem by rescaling the incorrect width - // back to where it *should* be, regardless of how Flash Player/Scaleform has calculated the value. - // DisplayObject.scaleX and DisplayObject.scaleY still affect the original axises of the DisplayObject, - // which is why they work here. - if (isHorizontal && actualWidth != width) { - var yScaleFix:Number = width / actualWidth; - scaleY = yScaleFix; - } - } - - override protected function updateThumb():void { - var per:Number = Math.max(1, _maxPosition - _minPosition + _pageSize); - var trackHeight:Number = track.height + offsetTop + offsetBottom; // Uses the track as the height indicator, since ScrollIndicator can use just gfx as a track. - thumb.height = Math.max(_minThumbSize, Math.min(trackHeight, _pageSize / per * trackHeight)); - if (thumb is UIComponent) { (thumb as UIComponent).validateNow(); } - updateThumbPosition(); - } - - override protected function updateThumbPosition():void { - var percent:Number = (_position - _minPosition) / (_maxPosition - _minPosition); - var top:Number = track.y - offsetTop; - var yPos:Number = Math.round(percent * availableHeight + top); - - thumb.y = Math.max(top, Math.min(track.y + track.height - thumb.height + offsetBottom, yPos)); - thumb.visible = !(isNaN(percent) || isNaN(_pageSize) || _maxPosition <= 0 || _maxPosition == Infinity); - - var showThumb:Boolean = thumb.visible && enabled; - if (upArrow) { - upArrow.enabled = showThumb && (_position > _minPosition); - upArrow.validateNow(); - } - if (downArrow) { - downArrow.enabled = showThumb && (_position < _maxPosition); - downArrow.validateNow(); - } - track.enabled = track.mouseEnabled = showThumb; - } - - protected function handleUpArrowClick(event:ButtonEvent):void { - if (event.isRepeat) { - scrollUp(); - } - } - protected function handleUpArrowPress(event:ButtonEvent):void { - scrollUp(); - } - - protected function handleDownArrowClick(event:ButtonEvent):void { - if (event.isRepeat) { - scrollDown(); - } - } - protected function handleDownArrowPress(event:ButtonEvent):void { - scrollDown(); - } - - protected function handleThumbPress(event:Event):void { - if (_isDragging) { return; } - _isDragging = true; - stage.addEventListener(MouseEvent.MOUSE_MOVE, doDrag, false, 0, true); - stage.addEventListener(MouseEvent.MOUSE_UP, endDrag, false, 0, true); - _dragOffset = new Point(0, mouseY - thumb.y); - } - - protected function doDrag(event:MouseEvent):void { - var percent:Number = (mouseY - _dragOffset.y - track.y) / availableHeight; - position = _minPosition + percent * (_maxPosition - _minPosition); - } - - protected function endDrag(event:MouseEvent):void { - stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag); - stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag); - _isDragging = false; - - //LM: Needs review. - // If the thumb became draggable on a track press, - // manually generate the thumb events. - /*if (trackDragMouseIndex > -1) { - if (!thumb.hitTest(stage.mouseX, stage.mouseY)) { - //thumb.onReleaseOutside(trackDragMouseIndex); - } else { - thumb.onRelease(trackDragMouseIndex); - } - } - delete trackDragMouseIndex;*/ - } - - protected function handleTrackPress(event:MouseEvent):void { - if (event.shiftKey || trackMode == ScrollBarTrackMode.SCROLL_TO_CURSOR) { - var percent:Number = (mouseY - thumb.height/2 - track.y) / availableHeight; - position = Math.round(percent * (_maxPosition - _minPosition) + _minPosition); - - thumb.dispatchEventAndSound(new MouseEvent(MouseEvent.MOUSE_OVER)); - thumb.dispatchEventAndSound(new MouseEvent(MouseEvent.MOUSE_DOWN)); - handleThumbPress(event); - _dragOffset = new Point(0, thumb.height/2); - } - - if (_isDragging || position == _trackScrollPosition) { return; } - if (mouseY > thumb.y && mouseY < thumb.y + thumb.height) { return; } - position += (thumb.y < mouseY) ? trackScrollPageSize : -trackScrollPageSize; - } - - protected function handleTrackClick(event:ButtonEvent):void { - if (event.isRepeat) { - if (_isDragging || position == _trackScrollPosition) { return; } - if (mouseY > thumb.y && mouseY < thumb.y + thumb.height) { return; } - position += (thumb.y < mouseY) ? trackScrollPageSize : -trackScrollPageSize; - } - } - - protected function updateScrollTarget():void { - if (_scrollTarget == null || !enabled) { return; } - var target:TextField = _scrollTarget as TextField; - if (target != null) { - _scrollTarget.scrollV = _position; - } - } - - protected function handleMouseWheel(event:MouseEvent):void { - position -= (event.delta > 0 ? 1 : -1) * _pageScrollSize; - } - - override protected function changeFocus():void { - thumb.displayFocus = _focused || _displayFocus; - } - } -} diff --git a/src/scaleform/clik/controls/ScrollIndicator.as b/src/scaleform/clik/controls/ScrollIndicator.as deleted file mode 100644 index 665f24a..0000000 --- a/src/scaleform/clik/controls/ScrollIndicator.as +++ /dev/null @@ -1,304 +0,0 @@ -/** - * The CLIK ScrollIndicator displays the scroll position of another component, such as a multiline textField. It can be pointed at a textField to automatically display its scroll position. All list-based components as well as the TextArea have a scrollBar property which can be pointed to a ScrollIndicator or ScrollBar instance or linkage ID. - - Inspectable Properties - The inspectable properties of the ScrollIndicator are: -
          -
        • scrollTarget: Set a TextArea or normal multiline textField as the scroll target to automatically respond to scroll events. Non-text field types have to manually update the ScrollIndicator properties.
        • -
        • visible: Hides the component if set to false.
        • -
        • enabled: Disables the component if set to false.
        • -
        • offsetTop: Thumb offset at the top. A positive value moves the thumb's top-most position higher.
        • -
        • offsetBottom: Thumb offset at the bottom. A positive value moves the thumb's bottom-most position lower.
        • -
        - - States - The ScrollIndicator does not have explicit states. It uses the states of its child elements, the thumb and track Button components. - - Events - All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.
          -
        • type: The event type.
        • -
        • target: The target that generated the event.
        - - The events generated by the ScrollIndicator component are listed below. The properties listed next to the event are provided in addition to the common properties. -
          -
        • ComponentEvent.SHOW: The visible property has been set to true at runtime.
        • -
        • ComponentEvent.HIDE: The visible property has been set to false at runtime.
        • -
        • Event.SCROLL: The scroll position has changed.
        • -
        - */ - -/************************************************************************** - -Filename : ScrollIndicator.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.MovieClip; - import flash.events.Event; - import flash.text.TextField; - - import scaleform.clik.constants.ScrollBarDirection; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.controls.Button; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.interfaces.IScrollBar; - import scaleform.clik.ui.InputDetails; - - [Event(name="scroll", type="flash.events.Event")] - - public class ScrollIndicator extends UIComponent implements IScrollBar { - - // Constants: - - // Public Properties: - /** The direction of the scroll bar. Valid values are ScrollBarDirection.VERTICAL / ScrollBarDirection.HORIZONTAL. */ - public var direction:String = ScrollBarDirection.VERTICAL; - /** Thumb offset at the top. A positive value moves the thumb's top-most position higher. */ - [Inspectable(defaultValue="0")] - public var offsetTop:Number = 0; - /** Thumb offset at the bottom. A positive value moves the thumb's bottom-most position lower. */ - [Inspectable(defaultValue="0")] - public var offsetBottom:Number = 0; - - // Protected Properties: - protected var _isDragging:Boolean = false; - protected var _maxPosition:Number = 10; - protected var _minPosition:Number = 0; - protected var _minThumbSize:Number = 10; - protected var _pageScrollSize:Number = 1; - protected var _pageSize:Number; - protected var _position:Number = 5; - protected var _scrollTarget:Object; - - // UI Elements: - /** A reference to the thumb symbol in the ScrollIndicator. */ - public var thumb:MovieClip; - /** A reference to the track symbol in the ScrollIndicator. */ - public var track:MovieClip; - - // Initialization: - public function ScrollIndicator() { - super(); - } - - override protected function initialize():void { - super.initialize(); - } - - // Public Getter / Setters: - /** - * Enables or disables the component. Disabled components should not receive mouse, keyboard, or any - * other kind of focus or interaction. - */ - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - if (value == super.enabled) { return; } - super.enabled = value; - gotoAndPlay(enabled ? "default" : "disabled"); // setState? - } - - /** - * The current position of the ScrollIndicator. - */ - public function get position():Number { return _position; } - public function set position(value:Number):void { - value = Math.max(_minPosition, Math.min(_maxPosition, value)); - if (value == _position) { return; } - _position = value; - dispatchEventAndSound(new Event(Event.SCROLL)); - invalidateData(); - } - - /** - * The minimum size for the thumb. - */ - [Inspectable(type="Number", defaultValue="10")] - public function get minThumbSize():Number { return _minThumbSize; } - public function set minThumbSize(value:Number):void { - value = Math.max(1, value); - _minThumbSize = value; - invalidateSize(); - } - - public function get isHorizontal():Boolean { return direction == ScrollBarDirection.HORIZONTAL; } - - [Inspectable(type="String", defaultValue="")] - public function get scrollTarget():Object { return _scrollTarget; } - public function set scrollTarget(value:Object):void { - if (value is String) { - if (!componentInspectorSetting || value.toString() == "" || parent == null) { return; } - value = parent.getChildByName(value.toString()); - if (value == null) { return; } - } - - var oldTarget:Object = _scrollTarget; - _scrollTarget = value; - - if (oldTarget != null) { - oldTarget.removeEventListener(Event.SCROLL, handleTargetScroll, false); - if (oldTarget.scrollBar != null) { oldTarget.scrollBar = null; } - // focusTarget = null; - // oldTarget.noAutoSelection = false; // @TODO: Look at replacing for AS3. - } - - // Check if the scrollTarget is on a component, and if it has a scrollBar property (like a List) - if (value is UIComponent && "scrollBar" in value) { - value.scrollBar = this; - return; - } - - if (_scrollTarget == null) { - tabEnabled = true; - return; - } - - _scrollTarget.addEventListener(Event.SCROLL, handleTargetScroll, false, 0, true); - - //_scrollTarget.noAutoSelection = true; // @TODO: Look at replacing for AS3. - if (_scrollTarget is UIComponent) { focusTarget = _scrollTarget as UIComponent; } - tabEnabled = false; - handleTargetScroll(null); - - invalidate(); - } - - /** - * Returns the available scrolling height of the component. - */ - public function get availableHeight():Number { - // thumbHeight may not be valid on the first invalidation. - var thumbHeight:Number = isNaN(thumb.height) ? 0 : thumb.height; - return (isHorizontal ? _width : _height) - thumbHeight + offsetBottom + offsetTop; - } - - // Public Methods: - /** - * Set the scroll properties of the component. - * @param pageSize The size of the pages to determine scroll distance. - * @param minPosition The minimum scroll position. - * @param maxPosition The maximum scroll position. - * @param pageScrollSize The amount to scroll when "paging". Not currently implemented. - */ - public function setScrollProperties(pageSize:Number, minPosition:Number, maxPosition:Number, pageScrollSize:Number = NaN):void { - this._pageSize = pageSize; - if (!isNaN(pageScrollSize)) { this._pageScrollSize = pageScrollSize; } - this._minPosition = minPosition; - this._maxPosition = maxPosition; - - invalidateSize(); - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - if (event.handled) { return; } - var details:InputDetails = event.details; - if (details.value == InputValue.KEY_UP) { return; } // Allow key-down and key-press - var isHorizontal:Boolean = (direction == ScrollBarDirection.HORIZONTAL); - switch (details.navEquivalent) { - case NavigationCode.UP: - if (isHorizontal) { return; } - position -= 1; - break; - case NavigationCode.DOWN: - if (isHorizontal) { return; } - position += 1; - break; - case NavigationCode.LEFT: - if (!isHorizontal) { return; } - position -= 1; - break; - case NavigationCode.RIGHT: - if (!isHorizontal) { return; } - position += 1; - break; - case NavigationCode.HOME: - position = 0; - break; - case NavigationCode.END: - position = _maxPosition; - break; - default: - return; - } - event.handled = true; - } - - /** @exclude */ - override public function toString():String { - return "[CLIK ScrollIndicator " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - - focusable = false; - mouseChildren = mouseEnabled = false; - - if (track == null) { track = new MovieClip(); } // Do not add to stage, this is just to avoid having to constantly check for it. - thumb.enabled = enabled; - - initSize(); - direction = (rotation != 0 && rotation != 180) ? ScrollBarDirection.HORIZONTAL : ScrollBarDirection.VERTICAL; //LM: Test 180º - } - - override protected function draw():void { - if (isInvalid(InvalidationType.SIZE)) { - // Ensure that the size is up to date before updating the layout and thumb. - setActualSize(_width, _height); - drawLayout(); - updateThumb(); - } else if (isInvalid(InvalidationType.DATA)) { // DATA refers to POSITION only - if (_scrollTarget is TextField) { - var target:TextField = _scrollTarget as TextField; - setScrollProperties(target.bottomScrollV - target.scrollV, 1, target.maxScrollV); - } - updateThumbPosition(); - } - } - - protected function drawLayout():void { - track.height = isHorizontal ? _width : _height; - if (track is UIComponent) { track.validateNow(); } - } - - protected function updateThumb():void { - var per:Number = Math.max(1, _maxPosition - _minPosition + _pageSize); - var trackHeight:Number = (isHorizontal ? _width : _height) + offsetTop + offsetBottom; - thumb.height = Math.max(_minThumbSize, Math.min(_height, _pageSize / per * trackHeight)); - if (thumb is UIComponent) { (thumb as UIComponent).validateNow(); } - updateThumbPosition(); - } - - protected function updateThumbPosition():void { - var percent:Number = (_position - _minPosition) / (_maxPosition - _minPosition); - if (isNaN(percent)) { percent = 0; } // In the case that the _maxPosition == _minPosition. - var yPos:Number = percent * availableHeight; - thumb.y = Math.max( -offsetTop, Math.min(availableHeight - offsetTop, yPos) ); - thumb.visible = !((_maxPosition == _minPosition) || isNaN(_pageSize) || _maxPosition == 0); - } - - // The scrollTarget TextField has changed its scroll position. - protected function handleTargetScroll(event:Event):void { - if (_isDragging) { return; } // Don't listen for scroll events while the thumb is dragging. - var target:TextField = _scrollTarget as TextField; - if (target != null) { - setScrollProperties(target.bottomScrollV - target.scrollV, 1, target.maxScrollV); - position = target.scrollV; - } - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/ScrollingList.as b/src/scaleform/clik/controls/ScrollingList.as deleted file mode 100644 index 8cc147c..0000000 --- a/src/scaleform/clik/controls/ScrollingList.as +++ /dev/null @@ -1,529 +0,0 @@ -/** - The ScrollingList is a list component that can scroll its elements. It can instantiate list items by itself - or use existing list items on the stage. A ScrollIndicator or ScrollBar component can also be attached to this - list component to provide scoll feedback and control. This component is populated via a DataProvider. The - dataProvider is assigned via code, as shown in the example below: - scrollingList.dataProvider = ["item1", "item2", "item3", "item4", ]; - - Inspectable Properties - A MovieClip that derives from the ScrollingList component will have the following inspectable properties: -
          -
        • enabled: Disables the component if set to false. This disables both the attached scrollbar and the list items (both internally created and external renderers).
        • -
        • focusable: By default, ScrollingList can receive focus for user interactions. Setting this property to false will disable focus acquisition.
        • -
        • itemRenderer: The symbol name of the ListItemRenderer. Used to create list item instances internally. Has no effect if the rendererInstanceName property is set.
        • -
        • rendererInstanceName: Prefix of the external list item renderers to use with this ScrollingList component. The list item instances on the stage must be prefixed with this property value. If this property is set to the value ‘r’, then all list item instances to be used with this component must have the following values: ‘r1’, ‘r2’, ‘r3’,… The first item should have the number 1.
        • -
        • margin: The margin between the boundary of the list component and the list items created internally. This value has no effect if the rendererInstanceName property is set. This margin also affects the automatically generated scrollbar.
        • -
        • rowHeight: The height of list item instances created internally. This value has no effect if the rendererInstanceName property is set.
        • -
        • padding: Extra padding at the top, bottom, left, and right for the list items. This value has no effect if the rendererInstanceName property is set. Does not affect the automatically generated scrollbar.
        • -
        • thumbOffset: ScrollIndicator thumb offset for top and bottom. Passed through to ScrollIndicator. This property has no effect if the list does not automatically create a scrollbar instance.
        • -
        • thumbSizeFactor: Page size factor for the scrollbar thumb. A value greater than 1.0 will increase the thumb size by the given factor. This positive value has no effect if a scrollbar is not attached to the list.
        • -
        • scrollBar: Instance name of a ScrollBar component on the stage or a symbol name. If an instance name is specified, then the ScrollingList will hook into that instance. If a symbol name is specified, an instance of the symbol will be created by the ScrollingList.
        • -
        • visible: Hides the component if set to false. This does not hide the attached scrollbar or any external list item renderers.
        • -
        - - States - The ScrollingList component supports three states based on its focused and disabled properties. -
          -
        • default or enabled state.
        • -
        • focused state, that typically highlights the component’s border area.
        • -
        • disabled state.
        • -
        - - Events - All event callbacks receive a single Object parameter that contains relevant information about the event. The following properties are common to all events.
          -
        • type: The event type.
        • -
        • target: The target that generated the event.
        - -
          -
        • ComponentEvent.SHOW: The visible property has been set to true at runtime.
        • -
        • ComponentEvent.HIDE: The visible property has been set to false at runtime.
        • -
        • FocusHandlerEvent.FOCUS_IN: The button has received focus.
        • -
        • FocusHandlerEvent.FOCUS_OUT: The button has lost focus.
        • -
        • ComponentEvent.STATE_CHANGE: The button's state has changed.
        • -
        • ListEvent.ITEM_PRESS: A list item has been pressed down.
        • -
        • ListEvent.ITEM_CLICK: A list item has been clicked.
        • -
        • ListEvent.ITEM_ROLL_OVER: The mouse cursor has rolled over a list item.
        • -
        • ListEvent.ITEM_ROLL_OUT: The mouse cursor has rolled out of a list item.
        • -
        • ListEvent.ITEM_DOUBLE_CLICK: The mouse cursor has been double clicked on a list item.
        • -
        • ListEvent.INDEX_CHANGE: The selected index has changed.
        • -
        - */ - -/************************************************************************** - -Filename : ScrollingList.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.DisplayObject; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.geom.Rectangle; - import flash.system.ApplicationDomain; - - import scaleform.clik.constants.WrappingMode; - import scaleform.clik.controls.ScrollBar; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.data.ListData; - import scaleform.clik.events.InputEvent; - import scaleform.clik.interfaces.IScrollBar; - import scaleform.clik.interfaces.IListItemRenderer; - import scaleform.clik.constants.InputValue; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.utils.Padding; - - [Event(name="change", type="flash.events.Event")] - [Event(name="itemClick", type="scaleform.clik.events.ListEvent")] - [Event(name="itemPress", type="scaleform.clik.events.ListEvent")] - [Event(name="itemRollOver", type="scaleform.clik.events.ListEvent")] - [Event(name="itemRollOut", type="scaleform.clik.events.ListEvent")] - [Event(name="itemDoubleClick", type="scaleform.clik.events.ListEvent")] - - public class ScrollingList extends CoreList { - - // Constants: - - // Public Properties: - //public var autoRowCount:Number; //LM: Do we need this? Might want to use an autoRowHeight:Boolean or something. - /** - * Determines how focus "wraps" when the end or beginning of the component is reached. -
          -
        • WrappingMode.NORMAL: The focus will leave the component when it reaches the end of the data
        • -
        • WrappingMode.WRAP: The selection will wrap to the beginning or end.
        • -
        • WrappingMode.STICK: The selection will stop when it reaches the end of the data.
        • -
        - */ - [Inspectable(enumeration="normal,stick,wrap", defaultValue="normal")] - public var wrapping:String = WrappingMode.NORMAL; - /** ScrollIndicator thumb offset for top and bottom. Passed through to ScrollIndicator. This property has no effect if the list does not automatically create a scrollbar instance. */ - public var thumbOffset:Object; - /** Page size factor for the scrollbar thumb. A value greater than 1.0 will increase the thumb size by the given factor. This positive value has no effect if a scrollbar is not attached to the list. */ - public var thumbSizeFactor:Number = 1; - - // Protected Properties: - protected var _rowHeight:Number = NaN; - protected var _autoRowHeight:Number = NaN; - protected var _rowCount:Number = NaN; - protected var _scrollPosition:uint = 0; - protected var _autoScrollBar:Boolean = false; - protected var _scrollBarValue:Object; - protected var _margin:Number = 0; - protected var _padding:Padding; - - // UI Elements: - protected var _scrollBar:IScrollBar; - - // Initialization: - public function ScrollingList() { - super(); - } - - override protected function initialize():void { - super.initialize(); - } - - // Public getter / setters: - /** - * The margin between the boundary of the list component and the list items created internally. This value has no effect if the rendererInstanceName property is set. This margin also affects the automatically generated scrollbar. - */ - [Inspectable(defaultValue="0")] - public function get margin():Number { return _margin; } - public function set margin(value:Number):void { - _margin = value; - invalidateSize(); - } - - /** - * Extra padding at the top, bottom, left, and right for the list items. Does not affect the automatically generated scrollbar. - */ - public function get padding():Padding { return _padding; } - public function set padding(value:Padding):void { - _padding = value; - invalidateSize(); - } - - /** @exclude */ - [Inspectable(name="padding", defaultValue="top:0,right:0,bottom:0,left:0")] - public function set inspectablePadding(value:Object):void { - if (!componentInspectorSetting) { return; } - padding = new Padding(value.top, value.right, value.bottom, value.left); - } - - /** - * The component to use to scroll the list. The {@code scrollBar} can be set as a library linkage ID, - * an instance name on the stage relative to the component, or a reference to an existing ScrollBar - * elsewhere in the application. The automatic behaviour in this component only supports a vertical - * scrollBar, positioned on the top right, the entire height of the component. - * @see ScrollBar - * @see ScrollIndicator - */ - [Inspectable(type="String")] - public function get scrollBar():Object { return _scrollBar; } - public function set scrollBar(value:Object):void { - _scrollBarValue = value; - invalidate(InvalidationType.SCROLL_BAR); - } - - /** - * The vertical scroll position of the list. - */ - public function get scrollPosition():Number { return _scrollPosition; } - public function set scrollPosition(value:Number):void { - value = Math.max(0, Math.min(_dataProvider.length - _totalRenderers, Math.round(value))); - if (_scrollPosition == value) { return; } - _scrollPosition = value; - invalidateData(); - /* //LM: Moved to invalidation. - refreshData(); - updateScrollBar();*/ - } - - /** - * The selected index of the {@code dataProvider}. The {@code itemRenderer} at the {@code selectedIndex} - * will be set to {@code selected=true}. - */ - override public function set selectedIndex(value:int):void { - if (value == _selectedIndex || value == _newSelectedIndex) { return; } - _newSelectedIndex = value; - invalidateSelectedIndex(); - } - - /** - * The amount of visible rows. Setting this property will immediately change the height of the component - * to accomodate the specified amount of rows. The {@code rowCount} property is not stored or maintained. - */ - public function get rowCount():uint { return _totalRenderers; } - public function set rowCount(value:uint):void { - var h:Number = rowHeight; - if (isNaN(rowHeight)) { calculateRendererTotal(availableWidth, availableHeight); } - h = rowHeight; - height = (h * value) + (margin * 2); // + padding.horizontal; - } - - /** - * The height of each item in the list. When set to {@code null} or 0, the default height of the - * renderer symbol is used. - */ - [Inspectable(defaultValue="0")] - public function get rowHeight():Number { return isNaN(_autoRowHeight) ? _rowHeight : _autoRowHeight; } - public function set rowHeight(value:Number):void { - if (value == 0) { - value = NaN; - if (_inspector){ return; } - } - _rowHeight = value; - _autoRowHeight = NaN; - invalidateSize(); - } - - /** Retireve the available width of the component. */ - override public function get availableWidth():Number { - return Math.round(_width) - (margin * 2)- (_autoScrollBar ? Math.round(_scrollBar.width) : 0); - } - - /** Retrieve the available height of the component (internal height - margin). */ - override public function get availableHeight():Number { - return Math.round(_height) - (margin * 2); - } - - // Public Methods: - /** - * Scroll the list to the specified index. If the index is currently visible, the position will not change. The scroll position will only change the minimum amount it has to to display the item at the specified index. - * @param index The index to scroll to. - */ - override public function scrollToIndex(index:uint):void { - if (_totalRenderers == 0) { return; } - if (index >= _scrollPosition && index < _scrollPosition + _totalRenderers) { - return; - } else if (index < _scrollPosition) { - scrollPosition = index; - } else { - scrollPosition = index - (_totalRenderers-1); - } - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - if (event.handled) { return; } // Already Handled. - - // Pass on to selected renderer first - var renderer:IListItemRenderer = getRendererAt(_selectedIndex, _scrollPosition); - if (renderer != null) { - renderer.handleInput(event); // Since we are just passing on the event, it won't bubble, and should properly stopPropagation. - if (event.handled) { return; } - } - - // Only allow actions on key down, but still set handled=true when it would otherwise be handled. - var details:InputDetails = event.details; - var keyPress:Boolean = (details.value == InputValue.KEY_DOWN || details.value == InputValue.KEY_HOLD); - switch(details.navEquivalent) { - case NavigationCode.UP: - if (selectedIndex == -1) { - if (keyPress) { selectedIndex = scrollPosition + _totalRenderers - 1; } - } else if (_selectedIndex > 0) { - if (keyPress) { selectedIndex--; } - } else if (wrapping == WrappingMode.STICK) { - // Nothing. - } else if (wrapping == WrappingMode.WRAP) { - if (keyPress) { selectedIndex = _dataProvider.length-1; } - } else { - return; - } - break; - - case NavigationCode.DOWN: - if (_selectedIndex == -1) { - if (keyPress) selectedIndex = _scrollPosition; - } else if (_selectedIndex < _dataProvider.length-1) { - if (keyPress) { selectedIndex++; } - } else if (wrapping == WrappingMode.STICK) { - // Nothing - } else if (wrapping == WrappingMode.WRAP) { - if (keyPress) { selectedIndex = 0; } - } else { - return; - } - break; - - case NavigationCode.END: - if (!keyPress) { - selectedIndex = _dataProvider.length-1; - } - break; - - case NavigationCode.HOME: - if (!keyPress) { selectedIndex = 0; } - break; - - case NavigationCode.PAGE_UP: - if (keyPress) { selectedIndex = Math.max(0, _selectedIndex - _totalRenderers); } - break; - - case NavigationCode.PAGE_DOWN: - if (keyPress) { selectedIndex = Math.min(_dataProvider.length-1, _selectedIndex + _totalRenderers); } - break; - - default: - return; - } - - event.handled = true; - } - - /** @exclude */ - override public function toString():String { - return "[CLIK ScrollingList "+ name +"]"; - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - if (padding == null) { padding = new Padding(); } - if (_itemRenderer == null && !_usingExternalRenderers) { itemRendererName = _itemRendererName } - } - - override protected function draw():void { - if (isInvalid(InvalidationType.SCROLL_BAR)) { - createScrollBar(); - } - - if (isInvalid(InvalidationType.RENDERERS)) { - _autoRowHeight = NaN; - } - - super.draw(); - - if (isInvalid(InvalidationType.DATA)) { - updateScrollBar(); - } - } - - override protected function drawLayout():void { - var l:uint = _renderers.length; - var h:Number = rowHeight; - var w:Number = availableWidth - padding.horizontal; - var rx:Number = margin + padding.left; - var ry:Number = margin + padding.top; - var dataWillChange:Boolean = isInvalid(InvalidationType.DATA); - for (var i:uint = 0; i < l; i++) { - var renderer:IListItemRenderer = getRendererAt(i); - renderer.x = rx; - renderer.y = ry + i * h; - renderer.width = w; - renderer.height = h; - if (!dataWillChange) { renderer.validateNow(); } - } - drawScrollBar(); - } - - protected function createScrollBar():void { - if (_scrollBar) { - _scrollBar.removeEventListener(Event.SCROLL, handleScroll, false); - _scrollBar.removeEventListener(Event.CHANGE, handleScroll, false); - _scrollBar.focusTarget = null; - if (container.contains(_scrollBar as DisplayObject)) { container.removeChild(_scrollBar as DisplayObject); } - _scrollBar = null; - } - - if (!_scrollBarValue || _scrollBarValue == "") { return; } - - _autoScrollBar = false; // Reset - - var sb:IScrollBar; - if (_scrollBarValue is String) { - if (parent != null) { - sb = parent.getChildByName(_scrollBarValue.toString()) as IScrollBar; - } - if (sb == null) { - var domain : ApplicationDomain = ApplicationDomain.currentDomain; - if (loaderInfo != null && loaderInfo.applicationDomain != null) domain = loaderInfo.applicationDomain; - var classRef:Class = domain.getDefinition(_scrollBarValue.toString()) as Class; - - if (classRef) { - sb = new classRef() as IScrollBar; - } - if (sb) { - _autoScrollBar = true; - var sbInst:Object = sb as Object; - if (sbInst && thumbOffset) { - sbInst.offsetTop = thumbOffset.top; - sbInst.offsetBottom = thumbOffset.bottom; - } - sb.addEventListener(MouseEvent.MOUSE_WHEEL, blockMouseWheel, false, 0, true); // Prevent duplicate scroll events - //if (sb.scale9Grid == null) { sb.scale9Grid = new Rectangle(0,0,1,1); } // Prevent scaling - container.addChild(sb as DisplayObject); - } - } - } else if (_scrollBarValue is Class) { - sb = new (_scrollBarValue as Class)() as IScrollBar; - sb.addEventListener(MouseEvent.MOUSE_WHEEL, blockMouseWheel, false, 0, true); - if (sb != null) { - _autoScrollBar = true; - (sb as Object).offsetTop = thumbOffset.top; - (sb as Object).offsetBottom = thumbOffset.bottom; - container.addChild(sb as DisplayObject); - } - } else { - sb = _scrollBarValue as IScrollBar; - } - _scrollBar = sb; - - invalidateSize(); // Redraw to reset scrollbar bounds, even if there is no scrollBar. - - if (_scrollBar == null) { return; } - // Now that we have a scrollBar, lets set it up. - _scrollBar.addEventListener(Event.SCROLL, handleScroll, false, 0, true); - _scrollBar.addEventListener(Event.CHANGE, handleScroll, false, 0, true); - _scrollBar.focusTarget = this; - _scrollBar.tabEnabled = false; - } - - protected function drawScrollBar():void { - if (!_autoScrollBar) { return; } - _scrollBar.x = _width - _scrollBar.width - margin; - _scrollBar.y = margin; - _scrollBar.height = availableHeight; - _scrollBar.validateNow(); - } - - protected function updateScrollBar():void { - if (_scrollBar == null) { return; } - var max:Number = Math.max(0, _dataProvider.length - _totalRenderers); - if (_scrollBar is ScrollIndicator) { - var scrollIndicator:ScrollIndicator = _scrollBar as ScrollIndicator; - scrollIndicator.setScrollProperties(_dataProvider.length-_totalRenderers, 0, _dataProvider.length-_totalRenderers); - //scrollIndicator.trackScrollPageSize = Math.max(1, _totalRenderers); - } else { - // Min/max - } - _scrollBar.position = _scrollPosition; - _scrollBar.validateNow(); - } - - override protected function changeFocus():void { - super.changeFocus(); - var renderer:IListItemRenderer = getRendererAt(_selectedIndex, _scrollPosition); - if (renderer != null) { - renderer.displayFocus = (focused > 0); - renderer.validateNow(); - } - } - - override protected function refreshData():void { - _scrollPosition = Math.min(Math.max(0, _dataProvider.length - _totalRenderers), _scrollPosition); - selectedIndex = Math.min(_dataProvider.length - 1, _selectedIndex); - updateSelectedIndex(); - _dataProvider.requestItemRange(_scrollPosition, Math.min(_dataProvider.length - 1, _scrollPosition + _totalRenderers - 1), populateData); - } - - override protected function updateSelectedIndex():void { - if (_selectedIndex == _newSelectedIndex) { return; } - if (_totalRenderers == 0) { return; } // Return if there are no renderers - - var renderer:IListItemRenderer = getRendererAt(_selectedIndex, scrollPosition); - if (renderer != null) { - renderer.selected = false; // Only reset items in range - renderer.validateNow(); - } - - super.selectedIndex = _newSelectedIndex; // Reset the new selected index value if we found a renderer instance - if (_selectedIndex < 0 || _selectedIndex >= _dataProvider.length) { return; } - - renderer = getRendererAt(_selectedIndex, _scrollPosition); - if (renderer != null) { - renderer.selected = true; // Item is in range. Just set it. - renderer.validateNow(); - } else { - scrollToIndex(_selectedIndex); // Will redraw - renderer = getRendererAt(_selectedIndex, scrollPosition); - renderer.selected = true; // Item is in range. Just set it. - renderer.validateNow(); - } - } - - override protected function calculateRendererTotal(width:Number, height:Number):uint { - if (isNaN(_rowHeight) && isNaN(_autoRowHeight)) { - var renderer:IListItemRenderer = createRenderer(0); - _autoRowHeight = renderer.height; - cleanUpRenderer(renderer); - } - - return (availableHeight - padding.vertical) / rowHeight >> 0; - } - - protected function handleScroll(event:Event):void { - scrollPosition = _scrollBar.position; - } - - protected function populateData(data:Array):void { - var dl:uint = data.length; - var l:uint = _renderers.length; - for (var i:uint = 0; i < l; i++) { - var renderer:IListItemRenderer = getRendererAt(i); - var index:uint = _scrollPosition + i; - var listData:ListData = new ListData(index, itemToLabel(data[i]), _selectedIndex == index); - renderer.enabled = (i >= dl) ? false : true; - renderer.setListData(listData); //LM: Consider passing renderer position also. (Support animation) - renderer.setData(data[i]); - renderer.validateNow(); - } - } - - override protected function scrollList(delta:int):void { - scrollPosition -= delta; - } - - protected function blockMouseWheel(event:MouseEvent):void { - event.stopPropagation(); - } - } -} diff --git a/src/scaleform/clik/controls/Slider.as b/src/scaleform/clik/controls/Slider.as deleted file mode 100644 index 9fd305d..0000000 --- a/src/scaleform/clik/controls/Slider.as +++ /dev/null @@ -1,394 +0,0 @@ -/** -* The Slider displays a numerical value in range, with a thumb to represent the value, as well as modify it via dragging. - Inspectable Properties - The inspectable properties of the Slider component are: -
          -
        • enabled: Disables the Slider if set to false.
        • -
        • focusable: By default, Slider can receive focus for user interactions. Setting this property to false will disable focus acquisition.
        • -
        • value: The numeric value displayed by the Slider.
        • -
        • minimum: The minimum value of the Slider’s range.
        • -
        • maximum: The maximum value of the Slider’s range.
        • -
        • snapping: If set to true, then the thumb will snap to values that are multiples of snapInterval.
        • -
        • snapInterval: The snapping interval which determines which multiples of values the thumb snaps to. It has no effect if snapping is set to false.
        • -
        • liveDragging: If set to true, then the Slider will generate a change event when dragging the thumb. If false, then the Slider will only generate a change event after the dragging is over.
        • -
        • offsetLeft: Left offset for the thumb. A positive value will push the thumb inward.
        • -
        • offsetRight: Right offset for the thumb. A positive value will push the thumb inward.
        • -
        • visible: Hides the component if set to false.
        • -
        - - States - Like the ScrollIndicator and the ScrollBar, the Slider does not have explicit states. It uses the states of its child elements, the thumb and track Button components. - - Events - All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.
          -
        • type: The event type.
        • -
        • target: The target that generated the event.
        - - The events generated by the Slider component are listed below. The properties listed next to the event are provided in addition to the common properties. -
          -
        • ComponentEvent.SHOW: The visible property has been set to true at runtime.
        • -
        • ComponentEvent.HIDE: The visible property has been set to false at runtime.
        • -
        • FocusHandlerEvent.FOCUS_IN: The component has received focus.
        • -
        • FocusHandlerEvent.FOCUS_OUT: The component has lost focus.
        • -
        • ComponentEvent.STATE_CHANGE: The component's state has changed.
        • -
        • SliderEvent.VALUE_CHANGE: The value of the Slider has changed.
        • -
        -*/ - -/************************************************************************** - -Filename : Slider.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.DisplayObject; - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.geom.Point; - - import scaleform.gfx.FocusManager; - import scaleform.gfx.MouseEventEx; - - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.events.SliderEvent; - import scaleform.clik.constants.ControllerType; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.utils.Constraints; - - [Event(name = "change", type = "flash.events.Event")] - - public class Slider extends UIComponent { - - // Constants: - - // Public Properties: - /** Determines if the Slider dispatches "change" events while dragging the thumb, or only after dragging is complete. */ - [Inspectable(defaultValue="true")] - public var liveDragging:Boolean = true; - /** The mouse state of the button. Mouse states can be "default", "disabled". */ - public var state:String = "default"; - /** Left offset for the thumb. A positive value will push the thumb inward. */ - [Inspectable(defaultValue=0, verbose=1)] - public var offsetLeft:Number = 0; - /** Right offset for the thumb. A positive value will push the thumb inward. */ - [Inspectable(defaultValue=0, verbose=1)] - public var offsetRight:Number = 0; - - // Private Properties: - protected var _minimum:Number = 0; - protected var _maximum:Number = 10; - protected var _value:Number = 0; - protected var _snapInterval:Number = 1; - protected var _snapping:Boolean = false; - protected var _dragOffset:Object; - protected var _trackDragMouseIndex:Number; - protected var _trackPressed:Boolean = false; - protected var _thumbPressed:Boolean = false; - - // UI Elements: - /** A reference to the thumb symbol in the Slider, used to display the slider {@code value}, and change the {@code value} via dragging. */ - public var thumb:Button; - /** A reference to the track symbol in the Slider used to display the slider range, but also to jump to a specific value via clicking. */ - public var track:Button; - - // Initialization: - public function Slider() { - super(); - } - - override protected function preInitialize():void { - constraints = new Constraints(this, ConstrainMode.REFLOW); - } - - override protected function initialize():void { - super.initialize(); - tabChildren = false; - mouseEnabled = mouseChildren = enabled; - } - - // Public getter / setters: - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - if (value == super.enabled) { return; } - super.enabled = value; - thumb.enabled = track.enabled = value; - // setState(defaultState); - } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * {@code focusable=false} will remove support for tab key, direction key and mouse - * button based focus changes. - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - super.focusable = value; - tabChildren = false; - } - - /** - * The value of the slider between the {@code minimum} and {@code maximum}. - * @see #maximum - * @see #minimum - */ - [Inspectable(defaultValue="0")] - public function get value():Number { return _value; } - public function set value(value:Number):void { - _value = lockValue(value); - dispatchEventAndSound( new SliderEvent(SliderEvent.VALUE_CHANGE, false, true, _value) ); - draw(); - } - - /** - * The maximum allowed value. The {@code value} property will always be less than or equal to the {@code maximum}. - */ - [Inspectable(defaultValue="10")] - public function get maximum():Number { return _maximum; } - public function set maximum(value:Number):void { - _maximum = value; - } - - /** - * The minimum allowed value. The {@code value} property will always be greater than or equal to the {@code minimum}. - */ - [Inspectable(defaultValue="0")] - public function get minimum():Number { return _minimum; } - public function set minimum(value:Number):void { - _minimum = value; - } - - /** - * The {@code value} of the {@code Slider}, to make it polymorphic with a {@link ScrollIndicator}. - */ - public function get position():Number { return _value; } - public function set position(value:Number):void { _value = value; } - - /** - * Whether or not the {@code value} "snaps" to a rounded value. When {@code snapping} is {@code true}, the value can only be set to multiples of the {@code snapInterval}. - * @see #snapInterval - */ - [Inspectable(defaultValue="false")] - public function get snapping():Boolean { return _snapping; } - public function set snapping(value:Boolean):void { - _snapping = value; - invalidateSettings(); - } - - /** - * The interval to snap to when {@code snapping} is {@code true}. - * @see #snapping - */ - [Inspectable(defaultValue="1")] - public function get snapInterval():Number { return _snapInterval; } - public function set snapInterval(value:Number):void { - _snapInterval = value; - invalidateSettings(); - } - - // Public Methods: - /** - * Marks the settings of the Slider (max, mix, snapping, snap interval) as invalid. These settings will be updated on the next Stage.RENDER event. - */ - public function invalidateSettings():void { - invalidate(InvalidationType.SETTINGS); - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - if (event.isDefaultPrevented()) { return; } - var details:InputDetails = event.details; - var index:uint = details.controllerIndex; - - var keyPress:Boolean = (details.value == InputValue.KEY_DOWN || details.value == InputValue.KEY_HOLD); - switch (details.navEquivalent) { - case NavigationCode.RIGHT: - if (keyPress) { - value += _snapInterval; - event.handled = true; - } - break; - case NavigationCode.LEFT: - if (keyPress) { - value -= _snapInterval; - event.handled = true; - } - break; - - case NavigationCode.HOME: - if (!keyPress) { - value = minimum; - event.handled = true; - } - break; - case NavigationCode.END: - if (!keyPress) { - value = maximum; - event.handled = true; - } - break; - default: - break; - } - } - - /** @exclude */ - override public function toString():String { - return "[CLIK Slider " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - - thumb.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag, false, 0, true); - track.addEventListener(MouseEvent.MOUSE_DOWN, trackPress, false, 0, true); - - tabEnabled = true; - thumb.focusTarget = track.focusTarget = this; - thumb.enabled = track.enabled = enabled; - - thumb.lockDragStateChange = true; - constraints.addElement("track", track, Constraints.LEFT | Constraints.RIGHT); - } - - override protected function draw():void { - if (isInvalid(InvalidationType.STATE)) { - gotoAndPlay(!enabled ? "disabled" : (_focused ? "focused" : "default")); - } - - // Resize and update constraints - if (isInvalid(InvalidationType.SIZE)) { - setActualSize(_width, _height); - constraints.update(_width, _height); - } - - updateThumb(); - } - - override protected function changeFocus():void { - super.changeFocus(); - invalidateState(); - - // NFM: Moved here from within draw(). - if (enabled) { - if (!_thumbPressed) { - thumb.displayFocus = (_focused != 0); - } - if (!_trackPressed) { - track.displayFocus = (_focused != 0); - } - } - } - - protected function updateThumb():void { - if (!enabled) { return; } - var trackWidth:Number = (_width - offsetLeft - offsetRight); - thumb.x = ((_value - _minimum) / (_maximum - _minimum) * trackWidth) - thumb.width / 2 + offsetLeft; - } - - protected function beginDrag(e:MouseEvent):void { - _thumbPressed = true; - - var lp:Point = globalToLocal( new Point(e.stageX, e.stageY) ); - _dragOffset = { x: (lp.x - thumb.x) - thumb.width / 2 }; - - stage.addEventListener(MouseEvent.MOUSE_MOVE, doDrag, false, 0, true); - stage.addEventListener(MouseEvent.MOUSE_UP, endDrag, false, 0, true); - } - - protected function doDrag(e:MouseEvent):void { - var lp:Point = globalToLocal( new Point(e.stageX, e.stageY) ); - var thumbPosition:Number = lp.x - _dragOffset.x; - var trackWidth:Number = (_width - offsetLeft - offsetRight); - var newValue:Number = lockValue( (thumbPosition - offsetLeft) / trackWidth * (_maximum - _minimum) + _minimum ); - - if (value == newValue) { return; } - _value = newValue; - - updateThumb(); - - if (liveDragging) { - dispatchEventAndSound( new SliderEvent(SliderEvent.VALUE_CHANGE, false, true, _value) ); - } - } - - protected function endDrag(e:MouseEvent):void { - stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag, false); - stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag, false); - - if (!liveDragging) { - dispatchEventAndSound( new SliderEvent(SliderEvent.VALUE_CHANGE, false, true, _value) ); - } - - // If the thumb became draggable on a track press, - // manually generate the thumb events. - /* - if (trackDragMouseIndex != undefined) { - if (!thumb.hitTest(_root._xmouse, _root._ymouse)) { - thumb.onReleaseOutside(trackDragMouseIndex); - } else { - thumb.onRelease(trackDragMouseIndex); - } - } - */ - - _trackDragMouseIndex = undefined; - _thumbPressed = false; - _trackPressed = false; - } - - protected function trackPress(e:MouseEvent):void { - _trackPressed = true; - - track.focused = _focused; - - var trackWidth:Number = (_width - offsetLeft - offsetRight); - var newValue:Number = lockValue( (e.localX * scaleX - offsetLeft) / trackWidth * (_maximum - _minimum) + _minimum); - - if (value == newValue) { return; } - value = newValue; - - if (!liveDragging) { - dispatchEventAndSound( new SliderEvent(SliderEvent.VALUE_CHANGE, false, true, _value) ); - } - - // Pressing on the track moves the grip to the cursor and the thumb becomes draggable. - _trackDragMouseIndex = 0 // e.mouseIdx; // @todo, NFM: This needs to use the multi-controller system. - - // thumb.onPress(trackDragMouseIndex); - _dragOffset = {x:0}; - } - - // Ensure the value is in range and snap it to the snapInterval - protected function lockValue( lvalue:Number ):Number { - lvalue = Math.max(_minimum, Math.min(_maximum, lvalue)); - if (!snapping) { return lvalue; } - var result:Number = Math.round(lvalue / snapInterval) * snapInterval; - return result; - } - - protected function scrollWheel(delta:Number):void { - if (_focused) { - value -= delta * _snapInterval; - dispatchEventAndSound( new Event(Event.CHANGE) ); - } - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/StatusIndicator.as b/src/scaleform/clik/controls/StatusIndicator.as deleted file mode 100644 index b39f492..0000000 --- a/src/scaleform/clik/controls/StatusIndicator.as +++ /dev/null @@ -1,137 +0,0 @@ -/** - * The StatusIndicator component displays the status of an event or action using its timeline as the visual indicator. The value of the StatusIndicator will be interpolated with the minimum and maximum values to generate a frame number that will be played in the component’s timeline. Since the component’s timeline is used to display the status, it provides absolute freedom in creating innovative visual indicators. - - Inspectable Properties - A MovieClip that derives from the StatusIndicator component will have the following inspectable properties: -
          -
        • enabled: Disables the component if set to false.
        • -
        • minimum: The minimum value used to interpolate the target frame.
        • -
        • maximum: The maximum value used to interpolate the target frame.
        • -
        • value: The status value of an event or action. It is interpolated between the minimum and maximum values to generate a frame number to be played.
        • -
        • visible: Hides the component if set to false.
        • -
        - - States - There are no states for the StatusIndicator component. The component’s frames are used to display the status of an event or action. - - Events - All event callbacks receive a single Object parameter that contains relevant information about the event. The following properties are common to all events.
          -
        • type: The event type.
        • -
        • target: The target that generated the event.
        - - No special events are generated by the StatusIndicator. The properties listed next to the event are provided in addition to the common properties.
          -
        • ComponentEvent.SHOW: The visible property has been set to true at runtime.
        • -
        • ComponentEvent.HIDE: The visible property has been set to false at runtime.
        • - */ - -/************************************************************************** - -Filename : StatusIndicator.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import scaleform.clik.core.UIComponent; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.ScrollBarDirection; - - public class StatusIndicator extends UIComponent { - - // Constants: - - // Public Properties: - - // Protected Properties: - protected var _maximum:Number = 10; - protected var _minimum:Number = 0; - protected var _value:Number = 0; - - // UI Elements: - - // Initialization: - public function StatusIndicator() { - super(); - } - - override protected function initialize():void { - super.initialize(); - } - - // Public getter / setters: - /** - * The maximum number the {@code value} can be set to. - */ - [Inspectable(defaultValue = "10")] - public function get maximum():Number { return _maximum; } - public function set maximum(value:Number):void { - _maximum = value; - } - - /** - * The minimum number the {@code value} can be set to. - */ - [Inspectable(defaultValue="0")] - public function get minimum():Number { return _minimum; } - public function set minimum(value:Number):void { - if (_minimum == value) { return; } - _minimum = value; - updatePosition(); - } - - /** - * The current value between the {@code maximum} and {@code minimum}. - * @see #maximum - * @see #minimum - */ - [Inspectable(defaultValue="0")] - public function get value():Number { return _value; } - public function set value(value:Number):void { - var range:Number = Math.max(_minimum, Math.min(_maximum, value)); - if (_value == range) { return; } - _value = range; - updatePosition(); - } - - /** - * The {@code value} of the {@code StatusIndicator}, to make it polymorphic with a {@link ScrollIndicator}. - */ - public function get position():Number { return _value; } - public function set position(value:Number):void { this.value = value; } - - // Public Methods: - /** @exclude */ - override public function toString():String { - return "[CLIK StatusIndicator " + name + "]"; - } - - // Private Methods: - override protected function configUI():void { - super.configUI(); - tabEnabled = focusable = false; - } - - override protected function draw():void { - if (isInvalid(InvalidationType.SIZE)) { - setActualSize(_width, _height); - } - - if (isInvalid(InvalidationType.DATA)) { - updatePosition(); - } - } - - // This is the default behaviour. which can be changed by overriding this method, or defining it in the timeline. - protected function updatePosition():void { - if (!enabled) { return; } - var percent:Number = (_value - _minimum) / (_maximum - _minimum); - gotoAndStop(Math.max(1, Math.round(percent * totalFrames))); - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/TextArea.as b/src/scaleform/clik/controls/TextArea.as deleted file mode 100644 index 0166879..0000000 --- a/src/scaleform/clik/controls/TextArea.as +++ /dev/null @@ -1,434 +0,0 @@ -/** - * TextArea is an editable text field component that supports multi-line text and an optional ScrollBar. It is derived from the CLIK TextInput component and thus includes all of the functionality and properties of TextInput. TextArea also shares the same states as its parent component. - - Inspectable Properties - The inspectable properties of the TextArea component are similar to TextInput with a couple of additions and the omission of the password property. The additions are related to the CLIK ScrollBar component: -
            -
          • text: Sets the text of the textField.
          • -
          • visible: Hides the component if set to false.
          • -
          • disabled: Disables the component if set to true.
          • -
          • editable: Makes the TextInput non-editable if set to false.
          • -
          • maxChars: A number greater than zero limits the number of characters that can be entered in the textField.
          • -
          • scrollBar: Instance name of the CLIK ScrollBar component to use, or a linkage ID to the ScrollBar symbol – an instance will be created by the TextArea in this case.
          • -
          • scrollPolicy: When set to “auto” the scrollBar will only show if there is enough text to scroll. The ScrollBar will always display if set to “on”, and never display if set to “off”. This property only affects the component if a ScrollBar is assigned to it (see the scrollBar property).
          • -
          • defaultText: Text to display when the textField is empty. This text is formatted by the defaultTextFormat object, which is by default set to light gray and italics.
          • -
          • actAsButton: If true, then the TextArea will behave similar to a Button when not focused and support rollOver and rollOut states. Once focused via mouse press or tab, the TextArea reverts to its normal mode until focus is lost.
          • -
          • enableInitCallback: If set to true, _global.CLIK_loadCallback() will be fired when a component is loaded and _global.CLIK_unloadCallback will be called when the component is unloaded. These methods receive the instance name, target path, and a reference the component as parameters. _global.CLIK_loadCallback and _global.CLIK_unloadCallback should be overriden from the game engine using GFx FunctionObjects.
          • -
          - - States - Like its parent, TextInput, the TextArea component supports three states based on its focused and disabled properties. -
            -
          • default or enabled state.
          • -
          • focused state, typically a represented by a highlighted border around the textField.
          • -
          • disabled state.
          • -
          -*/ - -/************************************************************************** - -Filename : TextArea.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.DisplayObject; - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.events.Event; - import flash.events.KeyboardEvent; - import flash.events.MouseEvent; - import flash.text.TextField; - import flash.system.ApplicationDomain; - - import scaleform.gfx.Extensions; // Allows for a basic ifScalefrom() check in draw(). - - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.controls.TextInput; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.interfaces.IScrollBar; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.utils.ConstrainedElement; - import scaleform.clik.utils.Constraints; - import scaleform.clik.utils.Padding; - - public class TextArea extends TextInput - { - - // Constants: - - // Public Properties: - - // Protected Properties: - protected var _scrollPolicy:String = "auto"; - // The current scroll position of the TextArea. - protected var _position:int = 1; - // Internal property used to to track the maximum scroll position for the TextArea. - protected var _maxScroll:Number = 1; - // Internal property to track whether the textField.scrollV should be updated. - protected var _resetScrollPosition:Boolean = false; - // A String that refers to a ScrollIndicator instance name or a Symbol's export name. - protected var _scrollBarValue:Object; - // true if the ScrollIndicator was auto-generated; false it was already on the stage. - protected var _autoScrollBar:Boolean = false; - // Offsets passed to auto-generated ScrollIndicator. - protected var _thumbOffset:Object = { top:0, bottom:0 } - // Minimum thumb size passed to auto-generated ScrollIndicator. - protected var _minThumbSize:uint = 1; - - // UI Elements: - /** A reference to the IScrollBar associated with this TextArea. */ - protected var _scrollBar:IScrollBar; - /** A container within the TextArea that any auto-generated content will be attached to. */ - public var container:Sprite; - - // Initialization: - public function TextArea() { - super(); - } - - override protected function preInitialize():void { - if (!constraintsDisabled) { - constraints = new Constraints(this, ConstrainMode.COUNTER_SCALE); - } - } - - override protected function initialize():void { - super.initialize(); - - // Take care of creating the container here so that it's available for set scrollBar which may be called by inspectables. - if (container == null) { - container = new Sprite(); - addChild(container); - } - } - - // Public Getter / Setters: - /** Enable/disable this component. Focus, keyboard, and mouse events will be suppressed if disabled. */ - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - super.enabled = value; - updateScrollBar(); - } - - /** The current scroll position of the TextArea. */ - public function get position():int { return _position; } - public function set position(value:int):void { - _position = value; - textField.scrollV = _position; - } - - /** A reference to the ScrollBar associated with this TextArea. */ - [Inspectable(type="String")] - public function get scrollBar():Object { return _scrollBar; } - public function set scrollBar(value:Object):void { - _scrollBarValue = value; - invalidate(InvalidationType.SCROLL_BAR); - } - - /** A minimum size for the ScrollIndicator's thumb in pixels. Passed through to the auto-generated ScrollIndicator. This property no effect if the component does not automatically generate a ScrollIndicator instance. */ - [Inspectable(defaultValue="1")] - public function get minThumbSize():uint { return _minThumbSize; } - public function set minThumbSize(value:uint):void { - _minThumbSize = value; - if (!_autoScrollBar) { return; } - var sb:ScrollIndicator = _scrollBar as ScrollIndicator; - sb.minThumbSize = value; - } - - /** ScrollIndicator thumb offsets for top and bottom. Passed through to to auto-generated ScrollIndicator. This property no effect if the component does not automatically generate a ScrollIndicator instance. */ - [Inspectable(name="thumbOffset", defaultValue="top:0,bottom:0")] - public function get thumbOffset():Object { return _thumbOffset; } - public function set thumbOffset(value:Object):void { - _thumbOffset = value; - if (!_autoScrollBar) { return; } - var sb:ScrollIndicator = _scrollBar as ScrollIndicator; - sb.offsetTop = _thumbOffset.top; - sb.offsetBottom = _thumbOffset.bottom; - } - - /** The available width of the component, taking into account any auto-generated ScrollIndicators. */ - public function get availableWidth():Number { - return Math.round(_width) - ((_autoScrollBar && (_scrollBar as MovieClip).visible) ? Math.round(_scrollBar.width) : 0); - } - - /** The available height of the component. */ - public function get availableHeight():Number { - return Math.round(_height); - } - - // Public Methods: - /** @exclude */ - override public function toString():String { - return "[CLIK TextArea " + name + "]"; - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - super.handleInput(event); - if (event.handled) { return; } - else if (_editable) { return; } - else { - var navEquivalent:String = event.details.navEquivalent; - switch(navEquivalent) { - case NavigationCode.UP: - if (position == 1) { return; } - position = Math.max(1, position - 1); - event.handled = true; - break; - - case NavigationCode.DOWN: - if (position == _maxScroll) { return; } - position = Math.min(_maxScroll, position + 1); - event.handled = true; - break; - - case NavigationCode.END: - position = _maxScroll; - event.handled = true; - break; - - case NavigationCode.HOME: - position = 1; - event.handled = true; - break; - - case NavigationCode.PAGE_UP: - var pageSize_up:Number = textField.bottomScrollV - textField.scrollV; - position = Math.max(1, position - pageSize_up); - event.handled = true; - break; - - case NavigationCode.PAGE_DOWN: - var pageSize_down:Number = textField.bottomScrollV - textField.scrollV; - position = Math.min(_maxScroll, position + pageSize_down); - event.handled = true; - break; - } - } - } - - // Private Methods: - /** - * Called to perform component configuration. configUI() is delayed one frame to allow sub-components to fully initialize, - * as some children may not have been initialized when this component’s constructor is called. Generally, any one-time - * configurations for this component or its children should occur here. - */ - override protected function configUI():void { - super.configUI(); - if (textField != null) { - textField.addEventListener(Event.SCROLL, onScroller, false, 0, true); - } - } - - /** - * Draw the component after it has been invalidated. Use this method to reflow component - * size and position, redraw data, etc. When appropriate, ensure that a call to - * {@code super.draw()} is made when extending a component and overriding this method. - */ - override protected function draw():void { - // If the ScrollBar is invalid, recreate it. - if (isInvalid(InvalidationType.SCROLL_BAR)) { - createScrollBar(); - } - - // If the State is invalid, change the state and update the textField. - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - updateAfterStateChange(); - updateTextField(); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.STATE_CHANGE)); - invalidate(InvalidationType.SIZE); - } - // If the State isn't invalid but the Data (text) has changed, just updated the textField. - else if (isInvalid(InvalidationType.DATA)) { - updateText(); - } - - // If the Size of the component has changed... - if (isInvalid(InvalidationType.SIZE)) { - removeChild(container); // Remove the container so it is not scaled by setActualSize. - setActualSize(_width, _height); // Update the size of the component. - - // Counterscale the container based on the component's new size. - container.scaleX = 1 / scaleX; - container.scaleY = 1 / scaleY; - - // Update the constraints on the TextField. - if (!constraintsDisabled) { - constraints.update(availableWidth, _height); - - // This is a hack for Flash Player. maxScrollV won't be updated until the next frame - // and even when it is, it won't call setScrollProperties() until the text has changed. - // To fix this, we request the textWidth, which forces an update of maxScrollV. In Scaleform, - // we update maxScrollV immediately when the TextField's size is changed. - if (!Extensions.enabled) { // If this is Flash Player. - var forceMaxScrollUpdate:uint = textField.textWidth; - // Might need to textField.appendText() here to force a setScrollProperties update - // in some cases, but this seems to work for now. - } - } - - addChild(container); // Replace the container. - if (_autoScrollBar) { drawScrollBar(); } // Update any auto-generated ScrollIndicator to reflect the new size. - } - } - - /** Create the ScrollIndicator using _scrollBarValue, which may be a Class or a Instance Name. */ - protected function createScrollBar():void { - // Destroy the old scroll bar. - if (_scrollBar != null) { - // Remove any outstanding eventListeners. - _scrollBar.removeEventListener(Event.SCROLL, handleScroll, false); - _scrollBar.removeEventListener(Event.CHANGE, handleScroll, false); - _scrollBar.focusTarget = null; - - // Remove the ScrollBar from the Display List - if (container.contains(_scrollBar as DisplayObject)) { - container.removeChild(_scrollBar as DisplayObject); - } - - _scrollBar = null; // Clean up any references. - } - - if (!_scrollBarValue || _scrollBarValue == "") { return; } // If _scrollBarValue is bad, no ScrollBar will be used. - _autoScrollBar = false; // Reset the _autoScrollBar property. - - var sb:IScrollBar; - if (_scrollBarValue is String) { - if (parent != null) { - sb = parent.getChildByName(_scrollBarValue.toString()) as IScrollBar; - } - if (sb == null) { - var domain : ApplicationDomain = ApplicationDomain.currentDomain; - if (loaderInfo != null && loaderInfo.applicationDomain != null) domain = loaderInfo.applicationDomain; - var classRef:Class = domain.getDefinition(_scrollBarValue.toString()) as Class; - - if (classRef) { - sb = new classRef() as IScrollBar; - } - if (sb) { - _autoScrollBar = true; - var sbInst:Object = sb as Object; - if (sbInst && _thumbOffset) { - sbInst.offsetTop = _thumbOffset.top; - sbInst.offsetBottom = _thumbOffset.bottom; - } - sb.addEventListener(MouseEvent.MOUSE_WHEEL, blockMouseWheel, false, 0, true); // Prevent duplicate scroll events - (sb as Object).minThumbSize = _minThumbSize; - //if (sb.scale9Grid == null) { sb.scale9Grid = new Rectangle(0,0,1,1); } // Prevent scaling - container.addChild(sb as DisplayObject); - } - } - } else if (_scrollBarValue is Class) { - sb = new (_scrollBarValue as Class)() as IScrollBar; - sb.addEventListener(MouseEvent.MOUSE_WHEEL, blockMouseWheel, false, 0, true); - if (sb != null) { - _autoScrollBar = true; - (sb as Object).offsetTop = _thumbOffset.top; - (sb as Object).offsetBottom = _thumbOffset.bottom; - (sb as Object).minThumbSize = _minThumbSize; - container.addChild(sb as DisplayObject); - } - } else { - sb = _scrollBarValue as IScrollBar; - } - - _scrollBar = sb; - invalidateSize(); // Redraw to reset scrollbar bounds, even if there is no scrollBar. - if (_scrollBar != null) { // Configure the ScrollBar - _scrollBar.addEventListener(Event.SCROLL, handleScroll, false, 0, true); - _scrollBar.addEventListener(Event.CHANGE, handleScroll, false, 0, true); - _scrollBar.focusTarget = this; - (_scrollBar as Object).scrollTarget = textField; - _scrollBar.tabEnabled = false; - } - } - - /** Updates the position and size auto-generated ScrollIndicator based on the size of the TextArea component. */ - protected function drawScrollBar():void { - if (!_autoScrollBar) { return; } - _scrollBar.x = _width - _scrollBar.width; - _scrollBar.height = availableHeight; - _scrollBar.validateNow(); // Should happen soon? - } - - /** Updates the scroll position and thumb size of the ScrollBar. */ - protected function updateScrollBar():void { - _maxScroll = textField.maxScrollV; - var sb:ScrollIndicator = _scrollBar as ScrollIndicator; - if (sb == null) { return; } - - var element:ConstrainedElement = constraints.getElement("textField"); - if (_scrollPolicy == "on" || (_scrollPolicy == "auto" && textField.maxScrollV > 1)) { - if (_autoScrollBar && !sb.visible) { // Add some space on the right for the scrollBar - if (element != null) { - constraints.update(_width, _height); - invalidate(); - } - _maxScroll = textField.maxScrollV; // Set this again, in case adding a scrollBar made the maxScroll larger. - } - sb.visible = true; - } - - // If no ScrollIndicator is needed, hide it. - if (_scrollPolicy == "off" || (_scrollPolicy == "auto" && textField.maxScrollV == 1)) { - if (_autoScrollBar && sb.visible) { // Remove any added space. - sb.visible = false; // Hide the ScrollBar before calling availableWidth to remove it from the calculation. - if (element != null) { - constraints.update(availableWidth, _height); - invalidate(); - } - } - } - - if (sb.enabled != enabled) { sb.enabled = enabled; } - } - - override protected function updateText():void { - super.updateText(); - updateScrollBar(); - } - - override protected function updateTextField():void { - _resetScrollPosition = true; - super.updateTextField(); - } - - protected function handleScroll(event:Event):void { - position = _scrollBar.position; - } - - protected function blockMouseWheel(event:MouseEvent):void { - event.stopPropagation(); - } - - override protected function handleTextChange(event:Event):void { - if (_maxScroll != textField.maxScrollV) { - updateScrollBar(); - } - super.handleTextChange(event); - } - - protected function onScroller(event:Event):void { - if (_resetScrollPosition) { textField.scrollV = _position; } - else { _position = textField.scrollV; } - _resetScrollPosition = false; - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/controls/TextInput.as b/src/scaleform/clik/controls/TextInput.as deleted file mode 100644 index 7783c1c..0000000 --- a/src/scaleform/clik/controls/TextInput.as +++ /dev/null @@ -1,488 +0,0 @@ -/** - * TextInput is an editable text field component used to capture textual user input. Similar to the Label, this component is merely a wrapper for a standard textField, and therefore supports the same capabilities of the textField such as password mode, maximum number of characters and HTML text. Only a handful of these properties are exposed by the component itself, while the rest can be modified by directly accessing the TextInput’s textField instance. - - The TextInput component should be used for input, since noneditable text can be displayed using the Label. Similar to the Label, developers may substitute standard textFields for TextInput components based on their requirements. However, when developing sophisticated UIs, especially for PC applications, the TextInput component provides valuable extended capabilities over the standard textField. - - For starters, TextInput supports the focused and disabled state, which are not easily achieved with the standard textField. Due to the separated focus state, TextInput can support custom focus indicators, which are not included with the standard textField. Complex AS2 code is required to change the visual style of a standard textField, while the TextInput visual style can be configured easily on the timeline. The TextInput inspectable properties provide an easy workflow for designers and programmers who are not familiar with Flash Studio. Developers can also easily listen for events fired by the TextInput to create custom behaviors. - - The TextInput also supports the standard selection and cut, copy, and paste functionality provided by the textField, including multi paragraph HTML formatted text. By default, the keyboard commands are select (Shift+Arrows), cut (Shift+Delete), copy (Ctrl+Insert), and paste (Shift+Insert). - - Inspectable Properties - The inspectable properties of the TextInput component are: -
            -
          • text: Sets the text of the textField.
          • -
          • enabled: Disables the component if set to false.
          • -
          • focusable: By default buttons receive focus for user interactions. Setting this property to false will disable focus acquisition.
          • -
          • editable: Makes the TextInput non-editable if set to false.
          • -
          • maxChars: A number greater than zero limits the number of characters that can be entered in the textField.
          • -
          • password: If true, sets the textField to display '*' characters instead of the real characters. The value of the textField will be the real characters entered by the user – returned by the text property.
          • -
          • defaultText: Text to display when the textField is empty. This text is formatted by the defaultTextFormat object, which is by default set to light gray and italics.
          • -
          • actAsButton: If true, then the TextInput will behave similar to a Button when not focused and support rollOver and rollOut states. Once focused via mouse press or tab, the TextInput reverts to its normal mode until focus is lost.
          • -
          • visible: Hides the component if set to false.
          • -
          - - States - The CLIK TextInput component supports three states based on its focused and disabled properties.
            -
          • default or enabled state.
          • -
          • focused state, typically a represented by a highlighted border around the textField.
          • -
          • disabled state.
          - */ - -/************************************************************************** - -Filename : TextInput.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.InteractiveObject; - import flash.events.Event; - import flash.events.FocusEvent; - import flash.events.KeyboardEvent; - import flash.events.MouseEvent; - import flash.text.TextField; - import flash.text.TextFormat; - import flash.text.TextFieldType; - - import scaleform.gfx.FocusManager; - import scaleform.gfx.MouseEventEx; - import scaleform.gfx.Extensions; - - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.InputValue; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.managers.FocusHandler; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.utils.Constraints; - import scaleform.clik.constants.ConstrainMode; - - [Event(name="stateChange", type="scaleform.clik.events.ComponentEvent")] - - public class TextInput extends UIComponent { - - // Constants: - - // Public Properties: - /** The text format used to display the default text. By default it is set to color:0xAAAAAA and italic:true. */ - public var defaultTextFormat:TextFormat; - /** True if constraints are disabled for the component. Setting the disableConstraintsproperty to {@code disableConstraints=true} will remove constraints from the textfield. This is useful for components with timeline based textfield size tweens, since constraints break them due to a Flash quirk. */ - public var constraintsDisabled:Boolean = false; - - // Protected Properties: - protected var _text:String = ""; - protected var _displayAsPassword:Boolean = false; - protected var _maxChars:uint = 0; - protected var _editable:Boolean = true; - protected var _actAsButton:Boolean = false; - protected var _alwaysShowSelection:Boolean = false; - protected var _isHtml:Boolean = false; - protected var _state:String = "default"; - protected var _newFrame:String; - protected var _textFormat:TextFormat; - protected var _usingDefaultTextFormat:Boolean = true; - protected var _defaultText:String = ""; - - // Private Properties: - private var hscroll:Number = 0; //LM: Not implemented. - - // UI Elements: - public var textField:TextField; - - // Initialization: - public function TextInput() { - super(); - } - - override protected function preInitialize():void { - if (!constraintsDisabled) { - constraints = new Constraints(this, ConstrainMode.COUNTER_SCALE); - } - } - - override protected function initialize():void { - super.tabEnabled = false; // Components with a TextField can not be tabEnabled, otherwise they will get tab focus separate from the TextField. - mouseEnabled = mouseChildren = enabled; - super.initialize(); - - _textFormat = textField.getTextFormat(); - - // Create a custom text format for the empty state (defaultTextFormat), which can be overridden by the user. - defaultTextFormat = new TextFormat(); - defaultTextFormat.italic = true; - defaultTextFormat.color = 0xAAAAAA; - } - - // Public Getter / Setters: - /** - * Enables or disables the component. Disabled components should not receive mouse, keyboard, or any - * other kind of focus or interaction. - */ - [Inspectable(defaultValue="true")] - override public function get enabled():Boolean { return super.enabled; } - override public function set enabled(value:Boolean):void { - super.enabled = value; - mouseChildren = value; - - super.tabEnabled = false; - tabChildren = _focusable; - setState(defaultState); - } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * {@code focusable=false} will remove support for tab key, direction key and mouse - * button based focus changes. - */ - [Inspectable(defaultValue="true")] - override public function get focusable():Boolean { return _focusable; } - override public function set focusable(value:Boolean):void { - _focusable = value; - - // If the component is no longer focusable but currently enabled, disable tabbing. - // If the component is no longer focusable but it is already disabled, do nothing. - if (!_focusable && enabled) { tabChildren = false; } - changeFocus(); - - if (_focusable && editable) { - addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown, false, 0, true); - } else { - removeEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown, false); - } - } - - /** - * The text to be displayed by the Label component. This property assumes that localization has been - * handled externally. - * @see #htmlText For formatted text, use the {@code htmlText} property. - */ - [Inspectable(type="String", defaultValue="")] - public function get text():String { return _text; } - public function set text(value:String):void { - _isHtml = false; - _text = value; - invalidateData(); - } - - /** - * The html text to be displayed by the label component. This property assumes that localization has - * been handled externally. - * @see #text For plain text use {@code text} property. - */ - public function get htmlText():String { return _text; } - public function set htmlText(value:String):void { - _isHtml = true; - _text = value; - invalidateData(); - } - - /** The default text to be shown when no text has been assigned or entered into this component. */ - [Inspectable(verbose=1, type="String", defaultValue="")] - public function get defaultText():String { return _defaultText; } - public function set defaultText(value:String):void { - _defaultText = value; - invalidateData(); - } - - /** - * The "displayAsPassword" mode of the text field. When {@code true}, the component will show asterisks - * instead of the typed letters. - */ - [Inspectable(defaultValue="false")] - public function get displayAsPassword():Boolean { return _displayAsPassword; } - public function set displayAsPassword(value:Boolean):void { - _displayAsPassword = value; - if (textField != null) { textField.displayAsPassword = value; } - } - - /** - * The maximum number of characters that the field can contain. - */ - [Inspectable(defaultValue="0")] - public function get maxChars():uint { return _maxChars; } - public function set maxChars(value:uint):void { - _maxChars = value; - if (textField != null) { textField.maxChars = value; } - } - - /** - * Determines if text can be entered into the TextArea, or if it is display-only. Text in a non-editable - * TextInput components can not be selected. - */ - [Inspectable(defaultValue="true")] - public function get editable():Boolean { return _editable; } - public function set editable(value:Boolean):void { - _editable = value; - if (textField != null) { - textField.type = (_editable && enabled) ? TextFieldType.INPUT : TextFieldType.DYNAMIC; - } - focusable = value; - } - - /** - * Override for .tabEnabled property to prevent users from changing the tabEnabled of the TextInput itself - * and instead passes the change on to the textField. TextInput.tabEnabled must always be false for focus reasons. - */ - override public function get tabEnabled():Boolean { return textField.tabEnabled; } - override public function set tabEnabled(value:Boolean):void { - textField.tabEnabled = value; - } - - /** - * Override for .tabIndex property to prevent users from changing the tabIndex of the TextInput itself - * and instead passes the change on to the textField. TextInput.tabIndex must always be -1 for focus reasons. - */ - override public function get tabIndex():int { return textField.tabIndex; } - override public function set tabIndex(value:int):void { - textField.tabIndex = value; - } - - /** - * If true, then the TextInput will behave similar to a Button when not focused and support rollOver and rollOut - * states. Once focused via mouse press or tab, the TextInput reverts to its normal mode until focus is lost. - */ - [Inspectable(defaultValue="false")] - public function get actAsButton():Boolean { return _actAsButton; } - public function set actAsButton(value:Boolean):void { - if (_actAsButton == value) { return; } - _actAsButton = value; - if (value) { - addEventListener(MouseEvent.ROLL_OVER, handleRollOver, false, 0, true); - addEventListener(MouseEvent.ROLL_OUT, handleRollOut, false, 0, true); - } else { - removeEventListener(MouseEvent.ROLL_OVER, handleRollOver, false); - removeEventListener(MouseEvent.ROLL_OUT, handleRollOut, false); - } - } - - /** - * When set to true and the text field is not in focus, the textField highlights the selection in the text - * field in gray - */ - public function get alwaysShowSelection():Boolean { return _alwaysShowSelection; } - public function set alwaysShowSelection(value:Boolean):void { - _alwaysShowSelection = value; - if (textField != null) { textField.alwaysShowSelection = value; } - } - - /** - * The length of the text in the textField. - */ - public function get length():uint { return textField.length; } - - public function get defaultState():String { - return (!enabled ? "disabled" : (focused ? "focused" : "default")); - } - - // Public Methods: - /** - * Append a new string to the existing text. The textField will be set to non-html rendering when this - * method is invoked. - */ - public function appendText(value:String):void { - _text += value; - _isHtml = false; - invalidateData(); - } - - /** - * Append a new html string to the existing text. The textField will be set to html rendering when this - * method is invoked. - */ - public function appendHtml(value:String):void { - _text += value; - _isHtml = true; - invalidateData(); - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - if (event.handled) { return; } // Already handled. - - var details:InputDetails = event.details; - if (details.value == InputValue.KEY_DOWN || details.value == InputValue.KEY_HOLD) { return; } // unhandled - return; //LM: Below needs testing. - - // LM: I think this is to ensure that the textField has focus to handle key events when only the component is focused. Might be unnecessary. - // if (stage.focus != null) { return; } - // event.handled = true; - // stage.focus = textField; //LM: No controller index - } - - /** @exclude */ - override public function toString():String { - return "[CLIK TextInput " + name + "]"; - } - - // Protected Methods: - override protected function configUI():void { - super.configUI(); - - if (!constraintsDisabled) { - constraints.addElement("textField", textField, Constraints.ALL); - } - - addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - textField.addEventListener(FocusEvent.FOCUS_IN, handleTextFieldFocusIn, false, 0, true); - - if (focusable && editable) { - addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown, false, 0, true); - } - - setState(defaultState, "default"); - } - - override protected function draw():void { - if (isInvalid(InvalidationType.STATE)) { - if (_newFrame) { - gotoAndPlay(_newFrame); - _newFrame = null; - } - updateAfterStateChange(); - updateTextField(); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.STATE_CHANGE)); - invalidate(InvalidationType.SIZE); - } - else if (isInvalid(InvalidationType.DATA)) { - updateText(); - } - - if (isInvalid(InvalidationType.SIZE)) { - setActualSize(_width, _height); - if (!constraintsDisabled) { - constraints.update(_width, _height); - } - } - } - - override protected function changeFocus():void { - setState(defaultState); - } - - protected function updateTextField():void { - if (textField == null) { trace(">>> Error :: " + this + ", textField is NULL."); return; } - - updateText(); - textField.maxChars = _maxChars; - textField.alwaysShowSelection = _alwaysShowSelection; - textField.selectable = enabled ? _editable : enabled; - textField.type = (_editable && enabled) ? TextFieldType.INPUT : TextFieldType.DYNAMIC; - textField.tabEnabled = _editable && enabled && _focusable; - // Note: In CLIK AS3, the focusTarget is not injected into the TextField. Instead, it uses a special case in FocusHandler to parent focus. - //textField.hscroll = hscroll; //LM: Is this still necessary? Evaluate. - - textField.addEventListener( Event.CHANGE, handleTextChange, false, 0, true ); - - // Extra logic for focus management within TextInput. - if (textField.hasEventListener(FocusEvent.FOCUS_IN)) { - textField.removeEventListener(FocusEvent.FOCUS_IN, handleTextFieldFocusIn, false); - } - textField.addEventListener(FocusEvent.FOCUS_IN, handleTextFieldFocusIn, false, 0, true); - } - - protected function handleTextFieldFocusIn(e:FocusEvent):void { - FocusHandler.getInstance().setFocus( this ); - } - - protected function updateText():void { - if (_focused && _usingDefaultTextFormat) { - textField.defaultTextFormat = _textFormat; - _usingDefaultTextFormat = false; - if ( _displayAsPassword && !textField.displayAsPassword ) { - textField.displayAsPassword = true; - } - } - if (_text != "") { - if (_isHtml) { - textField.htmlText = _text; - - } else { - textField.text = _text; - } - } else { - textField.text = ""; - if (!_focused && _defaultText != "") { - if ( _displayAsPassword ) { - textField.displayAsPassword = false; - } - textField.text = _defaultText; - _usingDefaultTextFormat = true; - if (defaultTextFormat != null) { - textField.setTextFormat(defaultTextFormat); - } - } - } - } - - protected function setState(...states:Array):void { - if (states.length == 1) { - var onlyState:String = states[0].toString(); - if (_state != onlyState && _labelHash[onlyState]) { - _state = _newFrame = onlyState; - invalidateState(); - } - return; - } - - var l:uint = states.length; - for (var i:uint=0; itileList.dataProvider = ["item1", "item2", "item3", "item4", ]; - - Inspectable Properties - A MovieClip that derives from the TileList component will have the following inspectable properties: -
            -
          • columnWidth: The width of list item instances created internally. This value has no effect if the rendererInstanceName property is set.
          • -
          • direction: The scrolling direction. The semantics of rows and columns do not change depending on this value.
          • -
          • enabled: Disables the component if set to false. This disables both the attached scrollbar and the list items (both internally created and external renderers).
          • -
          • externalColumnCount: When the rendererInstanceName property is set, this value is used to notify the TileList of the number of columns used by the external renderers.
          • -
          • focusable: By default, TileList can receive focus for user interactions. Setting this property to false will disable focus acquisition.
          • -
          • itemRenderer: The symbol name of the ListItemRenderer. Used to create list item instances internally. Has no effect if the rendererInstanceName property is set.
          • -
          • rendererInstanceName: Prefix of the external list item renderers to use with this TileList component. The list item instances on the stage must be prefixed with this property value. If this property is set to the value ‘r’, then all list item instances to be used with this component must have the following values: ‘r1’, ‘r2’, ‘r3’,… The first item should have the number 1.
          • -
          • margin: The margin between the boundary of the list component and the list items created internally. This value has no effect if the rendererInstanceName property is set. This margin also affects the automatically generated scrollbar.
          • -
          • rowHeight: The height of list item instances created internally. This value has no effect if the rendererInstanceName property is set.
          • -
          • padding: Extra padding at the top, bottom, left, and right for the list items. This value has no effect if the rendererInstanceName property is set. Does not affect the automatically generated scrollbar.
          • -
          • thumbOffset: ScrollIndicator thumb offset for top and bottom. Passed through to ScrollIndicator. This property has no effect if the list does not automatically create a scrollbar instance.
          • -
          • thumbSizeFactor: Page size factor for the scrollbar thumb. A value greater than 1.0 will increase the thumb size by the given factor. This positive value has no effect if a scrollbar is not attached to the list.
          • -
          • scrollBar: Instance name of a ScrollBar component on the stage or a symbol name. If an instance name is specified, then the TileList will hook into that instance. If a symbol name is specified, an instance of the symbol will be created by the TileList.
          • -
          • visible: Hides the component if set to false. This does not hide the attached scrollbar or any external list item renderers.
          • -
          - - States - The TileList component supports three states based on its focused and disabled properties. -
            -
          • default or enabled state.
          • -
          • focused state, that typically highlights the component’s border area.
          • -
          • disabled state.
          • -
          - - Events - All event callbacks receive a single Object parameter that contains relevant information about the event. The following properties are common to all events.
            -
          • type: The event type.
          • -
          • target: The target that generated the event.
          - -
            -
          • ComponentEvent.SHOW: The visible property has been set to true at runtime.
          • -
          • ComponentEvent.HIDE: The visible property has been set to false at runtime.
          • -
          • FocusHandlerEvent.FOCUS_IN: The button has received focus.
          • -
          • FocusHandlerEvent.FOCUS_OUT: The button has lost focus.
          • -
          • ComponentEvent.STATE_CHANGE: The button's state has changed.
          • -
          • ListEvent.ITEM_PRESS: A list item has been pressed down.
          • -
          • ListEvent.ITEM_CLICK: A list item has been clicked.
          • -
          • ListEvent.ITEM_ROLL_OVER: The mouse cursor has rolled over a list item.
          • -
          • ListEvent.ITEM_ROLL_OUT: The mouse cursor has rolled out of a list item.
          • -
          • ListEvent.ITEM_DOUBLE_CLICK: The mouse cursor has been double clicked on a list item.
          • -
          • ListEvent.INDEX_CHANGE: The selected index has changed.
          • -
          - */ - -/************************************************************************** - -Filename : TileList.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.DisplayObject; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.geom.Rectangle; - import flash.system.ApplicationDomain; - - import scaleform.clik.constants.DirectionMode; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.constants.WrappingMode; - import scaleform.clik.controls.ScrollBar; - import scaleform.clik.data.ListData; - import scaleform.clik.events.InputEvent; - import scaleform.clik.interfaces.IScrollBar; - import scaleform.clik.interfaces.IListItemRenderer; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.utils.Padding; - - [Event(name="change", type="flash.events.Event")] - [Event(name="itemClick", type="scaleform.clik.events.ListEvent")] - [Event(name="itemPress", type="scaleform.clik.events.ListEvent")] - [Event(name="itemRollOver", type="scaleform.clik.events.ListEvent")] - [Event(name="itemRollOut", type="scaleform.clik.events.ListEvent")] - [Event(name="itemDoubleClick", type="scaleform.clik.events.ListEvent")] - - public class TileList extends CoreList { - - // @TODO: ScrollBar's max and min seemed to be mapped to rowHeight rather than itemsPerSet. - - // Constants: - - // Public Properties: - /** - * Determines how focus "wraps" when the end or beginning of the component is reached. -
            -
          • WrappingMode.NORMAL: The focus will leave the component when it reaches the end of the data
          • -
          • WrappingMode.WRAP: The selection will wrap to the beginning or end.
          • -
          • WrappingMode.STICK: The selection will stop when it reaches the end of the data.
          • -
          - */ - [Inspectable(defaultValue="normal", enumeration="normal,wrap,stick")] - public var wrapping:String = WrappingMode.NORMAL; - - /** ScrollIndicator thumb offset for top and bottom. Passed through to ScrollIndicator. This property has no effect if the list does not automatically create a scrollbar instance. */ - public var thumbOffset:Object; - /** Page size factor for the scrollbar thumb. A value greater than 1.0 will increase the thumb size by the given factor. This positive value has no effect if a scrollbar is not attached to the list. */ - public var thumbSizeFactor:Number = 1; // @TODO: Currently unimplemented. - - /** The number of columns to use when setting external item renderers */ - [Inspectable(defaultValue="0")] - public var externalColumnCount:Number = 0; - - // Protected Properties: - // The height of the rows, if it was defined by the user. - protected var _rowHeight:Number = NaN; - // The height of the rows, calculated automatically if a user defined rowHeight was not provided. - protected var _autoRowHeight:Number = NaN; - // The total number of rows available (calculated based on the height). - protected var _totalRows:Number = 0; - // The width of the columns, if it was defined by the user. - protected var _columnWidth:Number = NaN; - // The width of the columns, calculated automatically if a user defined columnWidth was not provided. - protected var _autoColumnWidth:Number = NaN; - // The total number of rows available (calculated based on the width). - protected var _totalColumns:uint = 0; - // The current scroll position for the TileList. - protected var _scrollPosition:uint = 0; - // true if this component generated its own ScrollBar; false otherwise. - protected var _autoScrollBar:Boolean = false; - // Some reference to the ScrollBar (class name, instance name, direct ref, etc...). - protected var _scrollBarValue:Object; - // The margin between the boundary of the list component and the list items created internally. - protected var _margin:Number = 0; - // Extra padding at the top, bottom, left, and right for the list items. - protected var _padding:Padding; - // The direction of the TileList. - protected var _direction:String = DirectionMode.HORIZONTAL; - // The width of the ScrollBar before it was rotated. - protected var _siWidth:Number = 0; - - // UI Elements: - protected var _scrollBar:IScrollBar; - - // Initialization: - public function TileList() { - super(); - } - - override protected function initialize():void { - super.initialize(); - } - - /** - * The component to use to scroll the list. The {@code scrollBar} can be set as a library linkage ID, - * an instance name on the stage relative to the component, or a reference to an existing ScrollBar - * elsewhere in the application. The automatic behaviour in this component only supports a vertical - * scrollBar, positioned on the top right, the entire height of the component. - * @see ScrollBar - * @see ScrollIndicator - */ - [Inspectable(type="String")] - public function get scrollBar():Object { return _scrollBar; } - public function set scrollBar(value:Object):void { - _scrollBarValue = value; - invalidate(InvalidationType.SCROLL_BAR); - } - - /** - * The height of each item in the list. When set to {@code null} or 0, the default height of the - * renderer symbol is used. - */ - [Inspectable(defaultValue="0")] - public function get rowHeight():Number { return isNaN(_autoRowHeight) ? _rowHeight : _autoRowHeight; } - public function set rowHeight(value:Number):void { - if (value == 0) { - value = NaN; - if (_inspector){ return; } - } - _rowHeight = value; - _autoRowHeight = NaN; - invalidateSize(); - } - - /** - * Set the width of each column. By default, the width is 0, and determined by an itemRenderer instance. - */ - [Inspectable(defaultValue="0")] - public function get columnWidth():Number { return isNaN(_autoColumnWidth) ? _columnWidth : _autoColumnWidth; } - public function set columnWidth(value:Number):void { - if (value == 0) { - value = NaN; - if (_inspector){ return; } - } - _columnWidth = value; - _autoColumnWidth = NaN; - invalidateSize(); - } - - /** - * The amount of visible rows. Setting this property will immediately change the height of the component - * to accomodate the specified amount of rows. The {@code rowCount} property is not stored or maintained. - */ - public function get rowCount():uint { return _totalRows; } - public function set rowCount(value:uint):void { - var h:Number = rowHeight; - if (isNaN(h)) { - calculateRendererTotal(availableWidth, availableHeight); - h = rowHeight; - } - height = (h * value) + (margin * 2) + padding.vertical + ((_direction == DirectionMode.HORIZONTAL && _autoScrollBar) ? Math.round(_siWidth) : 0); - } - - - /** - * Set the width of the component to accommodate the number of columns specified. - */ - public function get columnCount():uint { return _totalColumns; } - public function set columnCount(value:uint):void { - var w:Number = columnWidth; - if (isNaN(w)) { - calculateRendererTotal(availableWidth, availableHeight); - w = columnWidth - } - - width = (w * value) + (margin * 2) + padding.horizontal + ((_direction == DirectionMode.VERTICAL && _autoScrollBar) ? Math.round(_siWidth) : 0); - } - - /** - * Set the scrolling direction of the TileList. The {@code direction} can be set to "horizontal" or "vertical". TileLists can only scroll in one direction at a time. - */ - [Inspectable(type="List", enumeration="horizontal,vertical", defaultValue="horizontal")] - public function get direction():String { return _direction; } - public function set direction(value:String):void { - if (value == _direction) { return; } - _direction = value; - invalidate(); // Invalidate everything. Renderers, data, and Scro - } - - /** - * The selected index of the {@code dataProvider}. The {@code itemRenderer} at the {@code selectedIndex} - * will be set to {@code selected=true}. - */ - override public function set selectedIndex(value:int):void { - if (value == _selectedIndex || value == _newSelectedIndex) { return; } - _newSelectedIndex = value; - invalidateSelectedIndex(); - } - - /** - * The margin between the boundary of the list component and the list items created internally. Does not affects any automatically generated ScrollBars. - * This value has no effect if the rendererInstanceName property is set. - */ - [Inspectable(defaultValue="0")] - public function get margin():Number { return _margin; } - public function set margin(value:Number):void { - _margin = value; - invalidateSize(); - } - - /** - * Extra padding at the top, bottom, left, and right for the list items. Also affects any automatically generated ScrollBars. - * This value has no effect if the rendererInstanceName property is set. - */ - public function get padding():Padding { return _padding; } - public function set padding(value:Padding):void { - _padding = value; - invalidateSize(); - } - - /** @exclude */ - [Inspectable(name="padding", defaultValue="top:0,right:0,bottom:0,left:0")] - public function set inspectablePadding(value:Object):void { - if (!componentInspectorSetting) { return; } - padding = new Padding(value.top, value.right, value.bottom, value.left); - } - - /** Retireve the available width of the component. */ - override public function get availableWidth():Number { - return Math.round(_width) - (padding.horizontal) - (margin * 2) - ((_direction == DirectionMode.VERTICAL && _autoScrollBar) ? Math.round(_siWidth) : 0); - } - - /** Retrieve the available height of the component. */ - override public function get availableHeight():Number { - return Math.round(_height) - (padding.vertical) - (margin * 2) - ((_direction == DirectionMode.HORIZONTAL && _autoScrollBar) ? Math.round(_siWidth) : 0); - } - - /** The scroll position of the list. */ - public function get scrollPosition():Number { return _scrollPosition; } - public function set scrollPosition(value:Number):void { - var maxScrollPosition:Number = Math.ceil((_dataProvider.length - _totalRows * _totalColumns) / (_direction == DirectionMode.HORIZONTAL ? _totalRows : _totalColumns)); // @TODO: Seems like this can be cached on invalidate. - value = Math.max(0, Math.min(maxScrollPosition, Math.round(value))); - if (_scrollPosition == value) { return; } - _scrollPosition = value; - invalidateData(); - } - - /** - * Retrieve a reference to an IListItemRenderer of the List. - * @param index The index of the renderer. - * @param offset An offset from the original scrollPosition (normally, the scrollPosition itself). - */ - override public function getRendererAt(index:uint, offset:int=0):IListItemRenderer { - if (_renderers == null) { return null; } - var rendererIndex:uint = index - offset * (_direction == DirectionMode.HORIZONTAL ? _totalRows : _totalColumns); - if (rendererIndex >= _renderers.length) { return null; } - return _renderers[rendererIndex] as IListItemRenderer; - } - - /** - * Scroll the list to the specified index. If the index is currently visible, the position will not change. The scroll position will only change the minimum amount it has to to display the item at the specified index. - * @param index The index to scroll to. - */ - override public function scrollToIndex(index:uint):void { - if (_totalRenderers == 0) { return; } - var factor:Number = (_direction == DirectionMode.HORIZONTAL ? _totalRows : _totalColumns); - var startIndex:Number = _scrollPosition * factor; - if (factor == 0) { return; } - if (index >= startIndex && index < startIndex + (_totalRows * _totalColumns)) { - return; - } else if (index < startIndex) { - scrollPosition = (index / factor >> 0); - } else { - scrollPosition = Math.floor(index / factor) - (_direction == DirectionMode.HORIZONTAL ? _totalColumns: _totalRows) + 1; - } - } - - /** @exclude */ - override public function handleInput(event:InputEvent):void { - if (event.handled) { return; } - - // Pass on to selected renderer first - var renderer:IListItemRenderer = getRendererAt(_selectedIndex, _scrollPosition); - if (renderer != null) { - renderer.handleInput(event); // Since we are just passing on the event, it won't bubble, and should properly stopPropagation. - if (event.handled) { return; } - } - - // Only allow actions on key down, but still set handled=true when it would otherwise be handled. - var details:InputDetails = event.details; - var keyPress:Boolean = (details.value == InputValue.KEY_DOWN || details.value == InputValue.KEY_HOLD); - var nextIndex:int = -1; - var nav:String = details.navEquivalent; - - // Directional navigation commands differ depending on layout direction. - if (_direction == DirectionMode.HORIZONTAL) { - switch (nav) { - case NavigationCode.RIGHT: - nextIndex = _selectedIndex + _totalRows; - break; - case NavigationCode.LEFT: - nextIndex = _selectedIndex - _totalRows; - break; - case NavigationCode.UP: - nextIndex = _selectedIndex - 1; - break; - case NavigationCode.DOWN: - nextIndex = _selectedIndex + 1; - break; - } - } - else { - switch (nav) { - case NavigationCode.DOWN: - nextIndex = _selectedIndex + _totalColumns; - break; - case NavigationCode.UP: - nextIndex = _selectedIndex - _totalColumns; - break; - case NavigationCode.LEFT: - nextIndex = _selectedIndex - 1; - break; - case NavigationCode.RIGHT: - nextIndex = _selectedIndex + 1; - break; - } - } - - if (nextIndex == -1) { - // These navigation commands don't change depending on direction. - switch (nav) { - case NavigationCode.HOME: - nextIndex = 0; - break; - case NavigationCode.END: - nextIndex = _dataProvider.length - 1; - break; - case NavigationCode.PAGE_DOWN: - nextIndex = Math.min(_dataProvider.length - 1, _selectedIndex + _totalColumns * _totalRows); - break; - case NavigationCode.PAGE_UP: - nextIndex = Math.max(0, _selectedIndex - _totalColumns * _totalRows); - break; - } - } - - // PPS: This is not an else clause. The previous block computes a new index if possible. - if (nextIndex != -1) { - if (!keyPress) { - event.handled = true; - return; // If the event is a Key.UP, bail now to avoid changing the selectedIndex. - } - if (nextIndex >= 0 && nextIndex < dataProvider.length) { // Out-of-range items do NOT get rounded. We just don't do anything. - selectedIndex = Math.max(0, Math.min(_dataProvider.length-1, nextIndex)); - event.handled = true; - } - else if (wrapping == WrappingMode.STICK) { - // Stick to top or bottom. - nextIndex = Math.max(0, Math.min(_dataProvider.length-1, nextIndex)); - if (selectedIndex != nextIndex) { - selectedIndex = nextIndex; - } - event.handled = true; - } - else if (wrapping == WrappingMode.WRAP) { - selectedIndex = (nextIndex < 0) ? _dataProvider.length-1 : (selectedIndex < _dataProvider.length-1) ? _dataProvider.length-1 : 0; - event.handled = true; - } - } - } - - /** @exclude */ - override public function toString():String { - return "[CLIK TileList "+ name +"]"; - } - - // Protected Functions: - override protected function configUI():void { - super.configUI(); - if (padding == null) { padding = new Padding(); } - if (_itemRenderer == null && !_usingExternalRenderers) { itemRendererName = _itemRendererName } - } - - override protected function draw():void { - if (isInvalid(InvalidationType.SCROLL_BAR)) { - createScrollBar(); - } - - if (isInvalid(InvalidationType.RENDERERS)) { - _autoRowHeight = NaN; - _autoColumnWidth = NaN; - - if (_usingExternalRenderers) { - _totalColumns = (externalColumnCount == 0) ? 1 : externalColumnCount; // Defaults to 1 if its not set. - _totalRows = Math.ceil(_renderers.length / _totalColumns); - } - } - - super.draw(); - - if (isInvalid(InvalidationType.DATA)) { - updateScrollBar(); - } - } - - protected function createScrollBar():void { - if (_scrollBar) { - _scrollBar.removeEventListener(Event.SCROLL, handleScroll); - _scrollBar.removeEventListener(Event.CHANGE, handleScroll); - _scrollBar.focusTarget = null; - if (container.contains(_scrollBar as DisplayObject)) { container.removeChild(_scrollBar as DisplayObject); } - _scrollBar = null; - } - - if (!_scrollBarValue || _scrollBarValue == "") { return; } - - _autoScrollBar = false; // Reset - - var sb:IScrollBar; - if (_scrollBarValue is String) { - if (parent != null) { - sb = parent.getChildByName(_scrollBarValue.toString()) as IScrollBar; - } - if (sb == null) { - var domain : ApplicationDomain = ApplicationDomain.currentDomain; - if (loaderInfo != null && loaderInfo.applicationDomain != null) domain = loaderInfo.applicationDomain; - var classRef:Class = domain.getDefinition(_scrollBarValue.toString()) as Class; - - if (classRef) { - sb = new classRef() as IScrollBar; - } - if (sb) { - _autoScrollBar = true; - var sbInst:Object = sb as Object; - if (sbInst && thumbOffset) { - sbInst.offsetTop = thumbOffset.top; - sbInst.offsetBottom = thumbOffset.bottom; - } - sb.addEventListener(MouseEvent.MOUSE_WHEEL, blockMouseWheel, false, 0, true); // Prevent duplicate scroll events - //if (sb.scale9Grid == null) { sb.scale9Grid = new Rectangle(0,0,1,1); } // Prevent scaling - container.addChild(sb as DisplayObject); - } - } - } else if (_scrollBarValue is Class) { - sb = new (_scrollBarValue as Class)() as IScrollBar; - sb.addEventListener(MouseEvent.MOUSE_WHEEL, blockMouseWheel, false, 0, true); - if (sb != null) { - _autoScrollBar = true; - (sb as Object).offsetTop = thumbOffset.top; - (sb as Object).offsetBottom = thumbOffset.bottom; - container.addChild(sb as DisplayObject); - } - } else { - sb = _scrollBarValue as IScrollBar; - } - _scrollBar = sb; - _siWidth = _scrollBar.width; // Store the width of the ScrollIndicator in case it is rotated later. - - invalidateSize(); // Redraw to reset scrollbar bounds, even if there is no scrollBar. - - if (_scrollBar == null) { return; } - // Now that we have a scrollBar, lets set it up. - _scrollBar.addEventListener(Event.SCROLL, handleScroll, false, 0, true); - _scrollBar.addEventListener(Event.CHANGE, handleScroll, false, 0, true); - _scrollBar.focusTarget = this; - _scrollBar.tabEnabled = false; - } - - override protected function calculateRendererTotal(width:Number, height:Number):uint { - var invalidRowHeight:Boolean = isNaN(_rowHeight) && isNaN(_autoRowHeight); - var invalidColumnWidth:Boolean = isNaN(_columnWidth) && isNaN(_autoColumnWidth); - - if (invalidRowHeight || invalidColumnWidth) { - var renderer:IListItemRenderer = createRenderer(0); - if (invalidRowHeight) { _autoRowHeight = renderer.height; } - if (invalidColumnWidth) { _autoColumnWidth = renderer.width; } - cleanUpRenderer(renderer); - } - - _totalRows = availableHeight / rowHeight >> 0; - _totalColumns = availableWidth / columnWidth >> 0; - _totalRenderers = _totalRows * _totalColumns; - - return _totalRenderers; - } - - override protected function updateSelectedIndex():void { - if (_selectedIndex == _newSelectedIndex) { return; } - if (_totalRenderers == 0) { return; } // Return if there are no renderers - - var renderer:IListItemRenderer = getRendererAt(_selectedIndex, scrollPosition); - if (renderer != null) { - renderer.selected = false; // Only reset items in range - renderer.validateNow(); - } - - super.selectedIndex = _newSelectedIndex; // Reset the new selected index value if we found a renderer instance - if (_selectedIndex < 0 || _selectedIndex >= _dataProvider.length) { return; } - - renderer = getRendererAt(_selectedIndex, _scrollPosition); - if (renderer != null) { - renderer.selected = true; // Item is in range. Just set it. - renderer.validateNow(); - } else { - scrollToIndex(_selectedIndex); // Will redraw - renderer = getRendererAt(_selectedIndex, scrollPosition); - if (renderer) { - renderer.selected = true; // Item is in range. Just set it. - renderer.validateNow(); - } - } - } - - // Protected Functions: - override protected function refreshData():void { - // Keep the items in range (in case the component grows larger than the number of renderers) - var itemsPerSet:Number = (_direction == DirectionMode.HORIZONTAL ? _totalRows : _totalColumns); // Number of items in each set (column or row) - var numberOfSets:Number = Math.ceil(_dataProvider.length / itemsPerSet); // Number of sets - var maxScrollPosition:Number = numberOfSets - (_direction == DirectionMode.HORIZONTAL ? _totalColumns : _totalRows); - _scrollPosition = Math.max(0, Math.min(maxScrollPosition, _scrollPosition)); - - var startIndex:Number = _scrollPosition * itemsPerSet; - var endIndex:Number = startIndex + (_totalColumns * _totalRows) -1; - - selectedIndex = Math.min(_dataProvider.length - 1, _selectedIndex); - updateSelectedIndex(); - - _dataProvider.requestItemRange(startIndex, endIndex, populateData); - } - - override protected function drawLayout():void { - var l:uint = _renderers.length; - var h:Number = rowHeight; - var w:Number = columnWidth; - var rx:Number = margin + padding.left; - var ry:Number = margin + padding.top; - var dataWillChange:Boolean = isInvalid(InvalidationType.DATA); - - for (var i:uint = 0; i < l; i++) { - var renderer:IListItemRenderer = getRendererAt(i); - - if (direction == DirectionMode.VERTICAL) { - renderer.y = (i % _totalRows) * h + ry; - renderer.x = (i / _totalRows >> 0) * w + rx; - } else { - renderer.x = (i % _totalColumns) * w + rx; - renderer.y = (i / _totalColumns >> 0) * h + ry; - } - - renderer.width = w; - renderer.height = h; - - if (!dataWillChange) { renderer.validateNow(); } - } - - drawScrollBar(); - } - - override protected function changeFocus():void { - super.changeFocus(); - var renderer:IListItemRenderer = getRendererAt(_selectedIndex, _scrollPosition); - if (renderer != null) { - renderer.displayFocus = (focused > 0); - renderer.validateNow(); - } - } - - protected function populateData(data:Array):void { - var dl:uint = data.length; - var l:uint = _renderers.length; - for (var i:uint = 0; i < l; i++) { - - var renderer:IListItemRenderer = getRendererAt(i); - var index:uint = _scrollPosition * ((_direction == DirectionMode.HORIZONTAL) ? _totalRows : _totalColumns) + i; - var listData:ListData = new ListData(index, itemToLabel(data[i]), _selectedIndex == index); - renderer.enabled = (i >= dl) ? false : true; - renderer.setListData(listData); - renderer.setData(data[i]); - renderer.validateNow(); - } - } - - protected function drawScrollBar():void { - if (!_autoScrollBar) { return; } - - var sb:ScrollIndicator = _scrollBar as ScrollIndicator; - sb.direction = _direction; - if (_direction == DirectionMode.VERTICAL) { - sb.rotation = 0; - sb.x = _width - sb.width + margin; - sb.y = margin; - sb.height = availableHeight + padding.vertical; - } else { - sb.rotation = -90; - sb.x = margin; - sb.y = _height - margin; // @TODO: No need for _scrollBar.height here? - sb.width = availableWidth + padding.horizontal; // When the ScrollBar is rotated, we can set its width instead. - } - - _scrollBar.validateNow(); - } - - protected function updateScrollBar():void { - if (_scrollBar == null) { return; } - - var max:Number; - if (direction == DirectionMode.HORIZONTAL) { - max = Math.ceil(_dataProvider.length / _totalRows) - _totalColumns; - } else { - max = Math.ceil(_dataProvider.length / _totalColumns) - _totalRows; - } - - if (_scrollBar is ScrollIndicator) { - var scrollIndicator:ScrollIndicator = _scrollBar as ScrollIndicator; - scrollIndicator.setScrollProperties( (_direction == DirectionMode.HORIZONTAL ? _totalColumns : _totalRows), 0, max); - } - - _scrollBar.position = _scrollPosition; - _scrollBar.validateNow(); - } - - protected function handleScroll(event:Event):void { - scrollPosition = _scrollBar.position; - } - - override protected function scrollList(delta:int):void { - scrollPosition -= delta; - } - - protected function blockMouseWheel(event:MouseEvent):void { - event.stopPropagation(); - } - } -} diff --git a/src/scaleform/clik/controls/UILoader.as b/src/scaleform/clik/controls/UILoader.as deleted file mode 100644 index 07e51a1..0000000 --- a/src/scaleform/clik/controls/UILoader.as +++ /dev/null @@ -1,283 +0,0 @@ -/** - * The CLIK UILoader loads an external SWF/GFX or image using only the path. UILoaders also support auto-sizing of the loaded asset to fit in its bounding box. Asset loading is asynchronous if both GFx and the platform running it has threading support. - * - *

          Inspectable Properties

          - *

          - * A MovieClip that derives from the UILoader component will have the following inspectable properties: - *

            - *
          • autoSize: If set to true, sizes the loaded to content to fit in the UILoader’s bounds.
          • - *
          • enableInitCallback: If set to true, Extensions.CLIK_addedToStageCallback() will be fired when a component is loaded. This method receives the instance name, target path, and a reference the component as parameters. Extensions.CLIK_addedToStageCallback() should be overriden from the game engine using GFx FunctionObjects.
          • - *
          • maintainAspectRatio: If true, the loaded content will be fit based on its aspect ratio inside the UILoader’s bounds. If false, then the content will be stretched to fit the UILoader bounds.
          • - *
          • source: The SWF/GFX or image filename to load.
          • - *
          • visible: Hides the component if set to false.
          • - *
          - *

          - * - *

          States

          - *

          - * There are no states for the UILoader component. If a SWF/GFX is loaded into the UILoader, then it may have its own states. - *

          - * - *

          Events

          - *

          - * All event callbacks receive a single Object parameter that contains relevant information about the event. The following properties are common to all events. - *

            - *
          • type: The event type.
          • - *
          • target: The target that generated the event.
          • - *
          - * - * The events generated by the UILoader component are listed below. The properties listed next to the event are provided in addition to the common properties. - *
            - *
          • ComponentEvent.SHOW: The component’s visible property has been set to true at runtime.
          • - *
          • ComponentEvent.HIDE: The component’s visible property has been set to false at runtime.
          • - *
          • ProgressEvent.PROGRESS: Content is in the process of being loaded regardless whether the content can or cannot be loaded. This event will be fired continuously until the content is loaded.
          • - *
          • Event.OPEN: Content loading has started.
          • - *
          • Event.INIT: The content being loaded is now accessible via the .content property.
          • - *
          • Event.COMPLETE: Content loading has been completed.
          • - *
          • IOErrorEvent.IO_ERROR: Content specified in the source property could not be loaded.
          • - *
          - *

          - */ - -/************************************************************************** - -Filename : UILoader.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls -{ - import flash.display.DisplayObject; - import flash.display.Loader; - import flash.display.LoaderInfo; - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.events.Event; - import flash.events.ProgressEvent; - import flash.events.IOErrorEvent; - import flash.net.URLRequest; - - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.ComponentEvent; - - [InspectableList("visible", "autoSize", "source", "maintainAspectRatio", "enableInitCallback")] - public class UILoader extends UIComponent - { - // Constants: - - // Public Properties: - public var bytesLoaded:int = 0; - public var bytesTotal:int = 0; - - // Protected Properties: - /** @private */ - protected var _source:String; - /** @private */ - protected var _autoSize:Boolean = true; - /** @private */ - protected var _maintainAspectRatio:Boolean = true; - /** @private */ - protected var _loadOK:Boolean = false; - /** @private */ - protected var _sizeRetries:Number = 0; - /** @private */ - protected var _visiblilityBeforeLoad:Boolean = true; - /** @private */ - protected var _isLoading:Boolean = false; - - // UI Elements: - /** @private */ - public var bg:Sprite; - public var loader:Loader; - - // Initialization: - public function UILoader() { - super(); - } - - // Public Getter / Setters: - /** Automatically scale the content to fit the container. */ - [Inspectable(defaultValue="true")] - public function get autoSize():Boolean { return _autoSize; } - public function set autoSize(value:Boolean):void { - _autoSize = value; - invalidateSize(); - } - - /** Set the source of the content to be loaded. */ - [Inspectable(defaultValue="")] - public function get source():String { return _source; } - public function set source(value:String):void { - if (_source == value) { return; } - if ((value == "" || value == null) && (loader != null && loader.content == null)) { - unload(); - } - else { - load(value); - } - } - - /** - * Maintain the original content's aspect ration when scaling it. If autoSize is false, this property is ignored. - */ - [Inspectable(defaultValue="true")] - public function get maintainAspectRatio():Boolean { return _maintainAspectRatio; } - public function set maintainAspectRatio(value:Boolean):void { - _maintainAspectRatio = value; - invalidateSize(); - } - - /** - * A read-only property that returns the loaded content of the UILoader. - */ - public function get content():DisplayObject { - return loader.content; - } - - /** - * A read-only property that returns the percentage that the content is loaded. The percentage is normalized to a 0-100 range. - */ - public function get percentLoaded():Number { - if (bytesTotal == 0 || _source == null) { return 0; } - return bytesLoaded / bytesTotal * 100; - } - - /** - * Show or hide the component. Allows the visible property to be overridden, and - * dispatch a "show" or "hide" event. - */ - [Inspectable(defaultValue="true")] - override public function get visible():Boolean { return super.visible; } - override public function set visible(value:Boolean):void { - if (_isLoading) { - _visiblilityBeforeLoad = value; - } - else { - super.visible = value; - } - } - - // Public Methods: - /** Unload the currently loaded content, or stop any pending or active load. */ - public function unload():void { - if (loader != null) { - visible = _visiblilityBeforeLoad; - loader.unloadAndStop(true); - } - _source = null; - _loadOK = false; - _sizeRetries = 0; - } - - /** @private */ - override public function toString():String { - return "[CLIK UILoader " + name + "]"; - } - - // Protected Methods: - /** @private */ - override protected function configUI():void { - super.configUI(); - initSize(); - if (bg != null) { - removeChild(bg); - bg = null; - } - if (loader == null && _source) { - load(_source); - } - } - - /** @private */ - protected function load(url:String):void { - if (url == "") { return; } - unload(); - _source = url; - _visiblilityBeforeLoad = visible; - visible = false; - if (loader == null) { - loader = new Loader(); - loader.contentLoaderInfo.addEventListener( Event.OPEN, handleLoadOpen, false, 0, true ); - loader.contentLoaderInfo.addEventListener( Event.INIT, handleLoadInit, false, 0, true ); - loader.contentLoaderInfo.addEventListener( Event.COMPLETE, handleLoadComplete, false, 0, true ); - loader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, handleLoadProgress, false, 0, true ); - loader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, handleLoadIOError, false, 0, true ); - } - addChild( loader ); - _isLoading = true; - loader.load( new URLRequest(_source) ); - } - - /** @private */ - override protected function draw():void { - if (!_loadOK) { return; } - if (isInvalid(InvalidationType.SIZE)) { - loader.scaleX = loader.scaleY = 1; - if (!_autoSize) { - visible = _visiblilityBeforeLoad; - } - else { - if (loader.width <= 0) { - if (_sizeRetries < 10) { - _sizeRetries++; - invalidateData(); - } - else { - trace("Error: " + this + " cannot be autoSized because content width is <= 0!"); - } - return; - } - if (_maintainAspectRatio) { - loader.scaleX = loader.scaleY = Math.min( height/loader.height, width/loader.width ); - loader.x = (_width - loader.width >> 1); - loader.y = (_height - loader.height >> 1); - } else { - loader.width = _width; - loader.height = _height; - } - visible = _visiblilityBeforeLoad; - } - } - } - - /** @private */ - protected function handleLoadIOError( ioe:Event ):void { - visible = _visiblilityBeforeLoad; - dispatchEventAndSound( ioe ); - } - - /** @private */ - protected function handleLoadOpen( e:Event ):void { - dispatchEventAndSound( e ); - } - - /** @private */ - protected function handleLoadInit( e:Event ):void { - dispatchEventAndSound( e ); - } - - /** @private */ - protected function handleLoadProgress( pe:ProgressEvent ):void { - bytesLoaded = pe.bytesLoaded; - bytesTotal = pe.bytesTotal; - dispatchEventAndSound( pe ); - } - - /** @private */ - protected function handleLoadComplete( e:Event ):void { - _loadOK = true; - _isLoading = false; - invalidateSize(); - validateNow(); - dispatchEventAndSound( e ); - } - - } -} diff --git a/src/scaleform/clik/controls/Window.as b/src/scaleform/clik/controls/Window.as deleted file mode 100644 index b4c1b85..0000000 --- a/src/scaleform/clik/controls/Window.as +++ /dev/null @@ -1,261 +0,0 @@ -/** - * A CLIK Window component that can be used to display forms constructed of Flash content / CLIK components. - * - * Buttons are the foundation component of the CLIK framework and are used anywhere a clickable interface control is required. The default Button class (gfx.controls.Button) supports a textField to display a label, and states to visually indicate user interaction. Buttons can be used on their own, or as part of a composite component, such as ScrollBar arrows or the Slider thumb. Most interactive components that are click-activated compose or extend Button. - - The CLIK Button is a general purpose button component, which supports mouse interaction, keyboard interaction, states and other functionality that allow it to be used in a multitude of user interfaces. It also supports toggle capability as well as animated states. The ToggleButton, AnimatedButton and AnimatedToggleButton provided in the Button.fla component source file all use the same base component class. - - Inspectable Properties - The inspectable properties of the Button component are: -
            -
          • enabled: Disables the component if set to false.
          • -
          • contentPadding: The top, bottom, left, and right padding that should be applied to the content loaded into the Window.
          • -
          • minWidth: The minimum width of the Window when it is resized via the resize Button.
          • -
          • maxWidth: The maximum width of the Window when it is resized via the resize Button.
          • -
          • minHeight: The minimum height of the Window when it is resized via the resize Button.
          • -
          • maxHeight: The maximum height of the Window when it is resized via the resize Button.
          • -
          • source: The export name of the symbol that should be loaded into the Window.
          • -
          • visible: Hides the component if set to false.
          • -
          - - States - The CLIK Window has no states as it loads and displays external content. - - Events - All event callbacks receive a single Event parameter that contains relevant information about the event. The following properties are common to all events.
            -
          • type: The event type.
          • -
          • target: The target that generated the event.
          - - The events generated by the Button component are listed below. The properties listed next to the event are provided in addition to the common properties. -
            -
          • ComponentEvent.SHOW: The visible property has been set to true at runtime.
          • -
          • ComponentEvent.HIDE: The visible property has been set to false at runtime or the window has been closed.
          • -
          - */ - -/************************************************************************** - -Filename : Window.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.controls { - - import flash.display.DisplayObject; - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.system.ApplicationDomain; - import scaleform.clik.events.ResizeEvent; - - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.core.UIComponent; - import scaleform.clik.controls.Button; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.utils.Constraints; - import scaleform.clik.utils.ConstrainedElement; - import scaleform.clik.utils.Padding; - - public class Window extends UIComponent { - - // Constants: - - // Public Properties: - /** The minimum width of the Window when it is resized via the resize Button. */ - [Inspectable(defaultValue=150)] - public var minWidth:Number = 150; - /** The maximum width of the Window when it is resized via the resize Button. */ - [Inspectable(defaultValue=500)] - public var maxWidth:Number = 500; - /** The minimum height of the Window when it is resized via the resize Button. */ - [Inspectable(defaultValue=150)] - public var minHeight:Number = 150; - /** The maximum height of the Window when it is resized via the resize Button. */ - [Inspectable(defaultValue=500)] - public var maxHeight:Number = 500; - - // Protected Properties: - protected var _title:String; - protected var _src:String = ""; - protected var _contentPadding:Padding; - protected var _content:DisplayObject; - protected var _dragProps:Array; - - // UI Elements: - public var closeBtn:Button; - public var okBtn:Button; - public var resizeBtn:Button; - public var titleBtn:Button; - public var background:MovieClip; - public var hit:MovieClip; - - // Initialization: - public function Window() { - super(); - - _contentPadding = new Padding(0, 0, 0, 0); - hitArea = hit; - } - - // Public Methods: - [Inspectable(defaultValue="My Window")] - public function get title():String { return _title; } - public function set title(value:String):void { - _title = value; - if (titleBtn != null && titleBtn.initialized) { titleBtn.label = _title; } - } - - [Inspectable(defaultValue="")] - public function get source():String { return _src; } - public function set source(value:String):void { - _src = value; - invalidate("source"); - // TODO: Dynamic loading of new source (only supports one time load currently; see configUI) - } - - [Inspectable(name = "contentPadding", defaultValue = "top:0,right:0,bottom:0,left:0")] - public function get contentPadding():Object { return _contentPadding; } - public function set contentPadding(value:Object):void { - _contentPadding = new Padding(value.top, value.right, value.bottom, value.left); - invalidate("padding"); - } - - // Protected Methods: - override protected function preInitialize():void { - constraints = new Constraints(this, ConstrainMode.REFLOW); - } - - override protected function initialize():void { - tabEnabled = false; // Components with a TextField can not be tabEnabled, otherwise they will get tab focus separate from the TextField. - mouseEnabled = mouseChildren = enabled; - super.initialize(); - } - - override protected function configUI():void { - initSize(); - - if (hitArea != null) { constraints.addElement("hitArea", hitArea, Constraints.ALL); } - if (background != null) { constraints.addElement("background", background, Constraints.ALL); } - - if (titleBtn != null) { - titleBtn.label = _title || "My Window"; - titleBtn.addEventListener(MouseEvent.MOUSE_DOWN, onWindowStartDrag, false, 0, true); - constraints.addElement("titleBtn", titleBtn, Constraints.TOP | Constraints.LEFT | Constraints.RIGHT); - } - if (closeBtn != null) { - closeBtn.addEventListener(MouseEvent.CLICK, onCloseButtonClick, false, 0, true); - constraints.addElement("closeBtn", closeBtn, Constraints.TOP | Constraints.RIGHT); - } - if (resizeBtn != null) { - constraints.addElement("resizeBtn", resizeBtn, Constraints.BOTTOM | Constraints.RIGHT); - resizeBtn.addEventListener(MouseEvent.MOUSE_DOWN, onResizeStartDrag, false, 0, true); - } - if (okBtn != null) { - constraints.addElement("okBtn", okBtn, Constraints.BOTTOM | Constraints.RIGHT); - okBtn.addEventListener(MouseEvent.CLICK, onCloseButtonClick, false, 0, true); - } - } - - override protected function draw():void { - if (isInvalid("source")) { - loadSource(); - reflowContent(); - } else if (isInvalid("padding")) { - reflowContent(); - } - - // Resize and update constraints - if (isInvalid(InvalidationType.SIZE)) { - constraints.update(_width, _height); - } - } - - protected function loadSource():void { - // TODO: Support external sources (swfs, images); only supports symbols currently - if (_src != "") { - if (_content) { - constraints.removeElement("content"); - removeChild(_content); - } - - var domain : ApplicationDomain = ApplicationDomain.currentDomain; - if (loaderInfo != null && loaderInfo.applicationDomain != null) domain = loaderInfo.applicationDomain; - var classRef:Class = domain.getDefinition(_src) as Class; - - if (classRef) { _content = new classRef(); } - else { - _content = null; - trace("Error: Cannot load content for " + name + "; symbol " + _src + " not found!"); - return; - } - addChild(_content); - constraints.addElement("content", _content, Constraints.ALL); - _content.name = "content"; - } - } - - protected function reflowContent():void { - if (!_content) return; - - var p:Padding = _contentPadding; - var element:ConstrainedElement = constraints.getElement("content"); - _content.x = element.left = p.left; - _content.y = element.top = p.top; - element.right = p.right; - element.bottom = p.bottom; - - _content.width = _width - p.horizontal; - _content.height = _height - p.vertical; - - // TODO: Add properties to define content area (by border offset) - // TODO: Add properties to define whether content is auto fit or window is auto fit - - invalidateSize(); - } - - protected function onWindowStartDrag(e:Event):void { - stage.addEventListener(MouseEvent.MOUSE_UP, onWindowStopDrag, false, 0, true); - startDrag(); - } - - protected function onWindowStopDrag(e:Event):void { - stage.removeEventListener(MouseEvent.MOUSE_UP, onWindowStopDrag, false); - stopDrag(); - } - - protected function onResizeStartDrag(e:Event):void { - stage.addEventListener(MouseEvent.MOUSE_UP, onResizeStopDrag, false, 0, true); - _dragProps = [parent.mouseX - (x + width), parent.mouseY - (y + height)]; - stage.addEventListener(MouseEvent.MOUSE_MOVE, onResizeMouseMove, false, 0, true); - } - - protected function onResizeStopDrag(e:Event):void { - stage.removeEventListener(MouseEvent.MOUSE_MOVE, onResizeMouseMove, false); - stage.removeEventListener(MouseEvent.MOUSE_UP, onResizeStopDrag, false); - } - - protected function onResizeMouseMove(e:Event):void { - var w:Number = Math.max(minWidth, Math.min(maxWidth, parent.mouseX - x - _dragProps[0])); - var h:Number = Math.max(minHeight, Math.min(maxHeight, parent.mouseY - y - _dragProps[1])); - if (w != _width || h != _height) { - setSize(w, h); - dispatchEventAndSound( new ResizeEvent(ResizeEvent.RESIZE, scaleX, scaleY) ); - //validateNow(); - } else { - // trace("Mouse move called: parent.mouseX=" + parent.mouseX + ", parent.mouseY=" + parent.mouseY); - } - } - - protected function onCloseButtonClick(e:MouseEvent):void { - parent.removeChild(this); - dispatchEventAndSound(new ComponentEvent(ComponentEvent.HIDE)); - } - } -} diff --git a/src/scaleform/clik/core/CLIK.as b/src/scaleform/clik/core/CLIK.as deleted file mode 100644 index 00827e3..0000000 --- a/src/scaleform/clik/core/CLIK.as +++ /dev/null @@ -1,186 +0,0 @@ -/** - * A global singleton for the CLIK framework that initializes the various CLIK subsystems (PopUpManager, FocusHandler, etc...). - */ - -/************************************************************************** - -Filename : CLIK.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.core -{ - import flash.display.DisplayObject; - import flash.display.DisplayObjectContainer; - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.display.Stage; - import flash.events.Event; - import flash.events.EventPhase; - import flash.utils.Dictionary; - - import scaleform.clik.managers.FocusHandler; - import scaleform.clik.managers.PopUpManager; - - import scaleform.gfx.Extensions; - - dynamic public class CLIK - { - // Constants: - - // Public Properties: - /** Reference to the Stage since this static class is not part of the Display List. */ - public static var stage:Stage; - /** true if this class has been initialized; false otherwise. */ - public static var initialized:Boolean = false; - - /** true if CLIK FocusHandler should never set focus to null or Stage. false to follow the default Flash focus behavior. */ - public static var disableNullFocusMoves:Boolean = false; - /** true if CLIK FocusHandler should never set focus to "dynamic" TextFields. false to follow the default Flash focus behavior. */ - public static var disableDynamicTextFieldFocus:Boolean = false; - /** true if prevent focus moves from TextField -> null. false to allow TextField -> null focus moves. */ - public static var disableTextFieldToNullFocusMoves:Boolean = true; - /** this option maps the keyboard NumPad to GamePad navigation input events */ - public static var testGamePad: Boolean = false; - - /** False by default. True if UIComponent initCallbacks should be fired immediately as they are received. False if each callback should be queued til the end of the frame and then fired in reverse order. */ - public static var useImmediateCallbacks:Boolean = false; - - // Protected Properties: - /** - * Whether the fireInitCallback listener is active (optimization). - * @private - */ - protected static var isInitListenerActive:Boolean = false; - /** - * Whether fireInitCallback() is currently running. Used to avoid multiple fireInitCallback() calls occuring simulatenously - * which will corrupt the Dictionaries they're sharing. - * @private - */ - protected static var firingInitCallbacks:Boolean = false; - /** - * A dictionary of dictionaries so that we can use weak references and order the queue by number of parents. - * initQueue[ number of parents ] = weak ref dictionary of objects with number of parents[ weak reference to an object as key ] = path to object. - * @private - */ - protected static var initQueue:Dictionary; - /** @private */ - protected static var validDictIndices:Vector.; - - // Initialization: - public static function initialize( stage:Stage, component:UIComponent ):void { - if (initialized) { return; } - - CLIK.stage = stage; - Extensions.enabled = true; - initialized = true; - - FocusHandler.init(stage, component); - PopUpManager.init(stage, false); - - initQueue = new Dictionary(true); - validDictIndices = new Vector.(); - } - - // Public Getter / Setters: - - // Public Methods: - public static function getTargetPathFor(clip:DisplayObjectContainer):String { - if (!clip.parent) { - return clip.name; - } - else { - var targetPath:String = clip.name; - return getTargetPathImpl(clip.parent as DisplayObjectContainer, targetPath); - } - } - - public static function queueInitCallback( ref:UIComponent ):void { - var path:String = getTargetPathFor( ref ); - - // In the unlikely case that we're queuing more callbacks while - // fireInitCallback is running, just fire the callback immediately. - // This will only occur if C++ interacts with the components immediately following - // their callback. If they call anything that causes a .gotoAndPlay(), that call will - // be executed immediately, potentially causing more EXIT_FRAME events to be fired simulatenously. - if ( useImmediateCallbacks || firingInitCallbacks ) { - Extensions.CLIK_addedToStageCallback( ref.name, path, ref ); - } - else { // Default behavior. - var parents:Array = path.split("."); - var numParents:uint = parents.length - 1; - var dict:Dictionary = initQueue[ numParents ]; - if (dict == null) { - dict = new Dictionary( true ); - initQueue[numParents] = dict; - validDictIndices.push( numParents ); - if (validDictIndices.length > 1) { - validDictIndices.sort( sortFunc ); - } - } - - dict[ref] = path; - if (!isInitListenerActive) { - isInitListenerActive = true; - stage.addEventListener(Event.EXIT_FRAME, fireInitCallback, false, 0, true); - } - } - } - - // Protected Methods: - /** @private */ - protected static function fireInitCallback(e:Event):void { - firingInitCallbacks = true; - stage.removeEventListener(Event.EXIT_FRAME, fireInitCallback, false); - isInitListenerActive = false; - - for (var i:uint; i < validDictIndices.length; i++) { - var numParents:uint = validDictIndices[i]; - var dict:Dictionary = initQueue[numParents] as Dictionary; - - for (var ref:Object in dict) { - var comp:UIComponent = ref as UIComponent; - Extensions.CLIK_addedToStageCallback(comp.name, dict[comp], comp); - dict[comp] = null; - } - } - - validDictIndices.length = 0; - clearQueue(); // Clean up all the keys in the initQueue by removing refs to the dictionaries. - firingInitCallbacks = false; - } - - /** Removes all of the reference to the Dictionaries used to track callbacks. @private */ - protected static function clearQueue():void { - for (var numDict:* in initQueue) { - initQueue[numDict] = null; - } - } - - /** Basic sorting function for the validDictIndices Vector. @private */ - protected static function sortFunc(a:uint, b:uint):Number { - if (a < b) { return -1; } - else if (a > b) { return 1; } - else { return 0; } - } - - /** @private */ - protected static function getTargetPathImpl(clip:DisplayObjectContainer, targetPath:String = ""):String { - if (!clip) { - return targetPath; - } - else { - var _name:String = (clip.name) ? (clip.name + ".") : ""; - targetPath = _name + targetPath; - return getTargetPathImpl(clip.parent as DisplayObjectContainer, targetPath); - } - } - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/core/UIComponent.as b/src/scaleform/clik/core/UIComponent.as deleted file mode 100644 index 692686a..0000000 --- a/src/scaleform/clik/core/UIComponent.as +++ /dev/null @@ -1,488 +0,0 @@ -/** - * The UIComponent is the basis for all components in the Scaleform framework. It contains functionality found in all components such as initialization, focus management, invalidation, sizing, and events. - */ - -/************************************************************************** - -Filename : UIComponent.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.core -{ - import flash.display.MovieClip; - import flash.events.Event; - import flash.events.FocusEvent; - import flash.events.MouseEvent; - import flash.external.ExternalInterface; - import flash.system.Capabilities; - - import scaleform.gfx.FocusManager; - import scaleform.gfx.Extensions; - - import scaleform.clik.core.CLIK; - import scaleform.clik.constants.InvalidationType; - import scaleform.clik.events.ComponentEvent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.layout.Layout; - import scaleform.clik.layout.LayoutData; - import scaleform.clik.managers.FocusHandler; - import scaleform.clik.utils.Constraints; - - [Event(name="SHOW", type="scaleform.clik.events.ComponentEvent")] - [Event(name="HIDE", type="scaleform.clik.events.ComponentEvent")] - - public class UIComponent extends MovieClip - { - // Constants: - public static var sdkVersion:String = "4.2.23"; - - // Public Properties: - public var initialized:Boolean = false; - - // Private Properties: - /** @private */ - protected var _invalidHash:Object; - /** @private */ - protected var _invalid:Boolean = false; - /** @private */ - protected var _width:Number = 0; // internal width - /** @private */ - protected var _height:Number = 0; // internal height - /** @private */ - protected var _originalWidth:Number = 0; - /** @private */ - protected var _originalHeight:Number = 0; - /** @private */ - protected var _focusTarget:UIComponent; - /** @private */ - protected var _focusable:Boolean = true; - /** @private */ - protected var _focused:Number = 0; - /** @private */ - protected var _displayFocus:Boolean = false; - /** @private */ - protected var _mouseWheelEnabled:Boolean = true; - /** @private */ - protected var _inspector:Boolean = false; - /** @private */ - protected var _labelHash:Object; - /** @private */ - protected var _layoutData:LayoutData; - /** @private */ - protected var _enableInitCallback:Boolean = false; - - // UI Elements: - public var constraints:Constraints; - - // Initialization: - public function UIComponent() { - preInitialize(); - super(); - - _invalidHash = {}; - initialize(); - addEventListener(Event.ADDED_TO_STAGE, addedToStage, false, 0, true); - } - - protected function preInitialize():void {} // Abstract. - - protected function initialize():void { - _labelHash = UIComponent.generateLabelHash(this); - - // Original width determines the width at 100% with original contents. - _originalWidth = super.width / super.scaleX; - _originalHeight = super.height / super.scaleY; - - if (_width == 0) { _width = super.width; } - if (_height == 0) { _height = super.height; } - - invalidate(); - } - - public static function generateLabelHash(target:MovieClip):Object { - var hash:Object = {}; - if (!target) { return hash; } - var labels:Array = target.currentLabels; - var l:uint = labels.length; - for (var i:uint=0; i 0; } - - /** - * Enable/disable focus management for the component. Setting the focusable property to - * {@code focusable=false} will remove support for tab key, direction key and mouse - * button based focus changes. - */ - public function get focusable():Boolean { return _focusable; } - public function set focusable(value:Boolean):void { - var changed:Boolean = (_focusable != value); - _focusable = value; - - // If the component is no longer focusable but currently enabled, disable tabbing. - // If the component is no longer focusable but it is already disabled, do nothing. - if (!_focusable && enabled) { tabEnabled = tabChildren = false; } - else if (_focusable && enabled) { tabEnabled = true; } - - // PPS: We may not need to call changeFocus(), and it may in fact cause visual artifacts.. - if (changed) changeFocus(); - } - - /** - * Get and set the focus of the component. This property is explicitly called by the FocusHandler - * when the stage or application focus is given to this component, but can also be set manually on - * the component to set or clear focus. Currently, an application can have only a single focus. - * When the focus on a component changes, a "focusIn" or "focusOut" event is fired. - */ - public function get focused():Number { return _focused; } // int? - public function set focused(value:Number):void { - if (value == _focused || !_focusable) { return; } - _focused = value; - - // Only run through multiple controller support if we're in Scaleform. - if (Extensions.isScaleform) { - var numFocusGroups:uint = FocusManager.numFocusGroups; - var numControllers:uint = Extensions.numControllers; - for (var i:Number = 0; i < numFocusGroups; i++) { - // Is the component focused by this focusGroup? - var isFocused:Boolean = ((_focused >> i) & 0x1) != 0; - if (isFocused) { - var controllerMask1:Number = FocusManager.getControllerMaskByFocusGroup( i ); - for (var j:Number = 0; j < numControllers; j++) { - // Is the component focused by this controller? - var controllerValue1:Boolean = ((controllerMask1 >> j) & 0x1) != 0; - if (controllerValue1 && FocusManager.getFocus(j) != this) { - FocusManager.setFocus(this, j); - } - } - } - } - } - else { - if (stage != null && _focused > 0) { - stage.focus = this; - } - } - - changeFocus(); - } - - /** - * Set the component to display itself as focused, even if it is not. This property is used by container - * components to make them appear focused. - */ - public function get displayFocus():Boolean { return _displayFocus; } - public function set displayFocus(value:Boolean):void { - if (value == _displayFocus) { return; } - _displayFocus = value; - changeFocus(); - } - - public function get focusTarget():UIComponent { return _focusTarget; } - public function set focusTarget(value:UIComponent):void { - _focusTarget = value; - } - - public function get layoutData():LayoutData { return _layoutData; } - public function set layoutData(value:LayoutData):void { - _layoutData = value; - } - - [Inspectable(defaultValue="false")] - public function get enableInitCallback():Boolean { return _enableInitCallback; } - public function set enableInitCallback(value:Boolean):void { - if (value == _enableInitCallback) { return; } - _enableInitCallback = value; - - // If we're already on the stage, fire the enableInitCallback immediately. - // This can occur if the component is on the timeline of the original .Swf, since inspectables are set - // after the component is added to the stage. Note that this behaviour is reversed for components - // added to the stage via code or loaded via a Loader (inspectables will be set before being added to - // the stage), thus the stage != null check. - if (_enableInitCallback && stage != null && Extensions.CLIK_addedToStageCallback != null) { - // Edge case for engines where CLIK may not be initialized when inspectables are fired. - if (!CLIK.initialized) { CLIK.initialize(stage, this); } - CLIK.queueInitCallback( this ); - } - } - - final public function get actualWidth():Number { return super.width; } - final public function get actualHeight():Number { return super.height; } - final public function get actualScaleX():Number { return super.scaleX; } - final public function get actualScaleY():Number { return super.scaleY; } - - // Public Methods: - /** - * Sets the width and height of the component at the same time using internal sizing mechanisms. - * @param width The new width of the component. - * @param height The new height of the component. - */ - public function setSize(width:Number, height:Number):void { - _width = width; - _height = height; - invalidateSize(); - } - - // Ablility to set actual metric size, since we override it. - public function setActualSize(newWidth:Number, newHeight:Number):void { - // If the clip is rotated, setting super.width and super.height can reset/unexpectedly affect one another. Seems to be - // a bug in Flash Player. - if (super.width != newWidth || _width != newWidth) { - super.width = _width = newWidth; - } - - if (super.height != newHeight || _height != newHeight) { - super.height = _height = newHeight; - } - } - - final public function setActualScale(scaleX:Number, scaleY:Number):void { - super.scaleX = scaleX; - super.scaleY = scaleY; - _width = _originalWidth * scaleX; - _height = _originalHeight * scaleY; - invalidateSize(); - } - - /** - * Handle input from the game, via controllers or keyboard. The default handleInput will handle standalone - * and composite components. - * @param event An InputEvent containing details about the interaction. - * @see InputEvent - * @see FocusHandler - * @see InputDetails - - */ - public function handleInput(event:InputEvent):void {} - - //LM: Untested. - public function dispatchEventToGame(event:Event):void { - ExternalInterface.call("__handleEvent", name, event); - } - - /** @exclude */ - override public function toString():String { - return "[CLIK UIComponent " + name + "]"; - } - - // Private Methods: - /** - * Configure the interface when the component is initialized. Use this method to set up - * sub-components, listeners, etc. - */ - protected function configUI():void { } // Abstract - - /** - * Draw the component after it has been invalidated. Use this method to reflow component - * size and position, redraw data, etc. When appropriate, ensure that a call to - * super.draw() is made when extending a component and overriding this method. - */ - protected function draw():void { } // Abstract - - /** - * Called after focus has been given or taken from the component. - * Use this method to change the appearance or behavior of the component when the focus changes. - */ - protected function changeFocus():void {} // Abstract - protected function beforeInspectorParams():void {} - protected function afterInspectorParams():void {} - - protected function initSize():void { - var w:Number = (_width == 0) ? actualWidth : _width; - var h:Number = (_height == 0) ? actualHeight : _height; - super.scaleX = super.scaleY = 1; - setSize(w,h); - } - - // Invalidation - /** - * An internal property of the component has changed, requiring a redraw. The invalidation - * mechanism lets components trigger multiple redraw commands at the same time, resulting in - * only a single redraw. the {@code invalidate()} method is public so that it can be called externally. - */ - public function invalidate(...invalidTypes:Array):void { - if (invalidTypes.length == 0) { - _invalidHash[InvalidationType.ALL] = true; - } else { - var l:uint = invalidTypes.length; - for (var i:uint=0; i -
          - - Inspectable Properties - A class that derives from Layout will have the following inspectable properties: -
            -
          • tiedToStageSize: true if this Layout's size should always be updated to match the stage size; false otherwise.
          • -
          • tiedToParent: true if this Layout's size should always be updated to match its parent's size; false otherwise.
          • -
          • hidden: true if this Layout should be hidden at runtime; false otherwise. Allows for the Layout to have a visible background or placeholder image that will be set to visible = false; immediately at runtime.
          • -
          - -
          -
          - - States - The Layout component does not support any states. - -
          -
          - - Events - The Layout component does not dispatch any Events. - */ - -/************************************************************************** - -Filename : Layout.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.layout { - - import flash.display.DisplayObject; - import flash.display.DisplayObjectContainer; - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.display.StageAlign; - import flash.events.Event; - import flash.geom.Rectangle; - - import scaleform.gfx.Extensions; - - import scaleform.clik.constants.LayoutMode; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.ResizeEvent; - import scaleform.clik.layout.LayoutData; - - public class Layout extends Sprite { // Layout extends Sprite so that it can be added to the stage. - - // Constants: - public static const STAGE_ALIGN_CENTER:String = ""; // Since there is no definition in StageAlign for CENTER. - - // Public Properties: - /** - * A unique identifer for this Layout to allow multiple Layouts to coexist in the same parent. - * LayoutData can be tied to a particular Layout using the Layout's identifier. - */ - public var identifier:String = null; - - // Protected Properties: - // The size of the Layout. - protected var _rect:Rectangle = null; - // true if this Layout's size should be bound to the stage size; false otherwise. - protected var _tiedToStageSize:Boolean = false; - // true if this Layout's size should be bound to the size of the parent; false otherwise. - protected var _tiedToParent:Boolean = false; - // true if this Layout should be hidden at runtime; false otherwise. - protected var _hidden:Boolean = false; - // The parent of this Layout on the Stage. Layout must be added to the Stage to work properly. - protected var _parent:Sprite = null; - // A list of Sprites that are currently being managed by the Layout. - protected var _managedSprites:Vector.; - // A String representation of the current AspectRatio. - protected var _aspectRatio:String = ""; - - // Initialization: - public function Layout() { - initialize(); - } - - public function initialize():void { - addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage, false, 0, true); - _managedSprites = new Vector.(); - } - - // Public Getter / Setters: - /** - * The "size" of the layout. Elements within will be laid out according to the x, y, width, and height of this property. - * If the Layout's width != 0 (tied to a Symbol and placed on Stage), it will use the MovieClip's x, y, width, and height. - * If the Layout's width == 0 (addChild() without a backing Symbol), it will use the parent's x, y, width, and height. - * You can also assign a custom Rectangle using the .rect property. - */ - public function get rect():Rectangle { return _rect; } - public function set rect(value:Rectangle):void { - _rect = value; - } - - /** true if this Layout's size should always be updated to match the stage size; false otherwise. */ - [Inspectable(defaultValue="false")] - public function get tiedToStageSize():Boolean { return _tiedToStageSize; } - public function set tiedToStageSize(value:Boolean):void { - if (value == _tiedToStageSize) { return;} - _tiedToStageSize = value; - _tiedToParent = false; - - // Make sure we've been added to the stage first. If not, it will be handled in handleAddedToStage(). - if (stage != null) { - // Faster than properly checking for a Listener for this particular Layout. - stage.removeEventListener(Event.RESIZE, handleStageResize, false); - if (_tiedToStageSize) { - stage.addEventListener(Event.RESIZE, handleStageResize, false, 0, true); - updateAspectRatio(); - } - } - } - - /** true if this Layout's size should always be updated to match its parent's size; false otherwise. */ - [Inspectable(defaultValue="false")] - public function get tiedToParent():Boolean { return _tiedToParent; } - public function set tiedToParent(value:Boolean):void { - if (value == _tiedToParent) { return;} - _tiedToParent = value; - _tiedToStageSize = false; - - if (_parent != null) { - // Faster than properly checking for a Listener for this particular Layout. - _parent.removeEventListener(ResizeEvent.RESIZE, handleParentResize, false); - if (_tiedToParent) { - _parent.addEventListener(ResizeEvent.RESIZE, handleParentResize, false, 0, true); - } - } - } - - /** - * true if this Layout should be hidden at runtime; false otherwise. Allows for the Layout to have - * a visible background or placeholder image that will be set to visible = false; immediately at runtime. - */ - [Inspectable(defaultValue="true")] - public function get hidden():Boolean { return _hidden; } - public function set hidden(value:Boolean):void { - _hidden = value; - visible = !_hidden; - } - - /** @exclude */ - override public function get width():Number { return super.width; } - override public function set width(value:Number):void { - super.width = value; - if (value > 0) { invalidate(); } - } - - /** @exclude */ - override public function get height():Number { return super.height; } - override public function set height(value:Number):void { - super.height = value; - if (value > 0) { invalidate() } - } - - /** @exclude */ - override public function get scaleX():Number { return super.scaleX } - override public function set scaleX(value:Number):void { - super.scaleX = value; - invalidate(); - } - - /** @exclude */ - override public function get scaleY():Number { return super.scaleY } - override public function set scaleY(value:Number):void { - super.scaleY = value; - invalidate(); - } - - // Public Methods: - /** Update the layout by reflowing the managed Sprites */ - public function reflow():void { - for (var i:uint = 0; i < _managedSprites.length; i++) { - var spr:Sprite = _managedSprites[i]; - var ld:LayoutData = spr["layoutData"] as LayoutData; // Sprites with null "layoutData" will never be added to Layout's managed list. - - // Store these values once for reuse. - var alignH:String = ld.alignH; - var alignV:String = ld.alignV; - - // If this Layout is tied to the stage size, then users can define their own hash table with values. - var offsetH:Number = (_tiedToStageSize && ld.offsetHashH[_aspectRatio] != undefined) ? ld.offsetHashH[_aspectRatio] : ld.offsetH; - var offsetV:Number = (_tiedToStageSize && ld.offsetHashV[_aspectRatio] != undefined) ? ld.offsetHashV[_aspectRatio] : ld.offsetV; - - // Cache a reference to the relativeToH Sprite, if valid. - var relativeH:String = ld.relativeToH; - var relHObject:Sprite = (relativeH != null) ? _parent.getChildByName( relativeH ) as Sprite : null;; - - // Cache a reference to the relativeToV Sprite, if valid. - var relativeV:String = ld.relativeToV; - var relVObject:Sprite = (relativeV != null) ? _parent.getChildByName( relativeV ) as Sprite : null; - - if (alignH != LayoutMode.ALIGN_NONE) { - if (alignH == LayoutMode.ALIGN_LEFT) { - // The object will be aligned to our rect. If the offset is -1, use it's offset - // from the Layout on the Stage. - if (relHObject == null) { - spr.x = rect.x + offsetH; - } - // The object will be aligned to relHObject. If the offset is -1, use it's offset - // from the Sprite on the Stage. - else { - spr.x = relHObject.x - spr.width + offsetH; - } - } - else if (alignH == LayoutMode.ALIGN_RIGHT) { - if (relHObject == null) { - spr.x = (rect.width - spr.width) + offsetH; - // If this Layout is tied to the Stage and the visibleRect changes and we're - // stage.align == CENTER, then the element will need to be further shifted by - // the .x of the visibleRect. - if (_tiedToStageSize && (stage.align == STAGE_ALIGN_CENTER || stage.align == StageAlign.TOP || stage.align == StageAlign.BOTTOM)) { - spr.x += rect.x; - } - } - // The object will be aligned to relVObject. If the offset is -1, use it's offset from - // the Sprite on the Stage. - else { - spr.x = relHObject.x + relHObject.width + offsetH; - } - } - else if (alignH == LayoutMode.ALIGN_CENTER) { - spr.x = (rect.width / 2 + rect.x) - ((spr.width/2) + offsetH); - } - } - - if (alignV != LayoutMode.ALIGN_NONE) { - if (alignV == LayoutMode.ALIGN_TOP) { - // The object will be aligned to our rect. If the offset is -1, use it's offset from the Layout on the Stage. - if (relVObject == null) { - spr.y = rect.y + offsetV; - } - // The object will be algined to relVObject. If the offset is -1, use it's offset from the Sprite on the Stage. - else { - spr.y = relVObject.y - spr.height + offsetV; - } - } - else if (alignV == LayoutMode.ALIGN_BOTTOM) { - if (relVObject == null) { - spr.y = (rect.height - spr.height) + offsetV; - // If this Layout is tied to the Stage and the visibleRect changes and we're - // stage.align == CENTER, then the element will need to be further shifted by - // the .x of the visibleRect. - if (_tiedToStageSize && (stage.align == STAGE_ALIGN_CENTER || stage.align == StageAlign.TOP || stage.align == StageAlign.BOTTOM)) { - spr.y += rect.y; - } - } - // The object will be algined to relVObject. If the offset is -1, use it's offset from the Sprite on the Stage. - else { - spr.y = relVObject.y + relVObject.height + offsetV; - } - } - else if (alignV == LayoutMode.ALIGN_CENTER) { - spr.y = (rect.height / 2 + rect.y) - ((spr.height/2) + offsetV); - } - } - } - } - - /** - * Resets the Layout by clearing its list of managed Sprites, searching for new Sprites with LayoutData - * and recaculating offsets / reflowing those new Sprites from scratch. - */ - public function reset():void { - if (stage == null) { return; } - _managedSprites = new Vector.; - configUI(); - } - - /** - * Sorts the managed Sprite list by their layoutData.layoutIndex property which defines the order in which - * the layout is applied. This should be called if any layoutIndex is changed after the initial setup - * of the Layout. - */ - public function resortManagedSprites():void { - var list:Vector. = new Vector.() - while (_managedSprites.length >= 1) { - insertIntoSortedVector( _managedSprites.pop(), list ); - } - _managedSprites = list; - } - - // Protected Methods: - // Internal method for invalidating the Layout. - protected function invalidate():void { - addEventListener(Event.RENDER, handleStageInvalidation, false, 0, true); - if (stage) { stage.invalidate(); } - } - - protected function handleStageInvalidation(e:Event):void { - removeEventListener(Event.RENDER, handleStageInvalidation, false); - _rect.x = x; - _rect.y = y; - _rect.width = width; - _rect.height = height; - reflow(); - } - - protected function handleAddedToStage(e:Event):void { - configUI(); - } - - protected function configUI():void { - removeEventListener(Event.ADDED_TO_STAGE, handleAddedToStage, false); - _parent = parent as MovieClip; - - visible = !_hidden; - - // If the layout is placed on the stage, use it's properties for laying out elements within it. - if (width > 0 && height > 0) { - _rect = new Rectangle(x, y, width, height); - } - - // By default, use the parent's width and height unless another 'rect' is provided. - if (_rect == null) { - // If the layout should be tied to the stage, have it match the stageWidth and stageHeight. - if (_tiedToStageSize) { - _rect = (Extensions.enabled) ? Extensions.visibleRect : new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); - } - // Otherwise, use the _parent's size. - else { - _rect = new Rectangle(0, 0, _parent.width, _parent.height); - _tiedToParent = true; - } - } - - // Delay the analysis of other Sprites a frame while they initialize. - // No good way to discern whether this was a result of a call to addChild() (which could call - // analyzeSprites() immediately) or adding to the Layout to the stage during design.. - addEventListener(Event.ENTER_FRAME, handleFirstEnterFrame, false, 0, true); - - _parent.addEventListener(Event.ADDED_TO_STAGE, handleSpriteAddedToParent, false, 0, true); - _parent.addEventListener(Event.REMOVED_FROM_STAGE, handleSpriteRemovedFromParent, false, 0, true); - - // Listen to resize events from the _parent if stage if this Layout is tied to the stage's size. - if (_tiedToStageSize) { - stage.addEventListener(Event.RESIZE, handleStageResize, false, 0, true); - } - // Listening for RESIZE events from the Parent may not be necessary in all cases, but - // the Event has to be implemented by the parent to track resizes to work, so we'll leave it to - // the discretion of the user. - else if (_tiedToParent){ - // The parent must implement dispatching this event when it's size changes or - // this Layout will not know that it's size has changed. - _parent.addEventListener(ResizeEvent.RESIZE, handleParentResize, false, 0, true); - } - } - - // Used to delay the analysis of other Sprites a frame while they initialize. - protected function handleFirstEnterFrame(e:Event):void { - removeEventListener(Event.ENTER_FRAME, handleFirstEnterFrame, false); - analyzeSpritesOnStage(); - } - - // Analyzes the Sprites currently within the Parent and evaluates them for layout management - // based on their "layoutData" property - protected function analyzeSpritesOnStage():void { - for (var i:uint = 0; i < _parent.numChildren; i++) { - var spr:Sprite = _parent.getChildAt(i) as Sprite; - if (spr != this) { // We don't want the Layout to manage itself. - evaluateLayoutForSprite(spr); - } - } - reflow(); - } - - // Listener for Sprites being added to the parent. - protected function handleSpriteAddedToParent(e:Event):void { - var spr:Sprite = e.target as Sprite; - if (spr.parent != _parent) { return; } // If the Sprite is of a different parent, ignore it. - evaluateLayoutForSprite(spr); - reflow(); - } - - // Listener for Sprites being removed from the parent. - protected function handleSpriteRemovedFromParent(e:Event):void { - var spr:Sprite = e.target as Sprite; - if (spr.parent != _parent) { return; } // If the Sprite is of a different parent, ignore it. - for (var i:uint = 0; i < _managedSprites.length; i++) { - if (_managedSprites[i] == spr) { - _managedSprites.splice(i, 1); - } - } - } - - protected function handleParentResize(e:Event):void { - _rect.width = _parent.width - _rect.height = _parent.height; - reflow(); - } - - protected function handleStageResize(e:Event):void { - updateAspectRatio(); - reflow(); - } - - protected function updateAspectRatio():void { - if (Extensions.enabled) { - _rect = Extensions.visibleRect; - var ar:Number = rect.width / rect.height; - switch (ar) { - case (4 / 3): - _aspectRatio = LayoutData.ASPECT_RATIO_4_3; - break; - case (16 / 9): - _aspectRatio = LayoutData.ASPECT_RATIO_16_9; - break; - case (16 / 10): - _aspectRatio = LayoutData.ASPECT_RATIO_16_10; - break - default: - break; - } - } - else { - _rect.width = stage.stageWidth; - _rect.height = stage.stageHeight; - } - } - - // NFM: Consider adding logic to UIComponent that fires an event when the layout properties are changed - // so we can update the _managedObjects list and reflow appropriately. For now, all settings must - // be in place before the Layout is added to the parent. - protected function evaluateLayoutForSprite(spr:Sprite):void { - if (spr == null) { return; } - var lData:LayoutData = null; - lData = spr["layoutData"]; - // Only add Sprites that have "layoutData" and have no layoutIdentifier or this layoutIdentifier set. - if (lData != null && (lData.layoutIdentifier == null || lData.layoutIdentifier == identifier)) { - insertIntoSortedVector(spr, _managedSprites); - calculateOffsets(spr); - } - } - - protected function insertIntoSortedVector(spr:Sprite, list:Vector.):void { - // If there's no other _managedObjects or if we don't have a particular layoutIndex (-1), just add us to the end. - var lIndex:int = (spr["layoutData"] as LayoutData).layoutIndex; - if (list.length == 0 || lIndex == -1) { - list.push(spr); - } - else { - var inserted:Boolean = false; - for (var i:uint = 0; i < list.length && !inserted; i++) { - var ld:LayoutData = list[i]["layoutData"] as LayoutData; - if (lIndex >= 0 && lIndex <= ld.layoutIndex) { - list.splice(i, 0, spr); - inserted = true; - } - } - // If we didn't find a spot for it, add it to the end. - if (!inserted) { - list.push(spr); - } - } - } - - protected function calculateOffsets(spr:Sprite):void { - var ld:LayoutData = spr["layoutData"] as LayoutData; - - // Store these values once for reuse. - var alignH:String = ld.alignH; - var alignV:String = ld.alignV; - - // Cache a reference to the relativeToH Sprite, if valid. - var relativeH:String = ld.relativeToH; - var relHObject:Sprite = (relativeH != null) ? _parent.getChildByName( relativeH ) as Sprite : null;; - - // Cache a reference to the relativeToV Sprite, if valid. - var relativeV:String = ld.relativeToV; - var relVObject:Sprite = (relativeV != null) ? _parent.getChildByName( relativeV ) as Sprite : null; - - // If no offsetH was provided in the LayoutData, the current horizontal offset will become the new offsetH. - if (ld.offsetH == -1) { - if (alignH != LayoutMode.ALIGN_NONE) { - if (alignH == LayoutMode.ALIGN_LEFT) { - // If the offset is -1, use its offset from the Layout on the Stage. - if (relHObject == null) { - ld.offsetH = spr.x - rect.x; - } - // The object will be algined to relHObject. If the offset is -1, use its offset from the Sprite on the Stage. - else { - ld.offsetH = spr.x - (relHObject.x + relHObject.width); - } - } - else if (alignH == LayoutMode.ALIGN_RIGHT) { - // If the offset is -1, use it's offset from the Layout on the Stage. - if (relHObject == null) { - ld.offsetH = (spr.x + spr.width)- rect.width; - } - // The object will be algined to relVObject. If the offset is -1, use it's offset from the Sprite on the Stage. - else { - ld.offsetH = spr.x - relHObject.x; - } - } - } - } - // If no offsetV was provided in the LayoutData, the current vertical offset will become the new offsetV. - if (ld.offsetV == -1) { - if (alignV != LayoutMode.ALIGN_NONE) { - if (alignV == LayoutMode.ALIGN_TOP) { - // If the offset is -1, use its offset from the Layout on the Stage. - if (relVObject == null) { - ld.offsetV = spr.y - rect.y; - } - // The object will be algined to relVObject. If the offset is -1, use its offset from the Sprite on the Stage. - else { - ld.offsetV = spr.y - (relVObject.y + relVObject.height); - } - } - else if (alignV == LayoutMode.ALIGN_BOTTOM) { - // If the offset is -1, use it's offset from the Layout on the Stage. - if (relVObject == null) { - ld.offsetV = (spr.y + spr.height) - rect.height; - } - // The object will be algined to relVObject. If the offset is -1, use it's offset from the Sprite on the Stage. - else { - ld.offsetV = spr.y - relVObject.y; - } - } - } - } - } - } -} diff --git a/src/scaleform/clik/layout/LayoutData.as b/src/scaleform/clik/layout/LayoutData.as deleted file mode 100644 index dc7185d..0000000 --- a/src/scaleform/clik/layout/LayoutData.as +++ /dev/null @@ -1,132 +0,0 @@ -/** - Data that defines the layout for this Sprite. Must be used with a valid scaleform.clik.layout.Layout instance. - */ - -/************************************************************************** - -Filename : LayoutData.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.layout { - - import flash.utils.Dictionary; - - public class LayoutData { - - // Constants: - /** String constant for 4:3 aspect ratio. Used for setting particular aspect ratio offsets in LayoutData.offsetHash Dictionaries. */ - public static const ASPECT_RATIO_4_3:String = "4:3"; - /** String constant for 16:9 aspect ratio. Used for setting particular aspect ratio offsets in LayoutData.offsetHash Dictionaries. */ - public static const ASPECT_RATIO_16_9:String = "16:9"; - /** String constant for 16:10 aspect ratio. Used for setting particular aspect ratio offsets in LayoutData.offsetHash Dictionaries. */ - public static const ASPECT_RATIO_16_10:String = "16:10"; - - // Public Properties: - /** - * The horizontal alignment for this Sprite. - * Valid values: LayoutMode.ALIGN_NONE, LayoutMode.ALIGN_LEFT, LayoutMode.ALIGN_RIGHT. - */ - public var alignH:String = null; - /** - * The vertical alignment for this Sprite. - * Valid values: LayoutMode.ALIGN_NONE, LayoutMode.TOP, LayoutMode.BOTTOM. - */ - public var alignV:String = null; - - /** - * The horizontal offset from the edge of the Layout or the relativeToH Sprite. - * If it is left unchanged (-1), the Layout will auto-set it to original horizontal offset from the Layout/Sprite on - * the Stage, as defined by the artist during design. - */ - public var offsetH:int = -1; - /** - * The vertical offset from the edge of the Layout or the relativeToV Sprite. - * If it is left unchanged (-1), the Layout will auto-set it to original vertical offset from the Layout/Sprite on - * the Stage, as defined by the artist during design. - */ - public var offsetV:int = -1; - - /** - * A hash table of user-defined horizontal offsets for various aspect ratios. These values will be queried if - * the Layout is tied to the stage's size (Layout.tiedToStageSize == true). - * For example, "LayoutData.offsetHashH[LayoutData.ASPECT_RATIO_4_3] = 70;" will cause this Sprite to use a - * horizontal offset of 70px if the Layout is tied to the Stage's size and the aspect ratio is currently 4:3. - */ - public var offsetHashH:Dictionary = null; - /** - * A hash table of user-defined vertical offsets for various aspect ratios. These values will be queried if - * the Layout is tied to the stage's size (Layout.tiedToStageSize == true). - * For example, "LayoutData.offsetHashV[LayoutData.ASPECT_RATIO_4_3] = 70;" will cause this Sprite to use a - * vertical offset of 70px if the Layout is tied to the Stage's size and the aspect ratio is currently 4:3. - */ - public var offsetHashV:Dictionary = null; - - /** - * The instance name of the Sprite that this Sprite should be relative to horizontally. If left as null, - * the Sprite will be aligned relative to the Layout. - */ - public var relativeToH:String = null; - /** - * The instance name of the Sprite that this Sprite should be relative to vertically. If left as null, - * the Sprite will be aligned relative to the Layout. - */ - public var relativeToV:String = null; - - /** - * The order in which this Sprite should be laid out relative to other Sprites in the same Layout. - * Should be set if using relativeToH or relativeToV to ensure that Sprite's Layout is updated before - * this Sprite. If the layoutIndex is left unchanged (-1), it will be added to the end of the list arbitrarily. - */ - public var layoutIndex:int = -1; // If the layoutIndex is -1, it will be ignored. - /** - * String that defines which Layout this LayoutData object should be associated with if multiple Layouts exist - * within a single DisplayObjectContainer. If left unchanged (null), it will be managed by all Layouts within - * the same parent automatically. This property, if set, should match a Layout instance's identifer property. - */ - public var layoutIdentifier:String = null; - - // Protected Properties: - - // Initialization: - public function LayoutData( _alignH:String = "none", // Can't use LayoutMode.ALIGN_NONE here, error 1047. - _alignV:String = "none", - _offsetH:int = -1, - _offsetV:int = -1, - _relativeToH:String = null, - _relativeToV:String = null, - _layoutIndex:int = -1, - _layoutIdentifer:String = null) { - - alignH = _alignH; - alignV = _alignV; - offsetH = _offsetH; - offsetV = _offsetV; - relativeToH = _relativeToH; - relativeToV = _relativeToV; - layoutIndex = _layoutIndex; - layoutIdentifier = _layoutIdentifer; - - // Just to save the user from having to create these if they want them. - offsetHashH = new Dictionary(); - offsetHashV = new Dictionary(); - } - - // Public Getter / Setters: - - // Public Methods: - public function toString():String { - return "[LayoutData, h: " + alignH + ", v: " + alignV + ", oh: " + offsetH + ", ov: " + offsetV + ", relh: " + relativeToH + ", relv: " + relativeToV + ", idx: " + layoutIndex + "]"; - } - - // Protected Methods: - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/managers/DragManager.as b/src/scaleform/clik/managers/DragManager.as deleted file mode 100644 index c640d02..0000000 --- a/src/scaleform/clik/managers/DragManager.as +++ /dev/null @@ -1,148 +0,0 @@ -/************************************************************************** - -Filename : DragManager.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.managers { - - import flash.display.DisplayObject; - import flash.display.DisplayObjectContainer; - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.display.Stage; - import flash.events.Event; - import flash.events.MouseEvent; - import flash.geom.Point; - import flash.display.Bitmap; - import flash.display.IBitmapDrawable; - import flash.display.BitmapData; - - import scaleform.gfx.FocusManager; - - import scaleform.clik.events.DragEvent; - import scaleform.clik.controls.DragSlot; - import scaleform.clik.interfaces.IDragSlot; - - public class DragManager { - - // Constants: - - // Protected Properties: - /** Reference to the Stage. */ - protected static var _stage:Stage; - /** Reference to the Sprite to which all dragged Sprites are attached while being dragged. */ - protected static var _dragCanvas:Sprite; - /** TRUE if the DragManager has been initialized using init(). FALSE if not. */ - protected static var _initialized:Boolean = false; - /** TRUE if the DragManager is currently dragging. FALSE if not. */ - protected static var _inDrag:Boolean = false; - - /** The data behind the Sprite that is currently being dragged. */ - protected static var _dragData:Object; - /** Reference to the Sprite being dragged by the DragManager. */ - protected static var _dragTarget:Sprite; - /** Reference to the original DragSlot that initiated the current drag. */ - protected static var _origDragSlot:IDragSlot; - - // Initialization: - public static function init(stage:Stage):void { - if (_initialized) { return; } - _initialized = true; - - DragManager._stage = stage; - _dragCanvas = new Sprite(); - _dragCanvas.mouseEnabled = _dragCanvas.mouseChildren = false; - _stage.addChild(_dragCanvas); - - _stage.addEventListener(DragEvent.DRAG_START, DragManager.handleStartDragEvent, false, 0, true); - } - - // Public Methods: - public static function inDrag():Boolean { return _inDrag; } - - public static function handleStartDragEvent( e:DragEvent ):void { - if (e.dragTarget == null || e.dragSprite == null) { return; } - - _dragTarget = e.dragSprite; - _dragData = e.dragData; - - // Store a reference to the original DragSlot so it can handle a failed Drag however it wants. - _origDragSlot = e.dragTarget; - - // When we reparent the _dragTarget, we want it in the same global location (otherwise it'll be at 0,0). - var dest:Point = _dragTarget.localToGlobal(new Point()); - var canvDest: Point = _dragCanvas.localToGlobal(new Point()); - - // NFM: This should be changed so that original IDragSlot decides what it does with the Sprite rather than - // have it immediately removeChild()'d by the DragManager. - // Remove the Sprite that we're dragging from it's parent. - // var targetParent:DisplayObjectContainer = _dragTarget.parent as DisplayObjectContainer; - // if (targetParent) { targetParent.removeChild(_dragTarget); } - - // _dragTarget = cloneDisplayObjectAsSprite(_dragTarget); - _dragCanvas.addChild(_dragTarget); - - _dragTarget.x = dest.x - canvDest.x; - _dragTarget.y = dest.y - canvDest.y; - - _inDrag = true; - _stage.addEventListener(MouseEvent.MOUSE_UP, handleEndDragEvent, false, 0, true); - - var dragMC:MovieClip = _dragTarget as MovieClip; - dragMC.startDrag(); - dragMC.mouseEnabled = dragMC.mouseChildren = false; - dragMC.trackAsMenu = true; // May not need any of this or cast stuff. Just mouseEnabled = mouseChildren. - } - - public static function handleEndDragEvent( e:MouseEvent ):void { - _stage.removeEventListener(MouseEvent.MOUSE_UP, handleEndDragEvent, false); - _inDrag = false; - - var isValidDrop:Boolean = false; - var dropTarget:IDragSlot = findSpriteAncestorOf(_dragTarget.dropTarget) as IDragSlot; - - if (dropTarget != null && dropTarget is IDragSlot && dropTarget != _origDragSlot) { - var dropEvent:DragEvent = new DragEvent(DragEvent.DROP, _dragData, _origDragSlot, dropTarget, _dragTarget); - isValidDrop = dropTarget.handleDropEvent(dropEvent); - } - - // Regardless of if the drop was valid or not, stop dragging the item around the stage. - _dragTarget.stopDrag(); - _dragTarget.mouseEnabled = _dragTarget.mouseChildren = true; - (_dragTarget as MovieClip).trackAsMenu = false; - _dragCanvas.removeChild(_dragTarget); - - // Give the original DragSlot a chance to handle the DRAG_END. - var dragEndEvent:DragEvent = new DragEvent(DragEvent.DRAG_END, _dragData, _origDragSlot, dropTarget, _dragTarget); - _origDragSlot.handleDragEndEvent(dragEndEvent, isValidDrop); // NFM: This event isn't being dispatched for perf (reduces the number of IDragSlots who will receive / process the event). - - // Have to dispatch the event from one of the dragTargets since this class is static. - _origDragSlot.dispatchEventAndSound(dragEndEvent); - - // Reset the drag references. - _dragTarget = null; - _origDragSlot = null; - } - - // Protected Methods: - protected static function handleStageAddedEvent(e:Event):void { - // NFM: We may need something like this for the DragSlot but we don't want it to intersect with a PopUp or anything. - // We'll probably need a special interface that uses the first few depths for DragManager / PopupManager / etc... - } - - // Finds a IDragSlot ancestor in the display list of the target DisplayObject. - protected static function findSpriteAncestorOf( obj:DisplayObject ):IDragSlot { - while (obj && !(obj is IDragSlot)) { - obj = obj.parent; - } - return obj as IDragSlot; - } - } -} \ No newline at end of file diff --git a/src/scaleform/clik/managers/FocusHandler.as b/src/scaleform/clik/managers/FocusHandler.as deleted file mode 100644 index 37a497d..0000000 --- a/src/scaleform/clik/managers/FocusHandler.as +++ /dev/null @@ -1,556 +0,0 @@ -/** - * Manage focus between the components. Intercept focus from the player, and hand it off to the "focused" component through the display-list hierarchy using a bubbling approach. Focus can be interupted or handled on every level. - */ - -/************************************************************************** - -Filename : FocusHandler.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ -package scaleform.clik.managers { - - import flash.display.DisplayObject; - import flash.display.DisplayObjectContainer; - import flash.display.InteractiveObject; - import flash.display.MovieClip; - import flash.display.Stage; - import flash.display.Sprite; - import flash.events.Event; - import flash.events.FocusEvent; - import flash.events.KeyboardEvent; - import flash.events.MouseEvent; - import flash.text.TextField; - import flash.utils.Dictionary; - import scaleform.clik.utils.WeakReference; - - import scaleform.gfx.FocusManager; - import scaleform.gfx.Extensions; - import scaleform.gfx.FocusEventEx; - import scaleform.gfx.SystemEx; - - import scaleform.clik.constants.FocusMode; - import scaleform.clik.core.CLIK; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.InputEvent; - import scaleform.clik.events.FocusHandlerEvent; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - import scaleform.clik.ui.InputDetails; - - [Event(name="input", type="gfx.events.InputEvent")] - public class FocusHandler { - - protected static var initialized:Boolean = false; - - public static var instance:FocusHandler; - public static function getInstance():FocusHandler { - if (instance == null) { instance = new FocusHandler(); } - return instance; - } - - public static function init(stage:Stage, component:UIComponent):void { - if (initialized) { return; } - var focusHandler:FocusHandler = FocusHandler.getInstance(); - focusHandler.stage = stage; - - FocusManager.alwaysEnableArrowKeys = true; - FocusManager.disableFocusKeys = true; - initialized = true; - } - - // Constants: - - // Public Properties: - - // Protected Properties: - - protected var _stage:Stage; - /** Dctionary of weak references to what holds focus within the CLIK FocusHandler framework. */ - protected var currentFocusLookup:Dictionary; - /** Dctionary of weak references to what the FocusHandler believes "stage.focus" currently references. */ - protected var actualFocusLookup:Dictionary;// NFM: This commonly will point to an InteractiveObject while stage.focus == null. - /** Internal boolean for tracking whether to prevent the stage from changing its focus. */ - protected var preventStageFocusChanges:Boolean = false; - - // Tracks the state of the left mouse button. This is required in Flash Player to work around a bug where if a - // Mouse is dragged on top of a TextField that TextField continously dispatches MOUSE_FOCUS_CHANGE events despite - // focus never moving. We track mouseDown so we know whether a MOUSE_FOCUS_CHANGE from a TextField in Flash Player - // is a "drag" (ignore) or a "click" (process). - protected var mouseDown:Boolean = false; - - // Initialization: - public function FocusHandler() { - currentFocusLookup = new Dictionary(); - actualFocusLookup = new Dictionary(); - } - - // Public Getter / Setters: - public function set stage(value:Stage):void { - if (_stage == null) { _stage = value; } - _stage.stageFocusRect = false; - - // Only track mouseDown if we're inside Flash Player (see mouseDown definition for more information). - if (Extensions.enabled) { - _stage.addEventListener(MouseEvent.MOUSE_DOWN, trackMouseDown, false, 0, true ); - _stage.addEventListener(MouseEvent.MOUSE_UP, trackMouseDown, false, 0, true ); - } - - _stage.addEventListener(FocusEvent.FOCUS_IN, updateActualFocus, false, 0, true); - _stage.addEventListener(FocusEvent.FOCUS_OUT, updateActualFocus, false, 0, true); - _stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, handleMouseFocusChange, false, 0, true); - _stage.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, handleMouseFocusChange, false, 0, true); - - var inputDelegate:InputDelegate = InputDelegate.getInstance(); - inputDelegate.initialize(_stage); - inputDelegate.addEventListener(InputEvent.INPUT, handleInput, false, 0, true); - } - - // Public Methods: - public function getFocus(focusGroupIdx:uint):InteractiveObject { return getCurrentFocusDisplayObject( focusGroupIdx ); } - public function setFocus(focus:InteractiveObject, focusGroupIdx:uint = 0, mouseChange:Boolean = false):void { - // trace("\n *** FocusHandler :: setFocus( " + focus + ", " + focusGroupIdx + " )"); - // if (focus == currentFocusLookup[index]) { return; } // NFM: This prevents some _stage.focus -> FocusHandler communication. - var focusParam:InteractiveObject = focus; - var focusComponent:UIComponent; - - // Determine Component focus - if (focus != null) { // New focus can be null if clicking on something that is not focus enabled. - // Recursive lookup to find final focusTarget - while (true) { - focusComponent = focus as UIComponent; - if (focusComponent == null) { break; } - if (focusComponent.focusTarget != null) { - focus = focusComponent.focusTarget; - } else { - break; - } - } - } - - if (focusComponent != null) { - if ( focusComponent.focusable == false) { - focus = null; - } - } - - // NFM: If _stage.focus is moved using the mouse, it cannot end up on a !tabEnabled InteractiveObject. - // If we return instead of (newFocus = null), focus will remain on previous InteractiveObject. - // Check if newFocus is a Sprite because TextFields are .tabEnabled == false but can receive stage - // focus via mouse click. - var spr:Sprite = focus as Sprite; - if (spr && mouseChange && spr.tabEnabled == false) { - focus = null; - } - - if (CLIK.disableNullFocusMoves && (focus == null || focus == _stage)) { - return; - } - - // Make focus change - var actualFocus:DisplayObject = getActualFocusDisplayObject( focusGroupIdx ); - var currentFocus:DisplayObject = getCurrentFocusDisplayObject( focusGroupIdx ); //LM: DisplayObjects? Maybe UIComponents.... - - // If component focus has changed - if (currentFocus != focus) { - // Turn off old focus - focusComponent = currentFocus as UIComponent; - if (focusComponent != null) { - focusComponent.focused = focusComponent.focused & ~(1 << focusGroupIdx); - } - if (currentFocus != null) { - if(currentFocus is UIComponent) - (currentFocus as UIComponent).dispatchEventAndSound( new FocusHandlerEvent(FocusHandlerEvent.FOCUS_OUT, true, false, focusGroupIdx) ); - else - currentFocus.dispatchEvent( new FocusHandlerEvent(FocusHandlerEvent.FOCUS_OUT, true, false, focusGroupIdx) ); - } - - // Turn on new focus. - currentFocus = focus; - setCurrentFocusDisplayObject( focusGroupIdx, focus ); - focusComponent = currentFocus as UIComponent; - if (focusComponent != null) { - focusComponent.focused = focusComponent.focused | (1 << focusGroupIdx); - } - if (currentFocus != null) - { - if(currentFocus is UIComponent) - (currentFocus as UIComponent).dispatchEventAndSound( new FocusHandlerEvent(FocusHandlerEvent.FOCUS_IN, true, false, focusGroupIdx) ); - else - currentFocus.dispatchEvent( new FocusHandlerEvent(FocusHandlerEvent.FOCUS_IN, true, false, focusGroupIdx) ); - } - } - - /* - * Stage focus has changed. This is important to do separately, in case a sub-component was clicked, and it might get stage focus. - * Note that in composite components, since the parent component will likely not have mouse events, the stage focus remains - * on the element that has been clicked. - * - * NFM: Only update stage.focus to match if actualFocus is not a textField who's focusTarget is a UIComponent (TextInput, for example). - */ - var isActualFocusTextField:Boolean = actualFocus is TextField; - var isCurrentFocusUIComponent:Boolean = currentFocus is UIComponent; - if (actualFocus != currentFocus && (!isActualFocusTextField || (isActualFocusTextField && !isCurrentFocusUIComponent))) { - // NFM: Since _stage.focus is going to control non-UIComponents, this is required so that MovieClips, textFields - // and Sprites are all properly updated via stage focus. - // - // Focus may now point to something other than the original component. In the case of a textField, focus - // and focusComponent may both be null, but the _stage.focus should still be set to the TextField if applicable. - if (focusParam is TextField && focusParam != focus && focus == null) { - focus = focusParam; - } - - preventStageFocusChanges = true; - - if (Extensions.isScaleform) { - var controllerMask:Number = FocusManager.getControllerMaskByFocusGroup(focusGroupIdx); //.getControllerMaskByFocusGroup(index); - var numControllers:uint = Extensions.numControllers; - for (var i:uint = 0; i < numControllers; i++) { - var controllerValue:Boolean = ((controllerMask >> i) & 0x1) != 0; - if ( controllerValue ) { - setSystemFocus(focus as InteractiveObject, i); - } - } - } - else { - setSystemFocus(focus as InteractiveObject); - } - - _stage.addEventListener(Event.ENTER_FRAME, clearFocusPrevention, false, 0, true); - } - } - - // PPS: We need to use a weak reference to store the focused elements since they may not be - // unloaded correctly. The WeakReference utility class provides this functionality. - // \BEGIN - protected function getCurrentFocusDisplayObject(focusGroupIdx:uint):InteractiveObject { - //return (currentFocusLookup.getValue( focusGroupIdx ) as InteractiveObject); - var ref:WeakReference = currentFocusLookup[focusGroupIdx] as WeakReference; - if (ref) return ref.value as InteractiveObject; - else return null; - } - protected function setCurrentFocusDisplayObject(focusGroupIdx:uint, dobj:InteractiveObject):void { - //currentFocusLookup.setValue(focusGroupIdx, dobj); - currentFocusLookup[focusGroupIdx] = new WeakReference(dobj); - } - protected function getActualFocusDisplayObject(focusGroupIdx:uint):InteractiveObject { - //return (actualFocusLookup.getValue( focusGroupIdx ) as InteractiveObject); - var ref:WeakReference = actualFocusLookup[focusGroupIdx] as WeakReference; - if (ref) return ref.value as InteractiveObject; - else return null; - } - protected function setActualFocusDisplayObject(focusGroupIdx:uint, dobj:InteractiveObject):void { - //actualFocusLookup.setValue(focusGroupIdx, dobj); - actualFocusLookup[focusGroupIdx] = new WeakReference(dobj); - } - // \END - - // Abstracts _stage.focus = for Scaleform / Flash Player. - protected function setSystemFocus(newFocus:InteractiveObject, controllerIdx:uint = 0):void { - if (Extensions.isScaleform) { - FocusManager.setFocus(newFocus, controllerIdx); - } - else { - _stage.focus = newFocus; - } - } - // Abstracts _stage.focus = for Scaleform / Flash Player. - protected function getSystemFocus(controllerIdx:uint = 0):InteractiveObject { - if (Extensions.isScaleform) { - return FocusManager.getFocus(controllerIdx); - } - else { - return _stage.focus; - } - } - - protected function clearFocusPrevention(e:Event):void { - preventStageFocusChanges = false; - _stage.removeEventListener(Event.ENTER_FRAME, clearFocusPrevention, false); - } - - //LM: Consider making handleInput a manual function - public function input(details:InputDetails):void { - var event:InputEvent = new InputEvent(InputEvent.INPUT, details); - handleInput(event); - } - - public function trackMouseDown( e:MouseEvent ):void { - mouseDown = e.buttonDown; - } - - // Protected Methods: - protected function handleInput(event:InputEvent):void { - var controllerIdx:Number = event.details.controllerIndex; - var focusGroupIdx:Number = FocusManager.getControllerFocusGroup(controllerIdx); - - /* - * Implementation notes: - * We will dispatch the Input Event from the focused component. Since it is a bubbling event - * it can be caught using the capture phase (on the way up from Stage), as well as back down from - * the component to the stage, which allows us to implement the same approaches used in the AS2 - * version, but with native code. It will be up to the components/developer to set handled=true - * to stop the event. - */ - - // Allow components to try and handle input - var component:InteractiveObject = getCurrentFocusDisplayObject( focusGroupIdx ); - if (component == null) { component = _stage; } // If nothing is selected, dispatch input from the stage? - var newEvent:InputEvent = event.clone() as InputEvent; // We have to do this to be able to check handled property when a component calls event.handled. If we use preventDefault on the initial event, it will not work. - - var ok:Boolean; - - if (component is UIComponent) - ok = (component as UIComponent).dispatchEventAndSound(newEvent); - else - ok = component.dispatchEvent(newEvent); - - if (!ok || newEvent.handled) { return; } - - // Default focus logic - if (event.details.value == InputValue.KEY_UP) { return; } // Only key-down events have a default behaviour - var nav:String = event.details.navEquivalent; - if (nav == null) { return; } // Only navigation equivalents have a default behaviour. - - // Get current stage-focused element - var focusedElement:InteractiveObject = getCurrentFocusDisplayObject( focusGroupIdx ); - // Get what we THINK is the stage-focused element - var actualFocus:InteractiveObject = getActualFocusDisplayObject( focusGroupIdx ); - var stageFocusedElement:InteractiveObject = getSystemFocus( focusGroupIdx ); - - // TextField edge case - if (actualFocus is TextField && actualFocus == focusedElement && handleTextFieldInput(nav, controllerIdx)) { return; } - if (actualFocus is TextField && handleTextFieldInput(nav, controllerIdx)) { return; } - - var dirX:Boolean = (nav == NavigationCode.LEFT || nav == NavigationCode.RIGHT); - var dirY:Boolean = (nav == NavigationCode.UP || NavigationCode.DOWN); - - /* - trace(" \n\n\n *********** FocusHandler :: handleInput() ***************** "); - trace("_stage.focus: \t\t" + getSystemFocus(controllerIdx)); - trace( "currentFocusLookup[" + focusGroupIdx + "]: \t" + getCurrentFocusDisplayObject(focusGroupIdx) ); - trace( "actualFocusLookup[" + focusGroupIdx + "]: \t" + getActualFocusDisplayObject(focusGroupIdx) ); - */ - - // NFM: If our focusedElement is null, check stage.focus and actualFocus to see if we have any reference - // to where focus should be. This could be removed if we don't want CLIK's null focus to start from - // where ever the stage is currently focused... ultimately a small behavior choice. - if (focusedElement == null) { - if (stageFocusedElement && stageFocusedElement is UIComponent) { - focusedElement = stageFocusedElement as UIComponent; - } - } - - if (focusedElement == null) { - if (actualFocus && actualFocus is UIComponent) { - focusedElement = actualFocus as UIComponent; - } - } - - // If the focusedElement is still null, focus is "lost" and input should not change focus. - if (focusedElement == null) { return; } - - var focusContext:DisplayObjectContainer = focusedElement.parent; - var focusMode:String = FocusMode.DEFAULT; - if (dirX || dirY) { - var focusProp:String = dirX ? FocusMode.HORIZONTAL : FocusMode.VERTICAL; - while (focusContext != null) { - if (focusProp in focusContext) { - focusMode = focusContext[focusProp]; - if (focusMode != null && focusMode != FocusMode.DEFAULT) { break; } - focusContext = focusContext.parent; - } else { - break; - } - } - } else { - focusContext = null; - } - - // NFM: If our focusedElement contains a TextField, we want to look for the next enabled element from - // the textField rather than using the component which may find the TextField. This fix may not - // be required if every component is setup perfectly, but it seems like a reasonable check to add - // to avoid bugs for custom CLIK components. - if (actualFocus is TextField && actualFocus.parent == focusedElement) { - focusedElement = getSystemFocus( controllerIdx ); - } - - // Change focus manually. - var newFocus:InteractiveObject = FocusManager.findFocus(nav, /*focusContext,*/ null, focusMode == FocusMode.LOOP, focusedElement, false, controllerIdx); - - // LM: Multiple calls to stage.focus may result in this call. - // Consider using the focused setter where possible (see commented code below that wasn't working yet) - if (newFocus != null) { - // NFM: KEY_FOCUS_CHANGE's necessity is still under review. - // focusedElement.dispatchEventAndSound( new FocusEvent( FocusEvent.KEY_FOCUS_CHANGE, true, false, newFocus ) ); - setFocus(newFocus, focusGroupIdx); - } - - /* - if (newFocus is UIComponent) { (newFocus as UIComponent).focused |= index; } - else { _stage.focus = newFocus; } //LM: Missing index. - }*/ - } - - // FocusEvent.MOUSE_FOCUS_CHANGE, FocusEvent.KEY_FOCUS_CHANGE - protected function handleMouseFocusChange(event:FocusEvent):void { - handleFocusChange(event.target as InteractiveObject, event.relatedObject as InteractiveObject, event); - } - - protected function handleFocusChange(oldFocus:InteractiveObject, newFocus:InteractiveObject, event:FocusEvent):void { - // trace("\n *** handleFocusChange (" + event.type + "): " + oldFocus + " -> " + newFocus); - - // Hack to work around bug in Flash where MOUSE_FOCUS_CHANGE is fired when a mouse is dragged ontop of a TextField. - // mouseDown will only ever be true within Flash Player. If this is a drag (mouseDown == true), ignore the event. - if (mouseDown && newFocus is TextField) { - event.preventDefault(); - return; - } - - // NFM, 10/31/2011: Non-selectable dynamic textFields can still receive focus. This can be undesirable - // in some cases. Setting CLIK.disableDynamicTextFieldFocus will prevent this for all - // dynamic TextFields (selectable AND non-selectable). - if (CLIK.disableDynamicTextFieldFocus && newFocus is TextField) { - var focusTF:TextField = newFocus as TextField; - if (focusTF.type == "dynamic") { - event.stopImmediatePropagation(); - event.stopPropagation(); - event.preventDefault(); - return; - } - } - - // NFM, 6/29/2011: Rather than allow the default behavior (stage.focus is moved to the target for keyboard - // and mouse focus changes [particularly mouse]), prevent the default behavior and let - // FocusHandler handle moving focus around and then setting stage.focus when it's complete. - // - // This should only be used for UIComponents (which call stage.focus = this; themselves in - // set focused()). MovieClips and TextFields can still use the default behavior. - if (newFocus is UIComponent) { - event.preventDefault(); - } - - // Do not allow the textField -> null default behaviour in the framework. Can be toggled off using CLIK.as. - if (oldFocus is TextField && newFocus == null && CLIK.disableTextFieldToNullFocusMoves) { - event.preventDefault(); - return; - } - - var sfEvent:FocusEventEx = event as FocusEventEx; - var controllerIdx:uint = sfEvent == null ? 0 : sfEvent.controllerIdx; - var focusGroupIdx:uint = FocusManager.getControllerFocusGroup(controllerIdx); - - /* - // AS2 Special Case: If the MovieClip that included focus was unloaded and reloaded, then the FocusHandler - // thinks the new instance is the unloaded one and considers the new instance as - // the currently focused element - which is incorrect. Check if actualFocus or - // actualFocus._parent.focused (for TextField) is false - if so, reapply focus. - // NFM: Not clear on whether this is necessary for AS2. - var actualFocus:MovieClip = actualFocusLookup[focusIdx]; - if (actualFocus == newFocus) { - var np:MovieClip = (newFocus instanceof TextField) ? newFocus._parent : newFocus; - var npf:Number = np.focused; - if (npf & (1 << focusIdx) == 0) { - np.focused = npf | (1 << focusIdx); - } - } - */ - - // Storing stage focus - setActualFocusDisplayObject( focusGroupIdx, newFocus ); - setFocus(newFocus, focusGroupIdx, (event.type == FocusEvent.MOUSE_FOCUS_CHANGE)); - } - - protected function updateActualFocus(event:FocusEvent):void { - var oldFocus:InteractiveObject; - var newFocus:InteractiveObject; - if (event.type == FocusEvent.FOCUS_IN) { // FOCUS_IN - oldFocus = event.relatedObject as InteractiveObject; // old -> event.relatedObject - newFocus = event.target as InteractiveObject; // new -> event.target. - } else { // FOCUS_OUT - oldFocus = event.target as InteractiveObject; // old -> event.target. - newFocus = event.relatedObject as InteractiveObject; // new -> event.relatedObject. - } - - // trace("\n *** updateActualFocus: (" + event.type + "): " + oldFocus + " -> " + newFocus); - - if (event.type == FocusEvent.FOCUS_OUT) { // NFM: Should this only be for FOCUS_OUT? (Probably, but could use review.) - if (preventStageFocusChanges) { - event.stopImmediatePropagation(); - event.stopPropagation(); - } - } - - var sfEvent:FocusEventEx = event as FocusEventEx; - var controllerIdx:uint = sfEvent == null ? 0 : sfEvent.controllerIdx; - var focusGroupIdx:uint = FocusManager.getControllerFocusGroup(controllerIdx); - setActualFocusDisplayObject(focusGroupIdx, newFocus); - - // In the case of a TextInput (or a similar component), we need to ensure that whenever focus is supposed to move - // to the TextInput (regardless of how [mouse, keyboard, stage.focus, FocusHandler.setFocus, tab, arrow keys, etc..], - // actualFocus == textField and currentFocus == TextInput. To do so, TextInput must change FocusHandler.focus - // and stage.focus when FocusIn events are fired by the textField or itself. - // - // To avoid unnecessary updates to stage.focus and FocusHandler, if stage.focus is being moved from - // the old currentFocus to a textField and the textField is a child of currentFocus, do not call setFocus() since - // this is (hopefully!) just the TextInput ensuring that all focus references are pointing to the correct - // targets. - var currentFocus:InteractiveObject = getCurrentFocusDisplayObject( focusGroupIdx ); - if (newFocus != null && newFocus is TextField && newFocus.parent != null && - currentFocus == newFocus.parent && currentFocus == oldFocus) { - return; - } - - // NFM: This logic allows users to use _stage.focus = rather than FocusHandler.setFocus(). - var isActualFocusTextField:Boolean = newFocus is TextField; - var isCurrentFocusUIComponent:Boolean = currentFocus is UIComponent; - // If _stage.focus doesn't match our current framework focus - if (newFocus != currentFocus) { - // If framework focus is a UIComponent and _stage.focus is pointed to a textField, leave both be. - // If _stage.focus was just set to null, make sure we update framework focus (eg. stage.focus = null). - if (!(isActualFocusTextField && isCurrentFocusUIComponent) || newFocus == null) { - if (!preventStageFocusChanges || isActualFocusTextField) { - setFocus(newFocus, focusGroupIdx); // Update the framework focus manually. - } - } - } - } - - // @TODO: Selection.getCaretIndex(controllerIdx:Number) in AS2 needs AS3 support. - protected function handleTextFieldInput(nav:String, controllerIdx:uint):Boolean { - var actualFocus:TextField = getActualFocusDisplayObject( controllerIdx ) as TextField; - if (actualFocus == null) { return false; } - - var position:int = actualFocus.caretIndex; //Selection.getCaretIndex(controllerIdx); //LM: Might have to look this up differently. - var focusIdx:Number = 0; //Selection.getControllerFocusGroup(controllerIdx); //LM: Not implemented in GFx yet. - - switch(nav) { - case NavigationCode.UP: - if (!actualFocus.multiline) { - return false; - } - // Fall through to next case. - case NavigationCode.LEFT: - return (position > 0); - - - case NavigationCode.DOWN: - if (!actualFocus.multiline) { - return false; - } - // Fall through to next case. - case NavigationCode.RIGHT: - return (position < actualFocus.length); - } - - return false; - } - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/managers/InputDelegate.as b/src/scaleform/clik/managers/InputDelegate.as deleted file mode 100644 index e29d462..0000000 --- a/src/scaleform/clik/managers/InputDelegate.as +++ /dev/null @@ -1,189 +0,0 @@ -/************************************************************************** - -Filename : InputDelegate.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.managers { - - import flash.display.Stage; - import flash.events.EventDispatcher; - import flash.events.KeyboardEvent; - import flash.ui.Keyboard; - import scaleform.clik.core.CLIK; - - import scaleform.clik.events.InputEvent; - import scaleform.clik.ui.InputDetails; - import scaleform.clik.constants.InputValue; - import scaleform.clik.constants.NavigationCode; - - import scaleform.gfx.KeyboardEventEx; - - [Event(name="input", type="scaleform.clik.events.InputEvent")] - - public class InputDelegate extends EventDispatcher { - - // Singleton access - private static var instance:InputDelegate; - public static function getInstance():InputDelegate { - if (instance == null) { instance = new InputDelegate(); } - return instance; - } - - // Constants: - public static const MAX_KEY_CODES:uint = 1000; - public static const KEY_PRESSED:uint = 1; - public static const KEY_SUPRESSED:uint = 2; - - // Public Properties: - public var stage:Stage; - public var externalInputHandler:Function; - - // Protected Properties: - protected var keyHash:Array; // KeyHash stores all key code states and supression rules. We use a flat array, which uses a max-keys multiplier to look up controller-specific key rules and states. Each key state is a bit containing the appropriate flags. - - // Initialization: - public function InputDelegate() { - keyHash = []; - } - - public function initialize(stage:Stage):void { - this.stage = stage; - stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown, false, 0, true); - stage.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp, false, 0, true); - } - - // Public getter / setters: - - // Public Methods: - public function setKeyRepeat(code:Number, repeat:Boolean, controllerIndex:uint=0):void { - var index:uint = controllerIndex * MAX_KEY_CODES + code; - // Note that bitwise operation against null is the same as against 0, so we don't have to initialize the property. - if (repeat) { - keyHash[index] &= ~KEY_SUPRESSED; - } else { - keyHash[index] |= KEY_SUPRESSED; - } - } - - public function inputToNav(type:String, code:Number, shiftKey:Boolean = false, value:*=null):String { - // Keys, likely the PC Keyboard. - - if (externalInputHandler != null) { - return externalInputHandler(type, code, value); - } - - if (type == "key") { - switch (code) { - case Keyboard.UP: - return NavigationCode.UP; - case Keyboard.DOWN: - return NavigationCode.DOWN; - case Keyboard.LEFT: - return NavigationCode.LEFT; - case Keyboard.RIGHT: - return NavigationCode.RIGHT; - case Keyboard.ENTER: - case Keyboard.SPACE: - return NavigationCode.ENTER; - case Keyboard.BACKSPACE: - return NavigationCode.BACK; - case Keyboard.TAB: - if (shiftKey) { return NavigationCode.SHIFT_TAB; } - else { return NavigationCode.TAB; } - case Keyboard.HOME: - return NavigationCode.HOME; - case Keyboard.END: - return NavigationCode.END; - case Keyboard.PAGE_DOWN: - return NavigationCode.PAGE_DOWN; - case Keyboard.PAGE_UP: - return NavigationCode.PAGE_UP; - case Keyboard.ESCAPE: - return NavigationCode.ESCAPE; - } - - if (CLIK.testGamePad) - { - switch (code) { - // Custom handlers for gamepad support - case 96: // NumPad_0 - return NavigationCode.GAMEPAD_A; - case 97: // NumPad_1 - return NavigationCode.GAMEPAD_B; - case 98: // NumPad_2 - return NavigationCode.GAMEPAD_X; - case 99: // NumPad_3 - return NavigationCode.GAMEPAD_Y; - case 100: // NumPad_4 - return NavigationCode.GAMEPAD_L1; - case 101: // NumPad_5 - return NavigationCode.GAMEPAD_L2; - case 102: // NumPad_6 - return NavigationCode.GAMEPAD_L3; - case 103: // NumPad_7 - return NavigationCode.GAMEPAD_R1; - case 104: // NumPad_8 - return NavigationCode.GAMEPAD_R2; - case 105: // NumPad_9 - return NavigationCode.GAMEPAD_R3; - case 106: // NumPad_Multiply - return NavigationCode.GAMEPAD_START; - case 107: // NumPad_Add - return NavigationCode.GAMEPAD_BACK; - } - } - } - - - return null; - } - - //LM: Review: Can we do function callBacks? - public function readInput(type:String, code:int, callBack:Function):Object { - // Look up game engine stuff - return null; - } - - // Protected Methods: - protected function handleKeyDown(event:KeyboardEvent):void { - var sfEvent:KeyboardEventEx = event as KeyboardEventEx; - var controllerIdx:uint = (sfEvent == null) ? 0 : sfEvent.controllerIdx; - - var code:Number = event.keyCode; - var keyStateIndex:uint = controllerIdx * MAX_KEY_CODES + code; - var keyState:uint = keyHash[keyStateIndex]; - - if (keyState & KEY_PRESSED) { - if ((keyState & KEY_SUPRESSED) == 0) { - handleKeyPress(InputValue.KEY_HOLD, code, controllerIdx, event.ctrlKey, event.altKey, event.shiftKey); - } - } else { - handleKeyPress(InputValue.KEY_DOWN, code, controllerIdx, event.ctrlKey, event.altKey, event.shiftKey); - keyHash[keyStateIndex] |= KEY_PRESSED; - } - } - - protected function handleKeyUp(event:KeyboardEvent):void { - var sfEvent:KeyboardEventEx = event as KeyboardEventEx; - var controllerIdx:uint = (sfEvent == null) ? 0 : sfEvent.controllerIdx; - - var code:Number = event.keyCode; - var keyStateIndex:uint = controllerIdx * MAX_KEY_CODES + code; - keyHash[keyStateIndex] &= ~KEY_PRESSED; - handleKeyPress(InputValue.KEY_UP, code, controllerIdx, event.ctrlKey, event.altKey, event.shiftKey); - } - - protected function handleKeyPress(type:String, code:Number, controllerIdx:Number, ctrl:Boolean, alt:Boolean, shift:Boolean):void { - var details:InputDetails = new InputDetails("key", code, type, inputToNav("key", code, shift), controllerIdx, ctrl, alt, shift); - dispatchEvent(new InputEvent(InputEvent.INPUT, details)); - } - - } -} \ No newline at end of file diff --git a/src/scaleform/clik/managers/PopUpManager.as b/src/scaleform/clik/managers/PopUpManager.as deleted file mode 100644 index 3e393e9..0000000 --- a/src/scaleform/clik/managers/PopUpManager.as +++ /dev/null @@ -1,166 +0,0 @@ -/************************************************************************** - -Filename : PopUpManager.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.managers { - - import flash.display.DisplayObject; - import flash.display.DisplayObjectContainer; - import flash.display.MovieClip; - import flash.display.Shape; - import flash.display.Sprite; - import flash.display.Stage; - import flash.events.Event; - import flash.geom.Point; - import scaleform.gfx.FocusManager; - - public class PopUpManager { - protected static var initialized:Boolean = false; - public static function init(stage:Stage, createCanvas: Boolean = true):void { - if (initialized) { return; } - PopUpManager._stage = stage; - - if(createCanvas) - checkDefaultPopupCanvasExists(); - - initialized = true; - } - - // Constants: - - // Protected Properties: - protected static var _stage:Stage; - protected static var _defaultPopupCanvas:MovieClip; - - protected static var _modalMc:Sprite; - protected static var _modalBg:Sprite; - - public static function checkDefaultPopupCanvasExists():void - { - if (_defaultPopupCanvas != null) - return; - _defaultPopupCanvas = new MovieClip(); - // Listen to children being removed from the _defaultPopupCanvas to track whether we need to actively keep - // _defaultPopupCanvas on top of everything else. - _defaultPopupCanvas.addEventListener(Event.REMOVED, handleRemovePopup, false, 0, true); - _stage.addChild(_defaultPopupCanvas); - } - - // Public Methods: - public static function show(mc:DisplayObject, x:Number = 0, y:Number = 0, scope:DisplayObjectContainer = null):void { - if (!_stage) { trace("PopUpManager has not been initialized. Automatic initialization has not occured or has failed; call PopUpManager.init() manually."); return; } - - // Remove from existing parent - if (mc.parent) { mc.parent.removeChild(mc); } - - // Reparent to popup canvas layer - handleStageAddedEvent(null); - - - checkDefaultPopupCanvasExists(); - _defaultPopupCanvas.addChild(mc); - - // Move to location by scope - if (!scope) { - scope = _stage; - } - - var p:Point = new Point(x, y); - p = scope.localToGlobal(p); - mc.x = p.x; - mc.y = p.y; - - _stage.setChildIndex(_defaultPopupCanvas, _stage.numChildren - 1); - _stage.addEventListener(Event.ADDED, PopUpManager.handleStageAddedEvent, false, 0, true); - } - - public static function showModal(mc:Sprite, mcX:Number = 0, mcY:Number = 0, bg:Sprite = null, controllerIdx:uint = 0, newFocus:Sprite = null):void { - if (!_stage) { trace("PopUpManager has not been initialized. Automatic initialization has not occured or has failed; call PopUpManager.init() manually."); return; } - - checkDefaultPopupCanvasExists(); - // Remove previous modal mc and bg if applicable - // - Background is removed via event listener automatically - if (_modalMc) { - _defaultPopupCanvas.removeChild(_modalMc); - } - - // If mc is null, return (Useful to clear a modal mc) - if (mc == null) { - return; - } - - // If bg is null, create an alpha 0 sprite the size of the stage and add it at 0, 0. - if (bg == null) { - bg = new Sprite(); - bg.graphics.lineStyle(0, 0xffffff, 0); - bg.graphics.beginFill(0xffffff, 0); - bg.graphics.drawRect(0, 0, _stage.stageWidth, _stage.stageHeight); - bg.graphics.endFill(); - } - - // Track current modal mc and bg - _modalMc = mc; - _modalBg = bg; - - // Reparent to popup canvas layer - _modalMc.x = mcX; - _modalMc.y = mcY; - _defaultPopupCanvas.addChild(_modalBg); - _defaultPopupCanvas.addChild(_modalMc); - FocusHandler.getInstance().setFocus(newFocus, controllerIdx, false); - FocusManager.setModalClip(_modalMc, controllerIdx); - - // Get notified when the modal mc is removed for cleanup purposes - _modalMc.addEventListener(Event.REMOVED_FROM_STAGE, handleRemoveModalMc, false, 0, true); - _stage.addEventListener(Event.ADDED, PopUpManager.handleStageAddedEvent, false, 0, true); - } - - // Protected Methods: - protected static function handleStageAddedEvent(e:Event):void { - // We make sure that the defaultPopupCanvas is always on top of everything else on the stage - checkDefaultPopupCanvasExists(); - _stage.setChildIndex(_defaultPopupCanvas, _stage.numChildren - 1); - } - - protected static function handleRemovePopup(e:Event):void { - removeAddedToStageListener(); - } - - protected static function handleRemoveModalMc(e:Event):void { - - _modalBg.removeEventListener(Event.REMOVED_FROM_STAGE, handleRemoveModalMc, false); - if (_modalBg) { - - checkDefaultPopupCanvasExists(); - // Remove modal background if applicable - _defaultPopupCanvas.removeChild(_modalBg); - } - - // Clear tracking variables - _modalMc = null; - _modalBg = null; - - // Remove from FocusManager - FocusManager.setModalClip(null); - - removeAddedToStageListener(); - } - - protected static function removeAddedToStageListener():void { - - checkDefaultPopupCanvasExists(); - if (_defaultPopupCanvas.numChildren == 0 && _modalMc == null) { - _stage.removeEventListener(Event.ADDED, PopUpManager.handleStageAddedEvent, false); - } - } - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/motion/Tween.as b/src/scaleform/clik/motion/Tween.as deleted file mode 100644 index ae08694..0000000 --- a/src/scaleform/clik/motion/Tween.as +++ /dev/null @@ -1,249 +0,0 @@ -/** - * Light-weight tween class specifically designed for use with GFx and CLIK. - * - * Usage: - * var tween1:Tween = new Tween(1000, myObject, {x:250, y:250, alpha:0}, {paused:false, ease:Strong.easeOut, onComplete:handleTweenComplete, loop:true}); - */ - -/************************************************************************** - -Filename : Tween.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.motion { - - import flash.display.Shape; - import flash.events.Event; - import flash.utils.getTimer; - - import flash.display.DisplayObject; - import flash.geom.Matrix; - import flash.geom.Transform; - - public class Tween { - - protected static var ticker:Shape = new Shape(); - protected static var workingMatrix:Matrix = new Matrix(); - ticker.addEventListener(Event.ENTER_FRAME, Tween.tick, false, 0, true); - - protected static var firstTween:Tween; - protected static var lastTime:uint = getTimer(); - protected static var degToRad:Number = 1/180*Math.PI; - - protected static function tick(evt:Event):void { - var t:Number = getTimer(); - var delta:Number = t-lastTime; - lastTime = t; - var tween:Tween = firstTween; - while (tween) { - var nextTween:Tween = tween.next; - tween.updatePosition(tween.frameBased ? 1 : delta); - tween = nextTween; - } - } - - /** Removes a particular tween from the list of tweens being executed. */ - protected static function removeTween(tween:Tween):void { - if (tween.prev) { tween.prev.next = tween.next; } - if (tween.next) { tween.next.prev = tween.prev; } - if (tween == firstTween) { firstTween = tween.next; } - tween.prev = tween.next = null; - } - - /** Removes all tweens from the list and stops execution. */ - public static function removeAllTweens():void { - firstTween = null; - } - - /* - // For debugging - public static function printTweens():void { - var ret:String = ">> Tweens: "; - if (firstTween) { - var t:Tween = firstTween; - while (t) { - ret += "\t" + t.target.name; - t = t.next; - } - } - trace(ret); - } - */ - - public static var propsDO:Object = {x:true,y:true,rotation:true,scaleX:true,scaleY:true,alpha:true}; - - public var target:Object; // The object to be tweened. - public var duration:Number; // The duration of the tween in milliseconds. - public var ease:Function; // This is the easing function - public var easeParam:Object; // This is an extra parameter you can pass to the easing function - public var onComplete:Function; // This closure will be called when the Tween finishes - public var onChange:Function; // This closure will be called when the Tween updates its values (every tick/frame) - public var data:Object; // Any custom data you want to attach to the Tween (this doesn't affect its behavior in any way) - public var nextTween:Tween; // Used if you want to chain another tween. The chained tween will be set to pause=false when the current Tween finishes. - public var frameBased:Boolean = false; // Use frame based timing instead of real time - public var delay:Number=0; // Delay the tween by x number of milli-seconds - public var loop:Boolean=false; // Loops the twee if true - public var fastTransform:Boolean=true; // Use matrix math for display object properties (better to keep it true always) - - protected var invalid:Boolean; - protected var next:Tween; // linked list - protected var prev:Tween; // linked list - protected var _position:Number=0; - protected var _paused:Boolean=true; - protected var startMatrix:Matrix; - protected var deltaMatrix:Matrix; - protected var transform:Transform; - protected var targetDO:DisplayObject; - protected var firstProp:Prop; - protected var props:Object; - - /** - * Create a new Tween. - * @param duration The duration of the tween in milliseconds. - * @param target The DisplayObject to be tweened. - * @param props An Object containing the properties and values that should be tweened to. - * @param quickSet An Object containing properties for the tween including paused, ease, onComplete, loop, delay, and nextTween. - */ - public function Tween(duration:Number, target:Object=null, props:Object=null, quickSet:Object=null) { - this.duration = duration; - this.target = target; - if (target is DisplayObject) { - targetDO = DisplayObject(target); - transform = targetDO.transform; - } - this.props = props; - if (quickSet) { this.quickSet(quickSet); } - if (quickSet == null || quickSet.paused == null) { this.paused = false; } - } - - public function set position(value:Number):void { - updatePosition(value+delay-_position); - } - public function get position():Number { - return _position-delay; - } - - public function get paused():Boolean { - return _paused; - } - public function set paused(value:Boolean):void { - if (value == _paused) { return; } - _paused = value; - if (value) { - removeTween(this); // When the tween is complete, it is immediately removed. - } else { - if (firstTween) { // Insert this tween at the front of the tween list. - firstTween.prev = this; - next = firstTween; - } - firstTween = this; - if (_position >= delay + duration) { _position = 0; } - } - } - - public function reset():void { - _position = 0; - } - - public function quickSet(props:Object):void { - for (var name:String in props) { - this[name] = props[name]; - } - } - - protected function constructProp(name:String):Prop { - var prop:Prop = new Prop(); - prop.name = name; - prop.prev = null; - if (firstProp) { firstProp.prev = prop; } - prop.next = firstProp; - return firstProp = prop; - } - - protected function init():void { - var useMatrix:Boolean = false - for (var name:String in props) { - if (fastTransform && transform && propsDO[name]) { useMatrix=true; continue; } - var prop:Prop = constructProp(name); - prop.delta = props[name]-(prop.start = target[name]); - } - if (useMatrix) { - startMatrix = new Matrix(targetDO.scaleX,targetDO.rotation*degToRad,targetDO.alpha,targetDO.scaleY,targetDO.x,targetDO.y); - deltaMatrix = new Matrix(isNaN(props.scaleX) ? 0 : props.scaleX-startMatrix.a, - isNaN(props.rotation) ? 0 : (props.rotation-targetDO.rotation)*degToRad, - isNaN(props.alpha) ? 0 : props.alpha-startMatrix.c, - isNaN(props.scaleY) ? 0 : props.scaleY-startMatrix.d, - isNaN(props.x) ? 0 : props.x-startMatrix.tx, - isNaN(props.y) ? 0 : props.y-startMatrix.ty); - } - props = null; - } - - protected function updatePosition(value:Number):void { - // Check to see if the target went out of scope. If so, stop advancing the tween. - if (target == null) { - paused = true; - complete = true; - return; - } - - _position += value; - if (_position <= delay) { return } - if (props) { init(); } - - var ratio:Number = (_position-delay)/duration; - var complete:Boolean = (ratio >= 1); - if (complete) { ratio = 1; _position = duration+delay; } - if (ease != null) { ratio = (easeParam == null) ? ease(ratio,0,1,1) : ease(ratio, 0,1,1, easeParam); } - - if (startMatrix) { - var r:Number = startMatrix.b+deltaMatrix.b*ratio; - if (r) { - var c:Number = Math.cos(r); - var s:Number = Math.sin(r); - } else { - c = 1; - s = 0; - } - workingMatrix.a = c*startMatrix.a+deltaMatrix.a*ratio; - workingMatrix.b = s; - workingMatrix.c = -s; - workingMatrix.d = c*startMatrix.d+deltaMatrix.d*ratio; - workingMatrix.tx = startMatrix.tx+deltaMatrix.tx*ratio; - workingMatrix.ty = startMatrix.ty+deltaMatrix.ty*ratio; - transform.matrix = workingMatrix; - if (deltaMatrix.c) { targetDO.alpha = startMatrix.c+deltaMatrix.c*ratio; } - } - - var prop:Prop = firstProp; - while (prop) { - target[prop.name] = prop.start + prop.delta*ratio; - prop = prop.next; - } - - if (onChange != null) { onChange(this); } - if (complete) { - if (loop) { reset(); } - else { paused = true; } - if (nextTween) { nextTween.paused = false; } - if (onComplete != null) { onComplete(this); } - } - } - } -} - -final class Prop { - public var next:Prop; - public var prev:Prop; - - public var name:String; - public var start:Number; - public var delta:Number; -} \ No newline at end of file diff --git a/src/scaleform/clik/ui/InputDetails.as b/src/scaleform/clik/ui/InputDetails.as deleted file mode 100644 index aa03b92..0000000 --- a/src/scaleform/clik/ui/InputDetails.as +++ /dev/null @@ -1,56 +0,0 @@ -/** - * An InputDetails object is generated by the InputDelegate, and contains relevant information about user input, such as controller buttons, keyboard keys, etc. - */ - -/************************************************************************** - -Filename : InputDetails.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.ui { - - public class InputDetails { - - // Constants: - // Public Properties: - public var type:String; - public var code:Number; - public var value:*; - public var navEquivalent:String; - public var controllerIndex:uint; - public var ctrlKey:Boolean; - public var altKey:Boolean; - public var shiftKey:Boolean - - // Private Properties: - // Initialization: - public function InputDetails(type:String, code:Number, value:*, navEquivalent:String = null, controllerIndex:uint = 0, - ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false) { - this.type = type; - this.code = code; - this.value = value; - this.navEquivalent = navEquivalent; - this.controllerIndex = controllerIndex; - this.ctrlKey = ctrlKey; - this.altKey = altKey; - this.shiftKey = shiftKey; - } - - // Public Methods: - public function toString():String { - return "[InputDetails code=" + code + ", type=" + type + " value=" + value + ", navEquivalent=" + navEquivalent + - ", controllerIndex=" + controllerIndex + ", ctrlKey=" + ctrlKey + ", altKey=" + altKey + ", shiftKey=" + shiftKey + "]"; - } - - // Private Methods: - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/utils/ConstrainedElement.as b/src/scaleform/clik/utils/ConstrainedElement.as deleted file mode 100644 index b1a3d3b..0000000 --- a/src/scaleform/clik/utils/ConstrainedElement.as +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Wrapper and data structure for a DisplayObject under CLIK Constraints. - */ - -/************************************************************************** - -Filename : ConstraintedElement.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.utils { - - import flash.display.DisplayObject; - - public class ConstrainedElement { - - // Constants: - - // Public Properties: - public var clip:DisplayObject; - public var edges:uint; - - public var left:Number; - public var top:Number; - public var right:Number; - public var bottom:Number; - - public var scaleX:Number; - public var scaleY:Number; - - // public var originalWidth:Number; - // public var originalHeight:Number; - - // Initialization: - public function ConstrainedElement(clip:DisplayObject, edges:uint, - left:Number, top:Number, right:Number, bottom:Number, - scaleX:Number, scaleY:Number) { - - this.clip = clip; - this.edges = edges; - - this.left = left; - this.top = top; - this.right = right; - this.bottom = bottom; - - this.scaleX = scaleX; - this.scaleY = scaleY; - } - - // Public getter / setters: - - // Public Methods: - public function toString():String { - return "[ConstrainedElement "+clip+", edges="+edges+", left="+left+", right="+right+", top="+top+", bottom="+bottom+", scaleX="+scaleX+", scaleY="+scaleY+"]"; - } - - // Protected Methods: - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/utils/Constraints.as b/src/scaleform/clik/utils/Constraints.as deleted file mode 100644 index 374b291..0000000 --- a/src/scaleform/clik/utils/Constraints.as +++ /dev/null @@ -1,338 +0,0 @@ -/** - * The Constraints utility helps symbols scale and align the assets contained within them. Elements can be added to a Constraints instance, and they will be reflowed when the {@code update(width,height)} method is called. - * - * This utility supports both re-scaling and counter-scaling methods. Rescaling occurs when the component is scaled back to 100%, and the assets are reflowed and scaled to look correct. Counter-scaling occurs when the component is left at its transformed size, and the assets are scaled inversely to the parent clip. - */ - -/************************************************************************** - -Filename : Constraints.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.utils { - - import flash.display.DisplayObject; - import flash.display.DisplayObjectContainer; - import flash.display.MovieClip; - import flash.display.Sprite; - import flash.display.Stage; - import flash.events.Event; - import flash.events.EventDispatcher; - import flash.text.TextField; - - import scaleform.clik.constants.ConstrainMode; - import scaleform.clik.controls.ScrollBar; - import scaleform.clik.core.UIComponent; - import scaleform.clik.events.ResizeEvent; - - public class Constraints extends EventDispatcher { - - // Constants: - public static const LEFT:uint = 1; - public static const RIGHT:uint = 2; - public static const TOP:uint = 4; - public static const BOTTOM:uint = 8; - public static var ALL:uint = LEFT | RIGHT | TOP | BOTTOM; - - public static const CENTER_H:uint = 16; - public static const CENTER_V:uint = 32; - - // Public Properties: - /** - * The component that owns the constraints, and which is the direct parent to the display objects - * getting constrained. - */ - public var scope:DisplayObject; - - /** - * Determines how the component scales its children. - */ - public var scaleMode:String = ConstrainMode.COUNTER_SCALE; - - /** - * The x scale factor of the parent, which is a composite scale that originates from the stage, factoring - * in all components or clips above it that use a constraints. This value does not include the current scope - * scale value. - * @default 1 - */ - public var parentXAdjust:Number = 1; - public var parentYAdjust:Number = 1; - - // Private Properties: - //LM: Consider using Dictionary instead for faster lookups - protected var elements:Object; - protected var elementCount:int = 0; - /** - * A reference to the constraints that belong to the first container above the scope that specifies - * a Constraints of its own. This is found by calling {@code addToParentConstraints()}. - */ - protected var parentConstraints:Constraints; - - /** - * The last width set on this constraints by the scope. This value is stored off in order to preserve - * it if the parent constraints updates its scale value. The component needs to be updated with its last - * known width and the new scale value. - */ - public var lastWidth:Number = NaN; - public var lastHeight:Number = NaN; - - // Initialization: - /** - * Create a new Constraints instance to assist in the positioning and scaling of an asset inside a component. - * Note that it is VERY important that constraints instances in components are created before the super() call - * to ensure parent constraints are initialized. - * @param scope The component scope which contains the constrained asset. - * @param scaleMode Determines how the component scales its elements. The default is counter-scaling. - */ - public function Constraints(scope:Sprite, scaleMode:String="counterScale") { - this.scope = scope; - this.scaleMode = scaleMode; - elements = {}; - - lastWidth = scope.width; - lastHeight = scope.height; - - scope.addEventListener(Event.ADDED_TO_STAGE, handleScopeAddedToStage, false, 0, true); - scope.addEventListener(Event.REMOVED_FROM_STAGE, handleScopeAddedToStage, false, 0, true); - } - - // Public Methods: - public function addElement(name:String, clip:DisplayObject, edges:uint):void { - if (clip == null) { return; } - - // Determine the scope width. If it is the stage, use the full swf size, otherwise we get 0,0. - var w:Number = scope.width; - var h:Number = scope.height; - if (scope.parent != null && scope.parent is Stage) { - w = scope.stage.stageWidth; - h = scope.stage.stageHeight; - } - - var element:ConstrainedElement = new ConstrainedElement( - clip, edges, - clip.x, - clip.y, - w/scope.scaleX - (clip.x + clip.width), - h/scope.scaleY - (clip.y + clip.height), - clip.scaleX, clip.scaleY - ); - - if (elements[name] == null) { elementCount++; } - elements[name] = element; - } - - public function removeElement(name:String):void { - if (elements[name] != null) { elementCount--; } - delete elements[name]; - } - - public function removeAllElements():void { - for (var name:String in elements) { - if (elements[name] is ConstrainedElement) { - elementCount--; - delete elements[name]; - } - } - } - - /** - * Get the contraints rules for a given object. - * @param clip A reference to the DisplayObject (Sprite or TextField) the contraints apply to. - * @returns the constraints rules object for the specified clip - */ - public function getElement(name:String):ConstrainedElement { - return elements[name] as ConstrainedElement; - } - - /** - * Update the reference to a display object. This is required if the component exists on multiple - * frames, as Flash will re-assign the reference, but not update external references, such as - * the {@code ConstrainedElement}. - * @param name The name of the clip in the ConstrainedElement - * @param clip The new reference to the display object. - */ - public function updateElement(name:String, clip:DisplayObject):void { - if (clip == null) { return; } - var element:ConstrainedElement = elements[name] as ConstrainedElement; - if (element == null) { return; } - element.clip = clip; - } - - /** - * Determine the x scale adjustment factoring in the parent scale and the scope scale. Used internally - * but is also requested by child constraints when determining their own scale. - */ - public function getXAdjust():Number { - if (scaleMode == ConstrainMode.REFLOW) { return parentXAdjust; } - return parentXAdjust / scope.scaleX; - } - - public function getYAdjust():Number { - if (scaleMode == ConstrainMode.REFLOW) { return parentYAdjust; } - return parentYAdjust / scope.scaleY; - } - - /** - * Change the width/height and x/y of each registered component based on the scope's updated size and the constraint rules. - * This is usually called by the scope when its size changes, but may also be called when a parent constraints changes its - * scale value. - * @param width The new width of the scope component. - * @param height The new height of the scope component. - */ - public function update(width:Number, height:Number):void { - lastWidth = width; - lastHeight = height; - if (elementCount == 0) { return; } - - // Deterine the counter-scale factor - var xAdjust:Number = getXAdjust(); - var yAdjust:Number = getYAdjust(); - - var counterScale:Boolean = (scaleMode == ConstrainMode.COUNTER_SCALE); - - // Loop through elements, and adjust each one - for (var n:String in elements) { - var element:ConstrainedElement = elements[n] as ConstrainedElement; - var edges:uint = element.edges; - var clip:DisplayObject = element.clip; - - if (counterScale) { - - clip.scaleX = element.scaleX * xAdjust; - clip.scaleY = element.scaleY * yAdjust; - - if ((edges & Constraints.CENTER_H) == 0) { - if ((edges & Constraints.LEFT) > 0) { - clip.x = element.left * xAdjust; - if ((edges & Constraints.RIGHT) > 0) { - var nw:Number = (width - element.left - element.right); - if (!(clip is TextField)) { nw = nw * xAdjust; } - clip.width = nw; - } - } else if ((edges & Constraints.RIGHT) > 0) { - clip.x = (width - element.right) * xAdjust - clip.width; - } - } - if ((edges & Constraints.CENTER_V) == 0) { - if ((edges & Constraints.TOP) > 0) { - clip.y = element.top * yAdjust; - if ((edges & Constraints.BOTTOM) > 0) { - var nh:Number = height - element.top - element.bottom; - if (!(clip is TextField)) { nh = nh * yAdjust; } - clip.height = nh; - } - } else if ((edges & Constraints.BOTTOM) > 0) { - clip.y = (height - element.bottom) * yAdjust - clip.height; - } - } - } - - // Use reflowing - else { - //LM: Might have to use xAdjust/yAdjust because a parent could use counterScaling. - //LM: Adjusted scale to accommodate counter-scaling. - if ((edges & Constraints.CENTER_H) == 0 && (edges & Constraints.RIGHT) > 0) { - if ((edges & Constraints.LEFT) > 0) { - clip.width = width - element.left - element.right; // Stretch - } else { - clip.x = width - clip.width - element.right; // Just move - } - } - - if ((edges & Constraints.CENTER_V) == 0 && (edges & Constraints.BOTTOM) > 0) { - if ((edges & Constraints.TOP) > 0) { - clip.height = height - element.top - element.bottom; - } else { - clip.y = height - clip.height - element.bottom; - } - } - - if (clip is UIComponent) { - (clip as UIComponent).validateNow(); - } - } - - if ((edges & Constraints.CENTER_H) > 0) { - clip.x = (width * 0.5 * xAdjust) - (clip.width * 0.5); - } - - if ((edges & Constraints.CENTER_V) > 0) { - clip.y = (height * 0.5 * yAdjust) - (clip.height * 0.5); - } - - } - - // Set this after, because it causes invalidation in components. - if (!counterScale) { - scope.scaleX = parentXAdjust; - scope.scaleY = parentYAdjust; - } - - if (hasEventListener(ResizeEvent.RESIZE)) { - dispatchEvent(new ResizeEvent(ResizeEvent.RESIZE, xAdjust, yAdjust)); - } - } - - /** @exclude */ - override public function toString():String { - var l:uint = elements.length; - var str:String = "[CLIK Constraints (" + l + ")]"; - for (var n:String in elements) { - str += "\n\t" + n + ": " + elements[n].toString(); - } - return str; - } - - // Protected Methods: - protected function handleScopeAddedToStage(event:Event):void { - addToParentConstraints(); - } - - protected function addToParentConstraints():void { - if (parentConstraints != null) { - parentConstraints.removeEventListener(ResizeEvent.RESIZE, handleParentConstraintsResize); - } - parentConstraints = null; - - var p:DisplayObjectContainer = scope.parent; - if (p == null) { return; } - - while (p != null) { - if (p.hasOwnProperty("constraints")) { - parentConstraints = p["constraints"] as Constraints; - // Only add if immediate parent is COUNTER_SCALED to compensate for parent's scaling. Immediate parent's scale - // will not change for reflowing. !! Experimental. - if (parentConstraints != null && parentConstraints.scaleMode == ConstrainMode.REFLOW) { return; } - else if (parentConstraints != null && scaleMode == ConstrainMode.REFLOW) { return; } // NFM: 10/10: Added for TextArea. - if (parentConstraints != null) { - parentConstraints.addEventListener(ResizeEvent.RESIZE, handleParentConstraintsResize, false, 0, true); - break; - } - } - p = p.parent; - } - - // TD: optimize: - if (parentConstraints != null) { - parentXAdjust = parentConstraints.getXAdjust(); - parentYAdjust = parentConstraints.getYAdjust(); - } - } - - // Event Handlers: - protected function handleParentConstraintsResize(event:ResizeEvent):void { - parentXAdjust = event.scaleX; - parentYAdjust = event.scaleY; - update(lastWidth, lastHeight); - } - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/utils/GameCenterInterface.as b/src/scaleform/clik/utils/GameCenterInterface.as deleted file mode 100644 index 481af19..0000000 --- a/src/scaleform/clik/utils/GameCenterInterface.as +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************************************** - -Filename : GameCenterInterface.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.utils -{ - import flash.external.ExternalInterface; - - /** - * The GameCenterInterface allows users to access Game Center from iOS applications. Be sure to call GameCenterInterface.init() in your AS2 code. - */ - public class GameCenterInterface - { - // To be overriden by native code FunctionObjects. - public static var _loginUser:Function; - public static var _openLeaderboardPane:Function; - public static var _setLeaderboardScore:Function; - public static var _openAchievementPane:Function; - public static var _setAchievementCompletion:Function; - public static var _resetAchievements:Function; - public static var _receiveOnlineResult:Function; - - public static function init():void { - ExternalInterface.call("GameCenterInterface.init", GameCenterInterface); - } - - public static function loginUser():void { - _loginUser(); - } - - public static function openLeaderboardPane():void { - _openLeaderboardPane(); - } - - public static function setLeaderboardScore(id:String, value:Number):void { - _setLeaderboardScore(id, value); - } - - public static function openAchievementPane():void { - _openAchievementPane(); - } - - public static function setAchievementCompletion(id:String, value:Number):void { - _setAchievementCompletion(id, value); - } - - public static function resetAchievements():Boolean { - return _resetAchievements(); - } - - public static function receiveOnlineResult():Boolean { - return _receiveOnlineResult(); - } - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/utils/Padding.as b/src/scaleform/clik/utils/Padding.as deleted file mode 100644 index 6cb66cb..0000000 --- a/src/scaleform/clik/utils/Padding.as +++ /dev/null @@ -1,67 +0,0 @@ -/** - * A data structure that defines padding for the top, bottom, left, and right of a component. Use of the Padding class is at the discretion of the component. - */ -/************************************************************************** - -Filename : Padding.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.clik.utils { - - public class Padding { - - // Constants: - - // Public Properties: - public var top:Number = 0; - public var bottom:Number = 0; - public var left:Number = 0; - public var right:Number = 0; - - // Initialization: - public function Padding(...args:Array) { - switch (args.length) { - case 0: - break; - case 1: - top = right = bottom = left = Number(args[0]); - break; - case 2: - top = bottom = Number(args[0]); - right = left = Number(args[1]); - break; - case 4: - top = Number(args[0]); - right = Number(args[1]); - bottom = Number(args[2]); - left = Number(args[3]); - break; - default: - throw(new Error("Padding can not have "+args.length+" values")); - break; - - } - } - - public function get vertical():Number { - return top + bottom; - } - - public function get horizontal():Number { - return left + right; - } - - public function toString():String { - return "[Padding top=" + top + " bottom=" + bottom + " left=" + left + " right=" + right + "]"; - } - - } - -} \ No newline at end of file diff --git a/src/scaleform/clik/utils/WeakReference.as b/src/scaleform/clik/utils/WeakReference.as deleted file mode 100644 index a5bc25e..0000000 --- a/src/scaleform/clik/utils/WeakReference.as +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************** - -Filename : WeakReference.as - -Copyright : Copyright 2012 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ -package scaleform.clik.utils { - - import flash.utils.Dictionary; - - public class WeakReference { - - // Constants: - - // Public Properties: - - // Protected Properties: - protected var _dictionary:Dictionary; - - // Initialization: - public function WeakReference(obj:Object) { - _dictionary = new Dictionary( true ); // Create a weak ref dictionary. - _dictionary[obj] = 1; - } - - // Public Getter / Setters: - - // Public Methods: - - public function get value():Object { - for (var dvalue:Object in _dictionary) { - return dvalue; - } - return null; - } - - // Protected Methods: - } - -} \ No newline at end of file diff --git a/src/scaleform/gfx/DisplayObjectEx.as b/src/scaleform/gfx/DisplayObjectEx.as deleted file mode 100644 index 954256f..0000000 --- a/src/scaleform/gfx/DisplayObjectEx.as +++ /dev/null @@ -1,28 +0,0 @@ -/************************************************************************** - -Filename : DisplayObjectEx.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.display.DisplayObject; - - public class DisplayObjectEx - { - static public function disableBatching(o:DisplayObject, b:Boolean) : void { } - static public function isBatchingDisabled(o:DisplayObject) : Boolean { return false; } - - static public function setRendererString(o:DisplayObject, s:String) : void { } - static public function getRendererString(o:DisplayObject) : String { return null; } - - static public function setRendererFloat(o:DisplayObject, f:Number) : void { } - static public function getRendererFloat(o:DisplayObject) : Number { return Number.NaN; } - } -} diff --git a/src/scaleform/gfx/Extensions.as b/src/scaleform/gfx/Extensions.as deleted file mode 100644 index 56db367..0000000 --- a/src/scaleform/gfx/Extensions.as +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************************************** - -Filename : Extensions.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.display.DisplayObject; - import flash.geom.Rectangle; - import flash.text.TextField - - public final class Extensions - { - // Enable/disable GFx extensions - static public function set enabled(value:Boolean) : void {} - static public function get enabled() : Boolean { return false; } - - // Enable/disable advance of invisible MovieClips (extensions must be enabled) - static public function set noInvisibleAdvance(value:Boolean) : void {} - static public function get noInvisibleAdvance() : Boolean { return false; } - - // Returns a topmost DisplayObject instance that can be found at (x, y) coordinates (stage - // coord space). The parameter testAll (default - false) lets to search for any displayObject (otherwise, only interactive - // ones with event handlers will be used). - static public function getTopMostEntity(x:Number, y:Number, testAll:Boolean = true) : DisplayObject - { return null; } - - // Returns a topmost DisplayObject instance that can be found at current mouse cursor position. - // The parameter testAll (default - false) lets to search for any displayObject (otherwise, only interactive - // ones with event handlers will be used), mouseIndex specifies an zero-based index of the mouse (default - 0). - static public function getMouseTopMostEntity(testAll:Boolean = true, mouseIndex:uint = 0) : DisplayObject - { return null; } - - // set/get mouse cursor type, similar to flash.ui.Mouse.cursor property but supports multiple - // mouse cursors. 'cursor' param - one of the value of flash.ui.MouseCursor enums. - static public function setMouseCursorType(cursor:String, mouseIndex:uint = 0) : void {} - static public function getMouseCursorType(mouseIndex:uint = 0) : String { return ""; } - - // Returns the number of controllers available (extensions must be enabled) - static public function get numControllers() : uint { return 1; } - - // Returns the visibleRect of the stage (extensions must be enabled). - static public function get visibleRect() : Rectangle { return new Rectangle(0, 0, 0, 0); } - - // Toggle EdgeAA per DisplayObject - // - // EdgeAA configuration modes for DisplayObject types - public static const EDGEAA_INHERIT:uint = 0; // Inherit the EdgeAA mode of parent; On by default - public static const EDGEAA_ON:uint = 1; // Use EdgeAA for DisplayObject and its children, unless disabled (see EDGEAA_DISABLE) - public static const EDGEAA_OFF:uint = 2; // Do not use EdgeAA for this DisplayObject or its children - public static const EDGEAA_DISABLE:uint = 3; // Disable EdgeAA for this DisplayObject and children, overriding EDGEAA_ON settings. - // - static public function getEdgeAAMode(dispObj:DisplayObject): uint { return EDGEAA_INHERIT; } - static public function setEdgeAAMode(dispObj:DisplayObject, mode:uint):void { } - - // Configure IME support - static public function setIMEEnabled(textField:TextField, isEnabled:Boolean): void {} - - static public function get isScaleform() : Boolean { return false; } - static public var isGFxPlayer:Boolean = false; - - static public var CLIK_addedToStageCallback:Function; - static public var gfxProcessSound:Function; - } -} diff --git a/src/scaleform/gfx/FocusEventEx.as b/src/scaleform/gfx/FocusEventEx.as deleted file mode 100644 index 37f1e20..0000000 --- a/src/scaleform/gfx/FocusEventEx.as +++ /dev/null @@ -1,23 +0,0 @@ -/************************************************************************** - -Filename : FocusEventEx.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.events.FocusEvent; - - public final class FocusEventEx extends FocusEvent - { - public var controllerIdx : uint = 0; - - public function FocusEventEx(type:String) { super(type); } - } -} \ No newline at end of file diff --git a/src/scaleform/gfx/FocusManager.as b/src/scaleform/gfx/FocusManager.as deleted file mode 100644 index d4bd07a..0000000 --- a/src/scaleform/gfx/FocusManager.as +++ /dev/null @@ -1,47 +0,0 @@ -/************************************************************************** - -Filename : FocusManager.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.display.DisplayObjectContainer; - import flash.display.InteractiveObject; - import flash.display.Sprite; - - public final class FocusManager - { - static public function set alwaysEnableArrowKeys(enable:Boolean) : void {} - static public function get alwaysEnableArrowKeys() : Boolean { return false; } - - static public function set disableFocusKeys(disable:Boolean) : void {} - static public function get disableFocusKeys() : Boolean { return false; } - - static public function moveFocus(keyToSimulate : String, startFromMovie:InteractiveObject = null, includeFocusEnabledChars : Boolean = false, controllerIdx : uint = 0) : InteractiveObject { return null; } - - static public function findFocus(keyToSimulate : String, parentMovie:DisplayObjectContainer = null, loop : Boolean = false, startFromMovie:InteractiveObject = null, includeFocusEnabledChars : Boolean = false, controllerIdx : uint = 0) : InteractiveObject { return null; } - - static public function setFocus(obj:InteractiveObject, controllerIdx:uint = 0) : void { trace("FocusManager.setFocus is only usable with GFx. Use stage.focus property in Flash."); } - static public function getFocus(controllerIdx:uint = 0) : InteractiveObject { trace("FocusManager.getFocus is only usable with GFx. Use stage.focus property in Flash."); return null; } - - static public function get numFocusGroups() : uint { return 1; } - - static public function setFocusGroupMask(obj:InteractiveObject, mask:uint) : void {} - static public function getFocusGroupMask(obj:InteractiveObject) : uint { return 0x1; } - - static public function setControllerFocusGroup(controllerIdx:uint, focusGroupIdx:uint) : Boolean { return false; } - static public function getControllerFocusGroup(controllerIdx:uint) : uint { return 0; } - - static public function getControllerMaskByFocusGroup(focusGroupIdx:uint) : uint { return 0; } - - static public function getModalClip(controllerIdx:uint = 0) : Sprite { return null; } - static public function setModalClip(mc:Sprite, controllerIdx:uint = 0) : void {} - } -} \ No newline at end of file diff --git a/src/scaleform/gfx/GamePad.as b/src/scaleform/gfx/GamePad.as deleted file mode 100644 index f5edc54..0000000 --- a/src/scaleform/gfx/GamePad.as +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************** - -Filename : GamePad.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - public final class GamePad - { - // The following constants will be filled in appropriately by - // Scaleform at runtime. Flash has no concept of a GamePad and - // therefore the constants (and this class) has no use other - // than for compiler sanity during content creation. - - public static const PAD_NONE:uint = 0; - public static const PAD_BACK:uint = 0; - public static const PAD_START:uint = 0; - public static const PAD_A:uint = 0; - public static const PAD_B:uint = 0; - public static const PAD_X:uint = 0; - public static const PAD_Y:uint = 0; - public static const PAD_R1:uint = 0; // RightShoulder; - public static const PAD_L1:uint = 0; // LeftShoulder; - public static const PAD_R2:uint = 0; // RightTrigger; - public static const PAD_L2:uint = 0; // LeftTrigger; - public static const PAD_UP:uint = 0; - public static const PAD_DOWN:uint = 0; - public static const PAD_RIGHT:uint = 0; - public static const PAD_LEFT:uint = 0; - public static const PAD_PLUS:uint = 0; - public static const PAD_MINUS:uint = 0; - public static const PAD_1:uint = 0; - public static const PAD_2:uint = 0; - public static const PAD_H:uint = 0; - public static const PAD_C:uint = 0; - public static const PAD_Z:uint = 0; - public static const PAD_O:uint = 0; - public static const PAD_T:uint = 0; - public static const PAD_S:uint = 0; - public static const PAD_SELECT:uint = 0; - public static const PAD_HOME:uint = 0; - public static const PAD_RT:uint = 0; // RightThumb; - public static const PAD_LT:uint = 0; // LeftThumb; - - // Will return true if the current platform supports emitting analog events - // for specific game pad controls (such as RT - right thumb, etc.) - public static function supportsAnalogEvents():Boolean { return false; } - } -} \ No newline at end of file diff --git a/src/scaleform/gfx/GamePadAnalogEvent.as b/src/scaleform/gfx/GamePadAnalogEvent.as deleted file mode 100644 index d281388..0000000 --- a/src/scaleform/gfx/GamePadAnalogEvent.as +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************** - -Filename : GamePadAnalogEvent.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.events.Event; - - public final class GamePadAnalogEvent extends Event - { - public static const CHANGE:String = "gamePadAnalogChange"; - - public var code : uint = 0; // See scaleform.gfx.GamePad for valid pad codes - public var controllerIdx : uint = 0; - public var xvalue : Number = 0; // Normalized [-1, 1] - public var yvalue : Number = 0; // Normalized [-1, 1] - - public function GamePadAnalogEvent(bubbles:Boolean, cancelable:Boolean, code:uint, - controllerIdx:uint = 0, xvalue:Number = 0, yvalue:Number = 0) - { - super(GamePadAnalogEvent.CHANGE, bubbles, cancelable); - this.code = code; - this.controllerIdx = controllerIdx; - this.xvalue = xvalue; - this.yvalue = yvalue; - } - } -} \ No newline at end of file diff --git a/src/scaleform/gfx/InteractiveObjectEx.as b/src/scaleform/gfx/InteractiveObjectEx.as deleted file mode 100644 index 5d4c0b6..0000000 --- a/src/scaleform/gfx/InteractiveObjectEx.as +++ /dev/null @@ -1,26 +0,0 @@ -/************************************************************************** - -Filename : InteractiveObjectEx.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.display.InteractiveObject; - - public class InteractiveObjectEx extends DisplayObjectEx - { - - static public function setHitTestDisable(o:InteractiveObject, f:Boolean) : void { } - static public function getHitTestDisable(o:InteractiveObject) : Boolean { return false; } - - static public function setTopmostLevel(o:InteractiveObject, f:Boolean) : void { } - static public function getTopmostLevel(o:InteractiveObject) : Boolean { return false; } - } -} diff --git a/src/scaleform/gfx/KeyboardEventEx.as b/src/scaleform/gfx/KeyboardEventEx.as deleted file mode 100644 index 00081de..0000000 --- a/src/scaleform/gfx/KeyboardEventEx.as +++ /dev/null @@ -1,23 +0,0 @@ -/************************************************************************** - -Filename : KeyboardEventEx.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.events.KeyboardEvent; - - public final class KeyboardEventEx extends KeyboardEvent - { - public var controllerIdx : uint = 0; - - public function KeyboardEventEx(type:String) { super(type); } - } -} \ No newline at end of file diff --git a/src/scaleform/gfx/MouseCursorEvent.as b/src/scaleform/gfx/MouseCursorEvent.as deleted file mode 100644 index 87a7ffd..0000000 --- a/src/scaleform/gfx/MouseCursorEvent.as +++ /dev/null @@ -1,27 +0,0 @@ -/************************************************************************** - -Filename : MouseCursorEvent.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.events.Event; - - public final class MouseCursorEvent extends Event - { - public var cursor : String = "auto"; // see flash.ui.MouseCursor core class - public var mouseIdx : uint = 0; - - static public const CURSOR_CHANGE : String = "mouseCursorChange"; - - public function MouseCursorEvent() { super("MouseCursorEvent", false, true); } - } - -} \ No newline at end of file diff --git a/src/scaleform/gfx/MouseEventEx.as b/src/scaleform/gfx/MouseEventEx.as deleted file mode 100644 index 3c0ff0c..0000000 --- a/src/scaleform/gfx/MouseEventEx.as +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - -Filename : MouseEventEx.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.events.MouseEvent; - - public final class MouseEventEx extends MouseEvent - { - public var mouseIdx : uint = 0; - public var nestingIdx : uint = 0; - - public var buttonIdx : uint = 0; // LEFT_BUTTON, RIGHT_BUTTON, ... - - public static const LEFT_BUTTON : uint = 0; - public static const RIGHT_BUTTON : uint = 1; - public static const MIDDLE_BUTTON : uint = 2; - - public function MouseEventEx(type:String) { super(type); } - } - -} \ No newline at end of file diff --git a/src/scaleform/gfx/SystemEx.as b/src/scaleform/gfx/SystemEx.as deleted file mode 100644 index c1c2b48..0000000 --- a/src/scaleform/gfx/SystemEx.as +++ /dev/null @@ -1,52 +0,0 @@ -/************************************************************************** - -Filename : System.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - public final class SystemEx - { - // Enable/Disable opcode tracing. - static public function set actionVerbose(v:Boolean) : void {} - static public function get actionVerbose() : Boolean { return false; } - - // Set the alpha [0.0 - 1.0] value of the SWF background (value of 0.0 will hide it completely) - static public function setBackgroundAlpha(value:Number) : void {} - - // Get current stack trace formatted as a string. - static public function getStackTrace() : String { return ""; } - - // Get file name of currently executed code. - static public function getCodeFileName() : String { return ""; } - - // Return an array of file names of all loaded swfs with ActionScript code sections. - static public function getCodeFileNames() : Array { return new Array; } - - // Return data type of "v". This method is different from the standard - // describeType() because it returns String and not XML, and it returns - // more useful type description for method closures. - static public function describeType(v:*) : String { return ""; } - - // Dump object dependency graph. This is useful for tracking down - // resources that have not been released after explicit unloading. - // In some cases, resources may have complicated dependencies that - // will cause them to still be in memory. - // - // Use the following flags with printObjectsReport() - static public const REPORT_SHORT_FILE_NAMES:uint = 0x1; - static public const REPORT_NO_CIRCULAR_REFERENCES:uint = 0x2; - static public const REPORT_SUPPRESS_OVERALL_STATS:uint = 0x4; - static public const REPORT_ONLY_ANON_OBJ_ADDRESSES:uint = 0x8; - // - static public function printObjectsReport(runGarbageCollector:Boolean = true, reportFlags:uint = 0xB, swfFilter:String = null) : void {} - } -} - diff --git a/src/scaleform/gfx/TextEventEx.as b/src/scaleform/gfx/TextEventEx.as deleted file mode 100644 index a4009e2..0000000 --- a/src/scaleform/gfx/TextEventEx.as +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************** - -Filename : TextEventEx.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.events.TextEvent; - - public final class TextEventEx extends TextEvent - { - // These events are fired only if a StyleSheet has been applied to the - // target TextField. - public static const LINK_MOUSE_OVER:String = "linkMouseOver"; - public static const LINK_MOUSE_OUT:String = "linkMouseOut"; - - public var controllerIdx : uint = 0; - public var buttonIdx : uint = 0; // MouseEventEx.LEFT_BUTTON, MouseEventEx.RIGHT_BUTTON, ... - - public function TextEventEx(type:String) { super(type); } - } -} \ No newline at end of file diff --git a/src/scaleform/gfx/TextFieldEx.as b/src/scaleform/gfx/TextFieldEx.as deleted file mode 100644 index 488fa66..0000000 --- a/src/scaleform/gfx/TextFieldEx.as +++ /dev/null @@ -1,80 +0,0 @@ -/************************************************************************** - -Filename : TextFieldEx.as - -Copyright : Copyright 2011 Autodesk, Inc. All Rights reserved. - -Use of this software is subject to the terms of the Autodesk license -agreement provided at the time of installation or download, or which -otherwise accompanies this software in either electronic or hard copy form. - -**************************************************************************/ - -package scaleform.gfx -{ - import flash.text.TextField - import flash.display.BitmapData; - - public final class TextFieldEx extends InteractiveObjectEx - { - public static const VALIGN_NONE:String = "none"; - public static const VALIGN_TOP:String = "top"; - public static const VALIGN_CENTER:String = "center"; - public static const VALIGN_BOTTOM:String = "bottom"; - - public static const TEXTAUTOSZ_NONE:String = "none"; - public static const TEXTAUTOSZ_SHRINK:String = "shrink"; - public static const TEXTAUTOSZ_FIT:String = "fit"; - - public static const VAUTOSIZE_NONE:String = "none"; - public static const VAUTOSIZE_TOP:String = "top"; - public static const VAUTOSIZE_CENTER:String = "center"; - public static const VAUTOSIZE_BOTTOM:String = "bottom"; - - // The flash.text.TextField specification includes appendText. - static public function appendHtml(textField:TextField, newHtml:String) : void { } - - static public function setIMEEnabled(textField:TextField, isEnabled:Boolean): void { } - - // Sets the vertical alignment of the text inside the textfield. - // Valid values are "none", "top" (same as none), "bottom" and "center" - static public function setVerticalAlign(textField:TextField, valign:String) : void { } - static public function getVerticalAlign(textField:TextField) : String { return "none"; } - - // Sets the vertical auto size of the text inside the textfield. - // Valid values are "none", "top" (same as none), "bottom" and "center" - static public function setVerticalAutoSize(textField:TextField, vautoSize:String) : void { } - static public function getVerticalAutoSize(textField:TextField) : String { return "none"; } - - // Enables automatic resizing of the text's font size to shrink or fit the textfield. - // Valid values are "none", "shrink", and "fit" - static public function setTextAutoSize(textField:TextField, autoSz:String) : void { } - static public function getTextAutoSize(textField:TextField) : String { return "none"; } - - static public function setImageSubstitutions(textField:TextField, substInfo:Object) : void {} - static public function updateImageSubstitution(textField:TextField, id:String, image:BitmapData) : void { } - - // Disable auto-translation support for the target textfield (see GFx::Translator) - static public function setNoTranslate(textField:TextField, noTranslate:Boolean) : void {} - static public function getNoTranslate(textField:TextField) : Boolean { return false; } - - static public function setBidirectionalTextEnabled(textField:TextField, en:Boolean) : void {} - static public function getBidirectionalTextEnabled(textField:TextField) : Boolean { return false; } - - // Sets gets selection text color - static public function setSelectionTextColor(textField:TextField, selColor:uint) : void {} - static public function getSelectionTextColor(textField:TextField) : uint { return 0xFFFFFFFF; } - - // Sets gets selection background color - static public function setSelectionBkgColor(textField:TextField, selColor:uint) : void {} - static public function getSelectionBkgColor(textField:TextField) : uint { return 0xFF000000; } - - // Sets gets inactive selection text color (for not focused textfield) - static public function setInactiveSelectionTextColor(textField:TextField, selColor:uint) : void {} - static public function getInactiveSelectionTextColor(textField:TextField) : uint { return 0xFFFFFFFF; } - - // Sets gets inactive selection background color (for not focused textfield) - static public function setInactiveSelectionBkgColor(textField:TextField, selColor:uint) : void {} - static public function getInactiveSelectionBkgColor(textField:TextField) : uint { return 0xFF000000; } - } -}