From 03c909dbeec9f709240e026dcb1ebb3297af8de9 Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 12 Aug 2013 12:55:08 +0200 Subject: [PATCH] added gui package --- com/abit/haxework/gui/IView.hx | 19 ++++ com/abit/haxework/gui/View.hx | 112 ++++++++++++++++++++++++ com/abit/haxework/gui/skin/ColorSkin.hx | 22 +++++ com/abit/haxework/gui/skin/FakeSkin.hx | 11 +++ com/abit/haxework/gui/skin/ISkin.hx | 5 ++ com/abit/haxework/net/BaseLoader.hx | 5 -- 6 files changed, 169 insertions(+), 5 deletions(-) create mode 100755 com/abit/haxework/gui/IView.hx create mode 100755 com/abit/haxework/gui/View.hx create mode 100755 com/abit/haxework/gui/skin/ColorSkin.hx create mode 100755 com/abit/haxework/gui/skin/FakeSkin.hx create mode 100755 com/abit/haxework/gui/skin/ISkin.hx diff --git a/com/abit/haxework/gui/IView.hx b/com/abit/haxework/gui/IView.hx new file mode 100755 index 0000000..77d6463 --- /dev/null +++ b/com/abit/haxework/gui/IView.hx @@ -0,0 +1,19 @@ +package com.abit.haxework.gui; + +import com.abit.haxework.gui.skin.ISkin; + +interface IView { + public var id(default, null):String; + + public var x(default, set):Float; + public var y(default, set):Float; + public var width(default, set):Float; + public var height(default, set):Float; + public var pWidth(default, set):Float; + public var pHeight(default, set):Float; + + public var content(default, null):C; + public var skin(default, set):ISkin>; + + public function update():Void; +} \ No newline at end of file diff --git a/com/abit/haxework/gui/View.hx b/com/abit/haxework/gui/View.hx new file mode 100755 index 0000000..b759f40 --- /dev/null +++ b/com/abit/haxework/gui/View.hx @@ -0,0 +1,112 @@ +package com.abit.haxework.gui; + +import flash.events.Event; +import flash.display.Stage; +import com.abit.haxework.gui.skin.FakeSkin; +import com.abit.haxework.gui.skin.ISkin; + +import flash.display.Sprite; + +class View implements IView { + + private static var counter:Int = 0; + public static var updater(default, null):Updater = new Updater(); + + public var id(default, null):String; + + public var x(default, set):Float; + public var y(default, set):Float; + public var width(default, set):Float; + public var height(default, set):Float; + public var pWidth(default, set):Float; + public var pHeight(default, set):Float; + + public var content(default, null):Sprite; + public var skin(default, set):ISkin>; + + public function new() { + id = Type.getClassName(Type.getClass(this)) + counter++; + content = new Sprite(); + skin = new FakeSkin(); + x = 0; + y = 0; + } + + private function invalidate():Void { + updater.invalidate(this); + } + + public function update():Void { + content.x = x; + content.y = y; + skin.draw(this); + } + + private function set_x(value:Float):Float { + x = value; + invalidate(); + return x; + } + private function set_y(value:Float):Float { + y = value; + invalidate(); + return y; + } + + private function set_width(value:Float):Float { + width = value; + invalidate(); + return width; + } + + private function set_height(value:Float):Float { + height = value; + invalidate(); + return height; + } + + private function set_pWidth(value:Float):Float { + pWidth = value; + invalidate(); + return pWidth; + } + + private function set_pHeight(value:Float):Float { + pHeight = value; + invalidate(); + return pHeight; + } + + private function set_skin(value:ISkin>):ISkin> { + skin = value; + invalidate(); + return skin; + } +} + + +class Updater { + + public var stage(null, set):Stage; + private var invalidated:Array>; + + public function new() { + invalidated = []; + } + + private function set_stage(value:Stage):Stage { + value.addEventListener(Event.ENTER_FRAME, update); + return value; + } + + public function invalidate(view:IView):Void { + invalidated.push(view); + } + + public function update(?_):Void { + while (invalidated.length > 0) { + invalidated.shift().update(); + } + } + +} \ No newline at end of file diff --git a/com/abit/haxework/gui/skin/ColorSkin.hx b/com/abit/haxework/gui/skin/ColorSkin.hx new file mode 100755 index 0000000..7ca2313 --- /dev/null +++ b/com/abit/haxework/gui/skin/ColorSkin.hx @@ -0,0 +1,22 @@ +package com.abit.haxework.gui.skin; + +import flash.display.Graphics; +import flash.display.Sprite; + +class ColorSkin implements ISkin> { + + public var color(default, default):Int; + + public function new(?color:Int = 0xffffff) { + this.color = color; + } + + public function draw(view:IView):Void { + var graphics:Graphics = view.content.graphics; + graphics.clear(); + graphics.beginFill(color); + graphics.drawRect(0, 0, view.width, view.height); + graphics.endFill(); + } + +} \ No newline at end of file diff --git a/com/abit/haxework/gui/skin/FakeSkin.hx b/com/abit/haxework/gui/skin/FakeSkin.hx new file mode 100755 index 0000000..2124dd6 --- /dev/null +++ b/com/abit/haxework/gui/skin/FakeSkin.hx @@ -0,0 +1,11 @@ +package com.abit.haxework.gui.skin; + +import flash.display.Sprite; + +class FakeSkin implements ISkin> { + + public function new() {} + + public function draw(view:IView):Void {} + +} \ No newline at end of file diff --git a/com/abit/haxework/gui/skin/ISkin.hx b/com/abit/haxework/gui/skin/ISkin.hx new file mode 100755 index 0000000..feed0f6 --- /dev/null +++ b/com/abit/haxework/gui/skin/ISkin.hx @@ -0,0 +1,5 @@ +package com.abit.haxework.gui.skin; + +interface ISkin> { + public function draw(view:V):Void; +} \ No newline at end of file diff --git a/com/abit/haxework/net/BaseLoader.hx b/com/abit/haxework/net/BaseLoader.hx index 493f174..43232c9 100755 --- a/com/abit/haxework/net/BaseLoader.hx +++ b/com/abit/haxework/net/BaseLoader.hx @@ -1,13 +1,8 @@ package com.abit.haxework.net; -import flash.net.URLLoaderDataFormat; -import flash.events.SecurityErrorEvent; import com.abit.haxework.net.callback.Callback; import com.abit.haxework.net.callback.ICallback; -import flash.events.IOErrorEvent; -import flash.net.URLRequest; import flash.events.Event; -import flash.net.URLLoader; import com.abit.haxework.net.ILoader.Method; class BaseLoader implements ILoader {