added gui package
This commit is contained in:
19
com/abit/haxework/gui/IView.hx
Executable file
19
com/abit/haxework/gui/IView.hx
Executable file
@@ -0,0 +1,19 @@
|
||||
package com.abit.haxework.gui;
|
||||
|
||||
import com.abit.haxework.gui.skin.ISkin;
|
||||
|
||||
interface IView<C> {
|
||||
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<C, IView<C>>;
|
||||
|
||||
public function update():Void;
|
||||
}
|
||||
112
com/abit/haxework/gui/View.hx
Executable file
112
com/abit/haxework/gui/View.hx
Executable file
@@ -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<Sprite> {
|
||||
|
||||
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<Sprite, IView<Sprite>>;
|
||||
|
||||
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<Sprite, IView<Sprite>>):ISkin<Sprite, IView<Sprite>> {
|
||||
skin = value;
|
||||
invalidate();
|
||||
return skin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Updater {
|
||||
|
||||
public var stage(null, set):Stage;
|
||||
private var invalidated:Array<IView<Sprite>>;
|
||||
|
||||
public function new() {
|
||||
invalidated = [];
|
||||
}
|
||||
|
||||
private function set_stage(value:Stage):Stage {
|
||||
value.addEventListener(Event.ENTER_FRAME, update);
|
||||
return value;
|
||||
}
|
||||
|
||||
public function invalidate(view:IView<Sprite>):Void {
|
||||
invalidated.push(view);
|
||||
}
|
||||
|
||||
public function update(?_):Void {
|
||||
while (invalidated.length > 0) {
|
||||
invalidated.shift().update();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
com/abit/haxework/gui/skin/ColorSkin.hx
Executable file
22
com/abit/haxework/gui/skin/ColorSkin.hx
Executable file
@@ -0,0 +1,22 @@
|
||||
package com.abit.haxework.gui.skin;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class ColorSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
|
||||
public var color(default, default):Int;
|
||||
|
||||
public function new(?color:Int = 0xffffff) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public function draw(view:IView<Sprite>):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(color);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
|
||||
}
|
||||
11
com/abit/haxework/gui/skin/FakeSkin.hx
Executable file
11
com/abit/haxework/gui/skin/FakeSkin.hx
Executable file
@@ -0,0 +1,11 @@
|
||||
package com.abit.haxework.gui.skin;
|
||||
|
||||
import flash.display.Sprite;
|
||||
|
||||
class FakeSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function draw(view:IView<Sprite>):Void {}
|
||||
|
||||
}
|
||||
5
com/abit/haxework/gui/skin/ISkin.hx
Executable file
5
com/abit/haxework/gui/skin/ISkin.hx
Executable file
@@ -0,0 +1,5 @@
|
||||
package com.abit.haxework.gui.skin;
|
||||
|
||||
interface ISkin<C, V:IView<C>> {
|
||||
public function draw(view:V):Void;
|
||||
}
|
||||
@@ -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<T> implements ILoader<T> {
|
||||
|
||||
Reference in New Issue
Block a user