added image view
This commit is contained in:
@@ -14,6 +14,7 @@ class Formatter implements IFormatter {
|
|||||||
case "nn": doubleDigit(date.getMinutes());
|
case "nn": doubleDigit(date.getMinutes());
|
||||||
case "hh": doubleDigit(date.getHours());
|
case "hh": doubleDigit(date.getHours());
|
||||||
case "dd": doubleDigit(date.getDate());
|
case "dd": doubleDigit(date.getDate());
|
||||||
|
case "d": Std.string(date.getDate());
|
||||||
case "mm": doubleDigit(date.getMonth() + 1);
|
case "mm": doubleDigit(date.getMonth() + 1);
|
||||||
case "yyyy": date.getFullYear() + "";
|
case "yyyy": date.getFullYear() + "";
|
||||||
case "month": locale.getArray("month")[date.getMonth()];
|
case "month": locale.getArray("month")[date.getMonth()];
|
||||||
|
|||||||
@@ -27,11 +27,16 @@ class GuiBuilder {
|
|||||||
private function new() {}
|
private function new() {}
|
||||||
|
|
||||||
public static function build(data:Dynamic, ?links:Dynamic):Dynamic {
|
public static function build(data:Dynamic, ?links:Dynamic):Dynamic {
|
||||||
var type:String = data.type;
|
if (Reflect.hasField(data, "type")) {
|
||||||
Reflect.deleteField(data, "type");
|
var type:String = data.type;
|
||||||
var object:Dynamic = instance(type);
|
Reflect.deleteField(data, "type");
|
||||||
fill(object, data, links);
|
var object:Dynamic = instance(type);
|
||||||
return object;
|
fill(object, data, links);
|
||||||
|
return object;
|
||||||
|
} else {
|
||||||
|
fill(data, data, links);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function fill(object:Dynamic, data:Dynamic, ?links:Dynamic):Void {
|
private static function fill(object:Dynamic, data:Dynamic, ?links:Dynamic):Void {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import haxework.gui.core.SizeType;
|
|||||||
typedef Content = {
|
typedef Content = {
|
||||||
var x:Float;
|
var x:Float;
|
||||||
var y:Float;
|
var y:Float;
|
||||||
|
var visible:Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IView<C:Content> {
|
interface IView<C:Content> {
|
||||||
@@ -45,6 +46,8 @@ interface IView<C:Content> {
|
|||||||
public var parent(default, null):Null<IView<Dynamic>>;
|
public var parent(default, null):Null<IView<Dynamic>>;
|
||||||
public var inLayout(default, set):Bool;
|
public var inLayout(default, set):Bool;
|
||||||
|
|
||||||
|
public var visible(default, set):Bool;
|
||||||
|
|
||||||
public function update():Void;
|
public function update():Void;
|
||||||
public function invalidate():Void;
|
public function invalidate():Void;
|
||||||
}
|
}
|
||||||
23
haxework/gui/ImageView.hx
Executable file
23
haxework/gui/ImageView.hx
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
package haxework.gui;
|
||||||
|
|
||||||
|
import haxework.gui.skin.BitmapSkin;
|
||||||
|
import haxework.gui.skin.ButtonBitmapSkin;
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
|
||||||
|
class ImageView extends SpriteView {
|
||||||
|
|
||||||
|
private var image(default, set):BitmapData;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_image(value:BitmapData):BitmapData {
|
||||||
|
if (image != value) {
|
||||||
|
image = value;
|
||||||
|
skin = untyped new BitmapSkin(image);
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ class MovieView extends View<MovieClip> {
|
|||||||
|
|
||||||
public var movie(get, set):MovieClip;
|
public var movie(get, set):MovieClip;
|
||||||
|
|
||||||
public function new(movie:MovieClip) {
|
public function new(?movie:MovieClip) {
|
||||||
super(movie);
|
super(movie);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,11 +16,15 @@ class MovieView extends View<MovieClip> {
|
|||||||
|
|
||||||
private function set_movie(value:MovieClip):MovieClip {
|
private function set_movie(value:MovieClip):MovieClip {
|
||||||
content = value;
|
content = value;
|
||||||
if (contentSize) {
|
|
||||||
width = value.loaderInfo.width;
|
|
||||||
height = value.loaderInfo.height;
|
|
||||||
}
|
|
||||||
invalidate();
|
invalidate();
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
if (contentSize && movie != null) {
|
||||||
|
width = movie.loaderInfo.width;
|
||||||
|
height = movie.loaderInfo.height;
|
||||||
|
}
|
||||||
|
super.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,8 @@ class View<C:Content> implements IView<C> {
|
|||||||
public var parent(default, null):Null<IView<Dynamic>>;
|
public var parent(default, null):Null<IView<Dynamic>>;
|
||||||
public var inLayout(default, set):Bool;
|
public var inLayout(default, set):Bool;
|
||||||
|
|
||||||
|
public var visible(default, set):Bool;
|
||||||
|
|
||||||
public function new(content:C) {
|
public function new(content:C) {
|
||||||
id = Type.getClassName(Type.getClass(this)) + counter++;
|
id = Type.getClassName(Type.getClass(this)) + counter++;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
@@ -62,6 +64,7 @@ class View<C:Content> implements IView<C> {
|
|||||||
vAlign = VAlign.NONE;
|
vAlign = VAlign.NONE;
|
||||||
hAlign = HAlign.NONE;
|
hAlign = HAlign.NONE;
|
||||||
inLayout = true;
|
inLayout = true;
|
||||||
|
visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function currentSkin():ISkin<C, IView<C>> {
|
private function currentSkin():ISkin<C, IView<C>> {
|
||||||
@@ -250,6 +253,14 @@ class View<C:Content> implements IView<C> {
|
|||||||
}
|
}
|
||||||
return inLayout;
|
return inLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function set_visible(value:Bool):Bool {
|
||||||
|
if (visible != value) {
|
||||||
|
visible = value;
|
||||||
|
if (content != null) content.visible = visible;
|
||||||
|
}
|
||||||
|
return visible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
40
haxework/gui/skin/BitmapSkin.hx
Executable file
40
haxework/gui/skin/BitmapSkin.hx
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import haxework.gui.utils.ColorUtils;
|
||||||
|
import haxework.gui.ButtonView.ButtonState;
|
||||||
|
import flash.display.Graphics;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
|
||||||
|
class BitmapSkin implements ISkin<Sprite, SpriteView> implements ISize {
|
||||||
|
|
||||||
|
public var width(default, null):Float;
|
||||||
|
public var height(default, null):Float;
|
||||||
|
|
||||||
|
public var image(null, set):BitmapData;
|
||||||
|
|
||||||
|
public function new(?image:BitmapData = null) {
|
||||||
|
if (image != null) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_image(value:BitmapData):BitmapData {
|
||||||
|
if (image != value) {
|
||||||
|
image = value;
|
||||||
|
width = image.width;
|
||||||
|
height = image.height;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:SpriteView):Void {
|
||||||
|
if (image == null) return;
|
||||||
|
var graphics:Graphics = view.content.graphics;
|
||||||
|
graphics.clear();
|
||||||
|
graphics.beginBitmapFill(image, null, false, true);
|
||||||
|
graphics.drawRect(0, 0, view.width, view.height);
|
||||||
|
graphics.endFill();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user