[view] rename from gui
This commit is contained in:
160
src/main/haxework/view/View.hx
Executable file
160
src/main/haxework/view/View.hx
Executable file
@@ -0,0 +1,160 @@
|
||||
package haxework.view;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.InteractiveObject;
|
||||
import haxework.view.core.Geometry;
|
||||
import haxework.view.skin.ISkin.ISizeSkin;
|
||||
import haxework.view.skin.ISkin.SkinSet;
|
||||
import haxework.resources.IResources;
|
||||
|
||||
class View<C:DisplayObject> implements IView<C> {
|
||||
@:provide private var r:IResources;
|
||||
|
||||
private static var counter:Int = 0;
|
||||
public static var updater(default, null):ViewUpdater = new ViewUpdater();
|
||||
|
||||
public var id(default, default):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 geometry(default, default):Geometry;
|
||||
|
||||
public var content(default, null):C;
|
||||
public var skin(default, set):SkinSet;
|
||||
public var skinId(null, set):String;
|
||||
|
||||
public var parent(default, null):Null<IGroupView>;
|
||||
|
||||
public var visible(default, set):Bool;
|
||||
public var index(default, set):Int;
|
||||
public var mouseEnabled(default, set):Bool = true;
|
||||
|
||||
public function new(content:C) {
|
||||
id = Type.getClassName(Type.getClass(this)) + counter++;
|
||||
this.content = content;
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 1;
|
||||
height = 1;
|
||||
geometry = new Geometry();
|
||||
visible = true;
|
||||
index = -1;
|
||||
skin = [];
|
||||
}
|
||||
|
||||
public function toRedraw():Void {
|
||||
updater.toRedraw(this);
|
||||
}
|
||||
|
||||
public function toUpdate():Void {
|
||||
updater.toUpdate(this);
|
||||
}
|
||||
|
||||
public function toUpdateParent():Void {
|
||||
if (parent != null) {
|
||||
updater.toUpdate(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
/*for (skin in this.skin) {
|
||||
if (Std.is(skin, ISizeSkin)) {
|
||||
var sizeSkin:ISizeSkin = cast skin;
|
||||
setContentSize(sizeSkin.width, sizeSkin.height, "skin");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public function redraw():Void {
|
||||
for (skin in this.skin) {
|
||||
if (Std.is(skin, ISizeSkin)) {
|
||||
var sizeSkin:ISizeSkin = cast skin;
|
||||
setContentSize(sizeSkin.width, sizeSkin.height, "skin");
|
||||
}
|
||||
skin.draw(this);
|
||||
}
|
||||
}
|
||||
|
||||
public function setContentSize(width:Float, height:Float, type:String="default"):Void {
|
||||
var contentSize = geometry.size.content.get(type);
|
||||
if (contentSize == null || width != contentSize.width || height != contentSize.height) {
|
||||
geometry.size.content.set(type, [width, height]);
|
||||
toUpdateParent();
|
||||
}
|
||||
}
|
||||
|
||||
public function remove():Void {
|
||||
if (parent != null) parent.removeView(this);
|
||||
}
|
||||
|
||||
private function set_x(value:Float):Float {
|
||||
if (x != value) {
|
||||
x = content.x = value;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
private function set_y(value:Float):Float {
|
||||
if (y != value) {
|
||||
y = content.y = value;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
private function set_width(value:Float):Float {
|
||||
if (width != value) {
|
||||
width = value;
|
||||
toRedraw();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
private function set_height(value:Float):Float {
|
||||
if (height != value) {
|
||||
height = value;
|
||||
toRedraw();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
private function set_skin(value:SkinSet):SkinSet {
|
||||
this.skin = value;
|
||||
toRedraw();
|
||||
return this.skin;
|
||||
}
|
||||
|
||||
private function set_skinId(value:String):String {
|
||||
r.skin.bind(value, this, "skin");
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_visible(value:Bool):Bool {
|
||||
if (visible != value) {
|
||||
visible = value;
|
||||
if (content != null) content.visible = visible;
|
||||
}
|
||||
return visible;
|
||||
}
|
||||
|
||||
private function set_index(value:Int):Int {
|
||||
if (index != value) {
|
||||
index = value;
|
||||
toUpdateParent();
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private function set_mouseEnabled(value:Bool):Bool {
|
||||
if (mouseEnabled != value) {
|
||||
mouseEnabled = value;
|
||||
if (content != null && Std.is(content, InteractiveObject)) {
|
||||
cast(content, InteractiveObject).mouseEnabled = mouseEnabled;
|
||||
}
|
||||
}
|
||||
return mouseEnabled;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user