[gui] public setContentSize method in View
This commit is contained in:
@@ -36,4 +36,6 @@ interface IView<C:DisplayObject> {
|
||||
public function toRedraw():Void;
|
||||
|
||||
public function remove():Void;
|
||||
|
||||
public function setContentSize(width:Float, height:Float, type:String="default"):Void;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package haxework.gui;
|
||||
import flash.display.BitmapData;
|
||||
import haxework.gui.skin.BitmapSkin;
|
||||
import haxework.gui.skin.ISkin;
|
||||
import haxework.gui.utils.BitmapUtil;
|
||||
import haxework.gui.utils.DrawUtil.FillType;
|
||||
import haxework.net.ImageLoader;
|
||||
|
||||
@@ -10,6 +11,7 @@ class ImageView extends SpriteView {
|
||||
|
||||
public var image(default, set):BitmapData;
|
||||
public var imageUrl(default, set):String;
|
||||
public var color(default, set):Int = -1;
|
||||
public var fillType(default, set):FillType;
|
||||
|
||||
private var bitmapSkin:BitmapSkin = new BitmapSkin();
|
||||
@@ -31,7 +33,10 @@ class ImageView extends SpriteView {
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
bitmapSkin.image = value;
|
||||
if (color > -1) {
|
||||
image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
bitmapSkin.image = image;
|
||||
toRedraw();
|
||||
}
|
||||
return image;
|
||||
@@ -50,7 +55,19 @@ class ImageView extends SpriteView {
|
||||
private function set_fillType(value:FillType):FillType {
|
||||
if (fillType != value) {
|
||||
bitmapSkin.fillType = fillType = value;
|
||||
toRedraw();
|
||||
}
|
||||
return fillType;
|
||||
}
|
||||
|
||||
private function set_color(value:Int):Int {
|
||||
if (color != value) {
|
||||
color = value;
|
||||
if (image != null) {
|
||||
image = BitmapUtil.colorize(image, color);
|
||||
toRedraw();
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class View<C:DisplayObject> implements IView<C> {
|
||||
}
|
||||
}
|
||||
|
||||
private function setContentSize(width:Float, height:Float, type:String="default"):Void {
|
||||
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]);
|
||||
|
||||
@@ -39,7 +39,8 @@ class FrameSwitcher extends GroupView {
|
||||
throw 'frame "$id" not found';
|
||||
}
|
||||
addView(current);
|
||||
update();
|
||||
toUpdate();
|
||||
//update();
|
||||
//ToDo:
|
||||
if (content.stage != null) content.stage.focus = cast(current, SpriteView).content;
|
||||
var onShowMethod:Dynamic = Reflect.field(current, "onShow");
|
||||
|
||||
@@ -29,7 +29,7 @@ class HorizontalLayout extends DefaultLayout {
|
||||
maxSize = Math.max(maxSize, view.height);
|
||||
}
|
||||
|
||||
group.geometry.size.content.set("group", [fixedSize, maxSize]);
|
||||
group.setContentSize(fixedSize, maxSize, "group");
|
||||
|
||||
leftSize -= fixedSize;
|
||||
for (view in views) {
|
||||
|
||||
@@ -28,13 +28,15 @@ class TailLayout extends DefaultLayout {
|
||||
height: 0,
|
||||
views: [],
|
||||
}
|
||||
var w:Float = 0;
|
||||
for (view in views) {
|
||||
setViewWidth(group, view);
|
||||
setViewHeight(group, view);
|
||||
if (
|
||||
(rowSize > 0 && row.views.length >= rowSize) ||
|
||||
(row.width + view.width + margin + group.geometry.margin.horizontal > group.width)
|
||||
(rowSize == 0 && row.width + view.width + margin + group.geometry.margin.horizontal > group.width)
|
||||
) {
|
||||
w = Math.max(w, row.width);
|
||||
rows.push(row);
|
||||
row = {
|
||||
width: 0,
|
||||
@@ -46,6 +48,7 @@ class TailLayout extends DefaultLayout {
|
||||
row.width += view.width + margin;
|
||||
row.height = Math.max(row.height, view.height);
|
||||
}
|
||||
w = Math.max(w, row.width);
|
||||
rows.push(row);
|
||||
var h:Float = Lambda.fold(rows, function(row, h) return row.height + h, 0) + margin * (rows.length - 1);
|
||||
var y:Float = Math.max(group.geometry.padding.top, (group.height - h) / 2);
|
||||
@@ -63,6 +66,6 @@ class TailLayout extends DefaultLayout {
|
||||
y += row.height + margin;
|
||||
}
|
||||
|
||||
group.geometry.size.content.set("group", [-1, h]);
|
||||
group.setContentSize(w, h, "group");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class VerticalLayout extends DefaultLayout {
|
||||
maxSize = Math.max(maxSize, view.width);
|
||||
}
|
||||
|
||||
group.geometry.size.content.set("group", [maxSize, fixedSize]);
|
||||
group.setContentSize(maxSize, fixedSize, "group");
|
||||
|
||||
leftSize -= fixedSize;
|
||||
for (view in views) {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package haxework.gui.utils;
|
||||
|
||||
import flash.geom.Point;
|
||||
import flash.display.BitmapData;
|
||||
import flash.filters.ColorMatrixFilter;
|
||||
import flash.geom.ColorTransform;
|
||||
import flash.display.BitmapData;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import haxework.color.Color;
|
||||
|
||||
class BitmapUtil {
|
||||
|
||||
@@ -43,4 +45,12 @@ class BitmapUtil {
|
||||
toCache(image, "grayscale:" + m, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
public static function colorize(data:BitmapData, color:Color):BitmapData {
|
||||
if (color.zero) return data;
|
||||
var result = data.clone();
|
||||
var transform = new ColorTransform(color.red / 255, color.green / 255, color.blue / 255, 1, 0, 0, 0, 0);
|
||||
result.colorTransform(new Rectangle(0, 0, result.width, result.height), transform);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user