[skin] process contentSize views in bitmap skins
This commit is contained in:
@@ -175,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) {
|
if (contentSize && _text != null && _text.length > 0) {
|
||||||
#if html5
|
#if html5
|
||||||
var h = _textHeight;
|
var h = _textHeight;
|
||||||
var w = _textWidth;
|
var w = _textWidth;
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ class FrameSwitcher extends GroupView implements IFrameSwitcher {
|
|||||||
prev = current;
|
prev = current;
|
||||||
}
|
}
|
||||||
current = frames.get(id);
|
current = frames.get(id);
|
||||||
|
if (current == null) {
|
||||||
|
throw 'frame "$id" not found';
|
||||||
|
}
|
||||||
addView(current);
|
addView(current);
|
||||||
//ToDo:
|
//ToDo:
|
||||||
if (content.stage != null) content.stage.focus = cast(current, SpriteView).content;
|
if (content.stage != null) content.stage.focus = cast(current, SpriteView).content;
|
||||||
|
|||||||
@@ -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, set):Int;
|
public var item_index(default, default):Int;
|
||||||
public var data(default, set):D;
|
public var data(default, set):D;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,33 +6,36 @@ import haxework.gui.utils.DrawUtil;
|
|||||||
|
|
||||||
class BitmapSkin implements ISkin<SpriteView> {
|
class BitmapSkin implements ISkin<SpriteView> {
|
||||||
|
|
||||||
public var width(default, null):Float;
|
public var width(default, null):Float;
|
||||||
public var height(default, null):Float;
|
public var height(default, null):Float;
|
||||||
|
|
||||||
public var image(null, set):BitmapData;
|
public var image(null, set):BitmapData;
|
||||||
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;
|
||||||
|
}
|
||||||
|
this.fillType = fillType;
|
||||||
|
this.color = color;
|
||||||
}
|
}
|
||||||
this.fillType = fillType;
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_image(value:BitmapData):BitmapData {
|
private function set_image(value:BitmapData):BitmapData {
|
||||||
if (image != value) {
|
if (image != value) {
|
||||||
image = value;
|
image = value;
|
||||||
width = image.width;
|
width = image.width;
|
||||||
height = image.height;
|
height = image.height;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function draw(view:SpriteView):Void {
|
|
||||||
if (image == null) return;
|
|
||||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public function draw(view:SpriteView):Void {
|
||||||
|
if (image == null) return;
|
||||||
|
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||||
|
if (view.contentSize) {
|
||||||
|
view.w = image.width;
|
||||||
|
view.h = image.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,60 +8,64 @@ import haxework.gui.utils.DrawUtil;
|
|||||||
|
|
||||||
class ButtonBitmapSkin implements ISkin<ButtonView> {
|
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;
|
||||||
|
|
||||||
public var fillType(default, default):FillType;
|
public var fillType(default, default):FillType;
|
||||||
public var color(default, default):Int;
|
public var color(default, default):Int;
|
||||||
public var image(null, set):BitmapData;
|
public var image(null, set):BitmapData;
|
||||||
public var upImage(null, set):BitmapData;
|
public var upImage(null, set):BitmapData;
|
||||||
public var overImage(null, set):BitmapData;
|
public var overImage(null, set):BitmapData;
|
||||||
public var downImage(null, set):BitmapData;
|
public var downImage(null, set):BitmapData;
|
||||||
public var disableImage(null, default):BitmapData;
|
public var disableImage(null, default):BitmapData;
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
this.fillType = fillType;
|
||||||
|
this.color = color;
|
||||||
}
|
}
|
||||||
this.fillType = fillType;
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_image(value:BitmapData):BitmapData {
|
private function set_image(value:BitmapData):BitmapData {
|
||||||
width = value.width;
|
width = value.width;
|
||||||
height = value.height;
|
height = value.height;
|
||||||
images.set(ButtonState.UP, value);
|
images.set(ButtonState.UP, value);
|
||||||
images.set(ButtonState.DOWN, BitmapUtil.multiply(value, 0.8));
|
images.set(ButtonState.DOWN, BitmapUtil.multiply(value, 0.8));
|
||||||
images.set(ButtonState.OVER, BitmapUtil.multiply(value, 1.2));
|
images.set(ButtonState.OVER, BitmapUtil.multiply(value, 1.2));
|
||||||
disable = BitmapUtil.grayscale(value, 0.2);
|
disable = BitmapUtil.grayscale(value, 0.2);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_upImage(value:BitmapData):BitmapData {
|
private function set_upImage(value:BitmapData):BitmapData {
|
||||||
width = value.width;
|
width = value.width;
|
||||||
height = value.height;
|
height = value.height;
|
||||||
images.set(ButtonState.UP, value);
|
images.set(ButtonState.UP, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_overImage(value:BitmapData):BitmapData {
|
private function set_overImage(value:BitmapData):BitmapData {
|
||||||
images.set(ButtonState.OVER, value);
|
images.set(ButtonState.OVER, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_downImage(value:BitmapData):BitmapData {
|
private function set_downImage(value:BitmapData):BitmapData {
|
||||||
images.set(ButtonState.DOWN, value);
|
images.set(ButtonState.DOWN, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(view:ButtonView):Void {
|
public function draw(view:ButtonView):Void {
|
||||||
if (images == null) return;
|
if (images == null) return;
|
||||||
var image:BitmapData = view.disabled ? disableImage == null ? disable : disableImage : images.get(view.state);
|
var image:BitmapData = view.disabled ? disableImage == null ? disable : disableImage : images.get(view.state);
|
||||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||||
}
|
if (view.contentSize) {
|
||||||
|
view.w = image.width;
|
||||||
|
view.h = image.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
package haxework.gui.skin;
|
package haxework.gui.skin;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
|
||||||
class Skin {
|
class Skin {
|
||||||
|
|
||||||
|
public static function bitmap(image:BitmapData): ISkin<SpriteView> {
|
||||||
|
return new BitmapSkin(image);
|
||||||
|
}
|
||||||
|
|
||||||
public static function color(color: Int, alpha: Float = 1.0): ISkin<SpriteView> {
|
public static function color(color: Int, alpha: Float = 1.0): ISkin<SpriteView> {
|
||||||
return new ColorSkin(color, alpha);
|
return new ColorSkin(color, alpha);
|
||||||
}
|
}
|
||||||
@@ -9,4 +15,12 @@ class Skin {
|
|||||||
public static function border(color: Int, alpha: Float = 1.0, tickness: Float = 1.0): ISkin<SpriteView> {
|
public static function border(color: Int, alpha: Float = 1.0, tickness: Float = 1.0): ISkin<SpriteView> {
|
||||||
return new BorderSkin(color, alpha, tickness);
|
return new BorderSkin(color, alpha, tickness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function size(width:Float, height:Float): ISkin<Dynamic> {
|
||||||
|
return new SizeSkin(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function text(fontColor:Int, fontSize:Int, fontFamily:String = null):ISkin<ITextView> {
|
||||||
|
return new TextSkin(fontColor, fontSize, fontFamily);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,18 @@ package haxework.gui.skin;
|
|||||||
class TextSkin implements ISkin<ITextView> {
|
class TextSkin implements ISkin<ITextView> {
|
||||||
|
|
||||||
public var fontColor(default, default):Int;
|
public var fontColor(default, default):Int;
|
||||||
|
public var fontSize(default, default):Int;
|
||||||
public var fontFamily(default, default):String;
|
public var fontFamily(default, default):String;
|
||||||
|
|
||||||
public function new(fontColor:Int = 0xffffff, fontFamily:String = null) {
|
public function new(fontColor:Int, fontSize:Int, fontFamily:String) {
|
||||||
this.fontColor = fontColor;
|
this.fontColor = fontColor;
|
||||||
|
this.fontSize = fontSize;
|
||||||
this.fontFamily = fontFamily;
|
this.fontFamily = fontFamily;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(view:ITextView):Void {
|
public function draw(view:ITextView):Void {
|
||||||
view.fontColor = fontColor;
|
view.fontColor = fontColor;
|
||||||
|
view.fontSize = fontSize;
|
||||||
view.fontFamily = fontFamily;
|
view.fontFamily = fontFamily;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user