Updated CreateJS project.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/1f399ec5 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/1f399ec5 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/1f399ec5 Branch: refs/heads/develop Commit: 1f399ec50a8400645b410c1b9ed543a52cdd6530 Parents: 6216d6f Author: Peter Ent <[email protected]> Authored: Tue Apr 19 11:14:57 2016 -0400 Committer: Peter Ent <[email protected]> Committed: Tue Apr 19 11:14:57 2016 -0400 ---------------------------------------------------------------------- .../CreateJS/src/main/flex/CreateJSClasses.as | 3 + .../org/apache/flex/createjs/Application.as | 331 ++++++++- .../flex/org/apache/flex/createjs/CheckBox.as | 156 ++++- .../flex/org/apache/flex/createjs/Container.as | 301 +++++++++ .../main/flex/org/apache/flex/createjs/Label.as | 150 ++++- .../flex/org/apache/flex/createjs/TextButton.as | 195 ++++-- .../apache/flex/createjs/core/CreateJSBase.as | 164 +++++ .../org/apache/flex/createjs/core/UIBase.as | 675 +++++++++++++------ .../flex/org/apache/flex/createjs/core/View.as | 325 +++++++++ .../org/apache/flex/createjs/core/ViewBase.as | 206 ------ .../org/apache/flex/createjs/graphics/Circle.as | 94 +++ .../flex/createjs/graphics/GraphicShape.as | 76 +++ .../org/apache/flex/createjs/graphics/Rect.as | 93 +++ .../src/main/resources/compile-asjs-config.xml | 1 + .../src/main/resources/compile-config.xml | 1 + .../src/main/resources/createjs-manifest.xml | 8 +- .../CreateJS/src/main/resources/defaults.css | 21 +- 17 files changed, 2258 insertions(+), 542 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as b/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as index eeafa52..816c665 100644 --- a/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as +++ b/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as @@ -27,6 +27,9 @@ package */ internal class CreateJSClasses { + import org.apache.flex.createjs.core.UIBase; UIBase; + import org.apache.flex.createjs.core.View; View; + import org.apache.flex.createjs.graphics.GraphicShape; GraphicShape; } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Application.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Application.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Application.as index 06ae1fb..46ca931 100644 --- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Application.as +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Application.as @@ -18,15 +18,14 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.createjs { - import org.apache.flex.core.ApplicationBase; - import org.apache.flex.core.IBead; - import org.apache.flex.core.IFlexInfo; - import org.apache.flex.core.IStrand; - import org.apache.flex.core.IUIBase; - import org.apache.flex.core.IValuesImpl; - import org.apache.flex.core.ValuesManager; - import org.apache.flex.createjs.core.ViewBase; - import org.apache.flex.events.Event; + import org.apache.flex.core.ApplicationBase; + import org.apache.flex.core.IApplicationView; + import org.apache.flex.core.IParent; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IValuesImpl; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; import org.apache.flex.utils.MXMLDataInterpreter; COMPILE::JS @@ -41,14 +40,82 @@ package org.apache.flex.createjs //-------------------------------------- /** - * Dispatched at startup. + * Dispatched at startup. Attributes and sub-instances of + * the MXML document have been created and assigned. + * The component lifecycle is different + * than the Flex SDK. There is no creationComplete event. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 */ [Event(name="initialize", type="org.apache.flex.events.Event")] - /** - * CreateJS Application - */ - public class Application extends org.apache.flex.core.Application implements IStrand, IFlexInfo + /** + * Dispatched at startup before the instances get created. + * Beads can call preventDefault and defer initialization. + * This event will be dispatched on every frame until no + * listeners call preventDefault(), then the initialize() + * method will be called. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="preinitialize", type="org.apache.flex.events.Event")] + + /** + * Dispatched at startup after the initial view has been + * put on the display list. This event is sent before + * applicationComplete is dispatched. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="viewChanged", type="org.apache.flex.events.Event")] + + /** + * Dispatched at startup after the initial view has been + * put on the display list. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="applicationComplete", type="org.apache.flex.events.Event")] + /** + * The Application class is the main class and entry point for a FlexJS + * application. This Application class is different than the + * Flex SDK's mx:Application or spark:Application in that it does not contain + * user interface elements. Those UI elements go in the views (ViewBase). This + * Application class expects there to be a main model, a controller, and + * an initial view. + * + * This is the CreateJS Application class which must be used in place of the normal + * FlexJS Application. CreateJS uses the HTML5 <canvas>, rather than the HTML DOM. This + * class sets up the canvas and injects the necessary HTML elements into the index.html + * file to bootstrap CreateJS. + * + * @see ViewBase + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + + COMPILE::AS3 + public class Application extends org.apache.flex.core.Application + { + // does nothing different for SWF side + } + + COMPILE::JS + public class Application extends ApplicationBase implements IStrand, IParent, IEventDispatcher { /** * FalconJX will inject html into the index.html file. Surround with @@ -63,16 +130,16 @@ package org.apache.flex.createjs super(); } - COMPILE::JS private var stage:Stage; /** + * @private * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement * @flexjsignorecoercion HTMLBodyElement * @flexjsignorecoercion HTMLCanvasElement + * @flexjsignorecoercion createjs.Stage */ - COMPILE::JS - override public function start():void + public function start():void { var body:HTMLBodyElement; var canvas:HTMLCanvasElement; @@ -91,11 +158,6 @@ package org.apache.flex.createjs body.appendChild(this.element); stage = new createjs.Stage('flexjsCanvas'); - - /* AJH is this needed - MXMLDataInterpreter.generateMXMLProperties(this, - MXMLProperties); - */ dispatchEvent('initialize'); @@ -106,15 +168,220 @@ package org.apache.flex.createjs stage.update(); } - - /** - * @flexjsignorecoercion createjs.DisplayObject - */ - COMPILE::JS - override public function addElement(c:Object, dispatchEvent:Boolean = true):void - { - stage.addChild(c.element as DisplayObject); - c.addedToParent(); - } + + /** + * The org.apache.flex.core.IValuesImpl that will + * determine the default values and other values + * for the application. The most common choice + * is org.apache.flex.core.SimpleCSSValuesImpl. + * + * @see org.apache.flex.core.SimpleCSSValuesImpl + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set valuesImpl(value:IValuesImpl):void + { + ValuesManager.valuesImpl = value; + ValuesManager.valuesImpl.init(this); + } + + /** + * The initial view. + * + * @see org.apache.flex.core.ViewBase + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Bindable("__NoChangeEvent__")] + public var initialView:IApplicationView; + + /** + * The data model (for the initial view). + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Bindable("__NoChangeEvent__")] + private var _model:Object; + + /** + * The data model (for the initial view). + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Bindable("__NoChangeEvent__")] + override public function get model():Object + { + return _model; + } + + /** + * @private + */ + [Bindable("__NoChangeEvent__")] + override public function set model(value:Object):void + { + _model = value; + } + + /** + * The controller. The controller typically watches + * the UI for events and updates the model accordingly. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var controller:Object; + + /** + * An array of data that describes the MXML attributes + * and tags in an MXML document. This data is usually + * decoded by an MXMLDataInterpreter + * + * @see org.apache.flex.utils.MXMLDataInterpreter + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get MXMLDescriptor():Array + { + return null; + } + + /** + * An method called by the compiler's generated + * code to kick off the setting of MXML attribute + * values and instantiation of child tags. + * + * The call has to be made in the generated code + * in order to ensure that the constructors have + * completed first. + * + * @param data The encoded data representing the + * MXML attributes. + * + * @see org.apache.flex.utils.MXMLDataInterpreter + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function generateMXMLAttributes(data:Array):void + { + MXMLDataInterpreter.generateMXMLProperties(this, data); + } + + /** + * The array property that is used to add additional + * beads to an MXML tag. From ActionScript, just + * call addBead directly. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var beads:Array; + + /** + * @copy org.apache.flex.core.IParent#addElement() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignorecoercion createjs.DisplayObject + */ + public function addElement(c:Object, dispatchEvent:Boolean = true):void + { + stage.addChild(c.element as DisplayObject); + c.addedToParent(); + } + + /** + * @copy org.apache.flex.core.IParent#addElementAt() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignorecoercion createjs.DisplayObject + */ + public function addElementAt(c:Object, index:int, dispatchEvent:Boolean = true):void + { + stage.addChildAt(c.element as DisplayObject, index); + c.addedToParent(); + } + + /** + * @copy org.apache.flex.core.IParent#getElementAt() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + */ + public function getElementAt(index:int):Object + { + var c:WrappedHTMLElement = stage.getChildAt(index) as WrappedHTMLElement; + return c.flexjs_wrapper; + } + + /** + * @copy org.apache.flex.core.IParent#getElementIndex() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignorecoercion createjs.DisplayObject + */ + public function getElementIndex(c:Object):int + { + return stage.getChildIndex(c.element as DisplayObject) + } + + /** + * @copy org.apache.flex.core.IParent#removeElement() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function removeElement(c:Object, dispatchEvent:Boolean = true):void + { + stage.removeChild(c.element as DisplayObject); + } + + /** + * @copy org.apache.flex.core.IParent#numElements + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get numElements():int + { + return stage.numChildren(); + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/CheckBox.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/CheckBox.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/CheckBox.as index 3ce2d50..f0dfbe8 100644 --- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/CheckBox.as +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/CheckBox.as @@ -25,58 +25,99 @@ package org.apache.flex.createjs COMPILE::JS { import createjs.Container; + import createjs.DisplayObject; import createjs.Shape; import createjs.Stage; import createjs.Text; - - import org.apache.flex.createjs.core.UIBase; + + import org.apache.flex.createjs.core.CreateJSBase; import org.apache.flex.core.WrappedHTMLElement; import org.apache.flex.events.Event; } + import org.apache.flex.core.IToggleButtonModel; + import org.apache.flex.core.graphics.IFill; + import org.apache.flex.core.graphics.SolidColor; + COMPILE::AS3 public class CheckBox extends org.apache.flex.html.CheckBox - { + { + /** + * @private + */ + public function get fill():IFill + { + return null; + } + public function set fill(value:IFill):void + { + } + + /** + * The color of the text. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get textColor():IFill + { + return null; + } + public function set textColor(value:IFill):void + { + } + + /** + * The font to use for the text. Any CSS-style font name may be used. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get fontName():String + { + return null; + } + public function set fontName(value:String):void + { + } } COMPILE::JS - public class CheckBox extends UIBase + public class CheckBox extends CreateJSBase { private var checkMark:Shape; - private var checkMarkBackground:Shape; private var checkBoxLabel:Text; + private var checkBackground:Shape; /** * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement */ - override public function createElement():WrappedHTMLElement + override protected function createElement():WrappedHTMLElement { - checkMarkBackground = new createjs.Shape(null); - checkMarkBackground.name = 'checkmarkbackground'; - checkMarkBackground.graphics.beginFill('red'). - drawRoundRect(0, 0, 40, 40, 8); - checkMark = new createjs.Shape(null); checkMark.name = 'checkmark'; - checkMark.graphics.beginFill('white').drawRoundRect(0, 0, 32, 32, 6); - checkMark.x = 4; - checkMark.y = 4; - checkMark.visible = false; - checkBoxLabel = new createjs.Text('checkbox', '20px Arial', '#ff7700'); + checkBoxLabel = new createjs.Text('checkbox', '20px Arial'); checkBoxLabel.name = 'label'; checkBoxLabel.textAlign = 'left'; checkBoxLabel.textBaseline = 'middle'; - checkBoxLabel.x = 45; - checkBoxLabel.y = 40 / 2; + + checkBackground = new createjs.Shape(null); + checkBackground.name = 'checkbackground'; var container:createjs.Container = new createjs.Container(); element = container as WrappedHTMLElement; container.name = 'checkbox'; - container.addChild(this.checkMarkBackground); + container.addChild(this.checkBackground); container.addChild(this.checkBoxLabel); container.addChild(this.checkMark); - container.onClick = clickHandler; + + checkBoxLabel.addEventListener("click", clickHandler); + checkMark.addEventListener("click", clickHandler); this.positioner = this.element; @@ -85,17 +126,18 @@ package org.apache.flex.createjs public function get text():String { - return checkBoxLabel.text; + return IToggleButtonModel(model).text; } public function set text(value:String):void { - checkBoxLabel.text = value; + IToggleButtonModel(model).text = value; + redrawShape(); } public function get selected():Boolean { - return checkMark.visible; + return IToggleButtonModel(model).selected;; } /** @@ -103,11 +145,71 @@ package org.apache.flex.createjs */ public function set selected(value:Boolean):void { - checkMark.visible = value; - var stage:Stage = (element as Container).getStage(); - if (stage) - stage.update(); + IToggleButtonModel(model).selected = value; + redrawShape(); + + dispatchEvent( new org.apache.flex.events.Event("change") ); } + + private var _fontName:String = "18px Arial" + + /** + * The font to use for the text. Any CSS-style font name may be used. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get fontName():String + { + return _fontName; + } + public function set fontName(value:String):void + { + _fontName = value; + redrawShape(); + } + + /** + * @private + * @flexjsignorecoercion createjs.Container + */ + override protected function redrawShape():void + { + var color:String = "black"; + if (textColor != null) { + color = convertColorToString((textColor as SolidColor).color, 1.0); + } + + var fillColor:String = "DeepSkyBlue"; + var fillAlpha:Number = 1.0; + if (fill != null) { + fillAlpha = (fill as SolidColor).alpha; + fillColor = convertColorToString((fill as SolidColor).color, fillAlpha); + } + + var label:createjs.Text = element as createjs.Text; + checkBoxLabel.text = text; + checkBoxLabel["font"] = fontName; + checkBoxLabel["color"] = color; + + checkBoxLabel.x = 45; + checkBoxLabel.y = 40 / 2; + + checkMark.graphics.setStrokeStyle(1); + checkMark.graphics.beginStroke('gray'); + checkMark.graphics.beginFill(selected?fillColor:'white'); + checkMark.graphics.drawRoundRect(0, 0, 32, 32, 6); + checkMark.graphics.endFill(); + checkMark.graphics.endStroke(); + checkMark.x = 4; + checkMark.y = 4; + + var stage:Stage = checkBoxLabel.getStage(); + if (stage) + stage.update(); + } /** http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Container.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Container.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Container.as new file mode 100644 index 0000000..697c41e --- /dev/null +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Container.as @@ -0,0 +1,301 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.createjs +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IChrome; + import org.apache.flex.core.IContainer; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.IMXMLDocument; + import org.apache.flex.core.IStatesObject; + import org.apache.flex.core.IStatesImpl; + import org.apache.flex.core.IContainer; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.ValueChangeEvent; + import org.apache.flex.states.State; + import org.apache.flex.utils.MXMLDataInterpreter; + + COMPILE::AS3 + { + import org.apache.flex.html.Container; + } + + COMPILE::JS + { + import createjs.Container; + import createjs.Stage; + import createjs.DisplayObject; + import org.apache.flex.core.WrappedHTMLElement; + + import org.apache.flex.createjs.core.UIBase; + } + + + + [DefaultProperty("mxmlContent")] + + /** + * Provides a nestable Container for CreateJS elements. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + COMPILE::AS3 + public class Container extends org.apache.flex.html.Container + { + // does nothing different for SWF version. + } + + + /** + * CreateJS Container + */ + COMPILE::JS + public class Container extends UIBase implements IStatesObject, IContainer + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function Container() + { + super(); + } + + /** + * @private + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + * @flexjsignorecoercion createjs.Container + */ + override protected function createElement():WrappedHTMLElement + { + if (element == null) { + var container:createjs.Container = new createjs.Container(); + container.name = 'container'; + element = container as WrappedHTMLElement; + } + if (positioner == null) { + positioner = element; + } + + element.flexjs_wrapper = this; + + return positioner; + } + + /** + * @private + */ + override public function addedToParent():void + { + if (!_initialized) + { + // each MXML file can also have styles in fx:Style block + ValuesManager.valuesImpl.init(this); + } + + super.addedToParent(); + + if (!_initialized) + { + MXMLDataInterpreter.generateMXMLInstances(_mxmlDocument, this, MXMLDescriptor); + + dispatchEvent(new Event("initBindings")); + dispatchEvent(new Event("initComplete")); + _initialized = true; + } + } + + /** + * @private + */ + public function childrenAdded():void + { + dispatchEvent(new Event("childrenAdded")); + } + + private var _mxmlDescriptor:Array; + private var _mxmlDocument:Object = this; + private var _initialized:Boolean; + + /** + * @copy org.apache.flex.core.Application#MXMLDescriptor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get MXMLDescriptor():Array + { + return _mxmlDescriptor; + } + + /** + * @private + */ + public function setMXMLDescriptor(document:Object, value:Array):void + { + _mxmlDocument = document; + _mxmlDescriptor = value; + } + + /** + * @copy org.apache.flex.core.Application#generateMXMLAttributes() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function generateMXMLAttributes(data:Array):void + { + MXMLDataInterpreter.generateMXMLProperties(this, data); + } + + /** + * @copy org.apache.flex.core.ItemRendererClassFactory#mxmlContent + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var mxmlContent:Array; + + private var _states:Array; + + /** + * The array of view states. These should + * be instances of org.apache.flex.states.State. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get states():Array + { + return _states; + } + + /** + * @private + * @flexjsignorecoercion Class + * @flexjsignorecoercion org.apache.flex.core.IBead + */ + public function set states(value:Array):void + { + _states = value; + _currentState = _states[0].name; + + try{ + if (getBeadByType(IStatesImpl) == null) + { + var c:Class = ValuesManager.valuesImpl.getValue(this, "iStatesImpl") as Class; + var b:Object = new c(); + addBead(b as IBead); + } + } + catch(e:Error) + { + // to do + } + + } + + /** + * <code>true</code> if the array of states + * contains a state with this name. + * + * @param state The state namem. + * @return True if state in state array + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function hasState(state:String):Boolean + { + for each (var s:State in _states) + { + if (s.name == state) + return true; + } + return false; + } + + private var _currentState:String; + + [Bindable("currentStateChange")] + /** + * The name of the current state. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get currentState():String + { + return _currentState; + } + + /** + * @private + */ + public function set currentState(value:String):void + { + var event:ValueChangeEvent = new ValueChangeEvent("currentStateChange", false, false, _currentState, value) + _currentState = value; + dispatchEvent(event); + } + + private var _transitions:Array; + + /** + * The array of transitions. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get transitions():Array + { + return _transitions; + } + + /** + * @private + */ + public function set transitions(value:Array):void + { + _transitions = value; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Label.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Label.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Label.as index 3540599..490b3b9 100644 --- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Label.as +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/Label.as @@ -28,54 +28,144 @@ package org.apache.flex.createjs import createjs.Text; import createjs.Stage; - import org.apache.flex.createjs.core.UIBase; + import org.apache.flex.createjs.core.CreateJSBase; import org.apache.flex.core.WrappedHTMLElement; } + + import org.apache.flex.core.ITextModel; + import org.apache.flex.core.graphics.IFill; + import org.apache.flex.core.graphics.SolidColor; + + /** + * The Label class provides a static text string which may be colored. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ COMPILE::AS3 public class Label extends org.apache.flex.html.Label - { - + { + /** + * @private + */ + public function get fill():IFill + { + return null; + } + public function set fill(value:IFill):void + { + } + + /** + * The color of the text. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get textColor():IFill + { + return null; + } + public function set textColor(value:IFill):void + { + } + + /** + * The font to use for the text. Any CSS-style font name may be used. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get fontName():String + { + return null; + } + public function set fontName(value:String):void + { + } } COMPILE::JS - public class Label extends UIBase + public class Label extends CreateJSBase { + private var _fontName:String = "18px Arial" + + /** + * The font to use for the text. Any CSS-style font name may be used. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get fontName():String + { + return _fontName; + } + public function set fontName(value:String):void + { + _fontName = value; + redrawShape(); + } + + /** + * The string to display. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get text():String + { + return ITextModel(model).text; + } + public function set text(value:String):void + { + ITextModel(model).text = value; + redrawShape(); + } /** + * @private * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement */ - override public function createElement():WrappedHTMLElement + override protected function createElement():WrappedHTMLElement { - var text:Text = new Text('default text', '20px Arial', '#ff7700'); - text.x = 0; - text.y = 20; + var text:Text = new Text('default text'); text.textBaseline = 'alphabetic'; - positioner = element = text as WrappedHTMLElement; + element = text as WrappedHTMLElement; + element.flexjs_wrapper = this; + + positioner = element; + return element; } - - - /** - * @flexjsignorecoercion createjs.Text - */ - public function get text():String - { - return (element as Text).text; - } - - /** - * @flexjsignorecoercion createjs.Text - */ - public function set text(value:String):void - { - var text:Text = element as Text; - text.text = value; - var stage:Stage = text.getStage(); - if (stage) - stage.update(); - } + + /** + * @private + * @flexjsignorecoercion createjs.Text + */ + override protected function redrawShape():void + { + var color:String = null; + if (textColor != null) { + color = convertColorToString((textColor as SolidColor).color, 1.0); + } + + var label:createjs.Text = element as createjs.Text; + label.text = text; + label["font"] = fontName; + label["color"] = color; + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/TextButton.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/TextButton.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/TextButton.as index f7a31f9..6d8415c 100644 --- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/TextButton.as +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/TextButton.as @@ -20,7 +20,6 @@ package org.apache.flex.createjs { COMPILE::AS3 { - import org.apache.flex.core.ITextModel; import org.apache.flex.html.Button; } COMPILE::JS @@ -30,11 +29,24 @@ package org.apache.flex.createjs import createjs.Shape; import createjs.Stage; - import org.apache.flex.createjs.core.UIBase; + import org.apache.flex.createjs.core.CreateJSBase; import org.apache.flex.core.WrappedHTMLElement; } + + import org.apache.flex.core.ITextModel; + import org.apache.flex.core.graphics.IFill; + import org.apache.flex.core.graphics.SolidColor; + + /** + * The TextButton class provides a clickable button. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ - COMPILE::AS3 + COMPILE::AS3 public class TextButton extends Button { public function TextButton() @@ -42,54 +54,108 @@ package org.apache.flex.createjs super(); } - public function get text():String + private var _fill:IFill; + + /** + * A solid color fill. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get fill():IFill { - return ITextModel(model).text; + return _fill; } - public function set text(value:String):void + public function set fill(value:IFill):void { - ITextModel(model).text = value; + _fill = value; + } + + private var _textColor:IFill; + + + /** + * The color of the text. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get textColor():IFill + { + return _textColor; + } + + public function set textColor(value:IFill):void + { + _textColor = value; } - public function get html():String + private var _fontName:String; + + /** + * The font to use for the button's label. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get fontName():String { - return ITextModel(model).html; + return _fontName; } - public function set html(value:String):void + + public function set fontName(value:String):void { - ITextModel(model).html = value; + _fontName = value; } - + + + /** + * The button's label. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get text():String + { + return ITextModel(model).text; + } + public function set text(value:String):void + { + ITextModel(model).text = value; + } } COMPILE::JS - public class TextButton extends UIBase + public class TextButton extends CreateJSBase { private var buttonBackground:Shape; private var buttonLabel:Text; - private var button:Container; + private var button:createjs.Container; + /** + * @private * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement */ - override public function createElement():WrappedHTMLElement - { + override protected function createElement():WrappedHTMLElement + { buttonBackground = new createjs.Shape(null); buttonBackground.name = 'background'; - buttonBackground.graphics.beginFill('red'). - drawRoundRect(0, 0, 200, 60, 10); - buttonLabel = new createjs.Text('button', 'bold 24px Arial', - '#FFFFFF'); + buttonLabel = new createjs.Text('button'); buttonLabel.name = 'label'; buttonLabel.textAlign = 'center'; buttonLabel.textBaseline = 'middle'; - buttonLabel.x = 200 / 2; - buttonLabel.y = 60 / 2; button = new createjs.Container(); button.name = 'button'; - button.x = 50; - button.y = 25; button.addChild(buttonBackground); button.addChild(buttonLabel); @@ -97,22 +163,71 @@ package org.apache.flex.createjs element.flexjs_wrapper = this; return element; } + + private var _fontName:String = "bold 18px Arial" + + /** + * The font to use for the button's label. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get fontName():String + { + return _fontName; + } + + public function set fontName(value:String):void + { + _fontName = value; + redrawShape(); + } - - /** - * @flexjsignorecoercion createjs.Text - */ - public function get text():String - { - return buttonLabel.text; - } - - /** - * @flexjsignorecoercion createjs.Text - */ - public function set text(value:String):void - { - buttonLabel.text = value; - } + /** + * The button's label + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get text():String + { + return ITextModel(model).text; + } + public function set text(value:String):void + { + ITextModel(model).text = value; + redrawShape(); + } + + /** + * @private + */ + override protected function redrawShape():void + { + if (isNaN(width) || isNaN(height)) return; + + var fillColor:String = null; + var fillAlpha:Number = 1.0; + if (fill != null) { + fillAlpha = (fill as SolidColor).alpha; + fillColor = convertColorToString((fill as SolidColor).color, fillAlpha); + } + buttonBackground.graphics.beginFill(fillColor). + drawRoundRect(0, 0, width, height, 8); + + var color:String = null; + if (textColor != null) { + color = convertColorToString((textColor as SolidColor).color, 1.0); + } + buttonLabel.x = width / 2; + buttonLabel.y = height / 2; + buttonLabel.text = text; + buttonLabel["font"] = fontName; + buttonLabel["color"] = color; + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/CreateJSBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/CreateJSBase.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/CreateJSBase.as new file mode 100644 index 0000000..d23359e --- /dev/null +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/CreateJSBase.as @@ -0,0 +1,164 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.createjs.core +{ + COMPILE::JS + { + import createjs.Container; + import createjs.Text; + import createjs.Shape; + import createjs.Stage; + + import org.apache.flex.createjs.core.UIBase; + import org.apache.flex.core.WrappedHTMLElement; + + import org.apache.flex.core.graphics.IFill; + import org.apache.flex.core.graphics.IStroke; + import org.apache.flex.core.graphics.SolidColor; + } + + /** + * This is the base class for CreateJS component wrappers used by FlexJS + * applications. This class provides standard properties that most of the + * FlexJS CreateJS wrapper classes use, such as a fill color. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + + COMPILE::AS3 + public class CreateJSBase extends org.apache.flex.core.UIBase + { + // does nothing for SWF version. + } + + COMPILE::JS + public class CreateJSBase extends UIBase + { + private var _stroke:IStroke; + + /** + * The color, weight, and alpha value of a stroke or outline. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get stroke():IStroke + { + return _stroke; + } + public function set stroke(value:IStroke):void + { + _stroke = value; + redrawShape(); + } + + private var _fill:IFill; + + /** + * The color and alpha values of a fill. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get fill():IFill + { + return _fill; + } + public function set fill(value:IFill):void + { + _fill = value; + redrawShape(); + } + + private var _textColor:IFill; + + /** + * The color and alpha for text. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + public function get textColor():IFill + { + return _textColor; + } + + public function set textColor(value:IFill):void + { + _textColor = value; + redrawShape(); + } + + /** + * @private + */ + override public function set x(value:Number):void + { + super.x = value; + redrawShape(); + } + + /** + * @private + */ + override public function set y(value:Number):void + { + super.y = value; + redrawShape(); + } + + /** + * @private + */ + override public function set width(value:Number):void + { + super.width = value; + redrawShape(); + } + + /** + * @private + */ + override public function set height(value:Number):void + { + super.height = value; + redrawShape(); + } + + /** + * The redrawShape function is called whenever visual changes are made + * to a component. This includes its size, position, and color. Each + * subclass provides this function. + * @private + */ + protected function redrawShape():void + { + // handle in subclass + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/UIBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/UIBase.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/UIBase.as index 10f18ab..467a2c8 100644 --- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/UIBase.as +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/UIBase.as @@ -20,10 +20,17 @@ package org.apache.flex.createjs.core { import org.apache.flex.core.HTMLElementWrapper; import org.apache.flex.core.IStrand; + import org.apache.flex.core.IStrandWithModel; + import org.apache.flex.core.IParentIUIBase; + import org.apache.flex.core.IStyleableObject; + import org.apache.flex.core.ILayoutChild; import org.apache.flex.core.IBeadModel; import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IBeadController; import org.apache.flex.core.IFlexJSElement; import org.apache.flex.core.IUIBase; + import org.apache.flex.core.ValuesManager; import org.apache.flex.events.Event; import org.apache.flex.events.IEventDispatcher; @@ -34,23 +41,300 @@ package org.apache.flex.createjs.core import createjs.Stage; import org.apache.flex.core.WrappedHTMLElement; } + + /** + * The CreateJS framework provides its own version of UIBase. CreateJS uses + * the HTML 5 <canvas> for its work and does not use the HTML DOM like the + * most of FlexJS, so this replacement for UIBase allows the CreateJS wrapper + * classes for FlexJS to fit in. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + + COMPILE::AS3 + public class UIBase extends org.apache.flex.core.UIBase + { + // nothing different for the SWF version + } - public class UIBase extends HTMLElementWrapper implements IStrand, IEventDispatcher, IUIBase, IFlexJSElement + COMPILE::JS + public class UIBase extends HTMLElementWrapper implements IStrandWithModel, IEventDispatcher, IUIBase, IFlexJSElement { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignorecoercion Class + */ public function UIBase() { super(); - COMPILE::JS - { - createElement(); - } + + createElement(); + } + + private var _view:IBeadView; + + /** + * @private + * @flexjsignorecoercion Class + */ + public function get view():IBeadView + { + if (_view == null) + { + var c:Class = ValuesManager.valuesImpl.getValue(this, "iBeadView") as Class; + if (c) + { + if (c) + { + _view = (new c()) as IBeadView; + addBead(_view); + } + } + } + return _view; + } + + /** + * @private + */ + public function set view(value:IBeadView):void + { + if (_view != value) + { + addBead(value as IBead); + dispatchEvent(new Event("viewChanged")); + } + } + + private var _id:String; + + /** + * An id property for MXML documents. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get id():String + { + return _id; + } + + /** + * @private + */ + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new Event("idChanged")); + } + } + + private var _style:Object; + + /** + * The style object has no meaning for CreateJS, but is provided for + * compatiability and, perhaps in the future, as a way to apply "styles" + * to CreateJS objects. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get style():Object + { + return _style; + } + + /** + * Style is not supported for CreateJS. + * @private + * @flexjsignorecoercion String + */ + public function set style(value:Object):void + { + if (_style != value) + { + if (value is String) + { + _style = ValuesManager.valuesImpl.parseStyles(value as String); + } + else + _style = value; + + dispatchEvent(new Event("stylesChanged")); + } + } + + private var _className:String; + + /** + * The classname. Often used for CSS. + * class selector lookups. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get className():String + { + return _className; } + /** + * @private + * Not supported for CreateJS + */ + public function set className(value:String):void + { + if (_className != value) + { + _className = value; + dispatchEvent(new Event("classNameChanged")); + } + } + + /** + * @copy org.apache.flex.core.Application#beads + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var beads:Array; + + /** + * The method called when added to a parent. This is a good + * time to set up beads. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignorecoercion Class + * @flexjsignorecoercion Number + */ + public function addedToParent():void + { + var c:Class; + + if (style) + ValuesManager.valuesImpl.applyStyles(this, style); + + if (isNaN(_explicitWidth) && isNaN(_percentWidth)) + { + var value:* = ValuesManager.valuesImpl.getValue(this,"width"); + if (value !== undefined) + { + if (value is String) + { + var s:String = String(value); + if (s.indexOf("%") != -1) + _percentWidth = Number(s.substring(0, s.length - 1)); + else + { + if (s.indexOf("px") != -1) + s = s.substring(0, s.length - 2); + _width = _explicitWidth = Number(s); + } + } + else + _width = _explicitWidth = value as Number; + } + } + + if (isNaN(_explicitHeight) && isNaN(_percentHeight)) + { + value = ValuesManager.valuesImpl.getValue(this,"height"); + if (value !== undefined) + { + if (value is String) + { + s = String(value); + if (s.indexOf("%") != -1) + _percentHeight = Number(s.substring(0, s.length - 1)); + else + { + if (s.indexOf("px") != -1) + s = s.substring(0, s.length - 2); + _height = _explicitHeight = Number(s); + } + } + else + _height = _explicitHeight = value as Number; + } + } + + for each (var bead:IBead in beads) + addBead(bead); + + if (getBeadByType(IBeadModel) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadModel") as Class; + if (c) + { + var model:IBeadModel = new c as IBeadModel; + if (model) + addBead(model); + } + } + if (_view == null && getBeadByType(IBeadView) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadView") as Class; + if (c) + { + var view:IBeadView = new c as IBeadView; + if (view) + addBead(view); + } + } + if (getBeadByType(IBeadController) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadController") as Class; + if (c) + { + var controller:IBeadController = new c as IBeadController; + if (controller) + addBead(controller); + } + } + dispatchEvent(new Event("beadsAdded")); + } + + /** + * @copy org.apache.flex.core.IUIBase#topMostEventDispatcher + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + * @flexjsignorecoercion org.apache.flex.events.IEventDispatcher + */ + public function get topMostEventDispatcher():IEventDispatcher + { + var e:WrappedHTMLElement = document.body as WrappedHTMLElement; + return e.flexjs_wrapper as IEventDispatcher; + } + /** * @flexjsignorecoercion createjs.Container * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function addElement(c:Object, dispatchEvent:Boolean = true):void { (element as Container).addChild(c.element as DisplayObject); @@ -60,7 +344,6 @@ package org.apache.flex.createjs.core * @flexjsignorecoercion createjs.Container * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function addElementAt(c:Object, index:int, dispatchEvent:Boolean = true):void { (element as Container).addChildAt(c.element as DisplayObject, index); @@ -71,7 +354,6 @@ package org.apache.flex.createjs.core * @flexjsignorecoercion createjs.Container * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function getElementIndex(c:Object):int { return (element as Container).getChildIndex(c.element as DisplayObject); @@ -82,7 +364,6 @@ package org.apache.flex.createjs.core * @flexjsignorecoercion createjs.Container * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function removeElement(c:Object, dispatchEvent:Boolean = true):void { (element as Container).removeChild(c.element as DisplayObject); @@ -93,7 +374,6 @@ package org.apache.flex.createjs.core * @flexjsignorecoercion createjs.Container * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function getElementAt(index:int):Object { return (element as Container).getChildAt(index); @@ -104,7 +384,6 @@ package org.apache.flex.createjs.core * @flexjsignorecoercion createjs.Container * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function get numElements():int { return (element as Container).numChildren; @@ -112,230 +391,241 @@ package org.apache.flex.createjs.core /** * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + * @flexjsignorecoercion createjs.Container */ - COMPILE::JS - public function createElement():WrappedHTMLElement + protected function createElement():WrappedHTMLElement { - element = new Container() as WrappedHTMLElement; + element = new createjs.Container() as WrappedHTMLElement; + element.flexjs_wrapper = this; positioner = this.element; return element; } + + + private var _explicitWidth:Number; + + /** + * The explicitly set width (as opposed to measured width + * or percentage width). + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get explicitWidth():Number + { + return _explicitWidth; + } + + /** + * @private + */ + public function set explicitWidth(value:Number):void + { + if (_explicitWidth == value) + return; + + // width can be pixel or percent not both + if (!isNaN(value)) + _percentWidth = NaN; + + _explicitWidth = value; + + dispatchEvent(new Event("explicitWidthChanged")); + } + + private var _explicitHeight:Number; + + /** + * The explicitly set width (as opposed to measured width + * or percentage width). + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get explicitHeight():Number + { + return _explicitHeight; + } + + /** + * @private + */ + public function set explicitHeight(value:Number):void + { + if (_explicitHeight == value) + return; + + // height can be pixel or percent not both + if (!isNaN(value)) + _percentHeight = NaN; + + _explicitHeight = value; + + dispatchEvent(new Event("explicitHeightChanged")); + } + + private var _percentWidth:Number; + + /** + * The requested percentage width this component + * should have in the parent container. Note that + * the actual percentage may be different if the + * total is more than 100% or if there are other + * components with explicitly set widths. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get percentWidth():Number + { + return _percentWidth; + } + + /** + * @private + */ + public function set percentWidth(value:Number):void + { + this._percentWidth = value; + if (!isNaN(value)) + this._explicitWidth = NaN; + + dispatchEvent(new Event("percentWidthChanged")); + } + + private var _percentHeight:Number; + + /** + * The requested percentage height this component + * should have in the parent container. Note that + * the actual percentage may be different if the + * total is more than 100% or if there are other + * components with explicitly set heights. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get percentHeight():Number + { + return _percentHeight; + } + + /** + * @private + */ + public function set percentHeight(value:Number):void + { + this._percentHeight = value; + if (!isNaN(value)) + this._explicitHeight = NaN; + + dispatchEvent(new Event("percentHeightChanged")); + } + + private var _x:Number; /** * @flexjsignorecoercion createjs.Container */ - COMPILE::JS public function get x():Number { - return (positioner as Container).x; + return _x; } /** * @flexjsignorecoercion createjs.Container */ - COMPILE::JS public function set x(value:Number):void { - var container:Container = positioner as Container; + var container:DisplayObject = positioner as DisplayObject; container.x = value; + _x = value; var stage:Stage = container.getStage(); if (stage) stage.update(); } + + private var _y:Number; - /** * @flexjsignorecoercion createjs.Container */ - COMPILE::JS public function get y():Number { - return (positioner as Container).y; + return _y; } /** * @flexjsignorecoercion createjs.Container */ - COMPILE::JS public function set y(value:Number):void { - var container:Container = positioner as Container; + var container:DisplayObject = positioner as DisplayObject; container.y = value; + _y = value; var stage:Stage = container.getStage(); if (stage) stage.update(); - } + } + + private var _width:Number; /** * @flexjsignorecoercion createjs.Container */ - COMPILE::JS public function get width():Number { - return (positioner as Container).width; + return _width; } /** - * @flexjsignorecoercion createjs.Container + * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function set width(value:Number):void { - var container:Container = positioner as Container; + var container:DisplayObject = positioner as DisplayObject; container.width = value; + _width = value; var stage:Stage = container.getStage(); if (stage) stage.update(); } + + private var _height:Number; /** * @flexjsignorecoercion createjs.Container */ - COMPILE::JS public function get height():Number { - return (positioner as Container).height; + return _height; } /** * @flexjsignorecoercion createjs.Container */ - COMPILE::JS public function set height(value:Number):void { - var container:Container = positioner as Container; + var container:DisplayObject = positioner as DisplayObject; container.height = value; + _height = value; var stage:Stage = container.getStage(); if (stage) stage.update(); } - - COMPILE::AS3 - private var _width:Number = 0; - COMPILE::AS3 - override public function get width():Number - { - return _width; - } - - COMPILE::AS3 - override public function set width(value:Number):void - { - if (_width != value) - { - _width = value; - dispatchEvent(new Event("widthChanged")); - } - } - COMPILE::AS3 - protected function get $width():Number - { - return super.width; - } - - COMPILE::AS3 - private var _height:Number = 0; - COMPILE::AS3 - override public function get height():Number - { - return _height; - } - COMPILE::AS3 - override public function set height(value:Number):void - { - if (_height != value) - { - _height = value; - dispatchEvent(new Event("heightChanged")); - } - } - COMPILE::AS3 - protected function get $height():Number - { - return super.height; - } - - COMPILE::AS3 - private var _model:IBeadModel; - COMPILE::AS3 - public function get model():IBeadModel - { - return _model; - } - COMPILE::AS3 - public function set model(value:IBeadModel):void - { - if (_model != value) - { - addBead(value as IBead); - dispatchEvent(new Event("modelChanged")); - } - } - - private var _id:String; - public function get id():String - { - return _id; - } - public function set id(value:String):void - { - if (_id != value) - { - _id = value; - dispatchEvent(new Event("idChanged")); - } - } - - // beads declared in MXML are added to the strand. - // from AS, just call addBead() - COMPILE::AS3 - public var beads:Array; - - COMPILE::AS3 - private var _beads:Vector.<IBead>; - COMPILE::AS3 - override public function addBead(bead:IBead):void - { - if (!_beads) - _beads = new Vector.<IBead>; - _beads.push(bead); - if (bead is IBeadModel) - _model = bead as IBeadModel; - bead.strand = this; - } - - COMPILE::AS3 - public function getBeadByType(classOrInterface:Class):IBead - { - for each (var bead:IBead in _beads) - { - if (bead is classOrInterface) - return bead; - } - return null; - } - - COMPILE::AS3 - public function removeBead(value:IBead):IBead - { - var n:int = _beads.length; - for (var i:int = 0; i < n; i++) - { - var bead:IBead = _beads[i]; - if (bead == value) - { - _beads.splice(i, 1); - return bead; - } - } - return null; - } /** * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function get visible():Boolean { return (positioner as DisplayObject).visible; @@ -344,7 +634,6 @@ package org.apache.flex.createjs.core /** * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function set visible(value:Boolean):void { var oldValue:Boolean = (positioner as DisplayObject).visible; @@ -367,7 +656,6 @@ package org.apache.flex.createjs.core /** * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function get alpha():Number { return (positioner as DisplayObject).alpha; @@ -376,19 +664,16 @@ package org.apache.flex.createjs.core /** * @flexjsignorecoercion createjs.DisplayObject */ - COMPILE::JS public function set alpha(value:Number):void { (positioner as DisplayObject).alpha = value; } - COMPILE::JS private var _positioner:WrappedHTMLElement; /** * The HTMLElement used to position the component. */ - COMPILE::JS public function get positioner():WrappedHTMLElement { return _positioner; @@ -397,53 +682,37 @@ package org.apache.flex.createjs.core /** * @private */ - COMPILE::JS public function set positioner(value:WrappedHTMLElement):void { _positioner = value; } - - /** - * @copy org.apache.flex.core.IUIBase#topMostEventDispatcher - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement - * @flexjsignorecoercion org.apache.flex.events.IEventDispatcher - */ - public function get topMostEventDispatcher():IEventDispatcher - { - COMPILE::AS3 - { - return null; - } - COMPILE::JS - { - var e:WrappedHTMLElement = document.body as WrappedHTMLElement; - return e.flexjs_wrapper as IEventDispatcher; - } - } - - public function addedToParent():void - { - - } - - /** - * @copy org.apache.flex.core.IUIBase#element - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - COMPILE::AS3 - public function get element():IFlexJSElement - { - return this; - } + + /** + * @flexjsignorecoercion createjs.Container + * @flexjsignorecoercion createjs.DisplayObject + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + */ + public function get parent():IUIBase + { + var pos:createjs.DisplayObject = this.positioner as createjs.DisplayObject; + var p:WrappedHTMLElement = pos['parent'] as WrappedHTMLElement; + var wrapper:IUIBase = p ? p.flexjs_wrapper as IUIBase : null; + return wrapper; + } + + // CreateJS - specific properties and functions + + protected function convertColorToString(value:uint, alpha:Number=1.0):String + { + // ideally, for CreateJS, we convert the color value and alpha into the + // format: "rgba(red,green,blue,alpha)" such as "rgba(255,0,0,1.0)" + // but for now we'll make it easy + var color:String = Number(value).toString(16); + if (color.length == 1) color = '00' + color; + if (color.length == 2) color = '00' + color; + if (color.length == 4) color = '00' + color; + return "#"+color; + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/View.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/View.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/View.as new file mode 100644 index 0000000..81cf83d --- /dev/null +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/View.as @@ -0,0 +1,325 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.createjs.core +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IContainer; + import org.apache.flex.core.IApplicationView; + import org.apache.flex.core.IPopUpHost; + import org.apache.flex.core.IMXMLDocument; + import org.apache.flex.core.IStatesImpl; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.ValueChangeEvent; + import org.apache.flex.states.State; + import org.apache.flex.utils.MXMLDataInterpreter; + + COMPILE::JS + { + import createjs.Stage; + import createjs.Container; + import org.apache.flex.core.WrappedHTMLElement; + } + + //-------------------------------------- + // Events + //-------------------------------------- + + /** + * Dispatched at startup. Attributes and sub-instances of + * the MXML document have been created and assigned. + * The component lifecycle is different + * than the Flex SDK. There is no creationComplete event. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="initComplete", type="org.apache.flex.events.Event")] + + [DefaultProperty("mxmlContent")] + + /** + * This version of View is specific for CreateJS since CreateJS does not + * use the HTML DOM. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + + COMPILE::AS3 + public class View extends org.apache.flex.core.ViewBase + { + // nothing different for the SWF version + } + + COMPILE::JS + public class View extends UIBase implements IPopUpHost, IApplicationView, IContainer + { + private var _applicationModel:Object; + + [Bindable("modelChanged")] + + /** + * A reference to the Application's model. Usually, + * a view is displaying the main model for an + * application. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get applicationModel():Object + { + return _applicationModel; + } + + /** + * @private + */ + public function set applicationModel(value:Object):void + { + _applicationModel = value; + dispatchEvent(new Event("modelChanged")); + } + + /** + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + * @flexjsignorecoercion createjs.Container + */ + override protected function createElement():WrappedHTMLElement + { + if (element == null) { + var container:createjs.Container = new createjs.Container(); + container.name = 'viewbase'; + container.x = 0; + container.y = 0; + element = container as WrappedHTMLElement; + } + if (positioner == null) { + positioner = element; + } + + element.flexjs_wrapper = this; + + return positioner; + } + + public function childrenAdded():void + { + dispatchEvent(new Event("childrenAdded")); + } + + + /** + * A ViewBase doesn't create its children until it is added to + * a parent. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function addedToParent():void + { + if (!_initialized) + { + // each MXML file can also have styles in fx:Style block + ValuesManager.valuesImpl.init(this); + } + + super.addedToParent(); + + if (!_initialized) + { + MXMLDataInterpreter.generateMXMLInstances(_mxmlDocument, this, MXMLDescriptor); + + dispatchEvent(new Event("initBindings")); + dispatchEvent(new Event("initComplete")); + _initialized = true; + } + } + + private var _mxmlDescriptor:Array; + private var _mxmlDocument:Object = this; + private var _initialized:Boolean; + + /** + * @copy org.apache.flex.core.Application#MXMLDescriptor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get MXMLDescriptor():Array + { + return _mxmlDescriptor; + } + + /** + * @private + */ + public function setMXMLDescriptor(document:Object, value:Array):void + { + _mxmlDocument = document; + _mxmlDescriptor = value; + } + + /** + * @copy org.apache.flex.core.Application#generateMXMLAttributes() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function generateMXMLAttributes(data:Array):void + { + MXMLDataInterpreter.generateMXMLProperties(this, data); + } + + /** + * @copy org.apache.flex.core.ItemRendererClassFactory#mxmlContent + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var mxmlContent:Array; + + private var _states:Array; + + /** + * The array of view states. These should + * be instances of org.apache.flex.states.State. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get states():Array + { + return _states; + } + + /** + * @private + * @flexjsignorecoercion Class + * @flexjsignorecoercion org.apache.flex.core.IBead + */ + public function set states(value:Array):void + { + _states = value; + _currentState = _states[0].name; + + try{ + if (getBeadByType(IStatesImpl) == null) + { + var c:Class = ValuesManager.valuesImpl.getValue(this, "iStatesImpl") as Class; + var b:Object = new c(); + addBead(b as IBead); + } + } + //TODO: Need to handle this case more gracefully + catch(e:Error) + { + + } + + } + + /** + * <code>true</code> if the array of states + * contains a state with this name. + * + * @param state The state namem. + * @return True if state in state array + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function hasState(state:String):Boolean + { + for each (var s:State in _states) + { + if (s.name == state) + return true; + } + return false; + } + + private var _currentState:String; + + [Bindable("currentStateChange")] + /** + * The name of the current state. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get currentState():String + { + return _currentState; + } + + /** + * @private + */ + public function set currentState(value:String):void + { + var event:ValueChangeEvent = new ValueChangeEvent("currentStateChange", false, false, _currentState, value) + _currentState = value; + dispatchEvent(event); + } + + private var _transitions:Array; + + /** + * The array of transitions. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get transitions():Array + { + return _transitions; + } + + /** + * @private + */ + public function set transitions(value:Array):void + { + _transitions = value; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/ViewBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/ViewBase.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/ViewBase.as deleted file mode 100644 index 9fb19e8..0000000 --- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/core/ViewBase.as +++ /dev/null @@ -1,206 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.createjs.core -{ - COMPILE::AS3 - { - import flash.display.DisplayObject; - import org.apache.flex.core.ViewBase; - } - - import org.apache.flex.core.IApplicationView; - import org.apache.flex.core.IParent; - import org.apache.flex.core.IUIBase; - import org.apache.flex.events.Event; - import org.apache.flex.utils.MXMLDataInterpreter; - - COMPILE::JS - { - import org.apache.flex.core.IBead; - import org.apache.flex.core.IStatesImpl; - import org.apache.flex.core.ValuesManager; - import org.apache.flex.events.ValueChangeEvent; - import org.apache.flex.states.State; - } - - COMPILE::AS3 - public class ViewBase extends org.apache.flex.core.ViewBase - { - - } - - [DefaultProperty("mxmlContent")] - COMPILE::JS - public class ViewBase extends UIBase implements IParent, IApplicationView - { - public function ViewBase() - { - super(); - } - - override public function addedToParent():void - { - /* AJH needed? - MXMLDataInterpreter.generateMXMLProperties(this, MXMLProperties); - */ - MXMLDataInterpreter.generateMXMLInstances(this, this, MXMLDescriptor); - } - - public function get MXMLDescriptor():Array - { - return null; - } - - /* - public function get MXMLProperties():Array - { - return null; - } - */ - - public var mxmlContent:Array; - - private var _applicationModel:Object; - - [Bindable("modelChanged")] - public function get applicationModel():Object - { - return _applicationModel; - } - - public function set applicationModel(value:Object):void - { - _applicationModel = value; - dispatchEvent(new Event("modelChanged")); - } - - private var _states:Array; - - /** - * The array of view states. These should - * be instances of org.apache.flex.states.State. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get states():Array - { - return _states; - } - - /** - * @private - * @flexjsignorecoercion Class - * @flexjsignorecoercion org.apache.flex.core.IBead - */ - public function set states(value:Array):void - { - _states = value; - _currentState = _states[0].name; - - try{ - if (getBeadByType(IStatesImpl) == null) - { - var c:Class = ValuesManager.valuesImpl.getValue(this, "iStatesImpl") as Class; - var b:Object = new c(); - addBead(b as IBead); - } - } - //TODO: Need to handle this case more gracefully - catch(e:Error) - { - } - - } - - /** - * <code>true</code> if the array of states - * contains a state with this name. - * - * @param state The state namem. - * @return True if state in state array - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function hasState(state:String):Boolean - { - for each (var s:State in _states) - { - if (s.name == state) - return true; - } - return false; - } - - private var _currentState:String; - - [Bindable("currentStateChange")] - /** - * The name of the current state. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get currentState():String - { - return _currentState; - } - - /** - * @private - */ - public function set currentState(value:String):void - { - var event:ValueChangeEvent = new ValueChangeEvent("currentStateChange", false, false, _currentState, value) - _currentState = value; - dispatchEvent(event); - } - - private var _transitions:Array; - - /** - * The array of transitions. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get transitions():Array - { - return _transitions; - } - - /** - * @private - */ - public function set transitions(value:Array):void - { - _transitions = value; - } - - } -} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1f399ec5/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/graphics/Circle.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/graphics/Circle.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/graphics/Circle.as new file mode 100644 index 0000000..040abc5 --- /dev/null +++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/graphics/Circle.as @@ -0,0 +1,94 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.createjs.graphics +{ + COMPILE::AS3 + { + import org.apache.flex.core.graphics.Circle + } + + COMPILE::JS + { + import createjs.Shape; + import createjs.Stage; + + import org.apache.flex.createjs.core.UIBase; + import org.apache.flex.core.WrappedHTMLElement; + } + + import org.apache.flex.core.graphics.IFill; + import org.apache.flex.core.graphics.SolidColor; + import org.apache.flex.core.graphics.SolidColorStroke; + + /** + * Creates a circle. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.0 + */ + + COMPILE::AS3 + public class Circle extends org.apache.flex.core.graphics.Circle + { + // nothing special for SWF version. + } + + COMPILE::JS + public class Circle extends GraphicShape + { + /** + * @private + * @flexjsignorecoercion createjs.Shape + */ + override protected function redrawShape():void + { + var minSize:Number = Math.min(width, height); + if (isNaN(minSize)) return; + + var radius:Number = minSize/2; + var fillColor:String = null; + var fillAlpha:Number = 1.0; + if (fill != null) { + fillAlpha = (fill as SolidColor).alpha; + fillColor = convertColorToString((fill as SolidColor).color, fillAlpha); + } + var strokeColor:String = null; + var strokeWeight:Number = 0; + var strokeAlpha:Number = 1.0; + if (stroke != null) { + strokeWeight = (stroke as SolidColorStroke).weight; + strokeAlpha = (stroke as SolidColorStroke).alpha; + strokeColor = convertColorToString((stroke as SolidColorStroke).color, strokeAlpha); + } + + var circle:createjs.Shape = element as createjs.Shape; + circle.graphics.setStrokeStyle(strokeWeight); + circle.graphics.beginStroke(strokeColor); + circle.graphics.beginFill(fillColor); + circle.graphics.drawCircle(0, 0, radius); + + var stage:createjs.Stage = circle.getStage(); + if (stage) + stage.update(); + } + + } +}
