[skin] update
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
-lib promhx
|
-lib promhx
|
||||||
-main ViewExample.hx
|
-main ViewExample.hx
|
||||||
--macro haxework.parser.Parser.auto()
|
--macro haxework.parser.Parser.auto()
|
||||||
|
-swf-version 10.1
|
||||||
-swf-header 800:600:30:000000
|
-swf-header 800:600:30:000000
|
||||||
-swf target/ViewExample.swf
|
-swf target/ViewExample.swf
|
||||||
#-as3 target
|
#-as3 target
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
echo "`pwd`/target" > ~/.macromedia/Flash_Player/#Security/FlashPlayerTrust/haxework_test.cfg
|
||||||
. /opt/sdk/haxe/3.4.7/activate
|
. /opt/sdk/haxe/3.4.7/activate
|
||||||
haxe build.hxml && flashplayerdebugger target/ViewExample.swf
|
haxe build.hxml && flashplayerdebugger target/ViewExample.swf
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package;
|
package;
|
||||||
|
|
||||||
|
import haxework.net.manage.LoaderManager;
|
||||||
|
import haxework.net.manage.ILoaderManager;
|
||||||
|
import haxework.net.JsonLoader;
|
||||||
|
import haxework.gui.skin.ISkin.SkinSet;
|
||||||
|
import haxework.gui.skin.ButtonColorSkin;
|
||||||
|
import haxework.gui.skin.TextSkin;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import haxework.gui.list.ListView.IListItemView;
|
import haxework.gui.list.ListView.IListItemView;
|
||||||
import haxework.gui.list.VListView;
|
import haxework.gui.list.VListView;
|
||||||
@@ -17,9 +23,13 @@ class FormView extends VGroupView {
|
|||||||
@:view public var button2(default, null):ButtonView;
|
@:view public var button2(default, null):ButtonView;
|
||||||
@:view public var button3(default, null):ButtonView;
|
@:view public var button3(default, null):ButtonView;
|
||||||
|
|
||||||
|
private var buttonSkin: SkinSet = [
|
||||||
|
new ButtonColorSkin(0x33aa33),
|
||||||
|
new TextSkin(0xffffff, "Courirer"),
|
||||||
|
];
|
||||||
|
|
||||||
private function init() {
|
private function init() {
|
||||||
trace("init");
|
trace("init");
|
||||||
list.data = [for (i in 0...100) StringTools.hex(Math.floor(Math.random() * 1e9))];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onPress(view:ButtonView):Void {
|
private function onPress(view:ButtonView):Void {
|
||||||
@@ -33,7 +43,10 @@ class FormView extends VGroupView {
|
|||||||
|
|
||||||
class ViewExample {
|
class ViewExample {
|
||||||
|
|
||||||
|
@:provide private static var manager:ILoaderManager;
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
|
manager = new LoaderManager(1);
|
||||||
new ViewExample();
|
new ViewExample();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,5 +57,10 @@ class ViewExample {
|
|||||||
trace(form.button1);
|
trace(form.button1);
|
||||||
trace(form.button2);
|
trace(form.button2);
|
||||||
trace(form.button3);
|
trace(form.button3);
|
||||||
|
new JsonLoader().GET("http://umix.tv/channel/data2/renova.json")
|
||||||
|
.then(function(data:Array<Dynamic>) {
|
||||||
|
form.list.data = data.map(function(item) return '${item.id}: ${item.message}');
|
||||||
|
})
|
||||||
|
.catchError(function(error) trace(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
$type: haxework.gui.VGroupView
|
$type: haxework.gui.VGroupView
|
||||||
paddings: 20
|
paddings: 20
|
||||||
layoutMargin: 10
|
layoutMargin: 10
|
||||||
skin: [ $type: [haxework.gui.skin.Skin.color, 0xff0000] ]
|
skin: [ $type: [haxework.gui.skin.Skin.color, 0x333333] ]
|
||||||
views:
|
views:
|
||||||
- id: list
|
- id: list
|
||||||
$type: haxework.gui.list.VListView<String>
|
$type: haxework.gui.list.VListView<String>
|
||||||
@@ -14,44 +14,34 @@ views:
|
|||||||
$type: haxework.gui.list.VScrollView
|
$type: haxework.gui.list.VScrollView
|
||||||
width: 10
|
width: 10
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
skin: [ $type: [haxework.gui.list.ScrollSkin.vertical, 0xcffcc, 0x55cc55] ]
|
skin: [ $type: [haxework.gui.list.ScrollSkin.vertical, 0x55cc55, 0xccffcc] ]
|
||||||
skin: [ $type: [haxework.gui.skin.Skin.color, 0xffffff] ]
|
skin: [ $type: [haxework.gui.skin.Skin.color, 0xffffff] ]
|
||||||
- $type: haxework.gui.SpriteView
|
|
||||||
vAlign: BOTTOM
|
|
||||||
width: 50
|
|
||||||
height: 50
|
|
||||||
leftMargin: 5
|
|
||||||
rightMargin: 10
|
|
||||||
skin: [ $type: [haxework.gui.skin.Skin.color, 0x0000ff] ]
|
|
||||||
- id: panel
|
- id: panel
|
||||||
$type: haxework.gui.HGroupView
|
$type: haxework.gui.HGroupView
|
||||||
layoutHAlign: RIGHT
|
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
height: 30
|
height: 60
|
||||||
paddings: 3
|
# contentSize: true
|
||||||
layoutMargin: 3
|
layoutMargin: 10
|
||||||
skin: [ $type: [haxework.gui.skin.Skin.color, 0xffff00] ]
|
skin: [ $type: [haxework.gui.skin.Skin.color, 0x555555] ]
|
||||||
views:
|
views:
|
||||||
- id: button1
|
- id: button1
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
+onPress: $this:onPress
|
+onPress: $this:onPress
|
||||||
width: 100
|
contentSize: true
|
||||||
pHeight: 100
|
paddings: 8
|
||||||
skin: [ $type: [haxework.gui.skin.ButtonSkin.color, 0xcc0000] ]
|
skin: $this:buttonSkin
|
||||||
text: Text1
|
text: OK
|
||||||
- id: button2
|
- id: button2
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
+onPress: $this:onPress
|
+onPress: $this:onPress
|
||||||
contentSize: true
|
contentSize: true
|
||||||
skin: [ $type: [haxework.gui.skin.ButtonSkin.color, 0x00cc00] ]
|
paddings: 8
|
||||||
text: Text2
|
skin: $this:buttonSkin
|
||||||
fontFamily: Georgia
|
text: Apply
|
||||||
fontColor: 0xffffff
|
|
||||||
- id: button3
|
- id: button3
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
+onPress: $this:onPress
|
+onPress: $this:onPress
|
||||||
contentSize: true
|
contentSize: true
|
||||||
skin: [ $type: [haxework.gui.skin.ButtonSkin.color, 0x00cccc] ]
|
paddings: 8
|
||||||
text: Text 3333333333 ddd
|
skin: $this:buttonSkin
|
||||||
fontFamily: Tahoma
|
text: Cancel
|
||||||
fontColor: 0xff0000
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package haxework.gui;
|
package haxework.gui;
|
||||||
|
|
||||||
import haxework.gui.skin.Skin.TSkinSet;
|
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import haxework.gui.core.VAlign;
|
import haxework.gui.core.VAlign;
|
||||||
import haxework.gui.core.HAlign;
|
import haxework.gui.core.HAlign;
|
||||||
import haxework.gui.core.SizeType;
|
import haxework.gui.core.SizeType;
|
||||||
|
import haxework.gui.skin.ISkin.SkinSet;
|
||||||
|
|
||||||
interface IView<C:DisplayObject> {
|
interface IView<C:DisplayObject> {
|
||||||
public var id(default, default):String;
|
public var id(default, default):String;
|
||||||
@@ -38,7 +38,7 @@ interface IView<C:DisplayObject> {
|
|||||||
public var margins(null, set):Float;
|
public var margins(null, set):Float;
|
||||||
|
|
||||||
public var content(default, null):C;
|
public var content(default, null):C;
|
||||||
public var skin(default, set):TSkinSet;
|
public var skin(default, set):SkinSet;
|
||||||
|
|
||||||
public var parent(default, null):Null<IGroupView>;
|
public var parent(default, null):Null<IGroupView>;
|
||||||
public var inLayout(default, set):Bool;
|
public var inLayout(default, set):Bool;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SpriteView extends View<Sprite> {
|
|||||||
super.update();
|
super.update();
|
||||||
this.content.graphics.clear();
|
this.content.graphics.clear();
|
||||||
for (skin in this.skin) {
|
for (skin in this.skin) {
|
||||||
skin(this);
|
skin.draw(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ package haxework.gui;
|
|||||||
|
|
||||||
import haxework.text.TextUtil;
|
import haxework.text.TextUtil;
|
||||||
import haxework.text.BitmapTextField;
|
import haxework.text.BitmapTextField;
|
||||||
import flash.geom.Point;
|
|
||||||
import flash.text.TextFieldAutoSize;
|
import flash.text.TextFieldAutoSize;
|
||||||
import haxework.gui.core.HAlign;
|
import haxework.gui.core.HAlign;
|
||||||
import haxework.gui.core.VAlign;
|
import haxework.gui.core.VAlign;
|
||||||
import flash.text.TextFormatAlign;
|
import flash.text.TextFormatAlign;
|
||||||
import haxework.gui.skin.ISize;
|
|
||||||
import flash.text.TextFormat;
|
import flash.text.TextFormat;
|
||||||
import flash.display.Sprite;
|
|
||||||
import flash.text.TextField;
|
import flash.text.TextField;
|
||||||
|
|
||||||
class TextView extends SpriteView implements ITextView {
|
class TextView extends SpriteView implements ITextView {
|
||||||
@@ -178,7 +175,7 @@ class TextView extends SpriteView implements ITextView {
|
|||||||
if (t != null) textField.text = t;
|
if (t != null) textField.text = t;
|
||||||
textField.setTextFormat(textFormat);
|
textField.setTextFormat(textFormat);
|
||||||
updateTextSize();
|
updateTextSize();
|
||||||
if (contentSize && !Std.is(skin, ISize)) {
|
if (contentSize) {
|
||||||
#if html5
|
#if html5
|
||||||
var h = _textHeight;
|
var h = _textHeight;
|
||||||
var w = _textWidth;
|
var w = _textWidth;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package haxework.gui;
|
package haxework.gui;
|
||||||
|
|
||||||
import haxework.gui.skin.Skin.TSkinSet;
|
import haxework.gui.skin.ISkin.SkinSet;
|
||||||
import flash.display.InteractiveObject;
|
import flash.display.InteractiveObject;
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import haxework.gui.core.SizeType;
|
import haxework.gui.core.SizeType;
|
||||||
@@ -9,7 +9,6 @@ import haxework.gui.core.VAlign;
|
|||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import flash.display.Stage;
|
import flash.display.Stage;
|
||||||
|
|
||||||
|
|
||||||
class View<C:DisplayObject> implements IView<C> {
|
class View<C:DisplayObject> implements IView<C> {
|
||||||
|
|
||||||
private static var counter:Int = 0;
|
private static var counter:Int = 0;
|
||||||
@@ -46,7 +45,7 @@ class View<C:DisplayObject> implements IView<C> {
|
|||||||
public var margins(null, set):Float;
|
public var margins(null, set):Float;
|
||||||
|
|
||||||
public var content(default, null):C;
|
public var content(default, null):C;
|
||||||
public var skin(default, set):TSkinSet;
|
public var skin(default, set):SkinSet;
|
||||||
|
|
||||||
public var parent(default, null):Null<IGroupView>;
|
public var parent(default, null):Null<IGroupView>;
|
||||||
public var inLayout(default, set):Bool;
|
public var inLayout(default, set):Bool;
|
||||||
@@ -257,7 +256,7 @@ class View<C:DisplayObject> implements IView<C> {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_skin(value:TSkinSet):TSkinSet {
|
private function set_skin(value:SkinSet):SkinSet {
|
||||||
skin = value;
|
skin = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
return skin;
|
return skin;
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
package haxework.gui.list;
|
package haxework.gui.list;
|
||||||
|
|
||||||
|
import flash.text.TextFormatAlign;
|
||||||
|
import haxework.gui.skin.ColorSkin;
|
||||||
import haxework.gui.list.ListView.IListItemView;
|
import haxework.gui.list.ListView.IListItemView;
|
||||||
|
|
||||||
class LabelListItem<T> extends LabelView implements IListItemView<T> {
|
class LabelListItem<T> extends LabelView implements IListItemView<T> {
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
public var item_index(default, set):Int;
|
||||||
public var data(default, set):T;
|
public var data(default, set):T;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
height = 20;
|
height = 20;
|
||||||
pWidth = 100;
|
pWidth = 100;
|
||||||
|
layoutHAlign = LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_item_index(value:Int):Int {
|
||||||
|
item_index = value;
|
||||||
|
skin = item_index % 2 == 1 ? [new ColorSkin(0xdddddd)] : [new ColorSkin(0xcccccc)];
|
||||||
|
return item_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_data(value:T):T {
|
private function set_data(value:T):T {
|
||||||
|
|||||||
@@ -231,6 +231,6 @@ class ListView<D> extends GroupView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IListItemView<D> extends IView<Dynamic> {
|
interface IListItemView<D> extends IView<Dynamic> {
|
||||||
public var item_index(default, default):Int;
|
public var item_index(default, set):Int;
|
||||||
public var data(default, set):D;
|
public var data(default, set):D;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,37 @@
|
|||||||
package haxework.gui.list;
|
package haxework.gui.list;
|
||||||
|
|
||||||
|
import haxework.gui.skin.ISkin;
|
||||||
|
|
||||||
class ScrollSkin {
|
class HScrollSkin implements ISkin<ScrollView> {
|
||||||
|
public var foreColor(default, default):Int;
|
||||||
|
public var backColor(default, default):Int;
|
||||||
|
|
||||||
public static function vertical(foreColor:Int = 0xffffff, backColor:Int = 0x707070) {
|
public function new(foreColor:Int = 0, backColor:Int = 0) {
|
||||||
return function(view: VScrollView):Void {
|
this.foreColor = foreColor;
|
||||||
|
this.backColor = backColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:ScrollView):Void {
|
||||||
|
if (view.ratio < 1) {
|
||||||
|
view.content.graphics.beginFill(backColor);
|
||||||
|
view.content.graphics.drawRect(0, 0, view.width, view.height);
|
||||||
|
view.content.graphics.beginFill(foreColor);
|
||||||
|
view.content.graphics.drawRect(view.width * view.position, 0, view.width * view.ratio, view.height);
|
||||||
|
view.content.graphics.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class VScrollSkin implements ISkin<ScrollView> {
|
||||||
|
public var foreColor(default, default):Int;
|
||||||
|
public var backColor(default, default):Int;
|
||||||
|
|
||||||
|
public function new(foreColor:Int = 0, backColor:Int = 0) {
|
||||||
|
this.foreColor = foreColor;
|
||||||
|
this.backColor = backColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:ScrollView):Void {
|
||||||
if (view.ratio < 1) {
|
if (view.ratio < 1) {
|
||||||
view.content.graphics.beginFill(backColor);
|
view.content.graphics.beginFill(backColor);
|
||||||
view.content.graphics.drawRect(0, 0, view.width, view.height);
|
view.content.graphics.drawRect(0, 0, view.width, view.height);
|
||||||
@@ -15,15 +42,13 @@ class ScrollSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ScrollSkin {
|
||||||
|
|
||||||
|
public static function vertical(foreColor:Int = 0xffffff, backColor:Int = 0x707070) {
|
||||||
|
return new VScrollSkin(foreColor, backColor);
|
||||||
|
}
|
||||||
|
|
||||||
public static function horizontal(foreColor:Int = 0xffffff, backColor:Int = 0x707070) {
|
public static function horizontal(foreColor:Int = 0xffffff, backColor:Int = 0x707070) {
|
||||||
return function(view: VScrollView):Void {
|
return new HScrollSkin(foreColor, backColor);
|
||||||
if (view.ratio < 1) {
|
|
||||||
view.content.graphics.beginFill(backColor);
|
|
||||||
view.content.graphics.drawRect(0, 0, view.width, view.height);
|
|
||||||
view.content.graphics.beginFill(foreColor);
|
|
||||||
view.content.graphics.drawRect(view.width * view.position, 0, view.width * view.ratio, view.height);
|
|
||||||
view.content.graphics.endFill();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
package haxework.gui.skin;
|
package haxework.gui.skin;
|
||||||
|
|
||||||
import flash.geom.Rectangle;
|
|
||||||
import flash.geom.Matrix;
|
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import haxework.gui.utils.ColorUtils;
|
import flash.geom.Rectangle;
|
||||||
import haxework.gui.utils.DrawUtil;
|
import haxework.gui.utils.DrawUtil;
|
||||||
import haxework.gui.ButtonView.ButtonState;
|
|
||||||
import flash.display.Graphics;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
|
|
||||||
class BitmapSkin implements ISkin<SpriteView> implements ISize {
|
class BitmapSkin implements ISkin<SpriteView> implements ISize {
|
||||||
|
|
||||||
@@ -18,7 +13,7 @@ class BitmapSkin implements ISkin<SpriteView> implements ISize {
|
|||||||
public var color(default, default):Int;
|
public var color(default, default):Int;
|
||||||
public var fillType(default, default):FillType;
|
public var fillType(default, default):FillType;
|
||||||
|
|
||||||
public function new(?image:BitmapData = null, ?fillType = null, ?color = -1) {
|
public function new(image:BitmapData = null, fillType = null, color = -1) {
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
this.image = image;
|
this.image = image;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
package haxework.gui.skin;
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import flash.geom.Rectangle;
|
||||||
|
import haxework.gui.ButtonView.ButtonState;
|
||||||
import haxework.gui.utils.BitmapUtil;
|
import haxework.gui.utils.BitmapUtil;
|
||||||
import haxework.gui.utils.DrawUtil;
|
import haxework.gui.utils.DrawUtil;
|
||||||
import flash.geom.Rectangle;
|
|
||||||
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<ButtonView> implements ISize {
|
class ButtonBitmapSkin implements ISkin<ButtonView> {
|
||||||
|
|
||||||
public var width(default, null):Float;
|
public var width(default, null):Float;
|
||||||
public var height(default, null):Float;
|
public var height(default, null):Float;
|
||||||
@@ -25,7 +22,7 @@ class ButtonBitmapSkin implements ISkin<ButtonView> implements ISize {
|
|||||||
private var images:Map<ButtonState, BitmapData>;
|
private var images:Map<ButtonState, BitmapData>;
|
||||||
private var disable:BitmapData;
|
private var disable:BitmapData;
|
||||||
|
|
||||||
public function new(?image:BitmapData = null, ?fillType:FillType = null, ?color = -1) {
|
public function new(image:BitmapData = null, fillType:FillType = null, color = -1) {
|
||||||
images = new Map<ButtonState, BitmapData>();
|
images = new Map<ButtonState, BitmapData>();
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
this.image = image;
|
this.image = image;
|
||||||
|
|||||||
38
src/main/haxework/gui/skin/ButtonColorSkin.hx
Normal file
38
src/main/haxework/gui/skin/ButtonColorSkin.hx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
import flash.display.Graphics;
|
||||||
|
import haxework.gui.utils.ColorUtils;
|
||||||
|
import haxework.gui.ButtonView.ButtonState;
|
||||||
|
|
||||||
|
class ButtonColorSkin implements ISkin<ButtonView> {
|
||||||
|
|
||||||
|
public var color(default, set):Int;
|
||||||
|
public var alpha(default, default):Float;
|
||||||
|
public var disable(default, default):Int;
|
||||||
|
private var colors:Map<ButtonState, Int>;
|
||||||
|
|
||||||
|
public function new(color:Int = 0xffffff, alpha:Float = 1.0) {
|
||||||
|
this.color = color;
|
||||||
|
this.alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_color(value:Int):Int {
|
||||||
|
colors = new Map<ButtonState, Int>();
|
||||||
|
colors.set(ButtonState.UP, value);
|
||||||
|
colors.set(ButtonState.DOWN, ColorUtils.diff(value, -64));
|
||||||
|
colors.set(ButtonState.OVER, ColorUtils.diff(value, 64));
|
||||||
|
//disable = ColorUtils.multiply(value, 0.6);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:ButtonView):Void {
|
||||||
|
var color:Int = selectColor(view);
|
||||||
|
var graphics:Graphics = view.content.graphics;
|
||||||
|
graphics.beginFill(color, alpha);
|
||||||
|
graphics.drawRect(0, 0, view.width, view.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function selectColor(view:ButtonView):Int {
|
||||||
|
return view.disabled ? disable : colors.get(view.state);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,47 +1,10 @@
|
|||||||
package haxework.gui.skin;
|
package haxework.gui.skin;
|
||||||
|
|
||||||
import flash.display.Graphics;
|
|
||||||
import haxework.gui.utils.ColorUtils;
|
|
||||||
import haxework.gui.skin.Skin.TSkin;
|
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
|
|
||||||
class ButtonColorSkin {
|
|
||||||
|
|
||||||
public var color(default, set):Int;
|
|
||||||
public var alpha(default, default):Float;
|
|
||||||
public var disable(default, default):Int;
|
|
||||||
private var colors:Map<ButtonState, Int>;
|
|
||||||
|
|
||||||
public function new(color:Int = 0xffffff, alpha:Float = 1.0) {
|
|
||||||
this.color = color;
|
|
||||||
this.alpha = alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_color(value:Int):Int {
|
|
||||||
colors = new Map<ButtonState, Int>();
|
|
||||||
colors.set(ButtonState.UP, value);
|
|
||||||
colors.set(ButtonState.DOWN, ColorUtils.diff(value, -64));
|
|
||||||
colors.set(ButtonState.OVER, ColorUtils.diff(value, 64));
|
|
||||||
//disable = ColorUtils.multiply(value, 0.6);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function draw(view:ButtonView):Void {
|
|
||||||
var color:Int = selectColor(view);
|
|
||||||
var graphics:Graphics = view.content.graphics;
|
|
||||||
graphics.beginFill(color, alpha);
|
|
||||||
graphics.drawRect(0, 0, view.width, view.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function selectColor(view:ButtonView):Int {
|
|
||||||
return view.disabled ? disable : colors.get(view.state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ButtonSkin {
|
class ButtonSkin {
|
||||||
|
|
||||||
public static function color(color: Int, alpha: Float = 1.0): TSkin<ButtonView> {
|
public static function color(color: Int, alpha: Float = 1.0): ISkin<ButtonView> {
|
||||||
return new ButtonColorSkin(color, alpha).draw;
|
return new ButtonColorSkin(color, alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/main/haxework/gui/skin/ColorSkin.hx
Normal file
18
src/main/haxework/gui/skin/ColorSkin.hx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
class ColorSkin implements ISkin<SpriteView> {
|
||||||
|
|
||||||
|
public var color(default, default):Int;
|
||||||
|
public var alpha(default, default):Float;
|
||||||
|
|
||||||
|
public function new(color:Int = 0xffffff, alpha:Float = 1.0) {
|
||||||
|
this.color = color;
|
||||||
|
this.alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:SpriteView):Void {
|
||||||
|
view.content.graphics.beginFill(color, alpha);
|
||||||
|
view.content.graphics.drawRect(0, 0, view.width, view.height);
|
||||||
|
view.content.graphics.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package haxework.gui.skin;
|
|
||||||
|
|
||||||
import flash.display.Graphics;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
|
|
||||||
class FakeSkin implements ISkin<IView> {
|
|
||||||
|
|
||||||
public function new() {}
|
|
||||||
|
|
||||||
public function draw(view:IView):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();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package haxework.gui.skin;
|
|
||||||
|
|
||||||
interface ISize {
|
|
||||||
public var width(default, null):Float;
|
|
||||||
public var height(default, null):Float;
|
|
||||||
}
|
|
||||||
7
src/main/haxework/gui/skin/ISkin.hx
Normal file
7
src/main/haxework/gui/skin/ISkin.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
interface ISkin<V:IView<Dynamic>> {
|
||||||
|
public function draw(view: V): Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef SkinSet = Array<ISkin<Dynamic>>;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package haxework.gui.skin;
|
package haxework.gui.skin;
|
||||||
|
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
import flash.display.Sprite;
|
|
||||||
import haxework.gui.skin.ISkin;
|
import haxework.gui.skin.ISkin;
|
||||||
|
|
||||||
class ProgressSkin implements ISkin<ProgressView> {
|
class ProgressSkin implements ISkin<ProgressView> {
|
||||||
|
|||||||
36
src/main/haxework/gui/skin/SizeSkin.hx
Normal file
36
src/main/haxework/gui/skin/SizeSkin.hx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
class SizeSkin implements ISkin<IView<Dynamic>> {
|
||||||
|
public var width(default, default):Float;
|
||||||
|
public var height(default, default):Float;
|
||||||
|
public var pHeight(default, default):Float;
|
||||||
|
public var pWidth(default, default):Float;
|
||||||
|
|
||||||
|
public function new(width:Float = -1, height:Float = -1, pHeight:Float = -1, pWidth:Float = -1) {
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.pHeight = pHeight;
|
||||||
|
this.pWidth = pWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:IView<Dynamic>):Void {
|
||||||
|
if (pHeight != -1) {
|
||||||
|
view.pHeight = pHeight;
|
||||||
|
}
|
||||||
|
if (pWidth != -1) {
|
||||||
|
view.pWidth = pWidth;
|
||||||
|
}
|
||||||
|
if (width != -1) {
|
||||||
|
view.width = width;
|
||||||
|
}
|
||||||
|
if (height != -1) {
|
||||||
|
view.height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function percent(pHeight:Float, pWidth:Float):SizeSkin {
|
||||||
|
return new SizeSkin(-1, -1, pHeight, pWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var FILL:SizeSkin = percent(100, 100);
|
||||||
|
}
|
||||||
@@ -1,17 +1,8 @@
|
|||||||
package haxework.gui.skin;
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
|
||||||
typedef TSkin<V:IView<Dynamic>> = V -> Void;
|
|
||||||
|
|
||||||
typedef TSkinSet = Array<TSkin<Dynamic>>;
|
|
||||||
|
|
||||||
class Skin {
|
class Skin {
|
||||||
|
|
||||||
public static function color(color: Int, alpha: Float = 1.0): TSkin<SpriteView> {
|
public static function color(color: Int, alpha: Float = 1.0): ISkin<SpriteView> {
|
||||||
return function(view: SpriteView) {
|
return new ColorSkin(color, alpha);
|
||||||
view.content.graphics.beginFill(color, alpha);
|
|
||||||
view.content.graphics.drawRect(0, 0, view.width, view.height);
|
|
||||||
view.content.graphics.endFill();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/main/haxework/gui/skin/TextSkin.hx
Normal file
17
src/main/haxework/gui/skin/TextSkin.hx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
class TextSkin implements ISkin<ITextView> {
|
||||||
|
|
||||||
|
public var fontColor(default, default):Int;
|
||||||
|
public var fontFamily(default, default):String;
|
||||||
|
|
||||||
|
public function new(fontColor:Int = 0xffffff, fontFamily:String = null) {
|
||||||
|
this.fontColor = fontColor;
|
||||||
|
this.fontFamily = fontFamily;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:ITextView):Void {
|
||||||
|
view.fontColor = fontColor;
|
||||||
|
view.fontFamily = fontFamily;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user