added resources & bitmap skin
This commit is contained in:
@@ -2,6 +2,8 @@ package haxework.gui;
|
||||
|
||||
|
||||
//ToDo:
|
||||
import haxework.resources.IResources;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.gui.View;
|
||||
import haxework.gui.GroupView;
|
||||
import haxework.gui.HGroupView;
|
||||
@@ -9,8 +11,10 @@ import haxework.gui.VGroupView;
|
||||
import haxework.gui.TextView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.ToggleButtonView;
|
||||
import haxework.gui.skin.ColorSkin;
|
||||
import haxework.gui.skin.ButtonColorSkin;
|
||||
import haxework.gui.skin.ButtonBitmapSkin;
|
||||
|
||||
import haxework.frame.FrameSwitcher;
|
||||
|
||||
@@ -36,12 +40,16 @@ class GuiBuilder {
|
||||
value = a;
|
||||
} else if (Std.is(value, String)) {
|
||||
var s:String = cast(value, String);
|
||||
if (s.charAt(0) == "#") {
|
||||
var c:String = s.charAt(0);
|
||||
if (c == "#") {
|
||||
value = Reflect.field(links, s.substr(1));
|
||||
} else if (s.charAt(0) == "~") {
|
||||
} else if (c == "~") {
|
||||
var a:Array<String> = s.substr(1).split(":");
|
||||
var e:Enum<Dynamic> = Type.resolveEnum(a[0]);
|
||||
value = Type.createEnum(e, a[1]);
|
||||
} else if (c == "@") {
|
||||
var a:Array<String> = s.substr(1).split(":");
|
||||
value = Reflect.field(Provider.get(IResources), a[0]).get(a[1]);
|
||||
} else if (~/0x[A-Fa-f\d]{6}/.match(value)) {
|
||||
value = Std.parseInt(value);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.skin.ISize;
|
||||
import flash.text.TextFormat;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
@@ -60,7 +61,7 @@ class TextView extends View implements ITextView<Sprite, TextField> {
|
||||
|
||||
override public function update():Void {
|
||||
textField.setTextFormat(textFormat);
|
||||
if (contentSize) {
|
||||
if (contentSize && !Std.is(skin, ISize)) {
|
||||
width = textField.width;
|
||||
height = textField.height;
|
||||
}
|
||||
|
||||
30
haxework/gui/ToggleButtonView.hx
Executable file
30
haxework/gui/ToggleButtonView.hx
Executable file
@@ -0,0 +1,30 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.display.Sprite;
|
||||
import haxework.gui.skin.ISkin;
|
||||
|
||||
class ToggleButtonView extends ButtonView {
|
||||
|
||||
public var on(default, set):Bool;
|
||||
public var onSkin(default, set):ISkin<Sprite, IView<Sprite>>;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
private function set_on(value:Bool):Bool {
|
||||
on = value;
|
||||
invalidate();
|
||||
return on;
|
||||
}
|
||||
|
||||
private function set_onSkin(value:ISkin<Sprite, IView<Sprite>>):ISkin<Sprite, IView<Sprite>> {
|
||||
onSkin = value;
|
||||
invalidate();
|
||||
return onSkin;
|
||||
}
|
||||
|
||||
override private function currentSkin():ISkin<Sprite, IView<Sprite>> {
|
||||
return on ? onSkin : skin;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.skin.ISize;
|
||||
import haxework.gui.core.SizeType;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
@@ -61,6 +62,10 @@ class View implements IView<Sprite> {
|
||||
hAlign = HAlign.NONE;
|
||||
}
|
||||
|
||||
private function currentSkin():ISkin<Sprite, IView<Sprite>> {
|
||||
return skin;
|
||||
}
|
||||
|
||||
private function invalidate():Void {
|
||||
updater.invalidate(this);
|
||||
}
|
||||
@@ -73,7 +78,12 @@ class View implements IView<Sprite> {
|
||||
public function update():Void {
|
||||
content.x = x;
|
||||
content.y = y;
|
||||
skin.draw(this);
|
||||
if (contentSize && skin != null && Std.is(skin, ISize)) {
|
||||
var size:ISize = cast(skin, ISize);
|
||||
if (!Math.isNaN(size.width)) width = size.width;
|
||||
if (!Math.isNaN(size.height)) height = size.height;
|
||||
}
|
||||
currentSkin().draw(this);
|
||||
}
|
||||
|
||||
private function set_x(value:Float):Float {
|
||||
|
||||
@@ -12,6 +12,7 @@ class HorizontalLayout extends DefaultLayout {
|
||||
override public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
var fixedSize:Float = group.layoutMargin * (views.length - 1);
|
||||
var leftSize:Float = group.width - group.leftPadding - group.rightPadding;
|
||||
var maxHeight:Float = 0;
|
||||
|
||||
for (view in views) {
|
||||
switch (view.widthType) {
|
||||
@@ -20,6 +21,12 @@ class HorizontalLayout extends DefaultLayout {
|
||||
}
|
||||
setViewHeight(group, view);
|
||||
placeViewVertical(group, view);
|
||||
maxHeight = Math.max(maxHeight, view.height);
|
||||
}
|
||||
|
||||
if (group.contentSize) {
|
||||
group.width = fixedSize;
|
||||
group.height = maxHeight;
|
||||
}
|
||||
|
||||
leftSize -= fixedSize;
|
||||
|
||||
@@ -12,6 +12,7 @@ class VerticalLayout extends DefaultLayout {
|
||||
override public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
var fixedSize:Float = group.layoutMargin * (views.length - 1);
|
||||
var leftSize:Float = group.height - group.topPadding - group.bottomPadding;
|
||||
var maxWidth:Float = 0;
|
||||
|
||||
for (view in views) {
|
||||
switch (view.heightType) {
|
||||
@@ -20,6 +21,12 @@ class VerticalLayout extends DefaultLayout {
|
||||
}
|
||||
setViewWidth(group, view);
|
||||
placeViewHorizontal(group, view);
|
||||
maxWidth = Math.max(maxWidth, view.width);
|
||||
}
|
||||
|
||||
if (group.contentSize) {
|
||||
group.width = maxWidth;
|
||||
group.height = fixedSize;
|
||||
}
|
||||
|
||||
leftSize -= fixedSize;
|
||||
|
||||
65
haxework/gui/skin/ButtonBitmapSkin.hx
Executable file
65
haxework/gui/skin/ButtonBitmapSkin.hx
Executable file
@@ -0,0 +1,65 @@
|
||||
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 ButtonBitmapSkin implements ISkin<Sprite, ButtonView> implements ISize {
|
||||
|
||||
public var width(default, null):Float;
|
||||
public var height(default, null):Float;
|
||||
|
||||
public var image(null, set):BitmapData;
|
||||
public var upImage(null, set):BitmapData;
|
||||
public var overImage(null, set):BitmapData;
|
||||
public var downImage(null, set):BitmapData;
|
||||
|
||||
private var images:Map<ButtonState, BitmapData>;
|
||||
|
||||
public function new(?image:BitmapData = null) {
|
||||
images = new Map<ButtonState, BitmapData>();
|
||||
if (image != null) {
|
||||
this.image = image;
|
||||
}
|
||||
}
|
||||
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
width = value.width;
|
||||
height = value.height;
|
||||
images.set(ButtonState.UP, value);
|
||||
images.set(ButtonState.DOWN, value);
|
||||
images.set(ButtonState.OVER, value);
|
||||
//images.set(ButtonState.DISABLE, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_upImage(value:BitmapData):BitmapData {
|
||||
width = value.width;
|
||||
height = value.height;
|
||||
images.set(ButtonState.UP, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_overImage(value:BitmapData):BitmapData {
|
||||
images.set(ButtonState.OVER, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_downImage(value:BitmapData):BitmapData {
|
||||
images.set(ButtonState.DOWN, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
if (images == null) return;
|
||||
var image:BitmapData = images.get(view.state);
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginBitmapFill(image, null, false, true);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,19 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class FakeSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function draw(view:IView<Sprite>):Void {}
|
||||
public function draw(view:IView<Sprite>):Void {
|
||||
/*var g:Graphics = view.content.graphics;
|
||||
g.clear();
|
||||
g.lineStyle(1, 0x00ff00);
|
||||
g.drawRect(0, 0, view.width, view.height);
|
||||
g.endFill();
|
||||
g.lineStyle();*/
|
||||
}
|
||||
|
||||
}
|
||||
6
haxework/gui/skin/ISize.hx
Executable file
6
haxework/gui/skin/ISize.hx
Executable file
@@ -0,0 +1,6 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
interface ISize {
|
||||
public var width(default, null):Float;
|
||||
public var height(default, null):Float;
|
||||
}
|
||||
8
haxework/resources/IResources.hx
Executable file
8
haxework/resources/IResources.hx
Executable file
@@ -0,0 +1,8 @@
|
||||
package haxework.resources;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
|
||||
interface IResources {
|
||||
public var image(default, null):Map<String, BitmapData>;
|
||||
public var color(default, null):Map<String, Int>;
|
||||
}
|
||||
14
haxework/resources/Resources.hx
Executable file
14
haxework/resources/Resources.hx
Executable file
@@ -0,0 +1,14 @@
|
||||
package haxework.resources;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
|
||||
class Resources implements IResources {
|
||||
|
||||
public var image(default, null):Map<String, BitmapData>;
|
||||
public var color(default, null):Map<String, Int>;
|
||||
|
||||
public function new() {
|
||||
image = new Map<String, BitmapData>();
|
||||
color = new Map<String, Int>();
|
||||
}
|
||||
}
|
||||
8
project.xml
Normal file → Executable file
8
project.xml
Normal file → Executable file
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<meta title="ViewExample" package="haxework.examples" version="1.0.0" company="MegaLoMania"/>
|
||||
<app path="target" file="ViewExample" main="examples.ViewExample"/>
|
||||
<app path="target" file="ViewExample" main="examples.ViewExample"/>
|
||||
<window width="800" height="600" if="desktop"/>
|
||||
<window width="0" height="0" if="html5"/>
|
||||
<source path="."/>
|
||||
<window width="0" height="0" if="html5"/>
|
||||
<source path="."/>
|
||||
<haxelib name="openfl"/>
|
||||
<assets path="examples" include="*"/>
|
||||
<assets path="examples" include="*"/>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user