From 301360df31457edd826d08dd942fd93d5bbb6f69 Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 12 Mar 2019 17:20:58 +0300 Subject: [PATCH] [gui] public setContentSize method in View --- src/main/haxework/gui/IView.hx | 2 ++ src/main/haxework/gui/ImageView.hx | 19 ++++++++++++++++++- src/main/haxework/gui/View.hx | 2 +- src/main/haxework/gui/frame/FrameSwitcher.hx | 3 ++- .../haxework/gui/layout/HorizontalLayout.hx | 2 +- src/main/haxework/gui/layout/TailLayout.hx | 7 +++++-- .../haxework/gui/layout/VerticalLayout.hx | 2 +- src/main/haxework/gui/utils/BitmapUtil.hx | 14 ++++++++++++-- 8 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/main/haxework/gui/IView.hx b/src/main/haxework/gui/IView.hx index c00bf7a..1cae3f9 100755 --- a/src/main/haxework/gui/IView.hx +++ b/src/main/haxework/gui/IView.hx @@ -36,4 +36,6 @@ interface IView { public function toRedraw():Void; public function remove():Void; + + public function setContentSize(width:Float, height:Float, type:String="default"):Void; } diff --git a/src/main/haxework/gui/ImageView.hx b/src/main/haxework/gui/ImageView.hx index 5d91a67..00dc299 100755 --- a/src/main/haxework/gui/ImageView.hx +++ b/src/main/haxework/gui/ImageView.hx @@ -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; + } } diff --git a/src/main/haxework/gui/View.hx b/src/main/haxework/gui/View.hx index d435614..a37d57e 100755 --- a/src/main/haxework/gui/View.hx +++ b/src/main/haxework/gui/View.hx @@ -72,7 +72,7 @@ class View implements IView { } } - 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]); diff --git a/src/main/haxework/gui/frame/FrameSwitcher.hx b/src/main/haxework/gui/frame/FrameSwitcher.hx index 88d347e..27c0548 100755 --- a/src/main/haxework/gui/frame/FrameSwitcher.hx +++ b/src/main/haxework/gui/frame/FrameSwitcher.hx @@ -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"); diff --git a/src/main/haxework/gui/layout/HorizontalLayout.hx b/src/main/haxework/gui/layout/HorizontalLayout.hx index 109f851..d47e8a3 100755 --- a/src/main/haxework/gui/layout/HorizontalLayout.hx +++ b/src/main/haxework/gui/layout/HorizontalLayout.hx @@ -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) { diff --git a/src/main/haxework/gui/layout/TailLayout.hx b/src/main/haxework/gui/layout/TailLayout.hx index e0e0e67..d05fe82 100644 --- a/src/main/haxework/gui/layout/TailLayout.hx +++ b/src/main/haxework/gui/layout/TailLayout.hx @@ -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"); } } diff --git a/src/main/haxework/gui/layout/VerticalLayout.hx b/src/main/haxework/gui/layout/VerticalLayout.hx index 8271d80..e1ff373 100755 --- a/src/main/haxework/gui/layout/VerticalLayout.hx +++ b/src/main/haxework/gui/layout/VerticalLayout.hx @@ -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) { diff --git a/src/main/haxework/gui/utils/BitmapUtil.hx b/src/main/haxework/gui/utils/BitmapUtil.hx index c3d16cb..bc13101 100755 --- a/src/main/haxework/gui/utils/BitmapUtil.hx +++ b/src/main/haxework/gui/utils/BitmapUtil.hx @@ -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; + } }