├── Assets ├── demo.zip └── Basic.fui ├── src ├── tweenxcore │ ├── geom │ │ ├── Point.hx │ │ ├── Matrix.hx │ │ └── PolarPoint.hx │ ├── expr │ │ ├── RoundTripKind.hx │ │ ├── InOutKind.hx │ │ ├── TernaryOpKind.hx │ │ ├── LineKind.hx │ │ ├── ComplexEasingKind.hx │ │ ├── SimpleEasingKind.hx │ │ ├── UnaryOpKind.hx │ │ ├── BinaryOpKind.hx │ │ ├── StandardEasingKind.hx │ │ ├── ExprMaker.hx │ │ ├── RoundTripKindTools.hx │ │ ├── LineKindTools.hx │ │ ├── ComplexEasingKindTools.hx │ │ ├── TernaryOpKindTools.hx │ │ └── SimpleEasingKindTools.hx │ ├── structure │ │ ├── BoundaryMode.hx │ │ ├── Direction.hx │ │ ├── FloatChangePart.hx │ │ ├── FloatChangeTimelinePart.hx │ │ ├── TimelineSearchResult.hx │ │ ├── FloatChangeRepeatPart.hx │ │ └── Timeline.hx │ └── color │ │ ├── ITransparentColor.hx │ │ ├── IColor.hx │ │ ├── AhsvColor.hx │ │ ├── ArgbColor.hx │ │ ├── RgbColor.hx │ │ └── HsvColor.hx ├── fairygui │ ├── IColorGear.hx │ ├── IAnimationGear.hx │ ├── event │ │ ├── IBubbleEvent.hx │ │ ├── StateChangeEvent.hx │ │ ├── DropEvent.hx │ │ ├── DragEvent.hx │ │ ├── ItemEvent.hx │ │ ├── FocusChangeEvent.hx │ │ └── GTouchEvent.hx │ ├── ITextColorGear.hx │ ├── display │ │ ├── UIDisplayObject.hx │ │ ├── Frame.hx │ │ ├── UIMovieClip.hx │ │ ├── UISprite.hx │ │ ├── UIImage.hx │ │ ├── UITextField.hx │ │ ├── UIRichTextField.hx │ │ └── PlayState.hx │ ├── IUISource.hx │ ├── IUIPackageReader.hx │ ├── text │ │ ├── IRichTextObjectFactory.hx │ │ ├── LinkButton.hx │ │ ├── BMGlyph.hx │ │ ├── HtmlNode.hx │ │ ├── HtmlElement.hx │ │ ├── RichTextObjectFactory.hx │ │ └── BitmapFont.hx │ ├── ScreenMatchMode.hx │ ├── DisplayListItem.hx │ ├── tree │ │ └── ITreeListener.hx │ ├── GroupLayoutType.hx │ ├── ButtonMode.hx │ ├── FillType.hx │ ├── VertAlignType.hx │ ├── ChildrenRenderOrder.hx │ ├── ScrollType.hx │ ├── utils │ │ ├── PixelHitTestData.hx │ │ ├── FontUtils.hx │ │ ├── PixelHitTest.hx │ │ ├── SimpleDispatcher.hx │ │ ├── ZipReader.hx │ │ ├── EaseLookup.hx │ │ ├── CharSize.hx │ │ ├── ColorMatrix.hx │ │ ├── GTimers.hx │ │ ├── UBBParser.hx │ │ └── CompatUtil.hx │ ├── FlipType.hx │ ├── AutoSizeType.hx │ ├── ScrollBarDisplayType.hx │ ├── ProgressTitleType.hx │ ├── ListSelectionMode.hx │ ├── OverflowType.hx │ ├── AlignType.hx │ ├── ZipUIPackageReader.hx │ ├── LoaderFillType.hx │ ├── ListLayoutType.hx │ ├── PackageItemType.hx │ ├── Margin.hx │ ├── action │ │ ├── ChangePageAction.hx │ │ ├── ControllerAction.hx │ │ └── PlayTransitionAction.hx │ ├── GearText.hx │ ├── GearIcon.hx │ ├── GearDisplay.hx │ ├── RelationType.hx │ ├── PageOption.hx │ ├── GObjectPool.hx │ ├── GearAnimation.hx │ ├── PackageItem.hx │ ├── UIConfig.hx │ ├── GearColor.hx │ ├── DragDropManager.hx │ ├── TextInputHistory.hx │ ├── GRichTextField.hx │ ├── GSwfObject.hx │ ├── GearXY.hx │ ├── GMovieClip.hx │ ├── UIObjectFactory.hx │ ├── GearBase.hx │ ├── GLabel.hx │ └── GearLook.hx ├── tweenx909 │ ├── EaseX.hx │ ├── advanced │ │ ├── CommandTypeX.hx │ │ ├── UpdateModeX.hx │ │ ├── TweenTypeX.hx │ │ ├── CommandX.hx │ │ ├── GroupX.hx │ │ └── DefaultsX.hx │ ├── rule │ │ ├── RuleX.hx │ │ ├── QuakeX.hx │ │ ├── BoolRuleX.hx │ │ ├── HsvRuleX.hx │ │ ├── RgbRuleX.hx │ │ ├── ArgbRuleX.hx │ │ ├── AhsvRuleX.hx │ │ ├── QuakeRuleX.hx │ │ ├── TimelineRuleX.hx │ │ └── ArrayRuleX.hx │ └── EventX.hx ├── WindowA.hx ├── WindowB.hx ├── FastXMLList.hx └── Main.hx ├── README.md ├── haxelib.json ├── FairyGUI-haxe.iml ├── LICENSE └── project.xml /Assets/demo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakuten/FairyGUI-haxe/HEAD/Assets/demo.zip -------------------------------------------------------------------------------- /Assets/Basic.fui: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rakuten/FairyGUI-haxe/HEAD/Assets/Basic.fui -------------------------------------------------------------------------------- /src/tweenxcore/geom/Point.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.geom; 2 | 3 | typedef Point = { 4 | var x:Float; 5 | var y:Float; 6 | } 7 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/RoundTripKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum RoundTripKind 4 | { 5 | Yoyo; 6 | Zigzag; 7 | } 8 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/InOutKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum InOutKind 4 | { 5 | In; 6 | Out; 7 | InOut; 8 | OutIn; 9 | } -------------------------------------------------------------------------------- /src/tweenxcore/expr/TernaryOpKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum TernaryOpKind 4 | { 5 | Crossfade(start:Float, end:Float); 6 | } 7 | -------------------------------------------------------------------------------- /src/fairygui/IColorGear.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | interface IColorGear 5 | { 6 | 7 | var color(get, set) : UInt; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/LineKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum LineKind 4 | { 5 | Bezier; 6 | Polyline; 7 | UniformQuadraticBSpline; 8 | } -------------------------------------------------------------------------------- /src/tweenxcore/structure/BoundaryMode.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.structure; 2 | 3 | @:enum abstract BoundaryMode(Int) { 4 | var Low = 0; 5 | var High = 1; 6 | } 7 | -------------------------------------------------------------------------------- /src/fairygui/IAnimationGear.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | interface IAnimationGear 5 | { 6 | var playing(get, set) : Bool; 7 | var frame(get, set) : Int; 8 | } 9 | -------------------------------------------------------------------------------- /src/tweenx909/EaseX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909; 2 | import tweenxcore.Tools.Easing; 3 | 4 | /** 5 | * for backward compatibility 6 | */ 7 | @:noCompletion 8 | typedef EaseX = Easing; 9 | -------------------------------------------------------------------------------- /src/fairygui/event/IBubbleEvent.hx: -------------------------------------------------------------------------------- 1 | package fairygui.event; 2 | 3 | 4 | interface IBubbleEvent 5 | { 6 | 7 | var propagationStopped(get, never) : Bool; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/tweenx909/advanced/CommandTypeX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.advanced; 2 | import tweenx909.TweenX; 3 | 4 | enum CommandTypeX{ 5 | TWEEN(tween:TweenX); 6 | WAIT(delay:Float); 7 | } 8 | -------------------------------------------------------------------------------- /src/tweenxcore/structure/Direction.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.structure; 2 | 3 | @:enum abstract Direction(Int) { 4 | var Backward = -1; 5 | var Stopped = 0; 6 | var Forward = 1; 7 | } 8 | -------------------------------------------------------------------------------- /src/fairygui/ITextColorGear.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.IColorGear; 4 | 5 | interface ITextColorGear extends IColorGear 6 | { 7 | var strokeColor(get, set):UInt; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/fairygui/display/UIDisplayObject.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import fairygui.GObject; 5 | 6 | interface UIDisplayObject 7 | { 8 | 9 | var owner(get, never) : GObject; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/ComplexEasingKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum ComplexEasingKind 4 | { 5 | Simple(kind:SimpleEasingKind); 6 | Op(easing:ComplexEasingKind, operation:UnaryOpKind); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /src/tweenxcore/geom/Matrix.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.geom; 2 | 3 | typedef Matrix = { 4 | var a:Float; 5 | var b:Float; 6 | var c:Float; 7 | var d:Float; 8 | var tx:Float; 9 | var ty:Float; 10 | } 11 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/SimpleEasingKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum SimpleEasingKind 4 | { 5 | Linear; 6 | Standard(easing:StandardEasingKind, inOut:InOutKind); 7 | Line(kind:LineKind, controls:Array); 8 | } 9 | -------------------------------------------------------------------------------- /src/fairygui/IUISource.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | interface IUISource 5 | { 6 | var fileName(get, set) : String; 7 | 8 | var loaded(get, never) : Bool; 9 | 10 | function load(callback : Dynamic) : Void; 11 | } 12 | -------------------------------------------------------------------------------- /src/tweenx909/advanced/UpdateModeX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.advanced; 2 | 3 | /** 4 | * ... 5 | * @author shohei909 6 | */ 7 | enum UpdateModeX{ 8 | MANUAL; 9 | TIME(frameRate:Float); 10 | #if (flash) 11 | FRAME; 12 | #end 13 | } 14 | -------------------------------------------------------------------------------- /src/fairygui/IUIPackageReader.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | import openfl.utils.ByteArray; 5 | 6 | interface IUIPackageReader 7 | { 8 | function readDescFile(fileName : String) : String; 9 | function readResFile(fileName : String) : ByteArray; 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FairyGUI-haxe 2 | A flexible UI framework for Haxe, working with the FREE professional Game UI Editor: FairyGUI Editor. 3 | 4 | Official website: http://en.fairygui.com 5 | 6 | --- 7 | ### Install 8 | 9 | `haxelib git fairygui https://github.com/rakuten/FairyGUI-haxe` 10 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/UnaryOpKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum UnaryOpKind 4 | { 5 | Repeat(repeat:Float); 6 | Lerp(from:Float, to:Float); 7 | Clamp(min:Float, max:Float); 8 | RoundTrip(kind:RoundTripKind); 9 | Op(easing:ComplexEasingKind, operation:BinaryOpKind); 10 | } 11 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/BinaryOpKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | 3 | enum BinaryOpKind 4 | { 5 | Composite; 6 | Multiply; 7 | Mix(strength:Float); 8 | Connect(switchTime:Float, switchValue:Float); 9 | OneTwo(switchTime:Float); 10 | Op(easing:ComplexEasingKind, operation:TernaryOpKind); 11 | } 12 | -------------------------------------------------------------------------------- /src/fairygui/text/IRichTextObjectFactory.hx: -------------------------------------------------------------------------------- 1 | package fairygui.text; 2 | 3 | 4 | import openfl.display.DisplayObject; 5 | 6 | interface IRichTextObjectFactory 7 | { 8 | 9 | function createObject(src : String, width : Int, height : Int) : DisplayObject; 10 | function freeObject(obj : DisplayObject) : Void; 11 | } 12 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/StandardEasingKind.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | import tweenxcore.expr.ComplexEasingKind; 3 | 4 | enum StandardEasingKind 5 | { 6 | Quad; 7 | Cubic; 8 | Quart; 9 | Quint; 10 | Sine; 11 | Circ; 12 | Expo; 13 | Back; 14 | Bounce; 15 | Elastic; 16 | Warp; 17 | } -------------------------------------------------------------------------------- /src/fairygui/ScreenMatchMode.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ScreenMatchMode 5 | { 6 | public static inline var MatchWidthOrHeight : Int = 0; 7 | public static inline var MatchWidth : Int = 1; 8 | public static inline var MatchHeight : Int = 2; 9 | 10 | public function new() 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/fairygui/event/StateChangeEvent.hx: -------------------------------------------------------------------------------- 1 | package fairygui.event; 2 | 3 | 4 | import openfl.events.Event; 5 | 6 | class StateChangeEvent extends Event 7 | { 8 | public static inline var CHANGED : String = "stateChanged"; 9 | 10 | public function new(type : String) 11 | { 12 | super(type, false, false); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/tweenx909/rule/RuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenx909.TweenX; 3 | 4 | /** 5 | * ... 6 | * @author shohei909 7 | */ 8 | typedef RuleX = { 9 | public var inputClass(default,null):Dynamic; 10 | public function calc(_from:T1, _to:T1, t1:Float, t2:Float,tween:TweenX):T2; 11 | public function defaultFrom(value:T2, _to:T1, tween:TweenX):T1; 12 | } 13 | -------------------------------------------------------------------------------- /src/fairygui/display/Frame.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import openfl.display.BitmapData; 5 | import openfl.geom.Rectangle; 6 | 7 | class Frame 8 | { 9 | public var rect : Rectangle; 10 | public var addDelay : Int = 0; 11 | public var image : BitmapData; 12 | 13 | public function new() 14 | { 15 | rect = new Rectangle(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/tweenx909/advanced/TweenTypeX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.advanced; 2 | 3 | /** 4 | * 5 | * @author shohei909 6 | */ 7 | enum TweenTypeX { 8 | GROUP(group:GroupX); 9 | ARRAY(targets:Iterable, _from:Array, _to:Array); 10 | FROM_TO(target:Dynamic, _from:Dynamic, _to:Dynamic); 11 | FUNC(func:Dynamic, _from:Array, _to:Array); 12 | CALL(func:Void->Void); 13 | } 14 | -------------------------------------------------------------------------------- /src/fairygui/event/DropEvent.hx: -------------------------------------------------------------------------------- 1 | package fairygui.event; 2 | 3 | 4 | import openfl.events.Event; 5 | 6 | class DropEvent extends Event 7 | { 8 | public static inline var DROP : String = "dropEvent"; 9 | 10 | public var source : Dynamic; 11 | 12 | public function new(type : String, source : Dynamic) 13 | { 14 | super(type, false, false); 15 | this.source = source; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/tweenxcore/color/ITransparentColor.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.color; 2 | 3 | interface ITransparentColor extends IColor { 4 | 5 | public function toArgb():ArgbColor; 6 | public function toAhsv():AhsvColor; 7 | 8 | public function getAlpha():Float; 9 | 10 | public function toArgbInt():Int; 11 | public function toArgbHexString():String; 12 | public function toRgbaCssString():String; 13 | } 14 | -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fairygui", 3 | "url": "https://github.com/rakuten/FairyGUI-haxe", 4 | "license": "MIT", 5 | "tags": [ "fairygui", "openfl", "ui", "flash", "js", "cpp", "desktop", "web"], 6 | "description": "A flexible UI framework for Haxe", 7 | "version": "1.4.0", 8 | "classPath": "src", 9 | "releasenote": "0", 10 | "contributors": [ "Rakutens" ], 11 | "dependencies": { 12 | "openfl": "" 13 | } 14 | } -------------------------------------------------------------------------------- /src/tweenx909/advanced/CommandX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.advanced; 2 | import haxe.io.Error; 3 | import haxe.Log; 4 | import haxe.PosInfos; 5 | 6 | class CommandX { 7 | public var command (default, null):CommandTypeX; 8 | public var definedPosInfos(default, null):PosInfos; 9 | function new (command:CommandTypeX, ?posInfos:PosInfos) { 10 | this.command = command; this.definedPosInfos = posInfos; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/tweenxcore/structure/FloatChangePart.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.structure; 2 | 3 | 4 | class FloatChangePart extends FloatChange { 5 | public inline function isEntrance():Bool { 6 | return (previous <= 0 && 0 < current) || (current < 1.0 && 1.0 <= previous); 7 | } 8 | 9 | public inline function isExit():Bool { 10 | return (current <= 0.0 && 0.0 < previous) || (previous < 1.0 && 1.0 <= current); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/fairygui/DisplayListItem.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.PackageItem; 4 | 5 | class DisplayListItem 6 | { 7 | public var packageItem : PackageItem; 8 | public var type : String; 9 | public var desc : FastXML; 10 | public var listItemCount : Int = 0; 11 | 12 | public function new(packageItem : PackageItem, type : String) 13 | { 14 | this.packageItem = packageItem; 15 | this.type = type; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/fairygui/display/UIMovieClip.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import fairygui.GObject; 5 | 6 | class UIMovieClip extends MovieClip implements UIDisplayObject 7 | { 8 | public var owner(get, never) : GObject; 9 | 10 | private var _owner : GObject; 11 | 12 | public function new(owner : GObject) 13 | { 14 | super(); 15 | _owner = owner; 16 | } 17 | 18 | private function get_owner() : GObject 19 | { 20 | return _owner; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/fairygui/tree/ITreeListener.hx: -------------------------------------------------------------------------------- 1 | package fairygui.tree; 2 | 3 | import fairygui.tree.TreeNode; 4 | 5 | import fairygui.GComponent; 6 | import fairygui.event.ItemEvent; 7 | 8 | interface ITreeListener 9 | { 10 | 11 | function treeNodeCreateCell(node : TreeNode) : GComponent; 12 | function treeNodeRender(node : TreeNode, obj : GComponent) : Void; 13 | function treeNodeWillExpand(node : TreeNode, expand : Bool) : Void; 14 | function treeNodeClick(node : TreeNode, evt : ItemEvent) : Void; 15 | } 16 | -------------------------------------------------------------------------------- /src/fairygui/text/LinkButton.hx: -------------------------------------------------------------------------------- 1 | package fairygui.text; 2 | 3 | 4 | import openfl.display.Sprite; 5 | 6 | class LinkButton extends Sprite 7 | { 8 | public var owner : HtmlNode; 9 | 10 | @:allow(fairygui.text) 11 | private function new() 12 | { 13 | super(); 14 | } 15 | 16 | public function setSize(w:Float, h:Float):Void 17 | { 18 | buttonMode = true; 19 | graphics.beginFill(0, 0); 20 | graphics.drawRect(0, 0, w, h); 21 | graphics.endFill(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/tweenx909/rule/QuakeX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | using tweenxcore.Tools.Easing; 3 | 4 | /** 5 | * ... 6 | * @author shohei909 7 | */ 8 | class QuakeX 9 | { 10 | public var ease:Float->Float; 11 | public var value:Float; 12 | public var scale:Float; 13 | 14 | public function new(value:Float, scale:Float, ease:Float->Float = null) { 15 | this.value = value; 16 | this.scale = scale; 17 | if (ease == null) this.ease = Easing.warpOut; 18 | else this.ease = ease; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/fairygui/display/UISprite.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import fairygui.GObject; 5 | import openfl.display.Sprite; 6 | 7 | class UISprite extends Sprite implements UIDisplayObject 8 | { 9 | public var owner(get, never) : GObject; 10 | 11 | private var _owner : GObject; 12 | 13 | public function new(owner : GObject) 14 | { 15 | super(); 16 | _owner = owner; 17 | } 18 | 19 | private function get_owner() : GObject 20 | { 21 | return _owner; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/fairygui/display/UIImage.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import openfl.display.Bitmap; 5 | 6 | import fairygui.GObject; 7 | 8 | class UIImage extends Bitmap implements UIDisplayObject 9 | { 10 | public var owner(get, never) : GObject; 11 | 12 | private var _owner : GObject; 13 | 14 | public function new(owner : GObject) 15 | { 16 | super(); 17 | _owner = owner; 18 | } 19 | 20 | private function get_owner() : GObject 21 | { 22 | return _owner; 23 | } 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/fairygui/display/UITextField.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import openfl.text.TextField; 5 | 6 | import fairygui.GObject; 7 | 8 | class UITextField extends TextField implements UIDisplayObject 9 | { 10 | public var owner(get, never) : GObject; 11 | 12 | private var _owner : GObject; 13 | 14 | public function new(owner : GObject) 15 | { 16 | super(); 17 | _owner = owner; 18 | } 19 | 20 | private function get_owner() : GObject 21 | { 22 | return _owner; 23 | } 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/fairygui/display/UIRichTextField.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import fairygui.GObject; 5 | import fairygui.text.RichTextField; 6 | 7 | class UIRichTextField extends RichTextField implements UIDisplayObject 8 | { 9 | public var owner(get, never) : GObject; 10 | 11 | private var _owner : GObject; 12 | 13 | public function new(owner : GObject) 14 | { 15 | super(); 16 | _owner = owner; 17 | } 18 | 19 | private function get_owner() : GObject 20 | { 21 | return _owner; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/fairygui/text/BMGlyph.hx: -------------------------------------------------------------------------------- 1 | package fairygui.text; 2 | 3 | 4 | import fairygui.PackageItem; 5 | 6 | class BMGlyph 7 | { 8 | public var x : Int = 0; 9 | public var y : Int = 0; 10 | public var offsetX : Int = 0; 11 | public var offsetY : Int = 0; 12 | public var width : Int = 0; 13 | public var height : Int = 0; 14 | public var advance : Int = 0; 15 | public var lineHeight : Int = 0; 16 | public var channel : Int = 0; 17 | public var imageItem : PackageItem; 18 | 19 | public function new() 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/tweenx909/rule/BoolRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenx909.TweenX; 3 | 4 | /** 5 | * Bool値に対するルール。 6 | * falseを0,trueを1とみなしてトゥイーンした後、 7 | * 0以下の数値をfalse、その他の数値をtrueとみなしてターゲットに値を反映 8 | * @author shohei909 9 | */ 10 | 11 | class BoolRuleX{ 12 | public static var inputClass(default,null):Dynamic = Bool; 13 | public static function calc(_from:Bool, _to:Bool, t1:Float, t2:Float, tween:TweenX):Bool { 14 | return 0 < (_from?1:0) * t2 + (_to?1:0) * t1; 15 | } 16 | public static function defaultFrom(value:Bool, _to:Bool, tween:TweenX):Bool { return value; } 17 | } 18 | -------------------------------------------------------------------------------- /src/tweenx909/EventX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909; 2 | 3 | /** 4 | * ... 5 | * @author shohei909 6 | */ 7 | 8 | class EventX { 9 | public static inline var PLAY = "play"; 10 | public static inline var DELAY = "delay"; 11 | public static inline var HEAD = "head"; 12 | public static inline var UPDATE = "update"; 13 | public static inline var FOOT = "foot"; 14 | public static inline var INTERVAL = "interval"; 15 | public static inline var REPEAT = "repeat"; 16 | public static inline var REST = "rest"; 17 | public static inline var FINISH = "finish"; 18 | public static inline var STOP = "stop"; 19 | } 20 | -------------------------------------------------------------------------------- /src/fairygui/GroupLayoutType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | class GroupLayoutType 3 | { 4 | public static var None:Int = 0; 5 | public static var Horizontal:Int = 1; 6 | public static var Vertical:Int = 2; 7 | 8 | public function new() 9 | { 10 | 11 | } 12 | 13 | public static function parse(value:String):Int 14 | { 15 | switch (value) 16 | { 17 | case "none": 18 | return None; 19 | case "hz": 20 | return Horizontal; 21 | case "vt": 22 | return Vertical; 23 | default: 24 | return None; 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/tweenx909/advanced/GroupX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.advanced; 2 | import tweenx909.TweenX; 3 | 4 | /** @private */ 5 | @:noCompletion 6 | class GroupX { 7 | public var current:Float = 0; 8 | public var tweens:Array; 9 | public var source:Iterable; 10 | public var type:GroupTypeX; 11 | public var defaults:DefaultsX; 12 | 13 | public function new(source:Iterable, type:GroupTypeX, defaults:DefaultsX) { 14 | this.source = source; 15 | this.type = type; 16 | if (defaults != null) this.defaults = defaults.clone(); 17 | } 18 | } 19 | 20 | private enum GroupTypeX { 21 | SERIAL; 22 | LAG(lag:Float); 23 | } 24 | -------------------------------------------------------------------------------- /src/fairygui/ButtonMode.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ButtonMode 5 | { 6 | public static inline var Common : Int = 0; 7 | public static inline var Check : Int = 1; 8 | public static inline var Radio : Int = 2; 9 | 10 | public function new() 11 | { 12 | } 13 | 14 | public static function parse(value : String) : Int 15 | { 16 | switch (value) 17 | { 18 | case "Common": 19 | return Common; 20 | case "Check": 21 | return Check; 22 | case "Radio": 23 | return Radio; 24 | default: 25 | return Common; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/fairygui/FillType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class FillType 5 | { 6 | public static inline var None : Int = 0; 7 | public static inline var Scale : Int = 3; 8 | public static inline var ScaleFree : Int = 4; 9 | 10 | public function new() 11 | { 12 | } 13 | 14 | public static function parse(value : String) : Int 15 | { 16 | switch (value) 17 | { 18 | case "none": 19 | return None; 20 | case "scale": 21 | return Scale; 22 | case "scaleFree": 23 | return ScaleFree; 24 | default: 25 | return None; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/fairygui/VertAlignType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class VertAlignType 5 | { 6 | public static inline var Top : Int = 0; 7 | public static inline var Middle : Int = 1; 8 | public static inline var Bottom : Int = 2; 9 | 10 | public function new() 11 | { 12 | } 13 | 14 | public static function parse(value : String) : Int 15 | { 16 | switch (value) 17 | { 18 | case "top": 19 | return Top; 20 | case "middle": 21 | return Middle; 22 | case "bottom": 23 | return Bottom; 24 | default: 25 | return Top; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/tweenxcore/structure/FloatChangeTimelinePart.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.structure; 2 | import haxe.ds.Option; 3 | 4 | class FloatChangeTimelinePart extends FloatChangePart 5 | { 6 | public var isMinerChange(default, null):Bool; 7 | public var index(default, null):Float; 8 | public var rangeLeft(default, null):Float; 9 | public var rangeRight(default, null):Float; 10 | 11 | public inline function new (previousValue:Float, currentValue:Float, index:Int, rangeLeft:Float, rangeRight:Float, isMinerChange:Bool) 12 | { 13 | super(previousValue, currentValue); 14 | this.index = index; 15 | this.rangeLeft = rangeLeft; 16 | this.rangeRight = rangeRight; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/fairygui/ChildrenRenderOrder.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ChildrenRenderOrder 5 | { 6 | public static inline var Ascent : Int = 0; 7 | public static inline var Descent : Int = 1; 8 | public static inline var Arch : Int = 2; 9 | 10 | public function new() 11 | { 12 | } 13 | 14 | public static function parse(value:String):Int 15 | { 16 | switch (value) 17 | { 18 | case "ascent": 19 | return Ascent; 20 | case "descent": 21 | return Descent; 22 | case "arch": 23 | return Arch; 24 | default: 25 | return Ascent; 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/fairygui/ScrollType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ScrollType 5 | { 6 | public static inline var Horizontal : Int = 0; 7 | public static inline var Vertical : Int = 1; 8 | public static inline var Both : Int = 2; 9 | 10 | public function new() 11 | { 12 | } 13 | 14 | public static function parse(value : String) : Int 15 | { 16 | switch (value) 17 | { 18 | case "horizontal": 19 | return Horizontal; 20 | case "vertical": 21 | return Vertical; 22 | case "both": 23 | return Both; 24 | default: 25 | return Vertical; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/tweenxcore/color/IColor.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.color; 2 | 3 | interface IColor 4 | { 5 | public function getRed():Float; 6 | public function getGreen():Float; 7 | public function getBlue():Float; 8 | 9 | public function getHue():Float; 10 | public function getSaturation():Float; 11 | public function getBrightness():Float; 12 | 13 | public function toRgb():RgbColor; 14 | public function toHsv():HsvColor; 15 | public function toRgbWithAlpha(alpha:Float):ArgbColor; 16 | public function toHsvWithAlpha(alpha:Float):AhsvColor; 17 | 18 | public function toRgbInt():Int; 19 | public function toRgbHexString():String; 20 | public function toRgbCssString():String; 21 | } 22 | -------------------------------------------------------------------------------- /src/tweenxcore/structure/TimelineSearchResult.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.structure; 2 | using tweenxcore.Tools; 3 | 4 | class TimelineSearchResult{ 5 | public var data(default, null):T; 6 | public var index(default, null):Int; 7 | public var rangeLeft(default, null):Float; 8 | public var rangeRight(default, null):Float; 9 | 10 | public inline function new(data:T, index:Int, rangeLeft:Float, rangeRight:Float) { 11 | this.data = data; 12 | this.index = index; 13 | this.rangeLeft = rangeLeft; 14 | this.rangeRight = rangeRight; 15 | } 16 | 17 | public inline function innerRate(rate:Float) 18 | { 19 | return rate.inverseLerp(rangeLeft, rangeRight); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/tweenx909/rule/HsvRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenxcore.color.HsvColor; 3 | import tweenx909.TweenX; 4 | 5 | /** 6 | * ... 7 | * @author shohei909 8 | */ 9 | class HsvRuleX { 10 | public static var inputClass(default, null):Dynamic = HsvColor; 11 | 12 | public static function calc(_from:HsvColor, _to:HsvColor, t1:Float, t2:Float, tween:TweenX):Int { 13 | var h = _from.h * t2 + _to.h * t1; 14 | var s = _from.s * t2 + _to.s * t1; 15 | var v = _from.v * t2 + _to.v * t1; 16 | 17 | return HsvColor.hsvToRgbInt(h, s, v); 18 | } 19 | 20 | public static function defaultFrom(value:Int, _to:HsvColor, tween:TweenX) { 21 | return HsvColor.of(value); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/tweenx909/rule/RgbRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenxcore.color.RgbColor; 3 | import tweenx909.TweenX; 4 | 5 | /** 6 | * ... 7 | * @author shohei909 8 | */ 9 | class RgbRuleX { 10 | public static var inputClass(default, null):Dynamic = RgbColor; 11 | 12 | public static function calc(_from:RgbColor, _to:RgbColor, t1:Float, t2:Float, tween:TweenX):Int { 13 | var r = _from.r * t2 + _to.r * t1; 14 | var g = _from.g * t2 + _to.g * t1; 15 | var b = _from.b * t2 + _to.b * t1; 16 | return RgbColor.rgbToInt(r, g, b); 17 | } 18 | 19 | public static function defaultFrom(value:Int, _to:RgbColor, tween:TweenX):RgbColor { 20 | return RgbColor.of(value); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/fairygui/utils/PixelHitTestData.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | import openfl.utils.ByteArray; 4 | 5 | class PixelHitTestData { 6 | public var pixelWidth:Int; 7 | public var scale:Float; 8 | public var pixels:Array; 9 | 10 | public function new() 11 | { 12 | } 13 | 14 | public function load(ba:ByteArray):Void 15 | { 16 | ba.readInt(); 17 | pixelWidth = ba.readInt(); 18 | scale = ba.readByte(); 19 | var len:Int = ba.readInt(); 20 | pixels = new Array(); 21 | for(i in 0...len) 22 | { 23 | var j:Int = ba.readByte(); 24 | if(j<0) 25 | j+=256; 26 | 27 | pixels[i] = j; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/fairygui/FlipType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class FlipType 5 | { 6 | public static inline var None : Int = 0; 7 | public static inline var Horizontal : Int = 1; 8 | public static inline var Vertical : Int = 2; 9 | public static inline var Both : Int = 3; 10 | 11 | public function new() 12 | { 13 | } 14 | 15 | public static function parse(value : String) : Int 16 | { 17 | switch (value) 18 | { 19 | case "hz": 20 | return FlipType.Horizontal; 21 | case "vt": 22 | return FlipType.Vertical; 23 | case "both": 24 | return FlipType.Both; 25 | default: 26 | return FlipType.None; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/tweenx909/rule/ArgbRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenxcore.color.ArgbColor; 3 | import tweenx909.TweenX; 4 | 5 | /** 6 | * ... 7 | * @author shohei909 8 | */ 9 | class ArgbRuleX { 10 | public static var inputClass(default, null):Dynamic = ArgbColor; 11 | 12 | public static function calc(_from:ArgbColor, _to:ArgbColor, t1:Float, t2:Float, tween:TweenX):Int { 13 | var a = _from.a * t2 + _to.a * t1; 14 | var r = _from.r * t2 + _to.r * t1; 15 | var g = _from.g * t2 + _to.g * t1; 16 | var b = _from.b * t2 + _to.b * t1; 17 | 18 | return ArgbColor.argbToInt(a, r, g, b); 19 | } 20 | 21 | public static function defaultFrom(value:Int, _to:ArgbColor, tween:TweenX) { 22 | return ArgbColor.of(value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/tweenx909/rule/AhsvRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenxcore.color.AhsvColor; 3 | import tweenx909.TweenX; 4 | 5 | /** 6 | * ... 7 | * @author shohei909 8 | */ 9 | class AhsvRuleX { 10 | public static var inputClass(default, null):Dynamic = AhsvColor; 11 | 12 | public static function calc(_from:AhsvColor, _to:AhsvColor, t1:Float, t2:Float, tween:TweenX):Int { 13 | var a = _from.a * t2 + _to.a * t1; 14 | var h = _from.h * t2 + _to.h * t1; 15 | var s = _from.s * t2 + _to.s * t1; 16 | var v = _from.v * t2 + _to.v * t1; 17 | 18 | return AhsvColor.ahsvToArgbInt(a, h, s, v); 19 | } 20 | 21 | public static function defaultFrom(value:Int, _to:AhsvColor, tween:TweenX) { 22 | return AhsvColor.of(value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/fairygui/AutoSizeType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class AutoSizeType 5 | { 6 | public static inline var None : Int = 0; 7 | public static inline var Both : Int = 1; 8 | public static inline var Height : Int = 2; 9 | public static inline var Shrink : Int = 3; 10 | 11 | public function new() 12 | { 13 | } 14 | 15 | public static function parse(value : String) : Int 16 | { 17 | switch (value) 18 | { 19 | case "none": 20 | return None; 21 | case "both": 22 | return Both; 23 | case "height": 24 | return Height; 25 | case "shrink": 26 | return Shrink; 27 | default: 28 | return None; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/tweenx909/rule/QuakeRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | 3 | import tweenx909.EaseX; 4 | import tweenx909.TweenX; 5 | import tweenx909.rule.QuakeX; 6 | 7 | /** 8 | * ... 9 | * @author shohei909 10 | */ 11 | 12 | class QuakeRuleX { 13 | public static var inputClass(default,null):Dynamic = QuakeX; 14 | public static function calc(_from:QuakeX, _to:QuakeX, t1:Float, t2:Float, tween:TweenX):Float { 15 | var p:Float = 16 | if (t1 < 0.5) _from.ease(t1 * 2); 17 | else _to.ease(t2 * 2); 18 | return _from.value * t2 + _to.value * t1 + p * (Math.random() * 2 - 1) * (_from.scale * t2 + _to.scale * t1); 19 | } 20 | public static function defaultFrom(value:Float, _to:QuakeX, tween:TweenX):QuakeX { 21 | return new QuakeX(value, _to.scale, _to.ease); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/tweenx909/rule/TimelineRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenx909.TweenX; 3 | import tweenxcore.structure.BoundaryMode; 4 | import tweenxcore.structure.Timeline; 5 | import tweenxcore.structure.TimelineSearchResult; 6 | 7 | /** 8 | * @author shohei909 9 | */ 10 | class TimelineRuleX { 11 | public static var inputClass(default, null):Dynamic = Timeline; 12 | 13 | public static function calc(_from:Searchable, _to:Searchable, t1:Float, t2:Float, tween:TweenX):Dynamic { 14 | return _to.search(t1).data; 15 | } 16 | 17 | public static function defaultFrom(value:Dynamic, _to:Timeline, tween:TweenX):Dynamic { return null; } 18 | } 19 | 20 | private typedef Searchable = { 21 | public function search(rate:Float, ?boundaryMode:BoundaryMode):TimelineSearchResult; 22 | } 23 | -------------------------------------------------------------------------------- /src/fairygui/ScrollBarDisplayType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ScrollBarDisplayType 5 | { 6 | public static inline var Default : Int = 0; 7 | public static inline var Visible : Int = 1; 8 | public static inline var Auto : Int = 2; 9 | public static inline var Hidden : Int = 3; 10 | 11 | public function new() 12 | { 13 | } 14 | 15 | public static function parse(value : String) : Int 16 | { 17 | switch (value) 18 | { 19 | case "default": 20 | return Default; 21 | case "visible": 22 | return Visible; 23 | case "auto": 24 | return Auto; 25 | case "hidden": 26 | return Hidden; 27 | default: 28 | return Default; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/fairygui/text/HtmlNode.hx: -------------------------------------------------------------------------------- 1 | package fairygui.text; 2 | 3 | 4 | import openfl.display.DisplayObject; 5 | 6 | class HtmlNode 7 | { 8 | public var charStart : Int = 0; 9 | public var charEnd : Int = 0; 10 | public var lineIndex : Int = 0; 11 | public var nodeIndex : Int = 0; 12 | 13 | public var element : HtmlElement; 14 | 15 | public var displayObject : DisplayObject; 16 | public var topY : Float = 0; 17 | public var posUpdated : Bool = false; 18 | 19 | @:allow(fairygui.text) 20 | private function new() 21 | { 22 | } 23 | 24 | public function reset() : Void 25 | { 26 | charStart = -1; 27 | charEnd = -1; 28 | lineIndex = -1; 29 | nodeIndex = -1; 30 | 31 | displayObject = null; 32 | posUpdated = false; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/fairygui/ProgressTitleType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ProgressTitleType 5 | { 6 | public static inline var Percent : Int = 0; 7 | public static inline var ValueAndMax : Int = 1; 8 | public static inline var Value : Int = 2; 9 | public static inline var Max : Int = 3; 10 | 11 | public function new() 12 | { 13 | } 14 | 15 | public static function parse(value : String) : Int 16 | { 17 | switch (value) 18 | { 19 | case "percent": 20 | return Percent; 21 | case "valueAndmax": 22 | return ValueAndMax; 23 | case "value": 24 | return Value; 25 | case "max": 26 | return Max; 27 | default: 28 | return Percent; 29 | } 30 | } 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/fairygui/text/HtmlElement.hx: -------------------------------------------------------------------------------- 1 | package fairygui.text; 2 | 3 | 4 | import openfl.text.TextFormat; 5 | 6 | class HtmlElement 7 | { 8 | public var type : Int = 0; //0-none, 1-link, 2-image 9 | 10 | public var start : Int = 0; 11 | public var end : Int = 0; 12 | public var textformat : TextFormat; 13 | public var id : String; 14 | public var width : Int = 0; 15 | public var height : Int = 0; 16 | 17 | //link 18 | public var href : String; 19 | public var target : String; 20 | 21 | //image 22 | public var src : String; 23 | public var realWidth : Int; 24 | public var realHeight : Int; 25 | 26 | public static inline var LINK : Int = 1; 27 | public static inline var IMAGE : Int = 2; 28 | 29 | @:allow(fairygui.text) 30 | private function new() 31 | { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/WindowA.hx: -------------------------------------------------------------------------------- 1 | 2 | import fairygui.GButton; 3 | import fairygui.GList; 4 | import fairygui.UIPackage; 5 | import fairygui.Window; 6 | 7 | class WindowA extends Window 8 | { 9 | public function new() 10 | { 11 | super(); 12 | } 13 | 14 | override private function onInit() : Void 15 | { 16 | this.contentPane = UIPackage.createObject("Basic", "WindowA").asCom; 17 | this.center(); 18 | } 19 | 20 | override private function onShown() : Void 21 | { 22 | var list : GList = this.contentPane.getChild("n6").asList; 23 | list.removeChildrenToPool(); 24 | 25 | for (i in 0...6){ 26 | var item : GButton = list.addItemFromPool().asButton; 27 | item.title = "" + i; 28 | item.icon = UIPackage.getItemURL("Basic", "r4"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/fairygui/ListSelectionMode.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ListSelectionMode 5 | { 6 | public static inline var Single : Int = 0; 7 | public static inline var Multiple : Int = 1; 8 | public static inline var Multiple_SingleClick : Int = 2; 9 | public static inline var None : Int = 3; 10 | 11 | public function new() 12 | { 13 | } 14 | 15 | public static function parse(value : String) : Int 16 | { 17 | switch (value) 18 | { 19 | case "single": 20 | return Single; 21 | case "multiple": 22 | return Multiple; 23 | case "multipleSingleClick": 24 | return Multiple_SingleClick; 25 | case "none": 26 | return None; 27 | default: 28 | return Single; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/fairygui/event/DragEvent.hx: -------------------------------------------------------------------------------- 1 | package fairygui.event; 2 | 3 | 4 | import openfl.events.Event; 5 | 6 | class DragEvent extends Event 7 | { 8 | public var stageX : Float; 9 | public var stageY : Float; 10 | public var touchPointID : Int; 11 | 12 | public static inline var DRAG_START : String = "startDrag"; 13 | public static inline var DRAG_END : String = "endDrag"; 14 | public static inline var DRAG_MOVING : String = "dragMoving"; 15 | 16 | public function new(type : String, stageX : Float = 0, stageY : Float = 0, touchPointID : Int = -1) 17 | { 18 | super(type, false, true); 19 | 20 | this.stageX = stageX; 21 | this.stageY = stageY; 22 | this.touchPointID = touchPointID; 23 | } 24 | 25 | override public function clone() : Event{ 26 | return new DragEvent(type, stageX, stageY, touchPointID); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/ExprMaker.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | import haxe.PosInfos; 3 | import haxe.macro.Context; 4 | import haxe.macro.Expr; 5 | import tweenxcore.expr.ExprMaker.ExprMakeTools; 6 | 7 | class ExprMakeTools 8 | { 9 | public static function floatToExpr(float:Float):ExprOf 10 | { 11 | return { 12 | expr: ExprDef.EConst(Constant.CFloat(Std.string(float))), 13 | pos: pos(), 14 | } 15 | } 16 | 17 | public static function floatArrayToExpr(floats:Array):ExprOf> 18 | { 19 | return { 20 | expr: ExprDef.EArrayDecl([for (float in floats) floatToExpr(float)]), 21 | pos: pos(), 22 | } 23 | } 24 | 25 | public static function pos():Position 26 | { 27 | return 28 | #if macro 29 | Context.currentPos(); 30 | #else 31 | null; 32 | #end 33 | } 34 | } -------------------------------------------------------------------------------- /src/fairygui/OverflowType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class OverflowType 5 | { 6 | public static inline var Visible : Int = 0; 7 | public static inline var Hidden : Int = 1; 8 | public static inline var Scroll : Int = 2; 9 | public static inline var Scale : Int = 3; 10 | public static inline var ScaleFree : Int = 4; 11 | 12 | public function new() 13 | { 14 | } 15 | 16 | public static function parse(value : String) : Int 17 | { 18 | switch (value) 19 | { 20 | case "visible": 21 | return Visible; 22 | case "hidden": 23 | return Hidden; 24 | case "scroll": 25 | return Scroll; 26 | case "scale": 27 | return Scale; 28 | case "scaleFree": 29 | return ScaleFree; 30 | default: 31 | return Visible; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/fairygui/AlignType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | import openfl.text.TextFormatAlign; 5 | 6 | class AlignType 7 | { 8 | public static inline var Left : Int = 0; 9 | public static inline var Center : Int = 1; 10 | public static inline var Right : Int = 2; 11 | 12 | public function new() 13 | { 14 | } 15 | 16 | public static function parse(value : String) : Int 17 | { 18 | switch (value) 19 | { 20 | case "left": 21 | return Left; 22 | case "center": 23 | return Center; 24 | case "right": 25 | return Right; 26 | default: 27 | return Left; 28 | } 29 | } 30 | 31 | public static function toString(type : Int) : String 32 | { 33 | return (type == Left) ? TextFormatAlign.LEFT : 34 | ((type == Center) ? TextFormatAlign.CENTER : TextFormatAlign.RIGHT); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/fairygui/ZipUIPackageReader.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | import fairygui.utils.ZipReader; 5 | import openfl.utils.ByteArray; 6 | 7 | class ZipUIPackageReader implements IUIPackageReader 8 | { 9 | private var _desc:ZipReader; 10 | private var _files:ZipReader; 11 | 12 | public function new(desc:ByteArray, res:ByteArray) 13 | { 14 | _desc = new ZipReader(desc); 15 | if (res != null && res.length > 0) 16 | _files = new ZipReader(res); 17 | else 18 | _files = _desc; 19 | } 20 | 21 | public function readDescFile(fileName:String):String 22 | { 23 | var ba:ByteArray = _desc.getEntryData(fileName); 24 | ba.position = 0; 25 | var str:String = ba.readUTFBytes(ba.length); 26 | ba.clear(); 27 | 28 | return str; 29 | } 30 | 31 | public function readResFile(fileName:String):ByteArray 32 | { 33 | return _files.getEntryData(fileName); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/fairygui/LoaderFillType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class LoaderFillType 5 | { 6 | public static inline var None : Int = 0; 7 | public static inline var Scale : Int = 1; 8 | public static inline var ScaleMatchHeight : Int = 2; 9 | public static inline var ScaleMatchWidth : Int = 3; 10 | public static inline var ScaleFree : Int = 4; 11 | 12 | public function new() 13 | { 14 | } 15 | 16 | public static function parse(value : String) : Int 17 | { 18 | switch (value) 19 | { 20 | case "none": 21 | return None; 22 | case "scale": 23 | return Scale; 24 | case "scaleMatchHeight": 25 | return ScaleMatchHeight; 26 | case "scaleMatchWidth": 27 | return ScaleMatchWidth; 28 | case "scaleFree": 29 | return ScaleFree; 30 | default: 31 | return None; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/fairygui/ListLayoutType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class ListLayoutType 5 | { 6 | public static inline var SingleColumn : Int = 0; 7 | public static inline var SingleRow : Int = 1; 8 | public static inline var FlowHorizontal : Int = 2; 9 | public static inline var FlowVertical : Int = 3; 10 | public static inline var Pagination : Int = 4; 11 | 12 | public function new() 13 | { 14 | } 15 | 16 | public static function parse(value : String) : Int 17 | { 18 | switch (value) 19 | { 20 | case "column": 21 | return SingleColumn; 22 | case "row": 23 | return SingleRow; 24 | case "flow_hz": 25 | return FlowHorizontal; 26 | case "flow_vt": 27 | return FlowVertical; 28 | case "pagination": 29 | return Pagination; 30 | default: 31 | return SingleColumn; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /FairyGUI-haxe.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/fairygui/event/ItemEvent.hx: -------------------------------------------------------------------------------- 1 | package fairygui.event; 2 | 3 | 4 | import openfl.events.Event; 5 | 6 | import fairygui.GObject; 7 | 8 | class ItemEvent extends Event 9 | { 10 | public var itemObject : GObject; 11 | public var stageX : Float; 12 | public var stageY : Float; 13 | public var clickCount : Int; 14 | public var rightButton : Bool; 15 | 16 | public static inline var CLICK : String = "itemClick"; 17 | 18 | public function new(type : String, itemObject : GObject = null, 19 | stageX : Float = 0, stageY : Float = 0, clickCount : Int = 1, rightButton : Bool = false) 20 | { 21 | super(type, false, false); 22 | this.itemObject = itemObject; 23 | this.stageX = stageX; 24 | this.stageY = stageY; 25 | this.clickCount = clickCount; 26 | this.rightButton = rightButton; 27 | } 28 | 29 | override public function clone() : Event{ 30 | return new ItemEvent(type, itemObject, stageX, stageY, clickCount, rightButton); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/fairygui/PackageItemType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class PackageItemType 5 | { 6 | public static inline var Image : Int = 0; 7 | public static inline var Swf : Int = 1; 8 | public static inline var MovieClip : Int = 2; 9 | public static inline var Sound : Int = 3; 10 | public static inline var Component : Int = 4; 11 | public static inline var Misc : Int = 5; 12 | public static inline var Font : Int = 6; 13 | 14 | public function new() 15 | { 16 | } 17 | 18 | public static function parseType(value : String) : Int 19 | { 20 | switch (value) 21 | { 22 | case "image": 23 | return Image; 24 | case "movieclip": 25 | return MovieClip; 26 | case "sound": 27 | return Sound; 28 | case "component": 29 | return Component; 30 | case "swf": 31 | return Swf; 32 | case "font": 33 | return Font; 34 | } 35 | return 0; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/fairygui/Margin.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class Margin 5 | { 6 | public var left : Int = 0; 7 | public var right : Int = 0; 8 | public var top : Int = 0; 9 | public var bottom : Int = 0; 10 | 11 | public function new() 12 | { 13 | } 14 | 15 | public function parse(str : String) : Void 16 | { 17 | var arr : Array = str.split(","); 18 | if (arr.length == 1) 19 | { 20 | var k : Int = Std.parseInt(arr[0]); 21 | top = k; 22 | bottom = k; 23 | left = k; 24 | right = k; 25 | } 26 | else 27 | { 28 | top = Std.parseInt(arr[0]); 29 | bottom = Std.parseInt(arr[1]); 30 | left = Std.parseInt(arr[2]); 31 | right = Std.parseInt(arr[3]); 32 | } 33 | } 34 | 35 | public function copy(source : Margin) : Void 36 | { 37 | top = source.top; 38 | bottom = source.bottom; 39 | left = source.left; 40 | right = source.right; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tweenxcore/structure/FloatChangeRepeatPart.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.structure; 2 | import haxe.ds.Option; 3 | 4 | class FloatChangeRepeatPart extends FloatChangePart 5 | { 6 | public var isMinerChange(default, null):Bool; 7 | public var repeatIndex(default, null):Int; 8 | public var repeatLength(default, null):Int; 9 | 10 | public inline function new (previousValue:Float, currentValue:Float, repeatIndex:Int, repeatLength:Int, isMinerChange:Bool) 11 | { 12 | super(previousValue, currentValue); 13 | this.repeatIndex = repeatIndex; 14 | this.repeatLength = repeatLength; 15 | this.isMinerChange = isMinerChange; 16 | } 17 | 18 | public inline function isFirstEntrance():Bool { 19 | return (repeatIndex == 0 && previous <= 0 && 0 < current) || 20 | (repeatIndex == repeatLength - 1 && current < 1.0 && 1.0 <= previous); 21 | } 22 | 23 | public inline function isLastExit():Bool { 24 | return (repeatIndex == 0 && current <= 0.0 && 0.0 < previous) || 25 | (repeatIndex == repeatLength - 1 && previous < 1.0 && 1.0 <= current); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Rakuten 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/fairygui/event/FocusChangeEvent.hx: -------------------------------------------------------------------------------- 1 | package fairygui.event; 2 | 3 | 4 | import openfl.events.Event; 5 | 6 | import fairygui.GObject; 7 | 8 | class FocusChangeEvent extends Event 9 | { 10 | public var oldFocusedObject(get, never) : GObject; 11 | public var newFocusedObject(get, never) : GObject; 12 | 13 | public static inline var CHANGED : String = "focusChanged"; 14 | 15 | private var _oldFocusedObject : GObject; 16 | private var _newFocusedObject : GObject; 17 | 18 | public function new(type : String, oldObject : GObject, newObject : GObject) 19 | { 20 | super(type, false, false); 21 | _oldFocusedObject = oldObject; 22 | _newFocusedObject = newObject; 23 | } 24 | 25 | @:final private function get_oldFocusedObject() : GObject 26 | { 27 | return _oldFocusedObject; 28 | } 29 | 30 | @:final private function get_newFocusedObject() : GObject 31 | { 32 | return _newFocusedObject; 33 | } 34 | 35 | override public function clone() : Event{ 36 | return new FocusChangeEvent(type, _oldFocusedObject, _newFocusedObject); 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/fairygui/action/ChangePageAction.hx: -------------------------------------------------------------------------------- 1 | package fairygui.action; 2 | class ChangePageAction extends ControllerAction 3 | { 4 | public var objectId:String; 5 | public var controllerName:String; 6 | public var targetPage:String; 7 | 8 | public function new() 9 | { 10 | super(); 11 | } 12 | 13 | override private function enter(controller:Controller):Void 14 | { 15 | if (controllerName == null) 16 | return; 17 | 18 | var gcom:GComponent; 19 | if (objectId != null) 20 | gcom = cast(controller.parent.getChildById(objectId), GComponent); 21 | else 22 | gcom = controller.parent; 23 | 24 | if (gcom != null) 25 | { 26 | var cc:Controller = gcom.getController(controllerName); 27 | if (cc != null && cc != controller && !cc.changing) 28 | cc.selectedPageId = targetPage; 29 | } 30 | } 31 | 32 | override public function setup(xml:FastXML):Void 33 | { 34 | super.setup(xml); 35 | 36 | objectId = xml.att.objectId; 37 | controllerName = xml.att.controller; 38 | targetPage = xml.att.targetPage; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/fairygui/GearText.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GObject; 4 | 5 | 6 | class GearText extends GearBase 7 | { 8 | private var _storage:Map; 9 | private var _default:String; 10 | 11 | public function new(owner:GObject) 12 | { 13 | super(owner); 14 | } 15 | 16 | override private function init():Void 17 | { 18 | _default = _owner.text; 19 | _storage = new Map(); 20 | } 21 | 22 | override private function addStatus(pageId:String, value:String):Void 23 | { 24 | if (pageId == null) 25 | _default = value; 26 | else 27 | _storage[pageId] = value; 28 | } 29 | 30 | override public function apply():Void 31 | { 32 | _owner._gearLocked = true; 33 | 34 | var data:String = _storage[_controller.selectedPageId]; 35 | if (data != null) 36 | _owner.text = data; 37 | else 38 | _owner.text = _default; 39 | 40 | _owner._gearLocked = false; 41 | } 42 | 43 | override public function updateState():Void 44 | { 45 | _storage[_controller.selectedPageId] = _owner.text; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/fairygui/GearIcon.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GObject; 4 | 5 | 6 | class GearIcon extends GearBase 7 | { 8 | private var _storage:Map; 9 | private var _default:String; 10 | 11 | public function new(owner:GObject) 12 | { 13 | super(owner); 14 | } 15 | 16 | override private function init():Void 17 | { 18 | _default = _owner.icon; 19 | _storage = new Map(); 20 | } 21 | 22 | override private function addStatus(pageId:String, value:String):Void 23 | { 24 | if (pageId == null) 25 | _default = value; 26 | else 27 | _storage[pageId] = value; 28 | } 29 | 30 | override public function apply():Void 31 | { 32 | _owner._gearLocked = true; 33 | 34 | var data:Dynamic = _storage[_controller.selectedPageId]; 35 | if (data != null) 36 | _owner.icon = Std.string(data); 37 | else 38 | _owner.icon = _default; 39 | 40 | _owner._gearLocked = false; 41 | } 42 | 43 | override public function updateState():Void 44 | { 45 | _storage[_controller.selectedPageId] = _owner.icon; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/fairygui/GearDisplay.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GObject; 4 | 5 | 6 | class GearDisplay extends GearBase 7 | { 8 | public var pages:Array; 9 | 10 | private var _visible:Int = 0; 11 | 12 | public var connected(get, never):Bool; 13 | 14 | public function new(owner:GObject) 15 | { 16 | super(owner); 17 | _displayLockToken = 1; 18 | } 19 | 20 | override private function init():Void 21 | { 22 | pages = null; 23 | } 24 | 25 | public function addLock():UInt 26 | { 27 | _visible++; 28 | return _displayLockToken; 29 | } 30 | 31 | public function releaseLock(token:UInt):Void 32 | { 33 | if (token == _displayLockToken) 34 | _visible--; 35 | } 36 | 37 | private function get_connected():Bool 38 | { 39 | return _controller == null || _visible > 0; 40 | } 41 | 42 | override public function apply():Void 43 | { 44 | _displayLockToken++; 45 | if (_displayLockToken == 0) 46 | _displayLockToken = 1; 47 | 48 | if (pages == null || pages.length == 0 || pages.indexOf(_controller.selectedPageId) != -1) 49 | _visible = 1; 50 | else 51 | _visible = 0; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/tweenxcore/geom/PolarPoint.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.geom; 2 | using tweenxcore.Tools; 3 | 4 | class PolarPoint { 5 | public var distance:Float; 6 | public var angle:Float; 7 | 8 | public var x(get, never):Float; 9 | function get_x() { 10 | return angle.cosByRate() * distance; 11 | } 12 | 13 | public var y(get, never):Float; 14 | function get_y() { 15 | return angle.sinByRate() * distance; 16 | } 17 | 18 | public inline function new(distance:Float, angle:Float) { 19 | this.distance = distance; 20 | this.angle = angle; 21 | } 22 | 23 | public static inline function fromXy(x:Float, y:Float):PolarPoint { 24 | return new PolarPoint(Math.sqrt(x * x + y * y), Math.atan2(y, x)); 25 | } 26 | 27 | public static inline function fromPoint(point:Point):PolarPoint { 28 | return fromXy(point.x, point.y); 29 | } 30 | 31 | public inline function setXy(x:Float, y:Float) { 32 | distance = Math.sqrt(x * x + y * y); 33 | angle = Math.atan2(y, x); 34 | } 35 | 36 | public inline function setPoint(point:Point) { 37 | distance = Math.sqrt(x * x + y * y); 38 | angle = Math.atan2(y, x); 39 | } 40 | 41 | public inline function clone(point:PolarPoint) { 42 | return new PolarPoint(distance, angle); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/fairygui/utils/FontUtils.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | 4 | import openfl.text.Font; 5 | import openfl.text.FontStyle; 6 | import openfl.text.TextFormat; 7 | 8 | class FontUtils 9 | { 10 | private static var sEmbeddedFonts:Array = null; 11 | 12 | public function new() 13 | { 14 | } 15 | 16 | public static function registerFont(fontName:String, path:String):Void 17 | { 18 | var font:Font = Font.fromFile(path); 19 | // font.fontName = fontName; 20 | Font.enumerateFonts().push(font); 21 | } 22 | 23 | public static function updateEmbeddedFonts():Void 24 | { 25 | sEmbeddedFonts = null; 26 | } 27 | 28 | //from starling 29 | public static function isEmbeddedFont(format:TextFormat):Bool 30 | { 31 | if (sEmbeddedFonts == null) 32 | sEmbeddedFonts = Font.enumerateFonts(false); 33 | 34 | for (font in sEmbeddedFonts) 35 | { 36 | var style:String = font.fontStyle; 37 | var isBold:Bool = style == FontStyle.BOLD || style == FontStyle.BOLD_ITALIC; 38 | var isItalic:Bool = style == FontStyle.ITALIC || style == FontStyle.BOLD_ITALIC; 39 | var fBold:Bool = format.bold == null ? false : format.bold; 40 | var fItalic:Bool = format.italic == null ? false : format.italic; 41 | 42 | 43 | if (format.font == font.fontName && fItalic == isItalic && fBold == isBold) 44 | return true; 45 | } 46 | 47 | return false; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/fairygui/action/ControllerAction.hx: -------------------------------------------------------------------------------- 1 | package fairygui.action; 2 | class ControllerAction 3 | { 4 | public var fromPage:Array; 5 | public var toPage:Array; 6 | 7 | public static function createAction(type:String):ControllerAction 8 | { 9 | switch(type) 10 | { 11 | case "play_transition": 12 | return new PlayTransitionAction(); 13 | 14 | case "change_page": 15 | return new ChangePageAction(); 16 | } 17 | return null; 18 | } 19 | 20 | public function new() 21 | { 22 | 23 | } 24 | 25 | public function run(controller:Controller, prevPage:String, curPage:String):Void 26 | { 27 | if ((fromPage == null || fromPage.length == 0 || fromPage.indexOf(prevPage) != -1) 28 | && (toPage == null || toPage.length == 0 || toPage.indexOf(curPage) != -1)) 29 | enter(controller); 30 | else 31 | leave(controller); 32 | } 33 | 34 | @:Allow(fairygui) 35 | private function enter(controller:Controller):Void 36 | { 37 | 38 | } 39 | 40 | @:Allow(fairygui) 41 | private function leave(controller:Controller):Void 42 | { 43 | 44 | } 45 | 46 | public function setup(xml:FastXML):Void 47 | { 48 | var str:String; 49 | 50 | str = xml.att.fromPage; 51 | if (str != null) 52 | fromPage = str.split(","); 53 | 54 | str = xml.att.toPage; 55 | if (str != null) 56 | toPage = str.split(","); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/WindowB.hx: -------------------------------------------------------------------------------- 1 | import tweenxcore.Tools.Easing; 2 | import tweenx909.TweenX; 3 | import fairygui.UIPackage; 4 | import fairygui.Window; 5 | 6 | class WindowB extends Window 7 | { 8 | public function new() 9 | { 10 | super(); 11 | } 12 | 13 | override private function onInit() : Void 14 | { 15 | this.contentPane = UIPackage.createObject("Basic", "WindowB").asCom; 16 | this.center(); 17 | 18 | //弹出窗口的动效已中心为轴心 19 | this.setPivot(0.5,0.5); 20 | } 21 | 22 | override private function doShowAnimation() : Void 23 | { 24 | this.setScale(0.1, 0.1); 25 | TweenX.tweenFunc2(setScale,0.1,0.1,1,1).time(0.3).ease(Easing.quadOut).onFinish(onShown); 26 | // TweenX.to(this, { 27 | // scaleX : 1, 28 | // scaleY : 1 29 | // }, 0.3).ease(Easing.quadOut).onFinish(onShown); 30 | } 31 | 32 | override private function doHideAnimation() : Void 33 | { 34 | TweenX.tweenFunc2(setScale,1,1,0.1,0.1).time(0.3).ease(Easing.quadOut).onFinish(hideImmediately); 35 | // TweenX.to(this, { 36 | // scaleX : 0.1, 37 | // scaleY : 0.1 38 | // }, 0.3).ease(Easing.quadOut).onFinish(hideImmediately); 39 | } 40 | 41 | override private function onShown() : Void 42 | { 43 | contentPane.getTransition("t1").play(); 44 | } 45 | 46 | override private function onHide() : Void 47 | { 48 | contentPane.getTransition("t1").stop(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/fairygui/RelationType.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class RelationType 5 | { 6 | public function new() 7 | { 8 | } 9 | 10 | public static inline var Left_Left : Int = 0; 11 | public static inline var Left_Center : Int = 1; 12 | public static inline var Left_Right : Int = 2; 13 | public static inline var Center_Center : Int = 3; 14 | public static inline var Right_Left : Int = 4; 15 | public static inline var Right_Center : Int = 5; 16 | public static inline var Right_Right : Int = 6; 17 | 18 | public static inline var Top_Top : Int = 7; 19 | public static inline var Top_Middle : Int = 8; 20 | public static inline var Top_Bottom : Int = 9; 21 | public static inline var Middle_Middle : Int = 10; 22 | public static inline var Bottom_Top : Int = 11; 23 | public static inline var Bottom_Middle : Int = 12; 24 | public static inline var Bottom_Bottom : Int = 13; 25 | 26 | public static inline var Width : Int = 14; 27 | public static inline var Height : Int = 15; 28 | 29 | public static inline var LeftExt_Left : Int = 16; 30 | public static inline var LeftExt_Right : Int = 17; 31 | public static inline var RightExt_Left : Int = 18; 32 | public static inline var RightExt_Right : Int = 19; 33 | public static inline var TopExt_Top : Int = 20; 34 | public static inline var TopExt_Bottom : Int = 21; 35 | public static inline var BottomExt_Top : Int = 22; 36 | public static inline var BottomExt_Bottom : Int = 23; 37 | 38 | public static inline var Size : Int = 24; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/fairygui/PageOption.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class PageOption 5 | { 6 | public var controller(never, set) : Controller; 7 | public var index(get, set) : Int; 8 | public var name(get, set) : String; 9 | public var id(get, set) : String; 10 | 11 | private var _controller : Controller; 12 | private var _id : String; 13 | 14 | public function new() 15 | { 16 | } 17 | 18 | private function set_controller(val : Controller) : Controller 19 | { 20 | _controller = val; 21 | return val; 22 | } 23 | 24 | private function set_index(pageIndex : Int) : Int 25 | { 26 | _id = _controller.getPageId(pageIndex); 27 | return pageIndex; 28 | } 29 | 30 | private function set_name(pageName : String) : String 31 | { 32 | _id = _controller.getPageIdByName(pageName); 33 | return pageName; 34 | } 35 | 36 | private function get_index() : Int 37 | { 38 | if (_id != null) 39 | return _controller.getPageIndexById(_id); 40 | else 41 | return -1; 42 | } 43 | 44 | private function get_name() : String 45 | { 46 | if (_id != null) 47 | return _controller.getPageNameById(_id); 48 | else 49 | return null; 50 | } 51 | 52 | public function clear() : Void 53 | { 54 | _id = null; 55 | } 56 | 57 | private function set_id(id : String) : String 58 | { 59 | _id = id; 60 | return id; 61 | } 62 | 63 | private function get_id() : String 64 | { 65 | return _id; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/tweenxcore/color/AhsvColor.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.color; 2 | using tweenxcore.Tools; 3 | 4 | class AhsvColor extends HsvColor implements ITransparentColor { 5 | /** alpha */ 6 | public var a:Float; 7 | 8 | public function new(alpha:Float, hue:Float, saturation:Float, value:Float) { 9 | this.a = alpha; 10 | super(hue, saturation, value); 11 | } 12 | 13 | public static inline function ahsvToArgbInt(a:Float, h:Float, s:Float, v:Float):Int { 14 | return (Std.int(a.clamp() * 0xFF) << 24) | HsvColor.hsvToRgbInt(h, s, v); 15 | } 16 | 17 | public static inline function of(color:Int, hueIndex:Int = 0) { 18 | var a = ((color >>> 24) & 0xFF) / 0xFF; 19 | return HsvColor.of(color & 0xFFFFFF, hueIndex).toHsvWithAlpha(a); 20 | } 21 | 22 | public static inline function fromArgb(a:Float, r:Float, g:Float, b:Float, hueIndex:Int = 0) { 23 | return HsvColor.fromRgb(r, g, b, hueIndex).toHsvWithAlpha(a); 24 | } 25 | 26 | public inline function getAlpha():Float { 27 | return a; 28 | } 29 | 30 | public inline function toArgb():ArgbColor { 31 | return ArgbColor.fromAhsv(a, h, s, v); 32 | } 33 | 34 | public inline function toAhsv():AhsvColor { 35 | return new AhsvColor(a, h, s, v); 36 | } 37 | 38 | public inline function toArgbInt():Int { 39 | return ahsvToArgbInt(a, h, s, v); 40 | } 41 | 42 | public inline function toArgbHexString():String { 43 | return StringTools.hex(toArgbInt(), 8); 44 | } 45 | 46 | public inline function toRgbaCssString():String { 47 | return toArgb().toRgbaCssString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/fairygui/action/PlayTransitionAction.hx: -------------------------------------------------------------------------------- 1 | package fairygui.action; 2 | class PlayTransitionAction extends ControllerAction 3 | { 4 | 5 | public var transitionName:String; 6 | public var repeat:Int; 7 | public var delay:Float; 8 | public var stopOnExit:Bool; 9 | 10 | private var _currentTransition:Transition; 11 | 12 | public function new() 13 | { 14 | super(); 15 | repeat = 1; 16 | delay = 0; 17 | } 18 | 19 | override private function enter(controller:Controller):Void 20 | { 21 | var trans:Transition = controller.parent.getTransition(transitionName); 22 | if (trans != null) 23 | { 24 | if (_currentTransition != null && _currentTransition.playing) 25 | trans.changeRepeat(repeat); 26 | else 27 | trans.play(null, null, repeat, delay); 28 | _currentTransition = trans; 29 | } 30 | } 31 | 32 | override private function leave(controller:Controller):Void 33 | { 34 | if (stopOnExit && _currentTransition != null) 35 | { 36 | _currentTransition.stop(); 37 | _currentTransition = null; 38 | } 39 | } 40 | 41 | override public function setup(xml:FastXML):Void 42 | { 43 | super.setup(xml); 44 | 45 | transitionName = xml.att.transition; 46 | 47 | var str:String; 48 | 49 | str = xml.att.repeat; 50 | if (str != null) 51 | repeat = Std.parseInt(str); 52 | 53 | str = xml.att.delay; 54 | if (str != null) 55 | delay = Std.parseFloat(str); 56 | 57 | str = xml.att.stopOnExit; 58 | stopOnExit = str == "true"; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/FastXMLList.hx: -------------------------------------------------------------------------------- 1 | class FastXMLList { 2 | var l : Array; 3 | 4 | public function new(?a:Array) { 5 | l = (a != null ? a : new Array()); 6 | } 7 | 8 | /** 9 | * Makes a copy of the FastXMLList 10 | **/ 11 | public function copy() : FastXMLList { 12 | return new FastXMLList(l.slice(0)); 13 | } 14 | 15 | public function descendants(name:String = "*") :FastXMLList { 16 | var a = new Array(); 17 | for(fx in l) { 18 | for(e in fx.x.elements()) { 19 | if(e.nodeName == name || name == "*") { 20 | a.push(new FastXML(e)); 21 | } else { 22 | var fx2 = new FastXML(e); 23 | a = a.concat(fx2.descendants(name).getArray()); 24 | } 25 | } 26 | } 27 | return new FastXMLList(a); 28 | } 29 | 30 | public function get(i:Int) : FastXML { 31 | return l[i]; 32 | } 33 | 34 | public function getArray() : Array { 35 | return l; 36 | } 37 | 38 | public function iterator() : Iterator { 39 | return l.iterator(); 40 | } 41 | 42 | public function length() : Int { 43 | return l.length; 44 | } 45 | 46 | /** 47 | * 48 | public function set(i:Int, v:FastXML) : FastXML { 49 | l[i] = v; 50 | return v; 51 | } 52 | */ 53 | 54 | public function toString() : String { 55 | var s = ""; 56 | var first = true; 57 | for(i in l) { 58 | if(!first) 59 | s += "\r\n"; 60 | first = false; 61 | s = s + i.toString(); 62 | } 63 | return s; 64 | } 65 | } -------------------------------------------------------------------------------- /src/fairygui/utils/PixelHitTest.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | import openfl.display.Graphics; 4 | import openfl.display.Sprite; 5 | import openfl.display.Shape; 6 | 7 | class PixelHitTest { 8 | private var _data:PixelHitTestData; 9 | 10 | public var offsetX:Int; 11 | public var offsetY:Int; 12 | 13 | private var _shape:Shape; 14 | 15 | public function PixelHitTest(data:PixelHitTestData, offsetX:Int=0, offsetY:Int=0) 16 | { 17 | _data = data; 18 | this.offsetX = offsetX; 19 | this.offsetY = offsetY; 20 | } 21 | 22 | public function createHitAreaSprite():Sprite 23 | { 24 | if(_shape==null) 25 | { 26 | _shape = new Shape(); 27 | var g:Graphics = _shape.graphics; 28 | g.beginFill(0,0); 29 | g.lineStyle(0,0,0); 30 | 31 | var arr:Array = _data.pixels; 32 | var cnt:Int = arr.length; 33 | var pw:Int = _data.pixelWidth; 34 | for(i in 0...cnt) 35 | { 36 | var pixel:Int = arr[i]; 37 | for(j in 0...8) 38 | { 39 | if(((pixel>>j)&0x01)==1) 40 | { 41 | var pos:Int = i*8+j; 42 | g.drawRect(pos%pw, Std.int(pos/pw), 1, 1); 43 | } 44 | } 45 | } 46 | g.endFill(); 47 | } 48 | 49 | var sprite:Sprite = new Sprite(); 50 | sprite.mouseEnabled = false; 51 | sprite.x = offsetX; 52 | sprite.y = offsetY; 53 | sprite.graphics.copyFrom(_shape.graphics); 54 | sprite.scaleX = sprite.scaleY = _data.scale; 55 | 56 | return sprite; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/tweenxcore/color/ArgbColor.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.color; 2 | using tweenxcore.Tools; 3 | 4 | class ArgbColor extends RgbColor implements ITransparentColor { 5 | /** alpha */ 6 | public var a:Float; 7 | 8 | public function new(alpha:Float, red:Float, green:Float, blue:Float) { 9 | this.a = alpha; 10 | super(red, green, blue); 11 | } 12 | 13 | public static inline function argbToInt(a:Float, r:Float, g:Float, b:Float):Int { 14 | return (Std.int(a.clamp() * 0xFF) << 24) | RgbColor.rgbToInt(r, g, b); 15 | } 16 | 17 | public static inline function of(color:Int) { 18 | return new ArgbColor( 19 | ((color >>> 24) & 0xFF) / 0xFF, 20 | ((color >> 16) & 0xFF) / 0xFF, 21 | ((color >> 8) & 0xFF) / 0xFF, 22 | (color & 0xFF) / 0xFF 23 | ); 24 | } 25 | 26 | public inline function getAlpha():Float { 27 | return a; 28 | } 29 | 30 | public inline function toArgb():ArgbColor { 31 | return new ArgbColor(a, r, g, b); 32 | } 33 | 34 | public inline function toAhsv():AhsvColor { 35 | return AhsvColor.fromArgb(a, r, g, b); 36 | } 37 | 38 | public inline function toArgbInt():Int { 39 | return argbToInt(a, r, g, b); 40 | } 41 | 42 | public inline function toArgbHexString():String { 43 | return StringTools.hex(toArgbInt(), 8); 44 | } 45 | 46 | public inline function toRgbaCssString():String { 47 | return "rgba(" + Std.int(r * 0xFF) + "," + Std.int(g * 0xFF) + "," + Std.int(b * 0xFF) + "," + a + ")"; 48 | } 49 | 50 | public static inline function fromAhsv(a:Float, h:Float, s:Float, v:Float, hueIndex:Int = 0) { 51 | return RgbColor.fromHsv(h, s, v).toRgbWithAlpha(a); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/fairygui/text/RichTextObjectFactory.hx: -------------------------------------------------------------------------------- 1 | package fairygui.text; 2 | 3 | 4 | import openfl.display.DisplayObject; 5 | 6 | import fairygui.LoaderFillType; 7 | import fairygui.GLoader; 8 | import fairygui.PackageItem; 9 | import fairygui.UIPackage; 10 | import fairygui.display.UIDisplayObject; 11 | 12 | class RichTextObjectFactory implements IRichTextObjectFactory 13 | { 14 | public var pool : Array; 15 | 16 | public function new() 17 | { 18 | pool = []; 19 | } 20 | 21 | public function createObject(src : String, width : Int, height : Int) : DisplayObject 22 | { 23 | var loader : GLoader; 24 | 25 | if (pool.length > 0) 26 | loader = pool.pop(); 27 | else 28 | { 29 | loader = new GLoader(); 30 | loader.fill = LoaderFillType.ScaleFree; 31 | } 32 | loader.url = src; 33 | 34 | var pi : PackageItem = UIPackage.getItemByURL(src); 35 | if (width != 0) 36 | loader.width = width; 37 | else 38 | { 39 | if (pi != null) 40 | width = pi.width; 41 | else 42 | width = 20; 43 | loader.width = width; 44 | } 45 | 46 | if (height != 0) 47 | loader.height = height; 48 | else 49 | { 50 | if (pi != null) 51 | height = pi.height; 52 | else 53 | height = 20; 54 | loader.height = height; 55 | } 56 | 57 | return loader.displayObject; 58 | } 59 | 60 | public function freeObject(obj : DisplayObject) : Void 61 | { 62 | var loader : GLoader = cast(cast(obj, UIDisplayObject).owner, GLoader); 63 | loader.url = null; 64 | pool.push(loader); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/RoundTripKindTools.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | import haxe.macro.Expr.ExprOf; 3 | import tweenxcore.expr.ComplexEasingKind; 4 | using tweenxcore.expr.ComplexEasingKindTools; 5 | using tweenxcore.Tools.FloatTools; 6 | 7 | class RoundTripKindTools 8 | { 9 | 10 | public static inline function toFunction(kind:RoundTripKind, easing:ComplexEasingKind):Float->Float 11 | { 12 | return switch (kind) 13 | { 14 | case RoundTripKind.Yoyo: 15 | var func = easing.toFunction(); 16 | function (value:Float):Float 17 | { 18 | return value.yoyo(func); 19 | } 20 | 21 | case RoundTripKind.Zigzag: 22 | var func = easing.toFunction(); 23 | function (value:Float):Float 24 | { 25 | return value.zigzag(func); 26 | } 27 | } 28 | } 29 | 30 | public static function toExpr(kind:RoundTripKind, easing:ComplexEasingKind, valueExpr:ExprOf):ExprOf 31 | { 32 | return switch (kind) 33 | { 34 | case RoundTripKind.Yoyo: 35 | var expr = easing.toFunctionExpr(); 36 | macro tweenxcore.Tools.FloatTools.yoyo($valueExpr, $expr); 37 | 38 | case RoundTripKind.Zigzag: 39 | var expr = easing.toFunctionExpr(); 40 | macro tweenxcore.Tools.FloatTools.zigzag($valueExpr, $expr); 41 | } 42 | } 43 | 44 | public static function toFunctionExpr(kind:RoundTripKind, easing:ComplexEasingKind):ExprOfFloat> 45 | { 46 | return switch (kind) 47 | { 48 | case RoundTripKind.Yoyo: 49 | var expr = easing.toFunctionExpr(); 50 | macro tweenxcore.Tools.FloatTools.yoyo.bind(_, $expr); 51 | 52 | case RoundTripKind.Zigzag: 53 | var expr = easing.toFunctionExpr(); 54 | macro tweenxcore.Tools.FloatTools.zigzag.bind(_, $expr); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/fairygui/GObjectPool.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | class GObjectPool 4 | { 5 | public var initCallback(get, set):Dynamic; 6 | public var count(get, never):Int; 7 | 8 | private var _pool:Map>; 9 | private var _count:Int = 0; 10 | private var _initCallback:Dynamic; 11 | 12 | public function new() 13 | { 14 | _pool = new Map>(); 15 | } 16 | 17 | private function get_initCallback():Dynamic 18 | { 19 | return _initCallback; 20 | } 21 | 22 | private function set_initCallback(value:Dynamic):Dynamic 23 | { 24 | _initCallback = value; 25 | return value; 26 | } 27 | 28 | public function clear():Void 29 | { 30 | for (url in _pool.keys()) 31 | { 32 | var arr:Array = _pool.get(url); 33 | var cnt:Int = arr.length; 34 | for (i in 0...cnt) 35 | { 36 | arr[i].dispose(); 37 | } 38 | } 39 | _pool = new Map>(); 40 | _count = 0; 41 | } 42 | 43 | private function get_count():Int 44 | { 45 | return _count; 46 | } 47 | 48 | public function getObject(url:String):GObject 49 | { 50 | url = UIPackage.normalizeURL(url); 51 | if (url == null) 52 | return null; 53 | 54 | var arr:Array = _pool[url]; 55 | if (arr != null && arr.length > 0) 56 | { 57 | _count--; 58 | return arr.shift(); 59 | } 60 | 61 | var child:GObject = UIPackage.createObjectFromURL(url); 62 | if (child != null) 63 | { 64 | if (_initCallback != null) 65 | _initCallback(child); 66 | } 67 | 68 | return child; 69 | } 70 | 71 | public function returnObject(obj:GObject):Void 72 | { 73 | var url:String = obj.resourceURL; 74 | if (url == null) 75 | return; 76 | 77 | var arr:Array = _pool[url]; 78 | if (arr == null) 79 | return; 80 | 81 | _count++; 82 | arr.push(obj); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Main.hx: -------------------------------------------------------------------------------- 1 | package ; 2 | 3 | import fairygui.ScreenMatchMode; 4 | import openfl.Assets; 5 | import fairygui.GRoot; 6 | import fairygui.UIConfig; 7 | import fairygui.UIPackage; 8 | import openfl.utils.ByteArray; 9 | import openfl.net.URLLoader; 10 | import openfl.display.StageAlign; 11 | import openfl.display.StageScaleMode; 12 | import openfl.display.StageQuality; 13 | 14 | import openfl.display.Sprite; 15 | 16 | #if (debug && flash) 17 | //import com.demonsters.debugger.MonsterDebugger; 18 | #end 19 | 20 | class Main extends Sprite { 21 | 22 | private var uiLoader:URLLoader; 23 | private var path:String = "assets/Basic.fui"; 24 | public function new() { 25 | super(); 26 | stage.color=0; 27 | stage.frameRate=24; 28 | 29 | stage.align=StageAlign.TOP_LEFT; 30 | stage.scaleMode=StageScaleMode .NO_SCALE; 31 | stage.quality = StageQuality.HIGH; 32 | 33 | #if (debug && flash) 34 | //MonsterDebugger.initialize(this); 35 | #end 36 | 37 | #if (debug && cpp) 38 | //new debugger.Local(true); 39 | #end 40 | 41 | Assets.loadBytes(path).onComplete(assetsCompleteHandler); 42 | } 43 | 44 | private function assetsCompleteHandler(by:ByteArray):Void 45 | { 46 | UIPackage.addPackage(by, null); 47 | 48 | UIConfig.defaultFont="Tahoma"; 49 | UIConfig.verticalScrollBar=UIPackage.getItemURL("Basic", "ScrollBar_VT"); 50 | UIConfig.horizontalScrollBar=UIPackage.getItemURL("Basic", "ScrollBar_HZ"); 51 | UIConfig.popupMenu=UIPackage.getItemURL("Basic", "PopupMenu"); 52 | UIConfig.defaultScrollBounceEffect=false; 53 | UIConfig.defaultScrollTouchEffect=false; 54 | UIConfig.buttonUseHandCursor = true; 55 | 56 | //等待图片资源全部解码,也可以选择不等待,这样图片会在用到的时候才解码 57 | // UIPackage.waitToLoadCompleted(continueInit); 58 | continueInit(); 59 | } 60 | 61 | private var _mainPanel:MainPanel; 62 | private function continueInit():Void 63 | { 64 | stage.addChild(GRoot.inst.displayObject); 65 | 66 | GRoot.inst.setFlashContextMenuDisabled(true); 67 | 68 | _mainPanel=new MainPanel(); 69 | } 70 | 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/fairygui/GearAnimation.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GObject; 4 | import fairygui.GearBase; 5 | import fairygui.IAnimationGear; 6 | 7 | 8 | class GearAnimation extends GearBase 9 | { 10 | private var _storage:Map; 11 | private var _default:GearAnimationValue; 12 | 13 | public function new(owner:GObject) 14 | { 15 | super(owner); 16 | } 17 | 18 | override private function init():Void 19 | { 20 | _default = new GearAnimationValue(cast(_owner, IAnimationGear).playing, cast(_owner, IAnimationGear).frame); 21 | _storage = new Map(); 22 | } 23 | 24 | override private function addStatus(pageId:String, value:String):Void 25 | { 26 | if (value == "-" || value.length == 0) 27 | return; 28 | 29 | var gv:GearAnimationValue; 30 | if (pageId == null) 31 | gv = _default; 32 | else 33 | { 34 | gv = new GearAnimationValue(); 35 | _storage[pageId] = gv; 36 | } 37 | var arr:Array = value.split(","); 38 | gv.frame = Std.parseInt(arr[0]); 39 | gv.playing = arr[1] == "p"; 40 | } 41 | 42 | override public function apply():Void 43 | { 44 | _owner._gearLocked = true; 45 | 46 | var gv:GearAnimationValue = _storage[_controller.selectedPageId]; 47 | if (gv == null) 48 | gv = _default; 49 | 50 | cast(_owner, IAnimationGear).playing = gv.playing; 51 | cast(_owner, IAnimationGear).frame = gv.frame; 52 | 53 | _owner._gearLocked = false; 54 | } 55 | 56 | override public function updateState():Void 57 | { 58 | var mc:IAnimationGear = cast(_owner, IAnimationGear); 59 | var gv:GearAnimationValue = _storage[_controller.selectedPageId]; 60 | if (gv == null) 61 | { 62 | gv = new GearAnimationValue(); 63 | _storage[_controller.selectedPageId] = gv; 64 | } 65 | 66 | gv.playing = mc.playing; 67 | gv.frame = mc.frame; 68 | } 69 | } 70 | 71 | 72 | class GearAnimationValue 73 | { 74 | public var playing:Bool; 75 | public var frame:Int; 76 | 77 | public function new(playing:Bool = true, frame:Int = 0) 78 | { 79 | this.playing = playing; 80 | this.frame = frame; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/LineKindTools.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | import haxe.macro.Expr.ExprOf; 3 | import tweenxcore.expr.ComplexEasingKind; 4 | import tweenxcore.expr.ExprMaker.ExprMakeTools; 5 | import tweenxcore.expr.SimpleEasingKind; 6 | using tweenxcore.expr.ComplexEasingKindTools; 7 | using tweenxcore.Tools.FloatTools; 8 | 9 | class LineKindTools 10 | { 11 | 12 | public static inline function toFunction(kind:LineKind, controls:Array):Float->Float 13 | { 14 | return switch (kind) 15 | { 16 | case LineKind.Bezier: 17 | FloatTools.bezier.bind(_, controls); 18 | 19 | case LineKind.Polyline: 20 | FloatTools.polyline.bind(_, controls); 21 | 22 | case LineKind.UniformQuadraticBSpline: 23 | FloatTools.uniformQuadraticBSpline.bind(_, controls); 24 | } 25 | } 26 | 27 | public static function toExpr(kind:LineKind, controls:Array, valueExpr:ExprOf):ExprOf 28 | { 29 | return switch (kind) 30 | { 31 | case LineKind.Bezier: 32 | macro tweenxcore.Tools.FloatTools.bezier($valueExpr, ${ExprMakeTools.floatArrayToExpr(controls)}); 33 | 34 | case LineKind.Polyline: 35 | macro tweenxcore.Tools.FloatTools.polyline($valueExpr, ${ExprMakeTools.floatArrayToExpr(controls)}); 36 | 37 | case LineKind.UniformQuadraticBSpline: 38 | macro tweenxcore.Tools.FloatTools.uniformQuadraticBSpline($valueExpr, ${ExprMakeTools.floatArrayToExpr(controls)}); 39 | 40 | } 41 | } 42 | 43 | public static function toFunctionExpr(kind:LineKind, controls:Array):ExprOfFloat> 44 | { 45 | return switch (kind) 46 | { 47 | case LineKind.Bezier: 48 | macro tweenxcore.Tools.FloatTools.bezier.bind(_, ${ExprMakeTools.floatArrayToExpr(controls)}); 49 | 50 | case LineKind.Polyline: 51 | macro tweenxcore.Tools.FloatTools.polyline.bind(_, ${ExprMakeTools.floatArrayToExpr(controls)}); 52 | 53 | case LineKind.UniformQuadraticBSpline: 54 | macro tweenxcore.Tools.FloatTools.uniformQuadraticBSpline.bind(_, ${ExprMakeTools.floatArrayToExpr(controls)}); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/fairygui/utils/SimpleDispatcher.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | 4 | import Reflect; 5 | class SimpleDispatcher 6 | { 7 | private var _elements:Array; 8 | private var _dispatching:Int = 0; 9 | 10 | public function new() 11 | { 12 | _elements = []; 13 | } 14 | 15 | public function addListener(type:Int, e:Dynamic):Void 16 | { 17 | var arr:Array = _elements[type]; 18 | if (arr == null) 19 | { 20 | arr = []; 21 | _elements[type] = arr; 22 | arr.push(e); 23 | } 24 | else if (Lambda.indexOf(arr, e) == -1) 25 | { 26 | arr.push(e); 27 | } 28 | } 29 | 30 | public function removeListener(type:Int, e:Dynamic):Void 31 | { 32 | var arr:Array = _elements[type]; 33 | if (arr != null) 34 | { 35 | var i:Int = Lambda.indexOf(arr, e); 36 | if (i != -1) 37 | arr[i] = null; 38 | } 39 | } 40 | 41 | public function hasListener(type:Int):Bool 42 | { 43 | var arr:Array = _elements[type]; 44 | if (arr != null && arr.length > 0) 45 | return true; 46 | else 47 | return false; 48 | } 49 | 50 | public function dispatch(source:Dynamic, type:Int):Void 51 | { 52 | var arr:Array = _elements[type]; 53 | if (arr == null || arr.length == 0) 54 | return; 55 | 56 | var hasDeleted:Bool = false; 57 | var i:Int = 0; 58 | _dispatching++; 59 | var e:Dynamic; 60 | while (i < arr.length) 61 | { 62 | e = arr[i]; 63 | if (e != null) 64 | { 65 | if (Reflect.field(e, "length") == 1) 66 | e(source); 67 | else 68 | e(); 69 | } 70 | else 71 | hasDeleted = true; 72 | i++; 73 | } 74 | _dispatching--; 75 | 76 | if (hasDeleted && _dispatching == 0) 77 | { 78 | i = 0; 79 | while (i < arr.length) 80 | { 81 | e = arr[i]; 82 | if (e == null) 83 | arr.splice(i, 1); 84 | else 85 | i++; 86 | } 87 | } 88 | } 89 | 90 | public function clear():Void 91 | { 92 | _elements.splice(0, _elements.length); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/fairygui/PackageItem.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.UIPackage; 4 | 5 | import openfl.display.BitmapData; 6 | import openfl.geom.Rectangle; 7 | import openfl.media.Sound; 8 | 9 | import fairygui.display.Frame; 10 | import fairygui.text.BitmapFont; 11 | 12 | class PackageItem 13 | { 14 | public var owner : UIPackage; 15 | 16 | public var type : Int = 0; 17 | public var id : String; 18 | public var name : String; 19 | public var width : Int = 0; 20 | public var height : Int = 0; 21 | public var file : String; 22 | public var lastVisitTime : Int = 0; 23 | 24 | public var callbacks : Array = []; 25 | public var loading : Int = 0; 26 | public var loaded : Bool = false; 27 | 28 | //image 29 | public var scale9Grid : Rectangle; 30 | public var scaleByTile : Bool = false; 31 | public var smoothing : Bool = false; 32 | public var tileGridIndice : Int = 0; 33 | public var image : BitmapData; 34 | 35 | //movieclip 36 | public var interval : Float = 0; 37 | public var repeatDelay : Float = 0; 38 | public var swing : Bool = false; 39 | public var frames : Array; 40 | 41 | //componenet 42 | public var componentData : FastXML; 43 | public var displayList : Array; 44 | public var extensionType:Class; 45 | 46 | //sound 47 | public var sound : Sound; 48 | 49 | //font 50 | public var bitmapFont : BitmapFont; 51 | 52 | public function new() 53 | { 54 | } 55 | 56 | public function addCallback(callback :Dynamic) : Void 57 | { 58 | var i : Int = Lambda.indexOf(callbacks, callback); 59 | if (i == -1) 60 | callbacks.push(callback); 61 | } 62 | 63 | public function removeCallback(callback :Dynamic) :Dynamic 64 | { 65 | var i : Int = Lambda.indexOf(callbacks, callback); 66 | if (i != -1) 67 | { 68 | callbacks.splice(i, 1); 69 | return callback; 70 | } 71 | else 72 | return null; 73 | } 74 | 75 | public function completeLoading() : Void 76 | { 77 | loading = 0; 78 | loaded = true; 79 | var arr : Array = callbacks.copy(); 80 | for (callback in arr) 81 | callback(this); 82 | callbacks.splice(0, callbacks.length); 83 | } 84 | 85 | public function toString() : String 86 | { 87 | return name; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/tweenxcore/structure/Timeline.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.structure; 2 | using tweenxcore.Tools; 3 | 4 | class Timeline 5 | { 6 | public var totalWeight(default, null):Float; 7 | var dataArray:Array; 8 | var weightArray:Array; 9 | 10 | public var length(get, null):Int; 11 | 12 | function get_length():Int 13 | { 14 | return dataArray.length; 15 | } 16 | 17 | public inline function new() 18 | { 19 | this.dataArray = []; 20 | this.weightArray = []; 21 | totalWeight = 0; 22 | } 23 | 24 | public inline function add(data:T, weight:Float = 1.0):Timeline 25 | { 26 | if (weight <= 0) { 27 | throw "weight must be positive number"; 28 | } 29 | if (dataArray.length == 0) { 30 | totalWeight = weight; 31 | } else { 32 | weightArray.push(totalWeight); 33 | totalWeight += weight; 34 | } 35 | dataArray.push(data); 36 | return this; 37 | } 38 | 39 | public inline function search(rate:Float, boundaryMode:BoundaryMode = BoundaryMode.High):TimelineSearchResult 40 | { 41 | if (dataArray.length == 0) { 42 | throw "timeline is not initialized"; 43 | } 44 | 45 | var searchResult = weightArray.binarySearch(rate * totalWeight, boundaryMode); 46 | var baseWeight = if (searchResult == 0) { 47 | 0; 48 | } else { 49 | weightArray[searchResult - 1] / totalWeight; 50 | } 51 | 52 | var nextWeight = if (searchResult == dataArray.length - 1) { 53 | 1; 54 | } else { 55 | weightArray[searchResult] / totalWeight; 56 | } 57 | 58 | return new TimelineSearchResult( 59 | dataArray[searchResult], 60 | searchResult, 61 | baseWeight, 62 | nextWeight 63 | ); 64 | } 65 | 66 | public inline function dataAt(index:Int):T 67 | { 68 | if (dataArray.length == 0) { 69 | throw "timeline is not initialized"; 70 | } 71 | return dataArray[index]; 72 | } 73 | 74 | public inline function rangeLeft(index:Int):Float 75 | { 76 | if (index == 0) 77 | { 78 | return 0.0; 79 | } 80 | 81 | return weightArray[index - 1] / totalWeight; 82 | } 83 | 84 | public inline function rangeRight(index:Int):Float 85 | { 86 | if (index == dataArray.length) 87 | { 88 | return 1.0; 89 | } 90 | 91 | return weightArray[index] / totalWeight; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/tweenx909/rule/ArrayRuleX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.rule; 2 | import tweenx909.TweenX; 3 | 4 | class ArrayRuleX { 5 | public static var inputClass(default,null):Dynamic = Array; 6 | public static function calc(_from:Iterable, _to:Iterable, t1:Float, t2:Float, tween:TweenX):Iterable { 7 | var fi = _from.iterator(); 8 | var arr = []; 9 | for (t in _to) { 10 | var f = fi.next(); 11 | arr.push(_calc(f, t, t1, t2, tween)); 12 | } 13 | return arr; 14 | } 15 | static private inline function _calc(_from:Dynamic, _to:Dynamic, t1:Float, t2:Float, tween:TweenX):Dynamic { 16 | if (Std.is(_to, Float)) { 17 | return _from * t2 + _to * t1; 18 | }else { 19 | var result:Dynamic = null, ok:Bool = false; 20 | for (r in TweenX.rules) { 21 | if (Std.is(_to, r.inputClass)) { 22 | ok = true; 23 | result = r.calc(_from, _to, t1, t2, tween); 24 | break; 25 | } 26 | } 27 | if (! ok) { 28 | var eh:ErrorHandler = tween; 29 | throw eh.error("The tween rule for " + Type.getClassName(Type.getClass(_to)) + " is not defined"); 30 | } 31 | return result; 32 | } 33 | } 34 | 35 | public static function defaultFrom(value:Iterable, _to:Iterable, tween:TweenX):Iterable { 36 | var eh:ErrorHandler = tween; 37 | if (value != null) { 38 | var arr = []; 39 | for (t in _to) { arr.push(null); } 40 | }else if (Lambda.count(value) != Lambda.count(_to)){ 41 | throw eh.error("The array length must be same with start."); 42 | } 43 | 44 | var result = []; 45 | var it = _to.iterator(); 46 | for (v in value) { 47 | var t = it.next(); 48 | result.push(_defaultFrom(v, t, tween)); 49 | } 50 | return result; 51 | } 52 | 53 | static private function _defaultFrom(value:Dynamic, _to:Dynamic, tween:TweenX):Dynamic { 54 | if (Std.is(_to, Float)) return value; 55 | for (r in TweenX.rules) { 56 | if (Std.is(_to, r.inputClass)) { 57 | return r.defaultFrom(value, _to, tween); 58 | } 59 | } 60 | var eh:ErrorHandler = tween; 61 | throw eh.error("The tween rule for " + Type.getClassName(Type.getClass(_to)) + " is not defined"); 62 | return null; 63 | } 64 | } 65 | 66 | private typedef ErrorHandler = { 67 | private function error(str:String):String; 68 | }; 69 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/ComplexEasingKindTools.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | import haxe.macro.Expr; 3 | import tweenxcore.Tools.Easing; 4 | 5 | class ComplexEasingKindTools 6 | { 7 | public static inline function toFunction(easing:ComplexEasingKind):Float->Float 8 | { 9 | return switch (easing) 10 | { 11 | case ComplexEasingKind.Simple(kind): 12 | SimpleEasingKindTools.toFunction(kind); 13 | 14 | case ComplexEasingKind.Op(easing, op): 15 | UnaryOpKindTools.toFunction(op, easing); 16 | } 17 | } 18 | 19 | public static function toJsonable(easing:ComplexEasingKind):Dynamic 20 | { 21 | return switch (easing) 22 | { 23 | case ComplexEasingKind.Simple(kind): 24 | [ 25 | "Simple", 26 | SimpleEasingKindTools.toJsonable(kind), 27 | ]; 28 | 29 | case ComplexEasingKind.Op(easing, op): 30 | [ 31 | "Op", 32 | ComplexEasingKindTools.toJsonable(easing), 33 | UnaryOpKindTools.toJsonable(op), 34 | ]; 35 | } 36 | } 37 | 38 | public static function fromJsonable(data:Dynamic):ComplexEasingKind 39 | { 40 | return switch (data) 41 | { 42 | case ["Simple", kind]: 43 | ComplexEasingKind.Simple( 44 | SimpleEasingKindTools.fromJsonable(kind) 45 | ); 46 | 47 | case ["Op", easing, op]: 48 | ComplexEasingKind.Op( 49 | ComplexEasingKindTools.fromJsonable(easing), 50 | UnaryOpKindTools.fromJsonable(op) 51 | ); 52 | 53 | case _: 54 | throw "unsupported ComplexEasingKind data: " + data; 55 | } 56 | } 57 | 58 | public static function toExpr(easing:ComplexEasingKind, valueExpr:ExprOf):ExprOf 59 | { 60 | return switch (easing) 61 | { 62 | case ComplexEasingKind.Simple(kind): 63 | SimpleEasingKindTools.toExpr(kind, valueExpr); 64 | 65 | case ComplexEasingKind.Op(easing, op): 66 | UnaryOpKindTools.toExpr(op, easing, valueExpr); 67 | } 68 | } 69 | 70 | public static function toFunctionExpr(easing:ComplexEasingKind):ExprOfFloat> 71 | { 72 | return switch (easing) 73 | { 74 | case ComplexEasingKind.Simple(kind): 75 | SimpleEasingKindTools.toFunctionExpr(kind); 76 | 77 | case ComplexEasingKind.Op(easing, op): 78 | UnaryOpKindTools.toFunctionExpr(op, easing); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/TernaryOpKindTools.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | import haxe.macro.Expr.ExprOf; 3 | import tweenxcore.Tools.FloatTools; 4 | import tweenxcore.expr.ComplexEasingKind; 5 | import tweenxcore.expr.ExprMaker.ExprMakeTools; 6 | using tweenxcore.expr.ComplexEasingKindTools; 7 | 8 | class TernaryOpKindTools 9 | { 10 | 11 | public static inline function toFunction(kind:TernaryOpKind, easing1:ComplexEasingKind, easing2:ComplexEasingKind, easing3:ComplexEasingKind):Float->Float 12 | { 13 | return switch (kind) 14 | { 15 | case TernaryOpKind.Crossfade(start, end): 16 | var func1 = easing1.toFunction(); 17 | var func2 = easing2.toFunction(); 18 | var func3 = easing3.toFunction(); 19 | FloatTools.crossfadeEasing.bind(_, func1, func2, func3, start, end); 20 | } 21 | } 22 | 23 | public static function toJsonable(kind:TernaryOpKind):Dynamic 24 | { 25 | return switch (kind) 26 | { 27 | case TernaryOpKind.Crossfade(start, end): 28 | ["Crossfade", start, end]; 29 | } 30 | } 31 | 32 | public static function fromJsonable(data:Dynamic):TernaryOpKind 33 | { 34 | return switch (data) 35 | { 36 | case ["Crossfade", start, end]: 37 | TernaryOpKind.Crossfade(cast(start, Float), cast(end, Float)); 38 | 39 | case _: 40 | throw "unsupported TernaryOpKind data: " + data; 41 | } 42 | } 43 | 44 | public static function toExpr(kind:TernaryOpKind, easing1:ComplexEasingKind, easing2:ComplexEasingKind, easing3:ComplexEasingKind, valueExpr:ExprOf):ExprOf 45 | { 46 | return switch (kind) 47 | { 48 | case TernaryOpKind.Crossfade(start, end): 49 | var func1 = easing1.toFunctionExpr(); 50 | var func2 = easing2.toFunctionExpr(); 51 | var func3 = easing3.toFunctionExpr(); 52 | macro tweenxcore.Tools.FloatTools.crossfadeEasing($valueExpr, $func1, $func2, $func3, ${ExprMakeTools.floatToExpr(start)}, ${ExprMakeTools.floatToExpr(end)}); 53 | } 54 | } 55 | 56 | public static function toFunctionExpr(kind:TernaryOpKind, easing1:ComplexEasingKind, easing2:ComplexEasingKind, easing3:ComplexEasingKind):ExprOfFloat> 57 | { 58 | 59 | return switch (kind) 60 | { 61 | case TernaryOpKind.Crossfade(start, end): 62 | var func1 = easing1.toFunctionExpr(); 63 | var func2 = easing2.toFunctionExpr(); 64 | var func3 = easing3.toFunctionExpr(); 65 | macro tweenxcore.Tools.FloatTools.crossfadeEasing.bind(_, $func1, $func2, $func3, ${ExprMakeTools.floatToExpr(start)}, ${ExprMakeTools.floatToExpr(end)}); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /src/fairygui/UIConfig.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | class UIConfig 5 | { 6 | public function new() 7 | { 8 | } 9 | 10 | //Default font name 11 | public static var defaultFont : String = ""; 12 | 13 | //Resource using in Window.ShowModalWait for locking the window. 14 | public static var windowModalWaiting : String; 15 | //Resource using in GRoot.ShowModalWait for locking the screen. 16 | public static var globalModalWaiting : String; //全局锁定时使用的资源, see GStage.showModalWait 17 | 18 | //When a modal window is in front, the background becomes dark. 19 | public static var modalLayerColor : Int = 0x333333; 20 | public static var modalLayerAlpha : Float = 0.2; 21 | 22 | //Default button click sound 23 | public static var buttonSound : String; 24 | public static var buttonSoundVolumeScale : Float = 1; 25 | 26 | public static var buttonUseHandCursor : Bool = false; 27 | 28 | //Resources for scrollbars 29 | public static var horizontalScrollBar : String; 30 | public static var verticalScrollBar : String; 31 | //Scrolling step in pixels 32 | public static var defaultScrollSpeed : Int = 25; 33 | // Speed ratio of scrollpane when its touch dragging. 34 | public static var defaultTouchScrollSpeedRatio:Float = 1; 35 | //Default scrollbar display mode. Recommened visible for Desktop and Auto for mobile. 36 | public static var defaultScrollBarDisplay : Int = ScrollBarDisplayType.Visible; 37 | //Allow dragging the content to scroll. Recommeded true for mobile. 38 | public static var defaultScrollTouchEffect : Bool = false; 39 | //The "rebound" effect in the scolling container. Recommeded true for mobile. 40 | public static var defaultScrollBounceEffect : Bool = false; 41 | 42 | //Resources for PopupMenu. 43 | public static var popupMenu : String; 44 | //Resources for seperator of PopupMenu. 45 | public static var popupMenu_seperator : String; 46 | //In case of failure of loading content for GLoader, use this sign to indicate an error. 47 | public static var loaderErrorSign : String; 48 | //Resources for tooltips. 49 | public static var tooltipsWin : String; 50 | 51 | //Max items displayed in combobox without scrolling. 52 | public static var defaultComboBoxVisibleItemCount : Int = 10; 53 | 54 | // Pixel offsets of finger to trigger scrolling. 55 | public static var touchScrollSensitivity : Int = 20; 56 | 57 | // Pixel offsets of finger to trigger dragging. 58 | public static var touchDragSensitivity : Int = 10; 59 | 60 | // Pixel offsets of mouse pointer to trigger dragging. 61 | public static var clickDragSensitivity : Int = 2; 62 | 63 | // When click the window, brings to front automatically. 64 | public static var bringWindowToFrontOnClick : Bool = true; 65 | 66 | public static var frameTimeForAsyncUIConstruction : Int = 2; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/fairygui/GearColor.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GObject; 4 | import fairygui.ITextColorGear; 5 | import fairygui.IColorGear; 6 | 7 | import fairygui.utils.ToolSet; 8 | 9 | class GearColor extends GearBase 10 | { 11 | private var _storage:Map; 12 | private var _default:GearColorValue; 13 | 14 | public function new(owner:GObject) 15 | { 16 | super(owner); 17 | } 18 | 19 | override private function init():Void 20 | { 21 | if (Std.is(_owner, ITextColorGear)) 22 | _default = new GearColorValue(cast(_owner, IColorGear).color, cast(_owner, ITextColorGear).strokeColor); 23 | else 24 | _default = new GearColorValue(cast(_owner, IColorGear).color); 25 | _storage = new Map(); 26 | } 27 | 28 | override private function addStatus(pageId:String, value:String):Void 29 | { 30 | if (value == "-" || value.length == 0) 31 | return; 32 | 33 | var pos:Int = value.indexOf(","); 34 | var col1:UInt; 35 | var col2:UInt; 36 | if (pos == -1) 37 | { 38 | col1 = ToolSet.convertFromHtmlColor(value); 39 | col2 = 0xFF000000; //为兼容旧版本,用这个值表示不设置 40 | } 41 | else 42 | { 43 | col1 = ToolSet.convertFromHtmlColor(value.substr(0, pos)); 44 | col2 = ToolSet.convertFromHtmlColor(value.substr(pos + 1)); 45 | } 46 | if (pageId == null) 47 | { 48 | _default.color = col1; 49 | _default.strokeColor = col2; 50 | } 51 | else 52 | _storage[pageId] = new GearColorValue(col1, col2); 53 | } 54 | 55 | override public function apply():Void 56 | { 57 | _owner._gearLocked = true; 58 | 59 | var gv:GearColorValue = _storage[_controller.selectedPageId]; 60 | if (gv == null) 61 | gv = _default; 62 | 63 | cast(_owner, IColorGear).color = gv.color; 64 | if (Std.is(_owner, ITextColorGear) && gv.strokeColor != (0xFF000000:UInt)) 65 | cast(_owner, ITextColorGear).strokeColor = gv.strokeColor; 66 | 67 | _owner._gearLocked = false; 68 | } 69 | 70 | override public function updateState():Void 71 | { 72 | var gv:GearColorValue = _storage[_controller.selectedPageId]; 73 | if (gv == null) 74 | { 75 | gv = new GearColorValue(); 76 | _storage[_controller.selectedPageId] = gv; 77 | } 78 | 79 | gv.color = cast(_owner, IColorGear).color; 80 | if (Std.is(_owner, ITextColorGear)) 81 | gv.strokeColor = cast(_owner, ITextColorGear).strokeColor; 82 | } 83 | } 84 | 85 | class GearColorValue 86 | { 87 | public var color:UInt; 88 | public var strokeColor:UInt; 89 | 90 | public function new(color:UInt = 0, strokeColor:UInt = 0) 91 | { 92 | this.color = color; 93 | this.strokeColor = strokeColor; 94 | } 95 | } -------------------------------------------------------------------------------- /src/fairygui/DragDropManager.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GLoader; 4 | import fairygui.GObject; 5 | import fairygui.event.DragEvent; 6 | import fairygui.event.DropEvent; 7 | import fairygui.utils.CompatUtil; 8 | import openfl.geom.Point; 9 | 10 | class DragDropManager 11 | { 12 | public static var inst(get, never):DragDropManager; 13 | public var dragAgent(get, never):GObject; 14 | public var dragging(get, never):Bool; 15 | 16 | private var _agent:GLoader; 17 | private var _sourceData:Dynamic; 18 | 19 | private static var _inst:DragDropManager; 20 | 21 | private static function get_inst():DragDropManager 22 | { 23 | if (_inst == null) 24 | _inst = new DragDropManager(); 25 | return _inst; 26 | } 27 | 28 | public function new() 29 | { 30 | _agent = new GLoader(); 31 | _agent.draggable = true; 32 | _agent.touchable = false; //important 33 | _agent.setSize(100, 100); 34 | _agent.setPivot(0.5, 0.5, true); 35 | _agent.align = AlignType.Center; 36 | _agent.verticalAlign = VertAlignType.Middle; 37 | _agent.sortingOrder = CompatUtil.INT_MAX_VALUE; 38 | _agent.addEventListener(DragEvent.DRAG_END, __dragEnd); 39 | } 40 | 41 | private function get_dragAgent():GObject 42 | { 43 | return _agent; 44 | } 45 | 46 | private function get_dragging():Bool 47 | { 48 | return _agent.parent != null; 49 | } 50 | 51 | public function startDrag(source:GObject, icon:String, sourceData:Dynamic, touchPointId:Int = -1):Void 52 | { 53 | if (_agent.parent != null) 54 | return; 55 | 56 | _sourceData = sourceData; 57 | _agent.url = icon; 58 | GRoot.inst.addChild(_agent); 59 | var pt:Point = GRoot.inst.globalToLocal(source.displayObject.stage.mouseX, source.displayObject.stage.mouseY); 60 | _agent.setXY(pt.x, pt.y); 61 | _agent.startDrag(touchPointId); 62 | } 63 | 64 | public function cancel():Void 65 | { 66 | if (_agent.parent != null) 67 | { 68 | _agent.stopDrag(); 69 | GRoot.inst.removeChild(_agent); 70 | _sourceData = null; 71 | } 72 | } 73 | 74 | private function __dragEnd(evt:DragEvent):Void 75 | { 76 | if (_agent.parent == null) //cancelled 77 | return; 78 | 79 | GRoot.inst.removeChild(_agent); 80 | 81 | var sourceData:Dynamic = _sourceData; 82 | _sourceData = null; 83 | 84 | var obj:GObject = GRoot.inst.getObjectUnderPoint(evt.stageX, evt.stageY); 85 | while (obj != null) 86 | { 87 | if (obj.hasEventListener(DropEvent.DROP)) 88 | { 89 | var dropEvt:DropEvent = new DropEvent(DropEvent.DROP, sourceData); 90 | obj.requestFocus(); 91 | obj.dispatchEvent(dropEvt); 92 | return; 93 | } 94 | 95 | obj = obj.parent; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/fairygui/utils/ZipReader.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | 4 | import String; 5 | import openfl.utils.ByteArray; 6 | import openfl.utils.Endian; 7 | 8 | 9 | 10 | 11 | class ZipReader 12 | { 13 | private var _stream : ByteArray; 14 | private var _entries : Map; 15 | public var entries(get, never) : Map; 16 | 17 | public function new(ba : ByteArray) 18 | { 19 | _stream = ba; 20 | _stream.endian = Endian.LITTLE_ENDIAN; 21 | _entries = new Map(); 22 | 23 | readEntries(); 24 | } 25 | 26 | private function get_entries():Map 27 | { 28 | return _entries; 29 | } 30 | 31 | 32 | private function readEntries() : Void{ 33 | 34 | _stream.position = _stream.length - 22; 35 | var buf : ByteArray = new ByteArray(); 36 | buf.endian = Endian.LITTLE_ENDIAN; 37 | _stream.readBytes(buf, 0, 22); 38 | buf.position = 10; 39 | var entryCount : Int = buf.readUnsignedShort(); 40 | buf.position = 16; 41 | _stream.position = buf.readUnsignedInt(); 42 | buf.clear(); 43 | 44 | for (i in 0...entryCount){ 45 | _stream.readBytes(buf, 0, 46); 46 | buf.position = 28; 47 | var len : Int = buf.readUnsignedShort(); 48 | var name : String = _stream.readUTFBytes(len); 49 | var len2 : Int = buf.readUnsignedShort() + buf.readUnsignedShort(); 50 | _stream.position += len2; 51 | var lastChar : String = name.charAt(name.length - 1); 52 | if (lastChar == "/" || lastChar == "\\") 53 | continue; 54 | 55 | name = name.split("\\").join("/"); 56 | // var regexp:EReg = new EReg("\\", "g"); 57 | // name = regexp.replace(name, "/"); 58 | var e : ZipEntry = new ZipEntry(); 59 | e.name = name; 60 | buf.position = 10; 61 | e.compress = buf.readUnsignedShort(); 62 | buf.position = 16; 63 | e.crc = buf.readUnsignedInt(); 64 | e.size = buf.readUnsignedInt(); 65 | e.sourceSize = buf.readUnsignedInt(); 66 | buf.position = 42; 67 | e.offset = buf.readUnsignedInt() + 30 + len; 68 | 69 | _entries[name] = e; 70 | } 71 | } 72 | 73 | public function getEntryData(n : String) : ByteArray{ 74 | var entry : ZipEntry = _entries[n]; 75 | if (entry == null) 76 | return null; 77 | 78 | var ba : ByteArray = new ByteArray(); 79 | if (entry.size < 1) 80 | return ba; 81 | 82 | _stream.position = entry.offset; 83 | _stream.readBytes(ba, 0, entry.size); 84 | if (entry.compress > 0) 85 | ba.inflate(); 86 | 87 | return ba; 88 | } 89 | } 90 | 91 | 92 | 93 | class ZipEntry 94 | { 95 | public var name : String; 96 | public var offset : Int = 0; 97 | public var size : Int = 0; 98 | public var sourceSize : Int = 0; 99 | public var compress : Int = 0; 100 | public var crc : Int = 0; 101 | 102 | public function new() 103 | { 104 | } 105 | } -------------------------------------------------------------------------------- /src/fairygui/TextInputHistory.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | import openfl.text.TextField; 5 | 6 | class TextInputHistory 7 | { 8 | public static var inst(get, never) : TextInputHistory; 9 | 10 | private static var _inst : TextInputHistory; 11 | private static function get_inst() : TextInputHistory 12 | { 13 | if (_inst == null) 14 | _inst = new TextInputHistory(); 15 | return _inst; 16 | } 17 | 18 | private var _undoBuffer : Array; 19 | private var _redoBuffer : Array; 20 | private var _currentText : String; 21 | private var _textField : TextField; 22 | private var _lock : Bool = false; 23 | 24 | public var maxHistoryLength : Int = 5; 25 | 26 | public function new() 27 | { 28 | _undoBuffer = new Array(); 29 | _redoBuffer = new Array(); 30 | } 31 | 32 | public function startRecord(textField : TextField) : Void 33 | { 34 | _undoBuffer.splice(0, _undoBuffer.length); 35 | _redoBuffer.splice(0, _redoBuffer.length); 36 | _textField = textField; 37 | _lock = false; 38 | _currentText = textField.text; 39 | } 40 | 41 | public function markChanged(textField : TextField) : Void 42 | { 43 | if (_textField != textField) 44 | return; 45 | 46 | if (_lock) 47 | return; 48 | 49 | var newText : String = _textField.text; 50 | if (_currentText == newText) 51 | return; 52 | 53 | _undoBuffer.push(_currentText); 54 | if (_undoBuffer.length > maxHistoryLength) 55 | _undoBuffer.splice(0, 1); 56 | 57 | _currentText = newText; 58 | } 59 | 60 | public function stopRecord(textField : TextField) : Void 61 | { 62 | if (_textField != textField) 63 | return; 64 | 65 | _undoBuffer.splice(0, _undoBuffer.length); 66 | _redoBuffer.splice(0, _redoBuffer.length); 67 | _textField = null; 68 | _currentText = null; 69 | } 70 | 71 | public function undo(textField : TextField) : Void 72 | { 73 | if (_textField != textField) 74 | return; 75 | 76 | if (_undoBuffer.length == 0) 77 | return; 78 | 79 | var text : String = _undoBuffer.pop(); 80 | _redoBuffer.push(_currentText); 81 | _lock = true; 82 | _textField.text = text; 83 | _currentText = text; 84 | _lock = false; 85 | } 86 | 87 | public function redo(textField : TextField) : Void 88 | { 89 | if (_textField != textField) 90 | return; 91 | 92 | if (_redoBuffer.length == 0) 93 | return; 94 | 95 | var text : String = _redoBuffer.pop(); 96 | _undoBuffer.push(_currentText); 97 | _lock = true; 98 | _textField.text = text; 99 | var dlen : Int = text.length - _currentText.length; 100 | if (dlen > 0) 101 | _textField.setSelection(_textField.caretIndex + dlen, _textField.caretIndex + dlen); 102 | 103 | _currentText = text; 104 | _lock = false; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/fairygui/GRichTextField.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GTextField; 4 | 5 | import openfl.text.TextFieldAutoSize; 6 | import openfl.text.TextFormat; 7 | 8 | import fairygui.display.UIRichTextField; 9 | import fairygui.text.RichTextField; 10 | import fairygui.utils.ToolSet; 11 | 12 | class GRichTextField extends GTextField 13 | { 14 | public var ALinkFormat(get, set) : TextFormat; 15 | public var AHoverFormat(get, set) : TextFormat; 16 | 17 | private var _richTextField : RichTextField; 18 | 19 | public function new() 20 | { 21 | super(); 22 | } 23 | 24 | override private function createDisplayObject() : Void 25 | { 26 | _richTextField = new UIRichTextField(this); 27 | _textField = _richTextField.nativeTextField; 28 | setDisplayObject(_richTextField); 29 | } 30 | 31 | private function get_ALinkFormat() : TextFormat{ 32 | return _richTextField.ALinkFormat; 33 | } 34 | 35 | private function set_ALinkFormat(val : TextFormat) : TextFormat{ 36 | _richTextField.ALinkFormat = val; 37 | render(); 38 | return val; 39 | } 40 | 41 | private function get_AHoverFormat() : TextFormat{ 42 | return _richTextField.AHoverFormat; 43 | } 44 | 45 | private function set_AHoverFormat(val : TextFormat) : TextFormat{ 46 | _richTextField.AHoverFormat = val; 47 | render(); 48 | return val; 49 | } 50 | 51 | override private function updateAutoSize():Void 52 | { 53 | //as版的RichText不支持自动宽度 54 | if(_heightAutoSize) 55 | _textField.autoSize = TextFieldAutoSize.LEFT; 56 | else 57 | _textField.autoSize = TextFieldAutoSize.NONE; 58 | } 59 | 60 | override private function render() : Void 61 | { 62 | renderNow(true); 63 | } 64 | 65 | override private function renderNow(updateBounds : Bool = true) : Void 66 | { 67 | _richTextField.defaultTextFormat = _textFormat; 68 | if (_ubbEnabled) 69 | _richTextField.text = ToolSet.parseUBB(_text); 70 | else 71 | _richTextField.text = _text; 72 | 73 | var renderSingleLine : Bool = _richTextField.numLines <= 1; 74 | 75 | _textWidth = Math.ceil(_richTextField.textWidth); 76 | if (_textWidth > 0) 77 | _textWidth += 5; 78 | _textHeight = Math.ceil(_richTextField.textHeight); 79 | if (_textHeight > 0) 80 | { 81 | if (renderSingleLine) 82 | _textHeight += 1 83 | else 84 | _textHeight += 4; 85 | } 86 | 87 | if (_heightAutoSize) 88 | { 89 | _richTextField.height = _textHeight + _fontAdjustment; 90 | 91 | _updatingSize = true; 92 | this.height = _textHeight; 93 | _updatingSize = false; 94 | } 95 | } 96 | 97 | override private function handleSizeChanged() : Void 98 | { 99 | if (!_updatingSize) 100 | { 101 | _richTextField.width = this.width; 102 | _richTextField.height = this.height + _fontAdjustment; 103 | } 104 | } 105 | } 106 | 107 | -------------------------------------------------------------------------------- /src/tweenxcore/color/RgbColor.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.color; 2 | import tweenxcore.color.AhsvColor; 3 | import tweenxcore.color.ArgbColor; 4 | import tweenxcore.color.RgbColor; 5 | using tweenxcore.Tools.FloatTools; 6 | 7 | class RgbColor implements IColor { 8 | /** red */ 9 | public var r:Float; 10 | /** green */ 11 | public var g:Float; 12 | /** blue */ 13 | public var b:Float; 14 | 15 | public inline function new(red:Float, green:Float, blue:Float) { 16 | this.r = red; 17 | this.g = green; 18 | this.b = blue; 19 | } 20 | 21 | public static inline function rgbToInt(r:Float, g:Float, b:Float):Int { 22 | r = r.clamp(); 23 | g = g.clamp(); 24 | b = b.clamp(); 25 | 26 | return (Std.int(r * 0xFF) << 16) | (Std.int(g * 0xFF) << 8) | Std.int(b * 0xFF); 27 | } 28 | 29 | public static inline function of(color:Int) { 30 | return new RgbColor( 31 | ((color >> 16) & 0xFF) / 0xFF, 32 | ((color >> 8) & 0xFF) / 0xFF, 33 | (color & 0xFF) / 0xFF 34 | ); 35 | } 36 | 37 | public static function fromHsv(h:Float, s:Float, v:Float) { 38 | h = (h - Math.floor(h)) * 6; 39 | var hi = Math.floor(h); 40 | 41 | s = s.clamp(); 42 | v = v.clamp(); 43 | 44 | var m = v * (1 - s); 45 | var f = h - hi; 46 | 47 | var r = 0.0, g = 0.0, b = 0.0; 48 | switch(hi) { 49 | case 0: r = v; g = v * (1 - s * (1 - f)); b = m; 50 | case 1: r = v * (1 - s * f); g = v; b = m; 51 | case 2: r = m; g = v; b = v * (1 - s * (1 - f)); 52 | case 3: r = m; g = v * (1 - s * f); b = v; 53 | case 4: r = v * (1 - s * (1 - f)); g = m; b = v; 54 | case 5: r = v; g = m; b = v * (1 - s * f); 55 | } 56 | 57 | return new RgbColor(r, g, b); 58 | } 59 | 60 | public inline function getRed():Float { 61 | return r; 62 | } 63 | 64 | public inline function getGreen():Float { 65 | return g; 66 | } 67 | 68 | public inline function getBlue():Float { 69 | return b; 70 | } 71 | 72 | public inline function getHue():Float { 73 | return toHsv().h; 74 | } 75 | 76 | public inline function getSaturation():Float { 77 | return toHsv().s; 78 | } 79 | 80 | public inline function getBrightness():Float { 81 | return toHsv().v; 82 | } 83 | 84 | public inline function toRgb():RgbColor { 85 | return new RgbColor(r, g, b); 86 | } 87 | 88 | public inline function toHsv():HsvColor { 89 | return HsvColor.fromRgb(r, g, b); 90 | } 91 | 92 | public inline function toRgbWithAlpha(alpha:Float):ArgbColor { 93 | return new ArgbColor(alpha, r, g, b); 94 | } 95 | 96 | public inline function toHsvWithAlpha(alpha:Float):AhsvColor { 97 | return AhsvColor.fromArgb(alpha, r, g, b); 98 | } 99 | 100 | public inline function toRgbInt():Int { 101 | return rgbToInt(r, g, b); 102 | } 103 | 104 | public inline function toRgbHexString():String { 105 | return StringTools.hex(toRgbInt(), 6); 106 | } 107 | 108 | public inline function toRgbCssString():String { 109 | return "rgb(" + Std.int(r * 0xFF) + "," + Std.int(g * 0xFF) + "," + Std.int(b * 0xFF) + ")"; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/tweenx909/advanced/DefaultsX.hx: -------------------------------------------------------------------------------- 1 | package tweenx909.advanced; 2 | import tweenx909.TweenX; 3 | 4 | /** 5 | * ... 6 | * @author shohei909 7 | */ 8 | class DefaultsX { 9 | private var _ease:Float->Float; 10 | private var _time:Float = TweenX.DEFAULT_TIME; 11 | private var _delay:Float = TweenX.DEFAULT_DELAY; 12 | private var _interval:Float = TweenX.DEFAULT_INTERVAL; 13 | private var _repeat:Int = TweenX.DEFAULT_REPEAT; 14 | private var _yoyo:Bool = TweenX.DEFAULT_YOYO; 15 | private var _zigzag:Bool = TweenX.DEFAULT_ZIGZAG; 16 | private var _autoPlay:Bool = TweenX.DEFAULT_AUTO_PLAY; 17 | //private var _autoFrom:Bool = TweenX.DEFAULT_AUTO_FROM; 18 | 19 | public function new() { 20 | _ease = TweenX.DEFAULT_EASE; 21 | } 22 | 23 | public function dump() { 24 | _time = TweenX.defaultTime; 25 | _ease = TweenX.defaultEase; 26 | _delay = TweenX.defaultDelay; 27 | _interval = TweenX.defaultInterval; 28 | _repeat = TweenX.defaultRepeat; 29 | _yoyo = TweenX.defaultYoyo; 30 | _zigzag = TweenX.defaultZigZag; 31 | _autoPlay = TweenX.defaultAutoPlay; 32 | //_autoFrom = TweenX.defaultAutoFrom; 33 | return this; 34 | } 35 | 36 | public function apply() { 37 | TweenX.defaultTime = _time; 38 | TweenX.defaultEase = _ease; 39 | TweenX.defaultDelay = _delay; 40 | TweenX.defaultInterval = _interval; 41 | TweenX.defaultRepeat = _repeat; 42 | TweenX.defaultYoyo = _yoyo; 43 | TweenX.defaultZigZag = _zigzag; 44 | TweenX.defaultAutoPlay = _autoPlay; 45 | //TweenX.defaultAutoFrom = _autoFrom; 46 | } 47 | 48 | public function clone() { 49 | var child = new DefaultsX(); 50 | 51 | child._time = _time; 52 | child._ease = _ease; 53 | child._delay = _delay; 54 | child._interval = _interval; 55 | child._repeat = _repeat; 56 | child._yoyo = _yoyo; 57 | child._zigzag = _zigzag; 58 | child._autoPlay = _autoPlay; 59 | //child._autoFrom = _autoFrom; 60 | 61 | return child; 62 | } 63 | 64 | public function time(value:Float) { 65 | _time = value; 66 | return this; 67 | } 68 | public function ease(value:Float->Float) { 69 | _ease = value; 70 | return this; 71 | } 72 | public function delay(value:Float) { 73 | _delay = value; 74 | return this; 75 | } 76 | public function interval(value:Float) { 77 | _interval = value; 78 | return this; 79 | } 80 | public function repeat(value:Int = 0) { 81 | _repeat = value; 82 | return this; 83 | } 84 | public function yoyo(value:Bool = true) { 85 | _yoyo = value; 86 | return this; 87 | } 88 | public function zigzag(value:Bool = true) { 89 | _zigzag = value; 90 | return this; 91 | } 92 | public function autoPlay(value:Bool = true) { 93 | _autoPlay = value; 94 | return this; 95 | } 96 | 97 | /*public function autoFrom(value:Bool = true) { 98 | _autoFrom = value; 99 | return this; 100 | }*/ 101 | } 102 | -------------------------------------------------------------------------------- /src/fairygui/display/PlayState.hx: -------------------------------------------------------------------------------- 1 | package fairygui.display; 2 | 3 | 4 | import fairygui.utils.GTimers; 5 | 6 | class PlayState 7 | { 8 | public var currentFrame(get, set):Int; 9 | 10 | public var reachEnding:Bool; //是否已播放到结尾 11 | public var reversed:Bool; //是否已反向播放 12 | public var repeatedCount:Int; //重复次数 13 | 14 | private var _curFrame:Int; //当前帧 15 | private var _curFrameDelay:Int; //当前帧延迟 16 | private var _lastUpdateSeq:Int; 17 | 18 | public function new() 19 | { 20 | } 21 | 22 | public function update(mc:MovieClip):Void 23 | { 24 | var elapsed:Float; 25 | var frameId:UInt = GTimers.workCount; 26 | if (frameId - _lastUpdateSeq != 1) 27 | { 28 | //1、如果>1,表示不是连续帧了,说明刚启动(或者停止过),这里不能用流逝的时间了,不然会跳过很多帧 29 | //2、如果==0,表示在本帧已经处理过了,这通常是因为一个PlayState用于多个MovieClip共享,目的是多个MovieClip同步播放 30 | elapsed = 0; 31 | } 32 | else 33 | elapsed = GTimers.deltaTime; 34 | _lastUpdateSeq = frameId; 35 | 36 | reachEnding = false; 37 | _curFrameDelay += Std.int(elapsed); 38 | var interval:Int = mc.interval + mc.frames[_curFrame].addDelay + ((_curFrame == 0 && repeatedCount > 0) ? mc.repeatDelay : 0); 39 | if (_curFrameDelay < interval) 40 | return; 41 | 42 | _curFrameDelay -= interval; 43 | if (_curFrameDelay > mc.interval) 44 | _curFrameDelay = mc.interval; 45 | 46 | if (mc.swing) 47 | { 48 | if (reversed) 49 | { 50 | _curFrame--; 51 | if (_curFrame <= 0) 52 | { 53 | _curFrame = 0; 54 | repeatedCount++; 55 | reversed = !reversed; 56 | } 57 | } 58 | else 59 | { 60 | _curFrame++; 61 | if (_curFrame > mc.frameCount - 1) 62 | { 63 | _curFrame = Std.int(Math.max(0, mc.frameCount - 2)); 64 | repeatedCount++; 65 | reachEnding = true; 66 | reversed = !reversed; 67 | } 68 | } 69 | } 70 | else 71 | { 72 | _curFrame++; 73 | if (_curFrame > mc.frameCount - 1) 74 | { 75 | _curFrame = 0; 76 | repeatedCount++; 77 | reachEnding = true; 78 | } 79 | } 80 | } 81 | 82 | private function get_currentFrame():Int 83 | { 84 | return _curFrame; 85 | } 86 | 87 | private function set_currentFrame(value:Int):Int 88 | { 89 | _curFrame = value; 90 | _curFrameDelay = 0; 91 | return value; 92 | } 93 | 94 | public function rewind():Void 95 | { 96 | _curFrame = 0; 97 | _curFrameDelay = 0; 98 | reversed = false; 99 | reachEnding = false; 100 | } 101 | 102 | public function reset():Void 103 | { 104 | _curFrame = 0; 105 | _curFrameDelay = 0; 106 | repeatedCount = 0; 107 | reachEnding = false; 108 | reversed = false; 109 | } 110 | 111 | public function copy(src:PlayState):Void 112 | { 113 | _curFrame = src._curFrame; 114 | _curFrameDelay = src._curFrameDelay; 115 | repeatedCount = src.repeatedCount; 116 | reachEnding = src.reachEnding; 117 | reversed = src.reversed; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/fairygui/event/GTouchEvent.hx: -------------------------------------------------------------------------------- 1 | package fairygui.event; 2 | 3 | 4 | import openfl.display.DisplayObject; 5 | import openfl.events.Event; 6 | import openfl.events.MouseEvent; 7 | import openfl.events.TouchEvent; 8 | 9 | class GTouchEvent extends Event 10 | { 11 | public var realTarget(get, never) : DisplayObject; 12 | public var clickCount(get, never) : Int; 13 | public var stageX(get, never) : Float; 14 | public var stageY(get, never) : Float; 15 | public var shiftKey(get, never) : Bool; 16 | public var ctrlKey(get, never) : Bool; 17 | public var touchPointID(get, never) : Int; 18 | public var isPropagationStop(get, never) : Bool; 19 | 20 | private var _stopPropagation : Bool; 21 | 22 | private var _realTarget : DisplayObject; 23 | private var _clickCount : Int; 24 | private var _stageX : Float; 25 | private var _stageY : Float; 26 | private var _shiftKey : Bool; 27 | private var _ctrlKey : Bool; 28 | private var _touchPointID : Int; 29 | 30 | public static inline var BEGIN : String = "beginGTouch"; 31 | public static inline var DRAG : String = "dragGTouch"; 32 | public static inline var END : String = "endGTouch"; 33 | public static inline var CLICK : String = "clickGTouch"; 34 | 35 | public function new(type : String) 36 | { 37 | super(type, false, false); 38 | } 39 | 40 | public function copyFrom(evt : Event, clickCount : Int = 1) : Void 41 | { 42 | if (Std.is(evt, MouseEvent)) 43 | { 44 | _stageX = cast(evt, MouseEvent).stageX; 45 | _stageY = cast(evt, MouseEvent).stageY; 46 | _shiftKey = cast(evt, MouseEvent).shiftKey; 47 | _ctrlKey = cast(evt, MouseEvent).ctrlKey; 48 | } 49 | else 50 | { 51 | _stageX = cast(evt, TouchEvent).stageX; 52 | _stageY = cast(evt, TouchEvent).stageY; 53 | _shiftKey = cast(evt, TouchEvent).shiftKey; 54 | _ctrlKey = cast(evt, TouchEvent).ctrlKey; 55 | _touchPointID = cast((evt), TouchEvent).touchPointID; 56 | } 57 | _realTarget = try cast(evt.target, DisplayObject) catch(e:Dynamic) null; 58 | _clickCount = clickCount; 59 | _stopPropagation = false; 60 | } 61 | 62 | @:final private function get_realTarget() : DisplayObject 63 | { 64 | return _realTarget; 65 | } 66 | @:final private function get_clickCount() : Int 67 | { 68 | return _clickCount; 69 | } 70 | @:final private function get_stageX() : Float 71 | { 72 | return _stageX; 73 | } 74 | @:final private function get_stageY() : Float 75 | { 76 | return _stageY; 77 | } 78 | @:final private function get_shiftKey() : Bool 79 | { 80 | return _shiftKey; 81 | } 82 | @:final private function get_ctrlKey() : Bool 83 | { 84 | return _ctrlKey; 85 | } 86 | @:final private function get_touchPointID() : Int 87 | { 88 | return _touchPointID; 89 | } 90 | override public function stopPropagation() : Void 91 | { 92 | _stopPropagation = true; 93 | } 94 | 95 | @:final private function get_isPropagationStop() : Bool 96 | { 97 | return _stopPropagation; 98 | } 99 | 100 | override public function clone() : Event{ 101 | var ret : GTouchEvent = new GTouchEvent(type); 102 | ret._realTarget = _realTarget; 103 | ret._clickCount = _clickCount; 104 | ret._stageX = _stageX; 105 | ret._stageY = _stageY; 106 | ret._shiftKey = _shiftKey; 107 | ret._ctrlKey = _ctrlKey; 108 | ret._touchPointID = _touchPointID; 109 | return ret; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/fairygui/utils/EaseLookup.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | 4 | import tweenxcore.Tools.Easing; 5 | class EaseLookup { 6 | public function new() { 7 | } 8 | 9 | /** 10 | * @private 11 | */ 12 | private static var _lookup:MapFloat>; 13 | 14 | /** 15 | * Finds the easing function associated with a particular name (String), like "cricOut". This can be useful when 16 | * loading in XML data that comes in as Strings but needs to be translated to native function references. You can pass in 17 | * the name with or without the period, and it is case insensitive, so any of the following will find the Easeing.cricOut function:

18 | * EaseLookup.find("Cric.easeOut")
19 | * EaseLookup.find("cricEaseOut")
20 | * EaseLookup.find("cricout")

21 | * 22 | * You can translate Strings directly when tweening, like this:
23 | * TweenX.to(mc, 1, {x:100, ease:EaseLookup.find(myString)});

24 | * 25 | * @param param The param of the easing function, with or without the period and case insensitive (i.e. "Cric.easeOut" or "cricOut") 26 | * @return The easing function associated with the name 27 | */ 28 | public static function find(param:String):Float->Float { 29 | if (_lookup == null) { 30 | buildLookup(); 31 | } 32 | return _lookup[param.toLowerCase()]; 33 | } 34 | 35 | private static function buildLookup():Void { 36 | _lookup = new MapFloat>(); 37 | 38 | addInOut("sine"); 39 | addInOut("quad"); 40 | addInOut("cubic"); 41 | addInOut("quart"); 42 | addInOut("quint"); 43 | addInOut("expo"); 44 | addInOut("circ"); 45 | addInOut("bounce"); 46 | addInOut("back"); 47 | addInOut("elastic"); 48 | addInOut("warp"); 49 | 50 | 51 | _lookup["linear.easenone"] = _lookup["lineareasenone"] = _lookup["linear"] = Easing.linear; 52 | } 53 | 54 | 55 | private static function addInOut(param:String):Void 56 | { 57 | var name:String = param.toLowerCase(); 58 | _lookup[name + ".easein"] = _lookup[name + "easein"] = _lookup[name + "in"] = Reflect.field(Easing, name+"In"); 59 | _lookup[name + ".easeout"] = _lookup[name + "easeout"] = _lookup[name + "out"] = Reflect.field(Easing, name+"Out"); 60 | _lookup[name + ".easeinout"] = _lookup[name + "easeinout"] = _lookup[name + "inout"] = Reflect.field(Easing, name+"InOut"); 61 | _lookup[name + ".easeoutin"] = _lookup[name + "easeoutin"] = _lookup[name + "outin"] = Reflect.field(Easing, name+"OutIn"); 62 | } 63 | 64 | // /** @private **/ 65 | // private static function buildLookup():Void { 66 | // _lookup = new MapFloat>(); 67 | // 68 | // addInOut(Back, ["back"]); 69 | // addInOut(Bounce, ["bounce"]); 70 | //// addInOut(Circ, ["circ", "circular"]); 71 | // addInOut(Cubic, ["cubic"]); 72 | // addInOut(Elastic, ["elastic"]); 73 | // addInOut(Expo, ["expo", "exponential"]); 74 | // addInOut(Linear, ["linear"]); 75 | // addInOut(Quad, ["quad", "quadratic"]); 76 | // addInOut(Quart, ["quart","quartic"]); 77 | // addInOut(Quint, ["quint", "quintic", "strong"]); 78 | // addInOut(Sine, ["sine"]); 79 | // 80 | // _lookup["linear.easenone"] = _lookup["lineareasenone"] = Linear.easeNone; 81 | // } 82 | 83 | // /** @private **/ 84 | // private static function addInOut(clz:Class, param:Array):Void { 85 | // var name:String; 86 | // var i:Int = param.length; 87 | // while (i-- > 0) { 88 | // name = param[i].toLowerCase(); 89 | // _lookup[name + ".easein"] = _lookup[name + "easein"] = Reflect.field(clz, "easeIn"); 90 | // _lookup[name + ".easeout"] = _lookup[name + "easeout"] = Reflect.field(clz, "easeOut"); 91 | // _lookup[name + ".easeinout"] = _lookup[name + "easeinout"] = Reflect.field(clz, "easeInOut"); 92 | // } 93 | // } 94 | } 95 | -------------------------------------------------------------------------------- /src/fairygui/utils/CharSize.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | import Reflect; 4 | import openfl.display.BitmapData; 5 | import openfl.geom.Rectangle; 6 | import openfl.text.TextField; 7 | import openfl.text.TextFieldAutoSize; 8 | import openfl.text.TextFormat; 9 | 10 | class CharSize 11 | { 12 | private static var testTextField:TextField; 13 | private static var testTextField2:TextField; 14 | private static var testTextFormat:TextFormat; 15 | private static var results:Dynamic; 16 | private static var boldResults:Dynamic; 17 | private static var holderResults:Dynamic; 18 | 19 | private static var helperBmd:BitmapData; 20 | 21 | public static var TEST_STRING:String = "fj|_我案愛爱"; 22 | public static var PLACEHOLDER_FONT:String = "Arial"; 23 | 24 | public static function getSize(size:Int, font:String, bold:Bool):Dynamic 25 | { 26 | if (testTextField == null) 27 | { 28 | testTextField = new TextField(); 29 | testTextField.autoSize = TextFieldAutoSize.LEFT; 30 | testTextField.text = TEST_STRING; 31 | 32 | if (testTextFormat == null) 33 | testTextFormat = new TextFormat(); 34 | 35 | results = { }; 36 | boldResults = { }; 37 | } 38 | var col:Dynamic = (bold) ? Reflect.field(boldResults, font) : Reflect.field(results, font); 39 | if (col == null) 40 | { 41 | col = { }; 42 | if (bold) 43 | Reflect.setField(boldResults, font, col); 44 | else 45 | Reflect.setField(results, font, col); 46 | } 47 | var ret:Dynamic = col[size]; 48 | if (ret != null) 49 | return ret; 50 | 51 | ret = { }; 52 | col[size] = ret; 53 | 54 | testTextFormat.font = font; 55 | testTextFormat.size = size; 56 | testTextFormat.bold = bold; 57 | testTextField.setTextFormat(testTextFormat); 58 | testTextField.embedFonts = FontUtils.isEmbeddedFont(testTextFormat); 59 | 60 | ret.height = testTextField.textHeight; 61 | if (ret.height == 0) 62 | ret.height = size; 63 | 64 | if (helperBmd == null || helperBmd.width < testTextField.width || helperBmd.height < testTextField.height) 65 | helperBmd = new BitmapData(Std.int(Math.max(128, testTextField.width)), Std.int(Math.max(128, testTextField.height)), true, 0); 66 | else 67 | helperBmd.fillRect(helperBmd.rect, 0); 68 | 69 | helperBmd.draw(testTextField); 70 | var bounds:Rectangle = helperBmd.getColorBoundsRect(0xFF000000, 0, false); 71 | ret.yIndent = bounds.top - 2 - Std.int((ret.height - Math.max(bounds.height, size)) / 2); 72 | return ret; 73 | } 74 | 75 | public static function getHolderWidth(font:String, size:Int):Int 76 | { 77 | if (testTextField2 == null) 78 | { 79 | testTextField2 = new TextField(); 80 | testTextField2.autoSize = TextFieldAutoSize.LEFT; 81 | testTextField2.text = " "; 82 | 83 | if (testTextFormat == null) 84 | testTextFormat = new TextFormat(); 85 | holderResults = {}; 86 | } 87 | var col:Dynamic = Reflect.field(holderResults,font); 88 | if (col == null) 89 | { 90 | col = {}; 91 | Reflect.setField(holderResults, font, col); 92 | } 93 | var ret:Dynamic = col[size]; 94 | if (Math.isNaN(ret)) 95 | { 96 | testTextFormat.font = font; 97 | testTextFormat.size = size; 98 | testTextFormat.bold = false; 99 | testTextField2.setTextFormat(testTextFormat); 100 | testTextField2.embedFonts = FontUtils.isEmbeddedFont(testTextFormat); 101 | 102 | ret = testTextField2.textWidth; 103 | col[size] = ret; 104 | } 105 | 106 | return Std.int(ret); 107 | } 108 | 109 | public function new() 110 | { 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/fairygui/GSwfObject.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.display.UISprite; 4 | import fairygui.IAnimationGear; 5 | import openfl.display.DisplayObject; 6 | import openfl.display.MovieClip; 7 | import openfl.display.Sprite; 8 | import openfl.errors.Error; 9 | 10 | class GSwfObject extends GObject implements IAnimationGear 11 | { 12 | public var movieClip(get, never):MovieClip; 13 | public var playing(get, set):Bool; 14 | public var frame(get, set):Int; 15 | 16 | private var _container:Sprite; 17 | private var _content:DisplayObject; 18 | private var _playing:Bool = false; 19 | private var _frame:Int = 0; 20 | 21 | public function new() 22 | { 23 | super(); 24 | _playing = true; 25 | _sizeImplType = 1; 26 | } 27 | 28 | override private function createDisplayObject():Void 29 | { 30 | _container = new UISprite(this); 31 | setDisplayObject(_container); 32 | } 33 | 34 | @:final private function get_movieClip():MovieClip 35 | { 36 | return cast((_content), MovieClip); 37 | } 38 | 39 | @:final private function get_playing():Bool 40 | { 41 | return _playing; 42 | } 43 | 44 | private function set_playing(value:Bool):Bool 45 | { 46 | if (_playing != value) 47 | { 48 | _playing = value; 49 | if (_content != null && Std.is(_content, MovieClip)) 50 | { 51 | if (_playing) 52 | cast(_content, MovieClip).gotoAndPlay(_frame + 1); 53 | else 54 | cast(_content, MovieClip).gotoAndStop(_frame + 1); 55 | } 56 | updateGear(5); 57 | } 58 | return value; 59 | } 60 | 61 | @:final private function get_frame():Int 62 | { 63 | return _frame; 64 | } 65 | 66 | private function set_frame(value:Int):Int 67 | { 68 | if (_frame != value) 69 | { 70 | _frame = value; 71 | if (_content != null && Std.is(_content, MovieClip)) 72 | { 73 | if (_playing) 74 | cast(_content, MovieClip).gotoAndPlay(_frame + 1); 75 | else 76 | cast(_content, MovieClip).gotoAndStop(_frame + 1); 77 | } 78 | updateGear(5); 79 | } 80 | return value; 81 | } 82 | 83 | override public function dispose():Void 84 | { 85 | packageItem.owner.removeItemCallback(packageItem, __swfLoaded); 86 | super.dispose(); 87 | } 88 | 89 | override public function constructFromResource():Void 90 | { 91 | sourceWidth = packageItem.width; 92 | sourceHeight = packageItem.height; 93 | initWidth = sourceWidth; 94 | initHeight = sourceHeight; 95 | 96 | setSize(sourceWidth, sourceHeight); 97 | 98 | packageItem.owner.addItemCallback(packageItem, __swfLoaded); 99 | } 100 | 101 | private function __swfLoaded(content:Dynamic):Void 102 | { 103 | if (_content != null) 104 | _container.removeChild(_content); 105 | _content = cast(content, DisplayObject); 106 | if (_content != null) 107 | { 108 | try 109 | { 110 | _container.addChild(_content); 111 | } 112 | catch (e:Error) 113 | { 114 | trace("__swfLoaded:" + e); 115 | _content = null; 116 | } 117 | } 118 | 119 | if (_content != null && Std.is(_content, MovieClip)) 120 | { 121 | if (_playing) 122 | cast(_content, MovieClip).gotoAndPlay(_frame + 1); 123 | else 124 | cast(_content, MovieClip).gotoAndStop(_frame + 1); 125 | } 126 | } 127 | 128 | override public function setup_beforeAdd(xml:FastXML):Void 129 | { 130 | super.setup_beforeAdd(xml); 131 | 132 | var str:String = xml.att.playing; 133 | _playing = str != "false"; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/tweenxcore/expr/SimpleEasingKindTools.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.expr; 2 | import haxe.EnumTools; 3 | import haxe.EnumTools.EnumValueTools; 4 | import haxe.macro.Expr; 5 | import tweenxcore.Tools.Easing; 6 | import tweenxcore.Tools.FloatTools; 7 | import tweenxcore.expr.LineKindTools; 8 | 9 | class SimpleEasingKindTools 10 | { 11 | public static inline function toFunction(easing:SimpleEasingKind):Float->Float 12 | { 13 | return switch (easing) 14 | { 15 | case SimpleEasingKind.Linear: 16 | Easing.linear; 17 | 18 | case SimpleEasingKind.Standard(easing, inOut): 19 | StandardEasingKindTools.toFunction(easing, inOut); 20 | 21 | case SimpleEasingKind.Line(polyline, controls): 22 | LineKindTools.toFunction(polyline, controls); 23 | } 24 | } 25 | 26 | public static function toJsonable(easing:SimpleEasingKind):Dynamic 27 | { 28 | return switch (easing) 29 | { 30 | case SimpleEasingKind.Linear: 31 | "Linear"; 32 | 33 | case SimpleEasingKind.Standard(easing, inOut): 34 | ([ 35 | "Standard", 36 | EnumValueTools.getName(easing), 37 | EnumValueTools.getName(inOut), 38 | ]:Array); 39 | 40 | case SimpleEasingKind.Line(kind, controls): 41 | ([ 42 | "Line", 43 | EnumValueTools.getName(kind), 44 | controls 45 | ]:Array); 46 | } 47 | } 48 | 49 | public static function fromJsonable(data:Dynamic):SimpleEasingKind 50 | { 51 | return if (Std.is(data, String)) 52 | { 53 | switch (data) 54 | { 55 | case "Linear": 56 | SimpleEasingKind.Linear; 57 | 58 | case _: 59 | throw "unsupported SimpleEasingKind data: " + data; 60 | } 61 | } 62 | else 63 | { 64 | switch (data) 65 | { 66 | case ["Standard", easing, inOut]: 67 | SimpleEasingKind.Standard( 68 | EnumTools.createByName(StandardEasingKind, easing), 69 | EnumTools.createByName(InOutKind, inOut) 70 | ); 71 | 72 | case ["Line", kind, controls]: 73 | SimpleEasingKind.Line( 74 | EnumTools.createByName(LineKind, kind), 75 | [for (c in (controls:Array)) cast(c, Float)] 76 | ); 77 | 78 | case _: 79 | throw "unsupported SimpleEasingKind data: " + data; 80 | } 81 | } 82 | } 83 | 84 | public static function toExpr(easing:SimpleEasingKind, valueExpr:ExprOf):ExprOf 85 | { 86 | return switch (easing) 87 | { 88 | case SimpleEasingKind.Linear: 89 | macro tweenxcore.Tools.Easing.linear($valueExpr); 90 | 91 | case SimpleEasingKind.Standard(easing, inOut): 92 | StandardEasingKindTools.toExpr(easing, inOut, valueExpr); 93 | 94 | case SimpleEasingKind.Line(polyline, controls): 95 | LineKindTools.toExpr(polyline, controls, valueExpr); 96 | } 97 | } 98 | 99 | public static function toFunctionExpr(easing:SimpleEasingKind):ExprOfFloat> 100 | { 101 | return switch (easing) 102 | { 103 | case SimpleEasingKind.Linear: 104 | macro tweenxcore.Tools.Easing.linear; 105 | 106 | case SimpleEasingKind.Standard(easing, inOut): 107 | StandardEasingKindTools.toFunctionExpr(easing, inOut); 108 | 109 | case SimpleEasingKind.Line(polyline, controls): 110 | LineKindTools.toFunctionExpr(polyline, controls); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/fairygui/text/BitmapFont.hx: -------------------------------------------------------------------------------- 1 | package fairygui.text; 2 | 3 | import fairygui.text.BMGlyph; 4 | 5 | import openfl.display.BitmapData; 6 | import openfl.display.BitmapDataChannel; 7 | import openfl.geom.ColorTransform; 8 | import openfl.geom.Matrix; 9 | import openfl.geom.Point; 10 | import openfl.geom.Rectangle; 11 | 12 | class BitmapFont 13 | { 14 | public var id : String; 15 | public var size : Int = 0; 16 | public var ttf : Bool = false; 17 | public var resizable : Bool = false; 18 | public var colored : Bool = false; 19 | public var atlas : BitmapData; 20 | public var glyphs : Map; 21 | 22 | public function new() 23 | { 24 | glyphs = new Map(); 25 | } 26 | 27 | public function dispose() : Void 28 | { 29 | if (atlas != null) 30 | atlas.dispose(); 31 | } 32 | 33 | public function translateChannel(channel : Int) : Int 34 | { 35 | switch (channel) 36 | { 37 | case 1: 38 | return BitmapDataChannel.BLUE; 39 | case 2: 40 | return BitmapDataChannel.GREEN; 41 | case 4: 42 | return BitmapDataChannel.RED; 43 | case 8: 44 | return BitmapDataChannel.ALPHA; 45 | default: 46 | return 0; 47 | } 48 | } 49 | 50 | private static var sHelperRect : Rectangle = new Rectangle(); 51 | private static var sTransform : ColorTransform = new ColorTransform(0, 0, 0, 1); 52 | private static var sHelperMat : Matrix = new Matrix(); 53 | private static var sHelperBmd : BitmapData = new BitmapData(200, 200, true, 0); 54 | private static var sPoint0 : Point = new Point(0, 0); 55 | 56 | public function draw(target : BitmapData, glyph : BMGlyph, charPosX : Float, charPosY : Float, color : Int, fontScale : Float) : Void 57 | { 58 | charPosX += Math.ceil(glyph.offsetX * fontScale); 59 | charPosY += Math.ceil(glyph.offsetY * fontScale); 60 | 61 | var drawBmd : BitmapData = null; 62 | 63 | if (ttf) 64 | { 65 | if (atlas != null) 66 | { 67 | sHelperBmd.fillRect(sHelperBmd.rect, 0); 68 | 69 | sHelperRect.x = 0; 70 | sHelperRect.y = 0; 71 | sHelperRect.width = glyph.width; 72 | sHelperRect.height = glyph.height; 73 | 74 | if (glyph.channel == 0) 75 | sHelperBmd.fillRect(sHelperRect, 0); 76 | else 77 | sHelperBmd.fillRect(sHelperRect, 0xFFFFFFFF); 78 | 79 | sHelperRect.x = glyph.x; 80 | sHelperRect.y = glyph.y; 81 | 82 | if (glyph.channel == 0) 83 | sHelperBmd.copyPixels(atlas, sHelperRect, sPoint0); 84 | else 85 | sHelperBmd.copyChannel(atlas, sHelperRect, sPoint0, glyph.channel, BitmapDataChannel.ALPHA); 86 | 87 | drawBmd = sHelperBmd; 88 | } 89 | } 90 | else if (glyph.imageItem != null) 91 | drawBmd = glyph.imageItem.image; 92 | 93 | if (drawBmd != null) 94 | { 95 | sHelperMat.identity(); 96 | sHelperMat.scale(fontScale, fontScale); 97 | sHelperMat.translate(charPosX, charPosY); 98 | sHelperRect.x = charPosX; 99 | sHelperRect.y = charPosY; 100 | sHelperRect.width = Math.ceil(glyph.width * fontScale); 101 | sHelperRect.height = Math.ceil(glyph.height * fontScale); 102 | if (colored) 103 | { 104 | sTransform.redMultiplier = ((color>>16)&0xFF)/255; 105 | sTransform.greenMultiplier = ((color>>8)&0xFF)/255; 106 | sTransform.blueMultiplier = (color&0xFF)/255; 107 | target.draw(drawBmd, sHelperMat, sTransform, null, sHelperRect, true); 108 | } 109 | else 110 | target.draw(drawBmd, sHelperMat, null, null, sHelperRect, true); 111 | } 112 | } 113 | } 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /src/tweenxcore/color/HsvColor.hx: -------------------------------------------------------------------------------- 1 | package tweenxcore.color; 2 | import tweenxcore.color.RgbColor; 3 | using tweenxcore.Tools; 4 | 5 | class HsvColor implements IColor { 6 | /** hue */ 7 | public var h:Float; 8 | /** saturation */ 9 | public var s:Float; 10 | /** value (brightness) */ 11 | public var v:Float; 12 | 13 | public inline function new(hue:Float, saturation:Float, value:Float) { 14 | this.h = hue; 15 | this.s = saturation; 16 | this.v = value; 17 | } 18 | 19 | public static function hsvToRgbInt(h:Float, s:Float, v:Float):Int { 20 | h = (h - Math.floor(h)) * 6; 21 | var hi = Math.floor(h); 22 | 23 | s = s.clamp(); 24 | v = v.clamp(); 25 | 26 | var m = v * (1 - s); 27 | var f = h - hi; 28 | 29 | var r = 0.0, g = 0.0, b = 0.0; 30 | switch(hi) { 31 | case 0: r = v; g = v * (1 - s * (1 - f)); b = m; 32 | case 1: r = v * (1 - s * f); g = v; b = m; 33 | case 2: r = m; g = v; b = v * (1 - s * (1 - f)); 34 | case 3: r = m; g = v * (1 - s * f); b = v; 35 | case 4: r = v * (1 - s * (1 - f)); g = m; b = v; 36 | case 5: r = v; g = m; b = v * (1 - s * f); 37 | } 38 | 39 | return (Std.int(r * 0xFF) << 16) | (Std.int(g * 0xFF) << 8) | Std.int(b * 0xFF); 40 | } 41 | 42 | public static inline function of(color:Int, hueIndex:Int = 0) { 43 | var r = ((color >> 16) & 0xFF) / 0xFF; 44 | var g = ((color >> 8) & 0xFF) / 0xFF; 45 | var b = (color & 0xFF) / 0xFF; 46 | return fromRgb(r, g, b, hueIndex); 47 | } 48 | 49 | public static function fromRgb(r:Float, g:Float, b:Float, hueIndex:Int = 0):HsvColor { 50 | var max, min, diff, h; 51 | if (r < g) { 52 | if (g < b) { 53 | max = b; 54 | min = r; 55 | h = (4 + (r - g) / (diff = max - min)) / 6; 56 | }else { 57 | max = g; 58 | min = (r < b) ? r : b; 59 | h = (2 + (b - r) / (diff = max - min)) / 6; 60 | } 61 | } else { 62 | if (r < b) { 63 | max = b; 64 | min = g; 65 | h = (4 + (r - g) / (diff = max - min)) / 6; 66 | }else { 67 | max = r; 68 | min = (g < b) ? g : b; 69 | h = (g - b) / (diff = max - min) / 6; 70 | } 71 | } 72 | 73 | if (h < 0) h += 1; 74 | var s = diff / max; 75 | 76 | if (Math.isNaN(h)) 77 | { 78 | h = 0; 79 | } 80 | if (Math.isNaN(s)) 81 | { 82 | s = 0; 83 | } 84 | return new HsvColor(h + hueIndex, s, max); 85 | } 86 | 87 | 88 | 89 | public inline function getRed():Float { 90 | return toRgb().r; 91 | } 92 | 93 | public inline function getGreen():Float { 94 | return toRgb().g; 95 | } 96 | 97 | public inline function getBlue():Float { 98 | return toRgb().b; 99 | } 100 | 101 | public inline function getHue():Float { 102 | return h; 103 | } 104 | 105 | public inline function getSaturation():Float { 106 | return s; 107 | } 108 | 109 | public inline function getBrightness():Float { 110 | return v; 111 | } 112 | 113 | public inline function toRgb():RgbColor { 114 | return RgbColor.fromHsv(h, s, v); 115 | } 116 | 117 | public inline function toHsv():HsvColor { 118 | return new HsvColor(h, s, v); 119 | } 120 | 121 | public inline function toHsvWithAlpha(alpha:Float):AhsvColor { 122 | return new AhsvColor(alpha, h, s, v); 123 | } 124 | 125 | public inline function toRgbWithAlpha(alpha:Float):ArgbColor { 126 | return ArgbColor.fromAhsv(alpha, h, s, v); 127 | } 128 | 129 | public inline function toRgbInt():Int { 130 | return hsvToRgbInt(h, s, v); 131 | } 132 | 133 | public inline function toRgbHexString():String { 134 | return StringTools.hex(toRgbInt(), 6); 135 | } 136 | 137 | public inline function toRgbCssString():String { 138 | return toRgb().toRgbCssString(); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/fairygui/GearXY.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import tweenx909.TweenX; 4 | import fairygui.GObject; 5 | 6 | import openfl.geom.Point; 7 | 8 | class GearXY extends GearBase 9 | { 10 | public var tweener:TweenX; 11 | 12 | private var _storage:Map; 13 | private var _default:Point; 14 | private var _tweenValue:Point; 15 | 16 | public function new(owner:GObject) 17 | { 18 | super(owner); 19 | } 20 | 21 | override private function init():Void 22 | { 23 | _default = new Point(_owner.x, _owner.y); 24 | _storage = new Map(); 25 | } 26 | 27 | override private function addStatus(pageId:String, value:String):Void 28 | { 29 | if (value == "-" || value.length == 0) 30 | return; 31 | 32 | var arr:Array = value.split(","); 33 | var pt:Point; 34 | if (pageId == null) 35 | pt = _default; 36 | else 37 | { 38 | pt = new Point(); 39 | _storage[pageId] = pt; 40 | } 41 | pt.x = Std.parseInt(arr[0]); 42 | pt.y = Std.parseInt(arr[1]); 43 | } 44 | 45 | override public function apply():Void 46 | { 47 | var pt:Point = _storage[_controller.selectedPageId]; 48 | if (pt == null) 49 | pt = _default; 50 | 51 | if (_tween && UIPackage._constructing <= 0 && !GearBase.disableAllTweenEffect) 52 | { 53 | if (tweener != null) 54 | { 55 | if (tweener.vars.x != pt.x || tweener.vars.y != pt.y) 56 | { 57 | _owner._gearLocked = true; 58 | _owner.setXY(tweener.vars.x, tweener.vars.y); 59 | _owner._gearLocked = false; 60 | tweener.stop(); 61 | tweener = null; 62 | _owner.releaseDisplayLock(_displayLockToken); 63 | _displayLockToken = 0; 64 | } 65 | else 66 | return; 67 | } 68 | 69 | if (_owner.x != pt.x || _owner.y != pt.y) 70 | { 71 | if (_owner.checkGearController(0, _controller)) 72 | _displayLockToken = _owner.addDisplayLock(); 73 | var vars = 74 | { 75 | x : pt.x, 76 | y : pt.y 77 | }; 78 | if (_tweenValue == null) 79 | _tweenValue = new Point(); 80 | _tweenValue.x = _owner.x; 81 | _tweenValue.y = _owner.y; 82 | tweener = TweenX.to(_tweenValue, vars, _tweenTime).ease(_easeType).delay(_delay).onUpdate(__tweenUpdate).onFinish(__tweenComplete); 83 | } 84 | } 85 | else 86 | { 87 | _owner._gearLocked = true; 88 | _owner.setXY(pt.x, pt.y); 89 | _owner._gearLocked = false; 90 | } 91 | } 92 | 93 | private function __tweenUpdate():Void 94 | { 95 | _owner._gearLocked = true; 96 | _owner.setXY(_tweenValue.x, _tweenValue.y); 97 | _owner._gearLocked = false; 98 | } 99 | 100 | private function __tweenComplete():Void 101 | { 102 | if (_displayLockToken != 0) 103 | { 104 | _owner.releaseDisplayLock(_displayLockToken); 105 | _displayLockToken = 0; 106 | } 107 | tweener = null; 108 | } 109 | 110 | override public function updateState():Void 111 | { 112 | var pt:Point = _storage[_controller.selectedPageId]; 113 | if (pt == null) 114 | { 115 | pt = new Point(); 116 | _storage[_controller.selectedPageId] = pt; 117 | } 118 | 119 | pt.x = _owner.x; 120 | pt.y = _owner.y; 121 | } 122 | 123 | override public function updateFromRelations(dx:Float, dy:Float):Void 124 | { 125 | if (_controller == null || _storage == null) 126 | return; 127 | 128 | for (i in _storage.keys()) 129 | { 130 | var pt:Point = _storage.get(i); 131 | pt.x += dx; 132 | pt.y += dy; 133 | } 134 | _default.x += dx; 135 | _default.y += dy; 136 | 137 | updateState(); 138 | } 139 | } 140 | 141 | -------------------------------------------------------------------------------- /src/fairygui/GMovieClip.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.display.UIMovieClip; 4 | import fairygui.IAnimationGear; 5 | import fairygui.IColorGear; 6 | import fairygui.PackageItem; 7 | import fairygui.utils.ToolSet; 8 | import openfl.geom.ColorTransform; 9 | import openfl.geom.Rectangle; 10 | 11 | class GMovieClip extends GObject implements IAnimationGear implements IColorGear 12 | { 13 | public var playing(get, set):Bool; 14 | public var frame(get, set):Int; 15 | public var color(get, set):UInt; 16 | 17 | private var _movieClip:UIMovieClip; 18 | private var _color:UInt; 19 | 20 | public function new() 21 | { 22 | super(); 23 | _sizeImplType = 1; 24 | _color = 0xFFFFFF; 25 | } 26 | 27 | override private function createDisplayObject():Void 28 | { 29 | _movieClip = new UIMovieClip(this); 30 | _movieClip.mouseEnabled = false; 31 | _movieClip.mouseChildren = false; 32 | setDisplayObject(_movieClip); 33 | } 34 | 35 | @:final private function get_playing():Bool 36 | { 37 | return _movieClip.playing; 38 | } 39 | 40 | @:final private function set_playing(value:Bool):Bool 41 | { 42 | if (_movieClip.playing != value) 43 | { 44 | _movieClip.playing = value; 45 | updateGear(5); 46 | } 47 | return value; 48 | } 49 | 50 | @:final private function get_frame():Int 51 | { 52 | return _movieClip.currentFrame; 53 | } 54 | 55 | private function set_frame(value:Int):Int 56 | { 57 | if (_movieClip.currentFrame != value) 58 | { 59 | _movieClip.currentFrame = value; 60 | updateGear(5); 61 | } 62 | return value; 63 | } 64 | 65 | //从start帧开始,播放到end帧(-1表示结尾),重复times次(0表示无限循环),循环结束后,停止在endAt帧(-1表示参数end) 66 | public function setPlaySettings(start:Int = 0, end:Int = -1, 67 | times:Int = 0, endAt:Int = -1, 68 | endCallback:Dynamic = null):Void 69 | { 70 | _movieClip.setPlaySettings(start, end, times, endAt, endCallback); 71 | } 72 | 73 | private function get_color():UInt 74 | { 75 | return _color; 76 | } 77 | 78 | private function set_color(value:UInt):UInt 79 | { 80 | if (_color != value) 81 | { 82 | _color = value; 83 | updateGear(4); 84 | applyColor(); 85 | } 86 | return value; 87 | } 88 | 89 | private function applyColor():Void 90 | { 91 | var ct:ColorTransform = _movieClip.transform.colorTransform; 92 | ct.redMultiplier = ((_color >> 16) & 0xFF) / 255; 93 | ct.greenMultiplier = ((_color >> 8) & 0xFF) / 255; 94 | ct.blueMultiplier = (_color & 0xFF) / 255; 95 | _movieClip.transform.colorTransform = ct; 96 | } 97 | 98 | override public function dispose():Void 99 | { 100 | super.dispose(); 101 | } 102 | 103 | override public function constructFromResource():Void 104 | { 105 | sourceWidth = packageItem.width; 106 | sourceHeight = packageItem.height; 107 | initWidth = sourceWidth; 108 | initHeight = sourceHeight; 109 | 110 | setSize(sourceWidth, sourceHeight); 111 | 112 | if (packageItem.loaded) 113 | __movieClipLoaded(packageItem); 114 | else 115 | packageItem.owner.addItemCallback(packageItem, __movieClipLoaded); 116 | } 117 | 118 | private function __movieClipLoaded(pi:PackageItem):Void 119 | { 120 | _movieClip.interval = Std.int(packageItem.interval); 121 | _movieClip.swing = packageItem.swing; 122 | _movieClip.repeatDelay = Std.int(packageItem.repeatDelay); 123 | _movieClip.frames = packageItem.frames; 124 | _movieClip.boundsRect = new Rectangle(0, 0, sourceWidth, sourceHeight); 125 | _movieClip.smoothing = packageItem.smoothing; 126 | } 127 | 128 | override public function setup_beforeAdd(xml:FastXML):Void 129 | { 130 | super.setup_beforeAdd(xml); 131 | 132 | var str:String; 133 | str = xml.att.frame; 134 | if (str != null) 135 | _movieClip.currentFrame = Std.parseInt(str); 136 | str = xml.att.playing; 137 | _movieClip.playing = str != "false"; 138 | str = xml.att.color; 139 | if (str != null) 140 | this.color = ToolSet.convertFromHtmlColor(str); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/fairygui/UIObjectFactory.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import openfl.errors.Error; 4 | class UIObjectFactory 5 | { 6 | @:allow(fairygui) 7 | private static var packageItemExtensions : Map> = new Map>(); 8 | private static var loaderType : Class; 9 | 10 | public function new() 11 | { 12 | } 13 | 14 | public static function setPackageItemExtension(url : String, type : Class) : Void 15 | { 16 | if (url == null) 17 | throw new Error("Invaild url: " + url); 18 | 19 | var pi:PackageItem = UIPackage.getItemByURL(url); 20 | if (pi != null) 21 | pi.extensionType = type; 22 | 23 | packageItemExtensions[url] = type; 24 | } 25 | 26 | public static function setLoaderExtension(type : Class) : Void 27 | { 28 | loaderType = type; 29 | } 30 | 31 | @:allow(fairygui) 32 | private static function resolvePackageItemExtension(pi:PackageItem):Void 33 | { 34 | pi.extensionType = packageItemExtensions["ui://" + pi.owner.id + pi.id]; 35 | if(pi.extensionType == null) 36 | pi.extensionType = packageItemExtensions["ui://" + pi.owner.name + "/" + pi.name]; 37 | } 38 | 39 | public static function newObject(pi : PackageItem) : GObject 40 | { 41 | switch (pi.type) 42 | { 43 | case PackageItemType.Image: 44 | return new GImage(); 45 | 46 | case PackageItemType.MovieClip: 47 | return new GMovieClip(); 48 | 49 | case PackageItemType.Swf: 50 | return new GSwfObject(); 51 | 52 | case PackageItemType.Component: 53 | { 54 | var cls : Class = pi.extensionType; 55 | if (cls != null) 56 | return Type.createInstance(cls, []); 57 | 58 | var xml : FastXML = pi.owner.getComponentData(pi); 59 | var extention : String = xml.att.extention; 60 | if (extention != null) 61 | { 62 | switch (extention) 63 | { 64 | case "Button": 65 | return new GButton(); 66 | 67 | case "Label": 68 | return new GLabel(); 69 | 70 | case "ProgressBar": 71 | return new GProgressBar(); 72 | 73 | case "Slider": 74 | return new GSlider(); 75 | 76 | case "ScrollBar": 77 | return new GScrollBar(); 78 | 79 | case "ComboBox": 80 | return new GComboBox(); 81 | 82 | default: 83 | return new GComponent(); 84 | } 85 | } 86 | else 87 | return new GComponent(); 88 | } 89 | } 90 | return null; 91 | } 92 | 93 | public static function newObject2(type : String) : GObject 94 | { 95 | switch (type) 96 | { 97 | case "image": 98 | return new GImage(); 99 | 100 | case "movieclip": 101 | return new GMovieClip(); 102 | 103 | case "swf": 104 | return new GSwfObject(); 105 | 106 | case "component": 107 | return new GComponent(); 108 | 109 | case "text": 110 | return new GTextField(); 111 | 112 | case "richtext": 113 | return new GRichTextField(); 114 | 115 | case "inputtext": 116 | return new GTextInput(); 117 | 118 | case "group": 119 | return new GGroup(); 120 | 121 | case "list": 122 | return new GList(); 123 | 124 | case "graph": 125 | return new GGraph(); 126 | 127 | case "loader": 128 | if (loaderType != null) 129 | return Type.createInstance(loaderType, []); 130 | else 131 | return new GLoader(); 132 | } 133 | return null; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/fairygui/GearBase.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | 4 | import tweenxcore.Tools.Easing; 5 | import fairygui.GObject; 6 | import fairygui.utils.EaseLookup; 7 | 8 | 9 | class GearBase 10 | { 11 | public var controller(get, set):Controller; 12 | public var tween(get, set):Bool; 13 | public var tweenTime(get, set):Float; 14 | public var delay(get, set):Float; 15 | public var easeType(get, set):Float -> Float; 16 | 17 | public static var disableAllTweenEffect:Bool = false; 18 | 19 | private var _tween:Bool = false; 20 | private var _easeType:Float -> Float; 21 | private var _tweenTime:Float = 0; 22 | private var _delay:Float = 0; 23 | public var _displayLockToken:UInt; 24 | 25 | private var _owner:GObject; 26 | private var _controller:Controller; 27 | 28 | public function new(owner:GObject) 29 | { 30 | _owner = owner; 31 | _easeType = Easing.quadOut; 32 | _tweenTime = 0.3; 33 | _delay = 0; 34 | } 35 | 36 | @:final private function get_controller():Controller 37 | { 38 | return _controller; 39 | } 40 | 41 | private function set_controller(val:Controller):Controller 42 | { 43 | if (val != _controller) 44 | { 45 | _controller = val; 46 | if (_controller != null) 47 | init(); 48 | } 49 | return val; 50 | } 51 | 52 | @:final private function get_tween():Bool 53 | { 54 | return _tween; 55 | } 56 | 57 | private function set_tween(val:Bool):Bool 58 | { 59 | _tween = val; 60 | return val; 61 | } 62 | 63 | @:final private function get_tweenTime():Float 64 | { 65 | return _tweenTime; 66 | } 67 | 68 | private function set_tweenTime(value:Float):Float 69 | { 70 | _tweenTime = value; 71 | return value; 72 | } 73 | 74 | @:final private function get_delay():Float 75 | { 76 | return _delay; 77 | } 78 | 79 | private function set_delay(value:Float):Float 80 | { 81 | _delay = value; 82 | return value; 83 | } 84 | 85 | @:final private function get_easeType():Float -> Float 86 | { 87 | return _easeType; 88 | } 89 | 90 | private function set_easeType(value:Float -> Float):Float -> Float 91 | { 92 | _easeType = value; 93 | return value; 94 | } 95 | 96 | public function setup(xml:FastXML):Void 97 | { 98 | _controller = _owner.parent.getController(xml.att.controller); 99 | if (_controller == null) 100 | return; 101 | 102 | init(); 103 | 104 | var str:String; 105 | 106 | str = xml.att.tween; 107 | if (str != null) 108 | _tween = true; 109 | 110 | str = xml.att.ease; 111 | if (str != null) 112 | { 113 | var pos:Int = str.indexOf("."); 114 | if (pos != -1) 115 | str = str.substr(0, pos) + ".ease" + str.substr(pos + 1); 116 | if (str == "Linear") 117 | _easeType = EaseLookup.find("linear.easenone"); 118 | else 119 | _easeType = EaseLookup.find(str); 120 | } 121 | 122 | str = xml.att.duration; 123 | if (str != null) 124 | _tweenTime = Std.parseFloat(str); 125 | 126 | str = xml.att.delay; 127 | if (str != null) 128 | _delay = Std.parseFloat(str); 129 | 130 | if (Std.is(this, GearDisplay)) 131 | { 132 | str = xml.att.pages; 133 | if (str != null) 134 | { 135 | var arr:Array = str.split(","); 136 | cast(this, GearDisplay).pages = arr; 137 | } 138 | } 139 | else 140 | { 141 | var pages:Array = null; 142 | var values:Array = null; 143 | 144 | str = xml.att.pages; 145 | if (str != null) 146 | pages = str.split(","); 147 | 148 | if (pages != null) 149 | { 150 | str = xml.att.values; 151 | values = str.split("|"); 152 | 153 | for (i in 0...pages.length) 154 | { 155 | str = values[i]; 156 | if(str == null) 157 | str = ""; 158 | addStatus(pages[i], str); 159 | } 160 | } 161 | 162 | str = xml.att.resolve("default"); 163 | if (str != null) 164 | addStatus(null, str); 165 | } 166 | } 167 | 168 | public function updateFromRelations(dx:Float, dy:Float):Void 169 | { 170 | } 171 | 172 | private function addStatus(pageId:String, value:String):Void 173 | { 174 | } 175 | 176 | private function init():Void 177 | { 178 | } 179 | 180 | public function apply():Void 181 | { 182 | } 183 | 184 | public function updateState():Void 185 | { 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/fairygui/utils/ColorMatrix.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | abstract ColorMatrix(Array) from Array to Array 4 | { 5 | 6 | // identity matrix constant: 7 | private static var IDENTITY_MATRIX : Array = [ 8 | 1, 0, 0, 0, 0, 9 | 0, 1, 0, 0, 0, 10 | 0, 0, 1, 0, 0, 11 | 0, 0, 0, 1, 0]; 12 | private static var LENGTH : Int = IDENTITY_MATRIX.length; 13 | 14 | private static inline var LUMA_R : Float = 0.299; 15 | private static inline var LUMA_G : Float = 0.587; 16 | private static inline var LUMA_B : Float = 0.114; 17 | 18 | public static function create(p_brightness : Float, p_contrast : Float, p_saturation : Float, p_hue : Float) : ColorMatrix{ 19 | var ret : ColorMatrix = new ColorMatrix(); 20 | ret.adjustColor(p_brightness, p_contrast, p_saturation, p_hue); 21 | return ret; 22 | } 23 | 24 | // initialization: 25 | public function new() 26 | { 27 | // super(); 28 | this = new Array(); 29 | reset(); 30 | } 31 | 32 | 33 | // public methods: 34 | public function reset() : Void{ 35 | for (i in 0...LENGTH){ 36 | this[i] = IDENTITY_MATRIX[i]; 37 | } 38 | } 39 | 40 | public function invert() : Void 41 | { 42 | multiplyMatrix([-1, 0, 0, 0, 255, 43 | 0, -1, 0, 0, 255, 44 | 0, 0, -1, 0, 255, 45 | 0, 0, 0, 1, 0]); 46 | } 47 | 48 | public function adjustColor(p_brightness : Float, p_contrast : Float, p_saturation : Float, p_hue : Float) : Void{ 49 | adjustHue(p_hue); 50 | adjustContrast(p_contrast); 51 | adjustBrightness(p_brightness); 52 | adjustSaturation(p_saturation); 53 | } 54 | 55 | public function adjustBrightness(p_val : Float) : Void{ 56 | p_val = cleanValue(p_val, 1) * 255; 57 | multiplyMatrix([ 58 | 1, 0, 0, 0, p_val, 59 | 0, 1, 0, 0, p_val, 60 | 0, 0, 1, 0, p_val, 61 | 0, 0, 0, 1, 0]); 62 | } 63 | 64 | public function adjustContrast(p_val : Float) : Void{ 65 | p_val = cleanValue(p_val, 1); 66 | var s : Float = p_val + 1; 67 | var o : Float = 128 * (1 - s); 68 | multiplyMatrix([ 69 | s, 0, 0, 0, o, 70 | 0, s, 0, 0, o, 71 | 0, 0, s, 0, o, 72 | 0, 0, 0, 1, 0]); 73 | } 74 | 75 | public function adjustSaturation(p_val : Float) : Void{ 76 | p_val = cleanValue(p_val, 1); 77 | p_val += 1; 78 | 79 | var invSat : Float = 1 - p_val; 80 | var invLumR : Float = invSat * LUMA_R; 81 | var invLumG : Float = invSat * LUMA_G; 82 | var invLumB : Float = invSat * LUMA_B; 83 | 84 | multiplyMatrix([ 85 | (invLumR + p_val), invLumG, invLumB, 0, 0, 86 | invLumR, (invLumG + p_val), invLumB, 0, 0, 87 | invLumR, invLumG, (invLumB + p_val), 0, 0, 88 | 0, 0, 0, 1, 0]); 89 | } 90 | 91 | public function adjustHue(p_val : Float) : Void{ 92 | p_val = cleanValue(p_val, 1); 93 | p_val *= Math.PI; 94 | 95 | var cos : Float = Math.cos(p_val); 96 | var sin : Float = Math.sin(p_val); 97 | 98 | multiplyMatrix([ 99 | ((LUMA_R + (cos * (1 - LUMA_R))) + (sin * -(LUMA_R))), ((LUMA_G + (cos * -(LUMA_G))) + (sin * -(LUMA_G))), ((LUMA_B + (cos * -(LUMA_B))) + (sin * (1 - LUMA_B))), 0, 0, 100 | ((LUMA_R + (cos * -(LUMA_R))) + (sin * 0.143)), ((LUMA_G + (cos * (1 - LUMA_G))) + (sin * 0.14)), ((LUMA_B + (cos * -(LUMA_B))) + (sin * -0.283)), 0, 0, 101 | ((LUMA_R + (cos * -(LUMA_R))) + (sin * -((1 - LUMA_R)))), ((LUMA_G + (cos * -(LUMA_G))) + (sin * LUMA_G)), ((LUMA_B + (cos * (1 - LUMA_B))) + (sin * LUMA_B)), 0, 0, 102 | 0, 0, 0, 1, 0]); 103 | } 104 | 105 | public function concat(p_matrix : Array) : Void{ 106 | if (p_matrix.length != LENGTH) {return; 107 | } 108 | multiplyMatrix(p_matrix); 109 | } 110 | 111 | public function clone() : ColorMatrix{ 112 | var result : ColorMatrix = new ColorMatrix(); 113 | result.copyMatrix(this); 114 | return result; 115 | } 116 | 117 | private function copyMatrix(p_matrix : Array) : Void{ 118 | var l : Int = LENGTH; 119 | for (i in 0...l){ 120 | this[i] = p_matrix[i]; 121 | } 122 | } 123 | 124 | private function multiplyMatrix(p_matrix : Array) : Void{ 125 | var col : Array = []; 126 | 127 | var i : Int = 0; 128 | 129 | for (y in 0...4){ 130 | for (x in 0...5){ 131 | col[i + x] = p_matrix[i] * this[x] + 132 | p_matrix[i + 1] * this[x + 5] + 133 | p_matrix[i + 2] * this[x + 10] + 134 | p_matrix[i + 3] * this[x + 15] + 135 | ((x == 4) ? p_matrix[i + 4] : 0); 136 | } 137 | 138 | i += 5; 139 | } 140 | 141 | copyMatrix(col); 142 | } 143 | 144 | private function cleanValue(p_val : Float, p_limit : Float) : Float{ 145 | return Math.min(p_limit, Math.max(-p_limit, p_val)); 146 | } 147 | } 148 | 149 | -------------------------------------------------------------------------------- /src/fairygui/utils/GTimers.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | import openfl.events.TimerEvent; 4 | import openfl.utils.Timer; 5 | import openfl.Lib; 6 | 7 | 8 | class GTimers 9 | { 10 | 11 | 12 | private var _items : Array; 13 | private var _itemPool : Array; 14 | private var _timer : Timer; 15 | 16 | private var _lastTime : Int = 0; 17 | 18 | private var _enumI : Int = 0; 19 | private var _enumCount : Int = 0; 20 | 21 | public static var deltaTime : Int = 0; 22 | public static var time : Int = 0; 23 | public static var workCount : Int = 0; 24 | 25 | private static var FPS24 : Int = Std.int(1000 / 24); 26 | 27 | public static var _inst:GTimers; 28 | public static var inst(get, never):GTimers; 29 | private static function get_inst():GTimers 30 | { 31 | if (_inst == null) 32 | new GTimers(); 33 | return _inst; 34 | } 35 | 36 | public function new() 37 | { 38 | if (_inst == null) 39 | _inst = this; 40 | 41 | _items = new Array(); 42 | _itemPool = new Array(); 43 | 44 | deltaTime = 1; 45 | _lastTime = Lib.getTimer(); 46 | time = _lastTime; 47 | 48 | _timer = new Timer(10); 49 | _timer.addEventListener(TimerEvent.TIMER, __timer); 50 | _timer.start(); 51 | } 52 | 53 | private function getItem() : TimerItem 54 | { 55 | if (_itemPool.length > 0) 56 | return _itemPool.pop(); 57 | else 58 | return new TimerItem(); 59 | } 60 | 61 | private function findItem(callback: Dynamic): TimerItem 62 | { 63 | var len: Int = this._items.length; 64 | for (i in 0...len) 65 | { 66 | var item: TimerItem = this._items[i]; 67 | if ( Reflect.compareMethods ( item.callback, callback ) ) 68 | return item; 69 | } 70 | return null; 71 | } 72 | 73 | public function add(delayInMiniseconds : Int, repeat : Int, callback : Dynamic, callbackParam : Dynamic = null) : Void{ 74 | var item : TimerItem = findItem(callback); 75 | if (item == null) 76 | { 77 | item = getItem(); 78 | item.callback = callback; 79 | item.hasParam = callbackParam!=null; 80 | _items.push(item); 81 | } 82 | item.delay = delayInMiniseconds; 83 | item.counter = 0; 84 | item.repeat = repeat; 85 | item.param = callbackParam; 86 | item.end = false; 87 | } 88 | 89 | public function callLater(callback : Dynamic, callbackParam : Dynamic = null) : Void 90 | { 91 | add(1, 1, callback, callbackParam); 92 | } 93 | 94 | public function callDelay(delay : Int, callback : Dynamic, callbackParam : Dynamic = null) : Void 95 | { 96 | add(delay, 1, callback, callbackParam); 97 | } 98 | 99 | public function callBy24Fps(callback : Dynamic, callbackParam : Dynamic = null) : Void 100 | { 101 | add(FPS24, 0, callback, callbackParam); 102 | } 103 | 104 | public function exists(callback : Dynamic) : Bool{ 105 | return findItem(callback) != null; 106 | } 107 | 108 | public function remove(callback : Dynamic) : Void{ 109 | var item : TimerItem = findItem(callback); 110 | if (item != null) 111 | { 112 | var i : Int = _items.indexOf(item); 113 | _items.splice(i, 1); 114 | if (i < _enumI) 115 | _enumI--; 116 | _enumCount--; 117 | 118 | item.callback = null; 119 | item.param = null; 120 | _itemPool.push(item); 121 | } 122 | } 123 | 124 | private function __timer(evt : TimerEvent) : Void{ 125 | time = Lib.getTimer(); 126 | workCount++; 127 | 128 | deltaTime = Std.int(time - _lastTime); 129 | _lastTime = time; 130 | 131 | if (deltaTime > 125) 132 | deltaTime = 125; 133 | 134 | _enumI = 0; 135 | _enumCount = _items.length; 136 | 137 | while (_enumI < _enumCount) 138 | { 139 | var item : TimerItem = _items[_enumI]; 140 | _enumI++; 141 | 142 | if (item.advance(deltaTime)) { 143 | if (item.end) 144 | { 145 | _enumI--; 146 | _enumCount--; 147 | _items.splice(_enumI, 1); 148 | _itemPool.push(item); 149 | } 150 | 151 | if (item.hasParam) 152 | item.callback(item.param); 153 | else 154 | item.callback(); 155 | } 156 | } 157 | } 158 | } 159 | 160 | 161 | class TimerItem 162 | { 163 | public var delay : Int; 164 | public var counter : Int; 165 | public var repeat : Int; 166 | public var callback : Dynamic; 167 | public var param : Dynamic; 168 | 169 | public var hasParam : Bool; 170 | public var end : Bool; 171 | 172 | public function new() 173 | { 174 | } 175 | 176 | public function advance(elapsed : Int) : Bool 177 | { 178 | counter += elapsed; 179 | if (counter >= delay) { 180 | counter -= delay; 181 | if (counter > delay) 182 | counter = delay; 183 | 184 | if (repeat > 0) 185 | { 186 | repeat--; 187 | if (repeat == 0) 188 | end = true; 189 | } 190 | 191 | return true; 192 | } 193 | else 194 | return false; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/fairygui/utils/UBBParser.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | 3 | 4 | class UBBParser 5 | { 6 | private var _text : String; 7 | private var _readPos : Int = 0; 8 | 9 | private var _handlers : Dynamic; 10 | 11 | public var smallFontSize : Int = 12; 12 | public var normalFontSize : Int = 14; 13 | public var largeFontSize : Int = 16; 14 | 15 | public var defaultImgWidth : Int = 0; 16 | public var defaultImgHeight : Int = 0; 17 | 18 | public static var inst : UBBParser = new UBBParser(); 19 | 20 | public function new() 21 | { 22 | _handlers = { }; 23 | Reflect.setField(_handlers, "url", onTag_URL); 24 | Reflect.setField(_handlers, "img", onTag_IMG); 25 | Reflect.setField(_handlers, "b", onTag_Simple); 26 | Reflect.setField(_handlers, "i", onTag_Simple); 27 | Reflect.setField(_handlers, "u", onTag_Simple); 28 | Reflect.setField(_handlers, "sup", onTag_Simple); 29 | Reflect.setField(_handlers, "sub", onTag_Simple); 30 | Reflect.setField(_handlers, "color", onTag_COLOR); 31 | Reflect.setField(_handlers, "font", onTag_FONT); 32 | Reflect.setField(_handlers, "size", onTag_SIZE); 33 | } 34 | 35 | private function onTag_URL(tagName : String, end : Bool, attr : String) : String{ 36 | if (!end) 37 | { 38 | if (attr != null) 39 | return ""; 40 | else 41 | { 42 | var href : String = getTagText(); 43 | return ""; 44 | } 45 | } 46 | else 47 | return ""; 48 | } 49 | 50 | private function onTag_IMG(tagName : String, end : Bool, attr : String) : String{ 51 | if (!end) 52 | { 53 | var src : String = getTagText(true); 54 | if (src == null) 55 | return null; 56 | 57 | if (defaultImgWidth != 0) 58 | return ""; 59 | else 60 | return ""; 61 | } 62 | else 63 | return null; 64 | } 65 | 66 | private function onTag_Simple(tagName : String, end : Bool, attr : String) : String{ 67 | return (end) ? ("") : ("<" + tagName + ">"); 68 | } 69 | 70 | private function onTag_COLOR(tagName : String, end : Bool, attr : String) : String{ 71 | if (!end) 72 | return ""; 73 | else 74 | return ""; 75 | } 76 | 77 | private function onTag_FONT(tagName : String, end : Bool, attr : String) : String{ 78 | if (!end) 79 | return ""; 80 | else 81 | return ""; 82 | } 83 | 84 | private function onTag_SIZE(tagName : String, end : Bool, attr : String) : String{ 85 | if (!end) { 86 | if (attr == "normal") 87 | attr = "" + normalFontSize; 88 | else if (attr == "small") 89 | attr = "" + smallFontSize; 90 | else if (attr == "large") 91 | attr = "" + largeFontSize; 92 | else if (attr.length > 0 && attr.charAt(0) == "+") 93 | attr = "" + (smallFontSize + Std.parseInt(attr.substr(1))); 94 | else if (attr.length > 0 && attr.charAt(0) == "-") 95 | attr = "" + (smallFontSize - Std.parseInt(attr.substr(1))); 96 | return ""; 97 | } 98 | else 99 | return ""; 100 | } 101 | 102 | private function getTagText(remove : Bool = false) : String{ 103 | var pos : Int = _text.indexOf("[", _readPos); 104 | if (pos == -1) 105 | return null; 106 | 107 | var ret : String = _text.substring(_readPos, pos); 108 | if (remove) 109 | _readPos = pos; 110 | return ret; 111 | } 112 | 113 | public function parse(text : String) : String{ 114 | _text = text; 115 | var pos1 : Int = 0; 116 | var pos2 : Int; 117 | var pos3 : Int; 118 | var end : Bool; 119 | var tag : String; 120 | var attr : String; 121 | var repl : String; 122 | var func : Dynamic; 123 | while ((pos2 = _text.indexOf("[", pos1)) != -1){ 124 | pos1 = pos2; 125 | pos2 = _text.indexOf("]", pos1); 126 | if (pos2 == -1) 127 | break; 128 | 129 | end = _text.charAt(pos1 + 1) == "/"; 130 | tag = _text.substring((end) ? pos1 + 2 : pos1 + 1, pos2); 131 | pos2++; 132 | _readPos = pos2; 133 | attr = null; 134 | repl = null; 135 | pos3 = tag.indexOf("="); 136 | if (pos3 != -1) { 137 | attr = tag.substring(pos3 + 1); 138 | tag = tag.substring(0, pos3); 139 | } 140 | tag = tag.toLowerCase(); 141 | func = Reflect.field(_handlers, tag); 142 | if (func != null) { 143 | repl = func(tag, end, attr); 144 | if (repl == null) 145 | repl = ""; 146 | } 147 | else { 148 | pos1 = pos2; 149 | continue; 150 | } 151 | _text = _text.substring(0, pos1) + repl + _text.substring(_readPos); 152 | } 153 | return _text; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/fairygui/utils/CompatUtil.hx: -------------------------------------------------------------------------------- 1 | package fairygui.utils; 2 | /** 3 | * AS3兼容性工具 4 | **/ 5 | class CompatUtil 6 | { 7 | public function new() 8 | { 9 | 10 | } 11 | 12 | /** 13 | * Runtime value of MAX_VALUE depends on target platform 14 | */ 15 | public static var MAX_VALUE(get, never):Float; 16 | 17 | static inline function get_MAX_VALUE():Float 18 | { 19 | #if flash 20 | return untyped __global__['Number'].MAX_VALUE; 21 | #elseif js 22 | return untyped __js__('Number.MAX_VALUE'); 23 | #elseif cs 24 | return untyped __cs__('double.MaxValue'); 25 | #elseif java 26 | return untyped __java__('Double.MAX_VALUE'); 27 | #elseif cpp 28 | return 10 ^ 10; 29 | // return 1.79769313486232e+308; 30 | // #elseif python 31 | // return PythonSysAdapter.float_info.max; 32 | #else 33 | return 1.79e+308; 34 | #end 35 | } 36 | 37 | /** 38 | * Runtime value of MIN_VALUE depends on target platform 39 | */ 40 | public static var MIN_VALUE(get, never):Float; 41 | 42 | static inline function get_MIN_VALUE():Float 43 | { 44 | #if flash 45 | return untyped __global__['Number'].MIN_VALUE; 46 | #elseif js 47 | return untyped __js__('Number.MIN_VALUE'); 48 | #elseif cs 49 | return untyped __cs__('double.MinValue'); 50 | #elseif java 51 | return untyped __java__('Double.MIN_VALUE'); 52 | #elseif cpp 53 | return 2.2250738585072e-308; 54 | // #elseif python 55 | // return PythonSysAdapter.float_info.min; 56 | #else 57 | return -1.79E+308; 58 | #end 59 | } 60 | 61 | public static var INT_MAX_VALUE(get, never):Int; 62 | 63 | static inline function get_INT_MAX_VALUE():Int 64 | { 65 | #if flash 66 | return untyped __global__['int'].MAX_VALUE; 67 | #elseif js 68 | return untyped __js__('Number.MAX_SAFE_INTEGER'); 69 | #elseif cs 70 | return untyped __cs__('int.MaxValue'); 71 | #elseif java 72 | return untyped __java__('Integer.MAX_VALUE'); 73 | #elseif cpp 74 | return 2147483647; 75 | // #elseif python 76 | // return PythonSysAdapter.maxint; 77 | #elseif php 78 | return untyped __php__('PHP_INT_MAX'); 79 | #else 80 | return 2 ^ 31 - 1; 81 | #end 82 | } 83 | 84 | /** 85 | * Runtime value of INT_MIN_VALUE depends on target platform 86 | */ 87 | public static var INT_MIN_VALUE(get, never):Int; 88 | 89 | static inline function get_INT_MIN_VALUE():Int 90 | { 91 | #if flash 92 | return untyped __global__['int'].MIN_VALUE; 93 | #elseif js 94 | return untyped __js__('Number.MIN_SAFE_INTEGER'); 95 | #elseif cs 96 | return untyped __cs__('int.MinValue'); 97 | #elseif java 98 | return untyped __java__('Integer.MIN_VALUE'); 99 | #elseif cpp 100 | return -2147483648; 101 | // #elseif python 102 | // return -PythonSysAdapter.maxint - 1; 103 | #elseif php 104 | return untyped __php__('PHP_INT_MIN'); 105 | #else 106 | return -2 ^ 31; 107 | #end 108 | } 109 | 110 | /** he largest representable 32-bit unsigned integer. */ 111 | inline public static var UINT_MAX_VALUE:UInt = 0xffffffff; 112 | 113 | static public #if !cs inline #end function toFixed(value:Float, digits:Int):String 114 | { 115 | #if (js || flash) 116 | return untyped value.toFixed(digits); 117 | #elseif php 118 | return untyped __call__("number_format", value, digits, ".", ""); 119 | #elseif java 120 | return untyped __java__("String.format({0}, {1})", '%.${digits}f', value); 121 | #elseif cs 122 | var separator:String = untyped __cs__('System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator'); 123 | untyped __cs__('System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator = ""'); 124 | var result = untyped value.ToString("N" + digits); 125 | untyped __cs__('System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator = separator'); 126 | return result; 127 | #else 128 | if (digits < 0 || digits > 20) 129 | throw 'toFixed have a range of 0 to 20. Specified value is not within expected range.'; 130 | 131 | var b = Math.pow(10, digits); 132 | var s = Std.string(value); 133 | var dotIndex = s.indexOf('.'); 134 | if (dotIndex >= 0) 135 | { 136 | var diff = digits - (s.length - (dotIndex + 1)); 137 | if (diff > 0) 138 | { 139 | s = StringTools.rpad(s, "0", s.length + diff); 140 | } 141 | else 142 | { 143 | s = Std.string(Math.round(value * b) / b); 144 | } 145 | } 146 | else 147 | { 148 | s += "."; 149 | s = StringTools.rpad(s, "0", s.length + digits); 150 | } 151 | return s; 152 | #end 153 | } 154 | 155 | public static var supportsCursor(get, null):Bool; 156 | 157 | static private function get_supportsCursor():Bool 158 | { 159 | #if flash 160 | var result:Bool = flash.ui.Mouse.supportsCursor; 161 | #else 162 | var result:Bool = false; 163 | #end 164 | return result; 165 | } 166 | 167 | static public function getTimer():UInt 168 | { 169 | return Math.round(haxe.Timer.stamp() * 1000); 170 | } 171 | 172 | 173 | } 174 | -------------------------------------------------------------------------------- /src/fairygui/GLabel.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import fairygui.GObject; 4 | 5 | import fairygui.utils.ToolSet; 6 | 7 | class GLabel extends GComponent implements IColorGear 8 | { 9 | public var title(get, set) : String; 10 | public var titleColor(get, set) : Int; 11 | public var editable(get, set) : Bool; 12 | public var titleFontSize(get, set): Int; 13 | public var color(get, set):UInt; 14 | 15 | private var _titleObject : GObject; 16 | private var _iconObject : GObject; 17 | 18 | public function new() 19 | { 20 | super(); 21 | } 22 | 23 | override private function get_icon() : String 24 | { 25 | if (_iconObject != null) 26 | return _iconObject.icon; 27 | else 28 | return null; 29 | } 30 | 31 | override private function set_icon(value : String) : String 32 | { 33 | if (_iconObject != null) 34 | _iconObject.icon = value; 35 | updateGear(7); 36 | return value; 37 | } 38 | 39 | @:final private function get_title() : String 40 | { 41 | if (_titleObject != null) 42 | return _titleObject.text; 43 | else 44 | return null; 45 | } 46 | 47 | private function set_title(value : String) : String 48 | { 49 | if (_titleObject != null) 50 | _titleObject.text = value; 51 | updateGear(6); 52 | return value; 53 | } 54 | 55 | @:final override private function get_text() : String 56 | { 57 | return this.title; 58 | } 59 | 60 | override private function set_text(value : String) : String 61 | { 62 | this.title = value; 63 | return value; 64 | } 65 | 66 | @:final private function get_titleColor() : Int 67 | { 68 | var tf:GTextField = getTextField(); 69 | if(tf!=null) 70 | return tf.color; 71 | else 72 | return 0; 73 | } 74 | 75 | private function set_titleColor(value : Int) : Int 76 | { 77 | var tf:GTextField = getTextField(); 78 | if(tf!=null) 79 | tf.color = value; 80 | updateGear(4); 81 | return value; 82 | } 83 | 84 | @:final public function get_titleFontSize():Int 85 | { 86 | var tf:GTextField = getTextField(); 87 | if(tf != null) 88 | return tf.fontSize; 89 | else 90 | return 0; 91 | } 92 | 93 | public function set_titleFontSize(value:Int):Int 94 | { 95 | var tf:GTextField = getTextField(); 96 | if(tf!=null) 97 | tf.fontSize = value; 98 | return value; 99 | } 100 | 101 | public function get_color():UInt 102 | { 103 | return this.titleColor; 104 | } 105 | 106 | public function set_color(value:UInt):UInt 107 | { 108 | this.titleColor = value; 109 | return value; 110 | } 111 | 112 | private function set_editable(val : Bool) : Bool 113 | { 114 | var tf:GTextField = getTextField(); 115 | if(tf!=null && Std.is(tf,GTextInput)) 116 | tf.asTextInput.editable = val; 117 | return val; 118 | } 119 | 120 | private function get_editable() : Bool 121 | { 122 | var tf:GTextField = getTextField(); 123 | if(tf!=null && Std.is(tf, GTextInput)) 124 | return tf.asTextInput.editable; 125 | else 126 | return false; 127 | } 128 | 129 | public function getTextField():GTextField 130 | { 131 | if (Std.is(_titleObject, GTextField)) 132 | return cast(_titleObject, GTextField); 133 | else if(Std.is(_titleObject, GLabel)) 134 | return cast(_titleObject, GLabel).getTextField(); 135 | else if(Std.is(_titleObject, GButton)) 136 | return cast(_titleObject, GButton).getTextField(); 137 | else 138 | return null; 139 | } 140 | 141 | override private function constructFromXML(xml : FastXML) : Void 142 | { 143 | super.constructFromXML(xml); 144 | 145 | _titleObject = getChild("title"); 146 | _iconObject = getChild("icon"); 147 | } 148 | 149 | override public function setup_afterAdd(xml : FastXML) : Void 150 | { 151 | super.setup_afterAdd(xml); 152 | 153 | xml = xml.nodes.Label.get(0); 154 | if (xml != null) 155 | { 156 | var str : String; 157 | str = xml.att.title; 158 | if (str != null) 159 | this.text = str; 160 | str = xml.att.icon; 161 | if (str != null) 162 | this.icon = str; 163 | str = xml.att.titleColor; 164 | if (str != null) 165 | this.titleColor = ToolSet.convertFromHtmlColor(str); 166 | str = xml.att.titleFontSize; 167 | if(str != null) 168 | this.titleFontSize = Std.parseInt(str); 169 | 170 | var tf:GTextField = getTextField(); 171 | if (Std.is(tf, GTextInput)) 172 | { 173 | str = xml.att.prompt; 174 | if (str != null) 175 | cast(tf, GTextInput).promptText = str; 176 | str = xml.att.maxLength; 177 | if (str != null) 178 | cast(tf, GTextInput).maxLength = Std.parseInt(str); 179 | str = xml.att.restrict; 180 | if (str != null) 181 | cast(tf, GTextInput).restrict = str; 182 | str = xml.att.password; 183 | if (str != null) 184 | cast(tf, GTextInput).password = str == "true"; 185 | } 186 | } 187 | } 188 | } 189 | 190 | 191 | -------------------------------------------------------------------------------- /src/fairygui/GearLook.hx: -------------------------------------------------------------------------------- 1 | package fairygui; 2 | 3 | import tweenx909.TweenX; 4 | import fairygui.GObject; 5 | 6 | import openfl.geom.Point; 7 | 8 | class GearLook extends GearBase 9 | { 10 | public var tweener:TweenX; 11 | 12 | private var _storage:Map; 13 | private var _default:GearLookValue; 14 | private var _tweenValue:Point; 15 | 16 | public function new(owner:GObject) 17 | { 18 | super(owner); 19 | } 20 | 21 | override private function init():Void 22 | { 23 | _default = new GearLookValue(_owner.alpha, _owner.rotation, _owner.grayed, _owner.touchable); 24 | _storage = new Map(); 25 | } 26 | 27 | override private function addStatus(pageId:String, value:String):Void 28 | { 29 | if (value == "-" || value.length == 0) 30 | return; 31 | 32 | var arr:Array = value.split(","); 33 | var gv:GearLookValue; 34 | if (pageId == null) 35 | gv = _default; 36 | else 37 | { 38 | gv = new GearLookValue(); 39 | _storage[pageId] = gv; 40 | } 41 | gv.alpha = Std.parseFloat(arr[0]); 42 | gv.rotation = Std.parseInt(arr[1]); 43 | gv.grayed = (arr[2] == "1"); 44 | if (arr.length < 4) 45 | gv.touchable = _owner.touchable; 46 | else 47 | gv.touchable = (arr[3] == "1"); 48 | } 49 | private var a:Bool; 50 | private var b:Bool; 51 | 52 | override public function apply():Void 53 | { 54 | var gv:GearLookValue = _storage[_controller.selectedPageId]; 55 | if (gv == null) 56 | gv = _default; 57 | 58 | if (_tween && UIPackage._constructing < 1 && !GearBase.disableAllTweenEffect) 59 | { 60 | _owner._gearLocked = true; 61 | _owner.grayed = gv.grayed; 62 | _owner.touchable = gv.touchable; 63 | _owner._gearLocked = false; 64 | 65 | // var a : Bool; 66 | // var b : Bool; 67 | if (tweener != null) 68 | { 69 | // a = tweener.vars.onUpdateParams[0]; 70 | // b = tweener.vars.onUpdateParams[1]; 71 | if (a && tweener.vars.x != gv.alpha || b && tweener.vars.y != gv.rotation) 72 | { 73 | _owner._gearLocked = true; 74 | if (a) 75 | _owner.alpha = tweener.vars.x; 76 | if (b) 77 | _owner.rotation = tweener.vars.y; 78 | _owner._gearLocked = false; 79 | tweener.stop(); 80 | tweener = null; 81 | if (_displayLockToken != 0) 82 | { 83 | _owner.releaseDisplayLock(_displayLockToken); 84 | _displayLockToken = 0; 85 | } 86 | } 87 | else 88 | { 89 | return; 90 | } 91 | } 92 | 93 | a = gv.alpha != _owner.alpha; 94 | b = gv.rotation != _owner.rotation; 95 | if (a || b) 96 | { 97 | if (_owner.checkGearController(0, _controller)) 98 | _displayLockToken = _owner.addDisplayLock(); 99 | var vars = 100 | { 101 | x : gv.alpha, 102 | y : gv.rotation 103 | }; 104 | 105 | if (_tweenValue == null) 106 | _tweenValue = new Point(); 107 | _tweenValue.x = _owner.alpha; 108 | _tweenValue.y = _owner.rotation; 109 | tweener = TweenX.to(_tweenValue, vars, _tweenTime).ease(_easeType).delay(_delay).onUpdate(__tweenUpdate.bind(a, b)).onFinish(__tweenComplete); 110 | } 111 | } 112 | else 113 | { 114 | _owner._gearLocked = true; 115 | _owner.alpha = gv.alpha; 116 | _owner.rotation = gv.rotation; 117 | _owner.grayed = gv.grayed; 118 | _owner.touchable = gv.touchable; 119 | _owner._gearLocked = false; 120 | } 121 | } 122 | 123 | private function __tweenUpdate(val1:Bool, val2:Bool):Void 124 | { 125 | _owner._gearLocked = true; 126 | if (val1) 127 | _owner.alpha = _tweenValue.x; 128 | if (val2) 129 | _owner.rotation = Std.int(_tweenValue.y); 130 | _owner._gearLocked = false; 131 | } 132 | 133 | private function __tweenComplete():Void 134 | { 135 | if (_displayLockToken != 0) 136 | { 137 | _owner.releaseDisplayLock(_displayLockToken); 138 | _displayLockToken = 0; 139 | } 140 | tweener = null; 141 | } 142 | 143 | override public function updateState():Void 144 | { 145 | var gv:GearLookValue = _storage[_controller.selectedPageId]; 146 | if (gv == null) 147 | { 148 | gv = new GearLookValue(); 149 | _storage[_controller.selectedPageId] = gv; 150 | } 151 | 152 | gv.alpha = _owner.alpha; 153 | gv.rotation = _owner.rotation; 154 | gv.grayed = _owner.grayed; 155 | gv.touchable = _owner.touchable; 156 | } 157 | } 158 | 159 | 160 | class GearLookValue 161 | { 162 | public var alpha:Float; 163 | public var rotation:Float; 164 | public var grayed:Bool; 165 | public var touchable:Bool; 166 | 167 | public function new(alpha:Float = 0, rotation:Float = 0, grayed:Bool = false, touchable:Bool = true) 168 | { 169 | this.alpha = alpha; 170 | this.rotation = rotation; 171 | this.grayed = grayed; 172 | this.touchable = touchable; 173 | } 174 | } 175 | --------------------------------------------------------------------------------