From 096b2dd3f5c599889e6d80f914b8b138d5af6e5e Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 16 Dec 2013 12:59:45 +0400 Subject: [PATCH] view refactored --- haxework/frame/FrameSwitcher.hx | 10 +++++----- haxework/frame/IFrameSwitcher.hx | 6 +++--- haxework/gui/GroupView.hx | 14 +++++++------- haxework/gui/GuiBuilder.hx | 2 ++ haxework/gui/IGroupView.hx | 11 ++++++----- haxework/gui/ITextView.hx | 3 ++- haxework/gui/IView.hx | 9 +++++++-- haxework/gui/MovieView.hx | 26 ++++++++++++++++++++++++++ haxework/gui/ProgressView.hx | 2 +- haxework/gui/SpriteView.hx | 10 ++++++++++ haxework/gui/TextView.hx | 2 +- haxework/gui/View.hx | 25 +++++++++++++------------ haxework/gui/list/ListView.hx | 2 +- haxework/gui/list/ScrollView.hx | 2 +- haxework/gui/skin/ColorSkin.hx | 2 +- haxework/gui/skin/ISkin.hx | 4 +++- haxework/net/manage/ILoaderManager.hx | 6 ++++++ haxework/net/manage/LoaderManager.hx | 26 ++++++++++++++++++++++++++ haxework/resources/IResources.hx | 2 ++ haxework/resources/Resources.hx | 3 +++ 20 files changed, 126 insertions(+), 41 deletions(-) create mode 100755 haxework/gui/MovieView.hx create mode 100755 haxework/gui/SpriteView.hx create mode 100755 haxework/net/manage/ILoaderManager.hx create mode 100755 haxework/net/manage/LoaderManager.hx diff --git a/haxework/frame/FrameSwitcher.hx b/haxework/frame/FrameSwitcher.hx index 9519ce3..b27430e 100755 --- a/haxework/frame/FrameSwitcher.hx +++ b/haxework/frame/FrameSwitcher.hx @@ -6,16 +6,16 @@ import haxework.gui.GroupView; class FrameSwitcher extends GroupView implements IFrameSwitcher { - public var current(default, null):Null>; - private var frames:Map>; + public var current(default, null):Null>; + private var frames:Map>; public function new() { super(); - frames = new Map>(); + frames = new Map>(); current = null; } - public function change(id:String):IView { + public function change(id:String):IView { if (current != null) { if (current.id == id) return current; removeView(current); @@ -25,7 +25,7 @@ class FrameSwitcher extends GroupView implements IFrameSwitcher { return current; } - override public function set_views(value:Array>):Array> { + override public function set_views(value:Array>):Array> { views = []; if (value.length > 0) { for (view in value) { diff --git a/haxework/frame/IFrameSwitcher.hx b/haxework/frame/IFrameSwitcher.hx index f6a6b1f..7919d20 100755 --- a/haxework/frame/IFrameSwitcher.hx +++ b/haxework/frame/IFrameSwitcher.hx @@ -2,7 +2,7 @@ package haxework.frame; import haxework.gui.IView; -interface IFrameSwitcher extends IView { - public var current(default, null):Null>; - public function change(id:String):IView; +interface IFrameSwitcher extends IView { + public var current(default, null):Null>; + public function change(id:String):IView; } \ No newline at end of file diff --git a/haxework/gui/GroupView.hx b/haxework/gui/GroupView.hx index 76549e9..184b016 100755 --- a/haxework/gui/GroupView.hx +++ b/haxework/gui/GroupView.hx @@ -6,9 +6,9 @@ import haxework.gui.layout.DefaultLayout; import haxework.gui.layout.ILayout; import flash.display.Sprite; -class GroupView extends View implements IGroupView { +class GroupView extends SpriteView implements IGroupView { - public var views(default, set):Array>; + public var views(default, set):Array>; public var layout(default, default):ILayout; public var layoutVAlign(default, set):VAlign; @@ -21,7 +21,7 @@ class GroupView extends View implements IGroupView { public var bottomPadding(default, set):Float; public var paddings(null, set):Float; - private var viewsById:Map>; + private var viewsById:Map>; public function new(?layout:ILayout) { super(); @@ -40,13 +40,13 @@ class GroupView extends View implements IGroupView { super.update(); } - public function set_views(value:Array>):Array> { + public function set_views(value:Array>):Array> { if (views == null) views = []; for (view in value) addView(view); return views; } - public function addView(view:IView):IView { + public function addView(view:IView):IView { views.push(view); viewsById.set(view.id, view); content.addChild(view.content); @@ -55,7 +55,7 @@ class GroupView extends View implements IGroupView { return view; } - public function removeView(view:IView):IView { + public function removeView(view:IView):IView { view.parent = null; viewsById.remove(view.id); views.remove(view); @@ -64,7 +64,7 @@ class GroupView extends View implements IGroupView { return view; } - public function removeViewById(id:String):IView { + public function removeViewById(id:String):IView { if (viewsById.exists(id)) { return removeView(viewsById.get(id)); } else { diff --git a/haxework/gui/GuiBuilder.hx b/haxework/gui/GuiBuilder.hx index 7a3b2c3..a155aae 100755 --- a/haxework/gui/GuiBuilder.hx +++ b/haxework/gui/GuiBuilder.hx @@ -5,6 +5,8 @@ package haxework.gui; import haxework.resources.IResources; import haxework.provider.Provider; import haxework.gui.View; +import haxework.gui.SpriteView; +import haxework.gui.MovieView; import haxework.gui.GroupView; import haxework.gui.HGroupView; import haxework.gui.VGroupView; diff --git a/haxework/gui/IGroupView.hx b/haxework/gui/IGroupView.hx index c9622b6..bd7f7ce 100755 --- a/haxework/gui/IGroupView.hx +++ b/haxework/gui/IGroupView.hx @@ -1,12 +1,13 @@ package haxework.gui; +import haxework.gui.IView.Content; import haxework.gui.core.HAlign; import haxework.gui.core.VAlign; import haxework.gui.layout.ILayout; -interface IGroupView extends IView { +interface IGroupView extends IView { - public var views(default, null):Array>; + public var views(default, null):Array>; public var layout(default, default):ILayout; public var layoutVAlign(default, set):VAlign; @@ -19,8 +20,8 @@ interface IGroupView extends IView { public var bottomPadding(default, set):Float; public var paddings(null, set):Float; - public function addView(view:IView):IView; - public function removeView(view:IView):IView; - public function removeViewById(id:String):IView; + public function addView(view:IView):IView; + public function removeView(view:IView):IView; + public function removeViewById(id:String):IView; public function findViewById>(id:String, ?clazz:Class):Null; } \ No newline at end of file diff --git a/haxework/gui/ITextView.hx b/haxework/gui/ITextView.hx index afad85c..c7880b1 100755 --- a/haxework/gui/ITextView.hx +++ b/haxework/gui/ITextView.hx @@ -1,8 +1,9 @@ package haxework.gui; +import haxework.gui.IView.Content; import flash.text.TextFormatAlign; -interface ITextView extends IView { +interface ITextView extends IView { public var textField(default, null):T; public var text(default, set):String; public var align(default, set):TextFormatAlign; diff --git a/haxework/gui/IView.hx b/haxework/gui/IView.hx index 74adc9b..773cdd3 100755 --- a/haxework/gui/IView.hx +++ b/haxework/gui/IView.hx @@ -5,7 +5,12 @@ import haxework.gui.core.HAlign; import haxework.gui.skin.ISkin; import haxework.gui.core.SizeType; -interface IView { +typedef Content = { + var x:Float; + var y:Float; +} + +interface IView { public var id(default, null):String; public var x(default, set):Float; @@ -37,7 +42,7 @@ interface IView { public var content(default, null):C; public var skin(default, set):ISkin>; - public var parent(default, null):Null>; + public var parent(default, null):Null>; public var inLayout(default, set):Bool; public function update():Void; diff --git a/haxework/gui/MovieView.hx b/haxework/gui/MovieView.hx new file mode 100755 index 0000000..3c83087 --- /dev/null +++ b/haxework/gui/MovieView.hx @@ -0,0 +1,26 @@ +package haxework.gui; + +import flash.display.MovieClip; + +class MovieView extends View { + + public var movie(get, set):MovieClip; + + public function new(movie:MovieClip) { + super(movie); + } + + private function get_movie():MovieClip { + return content; + } + + private function set_movie(value:MovieClip):MovieClip { + content = value; + if (contentSize) { + width = value.loaderInfo.width; + height = value.loaderInfo.height; + } + invalidate(); + return content; + } +} \ No newline at end of file diff --git a/haxework/gui/ProgressView.hx b/haxework/gui/ProgressView.hx index 86576aa..de8f1f9 100755 --- a/haxework/gui/ProgressView.hx +++ b/haxework/gui/ProgressView.hx @@ -1,6 +1,6 @@ package haxework.gui; -class ProgressView extends View { +class ProgressView extends SpriteView { public var value(default, set):Int; public var max(default, set):Int; diff --git a/haxework/gui/SpriteView.hx b/haxework/gui/SpriteView.hx new file mode 100755 index 0000000..8f618f7 --- /dev/null +++ b/haxework/gui/SpriteView.hx @@ -0,0 +1,10 @@ +package haxework.gui; + +import flash.display.Sprite; + +class SpriteView extends View { + + public function new() { + super(new Sprite()); + } +} \ No newline at end of file diff --git a/haxework/gui/TextView.hx b/haxework/gui/TextView.hx index 6b45106..ff38fa2 100755 --- a/haxework/gui/TextView.hx +++ b/haxework/gui/TextView.hx @@ -6,7 +6,7 @@ import flash.text.TextFormat; import flash.display.Sprite; import flash.text.TextField; -class TextView extends View implements ITextView { +class TextView extends SpriteView implements ITextView { public var textField(default, null):TextField; public var text(default, set):String; diff --git a/haxework/gui/View.hx b/haxework/gui/View.hx index bd0a284..4a11326 100755 --- a/haxework/gui/View.hx +++ b/haxework/gui/View.hx @@ -1,5 +1,6 @@ package haxework.gui; +import haxework.gui.IView.Content; import haxework.gui.skin.ISize; import haxework.gui.core.SizeType; import haxework.gui.core.HAlign; @@ -11,7 +12,7 @@ import haxework.gui.skin.ISkin; import flash.display.Sprite; -class View implements IView { +class View implements IView { private static var counter:Int = 0; public static var updater(default, null):Updater = new Updater(); @@ -44,16 +45,15 @@ class View implements IView { public var bottomMargin(default, set):Float; public var margins(null, set):Float; - public var content(default, null):Sprite; - public var skin(default, set):ISkin>; + public var content(default, null):C; + public var skin(default, set):ISkin>; - public var parent(default, null):Null>; + public var parent(default, null):Null>; public var inLayout(default, set):Bool; - public function new() { + public function new(content:C) { id = Type.getClassName(Type.getClass(this)) + counter++; - content = new Sprite(); - skin = new FakeSkin(); + this.content = content; x = 0; y = 0; width = 100; @@ -64,7 +64,7 @@ class View implements IView { inLayout = true; } - private function currentSkin():ISkin> { + private function currentSkin():ISkin> { return skin; } @@ -85,7 +85,8 @@ class View implements IView { if (!Math.isNaN(size.width)) width = size.width; if (!Math.isNaN(size.height)) height = size.height; } - currentSkin().draw(this); + var skin:ISkin> = currentSkin(); + if (skin != null) skin.draw(this); } private function set_x(value:Float):Float { @@ -236,7 +237,7 @@ class View implements IView { return value; } - private function set_skin(value:ISkin>):ISkin> { + private function set_skin(value:ISkin>):ISkin> { skin = value; invalidate(); return skin; @@ -255,7 +256,7 @@ class View implements IView { class Updater { public var stage(null, set):Stage; - private var invalidated:Array>; + private var invalidated:Array>; public function new() { invalidated = []; @@ -266,7 +267,7 @@ class Updater { return value; } - public function invalidate(view:IView):Void { + public function invalidate(view:IView):Void { invalidated.push(view); } diff --git a/haxework/gui/list/ListView.hx b/haxework/gui/list/ListView.hx index 4112cfc..41cc149 100755 --- a/haxework/gui/list/ListView.hx +++ b/haxework/gui/list/ListView.hx @@ -5,7 +5,7 @@ import haxework.gui.core.HAlign; import flash.display.Sprite; import haxework.gui.skin.ISkin; -class ListView extends VGroupView { +class ListView, D> extends VGroupView { public var data(default, set):Array; public var renderer(null, set):IRenderer; diff --git a/haxework/gui/list/ScrollView.hx b/haxework/gui/list/ScrollView.hx index 70f11a8..e7fe4c6 100755 --- a/haxework/gui/list/ScrollView.hx +++ b/haxework/gui/list/ScrollView.hx @@ -5,7 +5,7 @@ import flash.display.Sprite; import haxework.gui.skin.ISkin; import haxework.gui.View; -class ScrollView extends View { +class ScrollView extends SpriteView { public var position(default, set):Float; public var ratio(default, set):Float; diff --git a/haxework/gui/skin/ColorSkin.hx b/haxework/gui/skin/ColorSkin.hx index ba802b0..497f144 100755 --- a/haxework/gui/skin/ColorSkin.hx +++ b/haxework/gui/skin/ColorSkin.hx @@ -8,7 +8,7 @@ class ColorSkin implements ISkin> { public var color(default, default):Int; public var alpha(default, default):Float; - public function new(?color:Int = 0xfffff, ?alpha:Float = 1.0) { + public function new(?color:Int = 0x000000, ?alpha:Float = 1.0) { this.color = color; this.alpha = alpha; } diff --git a/haxework/gui/skin/ISkin.hx b/haxework/gui/skin/ISkin.hx index e725d4f..f61375d 100755 --- a/haxework/gui/skin/ISkin.hx +++ b/haxework/gui/skin/ISkin.hx @@ -1,5 +1,7 @@ package haxework.gui.skin; -interface ISkin> { +import haxework.gui.IView.Content; + +interface ISkin> { public function draw(view:V):Void; } \ No newline at end of file diff --git a/haxework/net/manage/ILoaderManager.hx b/haxework/net/manage/ILoaderManager.hx new file mode 100755 index 0000000..2f2e88d --- /dev/null +++ b/haxework/net/manage/ILoaderManager.hx @@ -0,0 +1,6 @@ +package haxework.net.manage; + +interface ILoaderManager { + public function add(loader:ILoader):Void; + public function release(loader:ILoader):Void; +} \ No newline at end of file diff --git a/haxework/net/manage/LoaderManager.hx b/haxework/net/manage/LoaderManager.hx new file mode 100755 index 0000000..388fa4a --- /dev/null +++ b/haxework/net/manage/LoaderManager.hx @@ -0,0 +1,26 @@ +package haxework.net.manage; + +import haxe.ds.ObjectMap; + +class LoaderManager implements ILoaderManager { + + private var queue:Array>; + private var actives:Array>; + private var limit:Int; + private var timeout:Map; + + public function new() { + queue = new Array>(); + actives = new Array>(); + limit = 10; + timeout = new ObjectMap(); + } + + public function add(loader:ILoader):Void { + + } + + public function release(loader:ILoader):Void { + + } +} \ No newline at end of file diff --git a/haxework/resources/IResources.hx b/haxework/resources/IResources.hx index 0bc53ed..b826caa 100755 --- a/haxework/resources/IResources.hx +++ b/haxework/resources/IResources.hx @@ -1,9 +1,11 @@ package haxework.resources; +import flash.display.MovieClip; import haxework.resources.Resources.ResMap; import flash.display.BitmapData; interface IResources { public var image(default, null):ResMap; public var color(default, null):ResMap; + public var movie(default, null):ResMap; } \ No newline at end of file diff --git a/haxework/resources/Resources.hx b/haxework/resources/Resources.hx index 80e75e9..661ed97 100755 --- a/haxework/resources/Resources.hx +++ b/haxework/resources/Resources.hx @@ -1,5 +1,6 @@ package haxework.resources; +import flash.display.MovieClip; import haxework.core.Tuple; import haxe.ds.StringMap; import flash.display.BitmapData; @@ -47,9 +48,11 @@ class Resources implements IResources { public var image(default, null):ResMap; public var color(default, null):ResMap; + public var movie(default, null):ResMap; public function new() { image = new ResMap(); color = new ResMap(); + movie = new ResMap(); } } \ No newline at end of file