[view] add Geometry size ratio param
This commit is contained in:
@@ -18,7 +18,7 @@ class BaseMediaLoader<T> extends BaseLoader<T> {
|
|||||||
private var loader:Loader;
|
private var loader:Loader;
|
||||||
|
|
||||||
override private function internalRequest(url:String):Void {
|
override private function internalRequest(url:String):Void {
|
||||||
L.d("BaseMediaLoader", "request: " + url);
|
//L.d("BaseMediaLoader", "request: " + url);
|
||||||
cockTimeout();
|
cockTimeout();
|
||||||
loader = buildLoader();
|
loader = buildLoader();
|
||||||
loader.load(new URLRequest(url), buildLoaderContext(false));
|
loader.load(new URLRequest(url), buildLoaderContext(false));
|
||||||
|
|||||||
37
src/main/haxework/view/ButtonImageView.hx
Normal file
37
src/main/haxework/view/ButtonImageView.hx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package haxework.view;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import haxework.view.skin.ButtonBitmapSkin;
|
||||||
|
import haxework.view.skin.ISkin;
|
||||||
|
import haxework.view.utils.BitmapUtil;
|
||||||
|
import haxework.view.utils.DrawUtil.FillType;
|
||||||
|
import haxework.net.ImageLoader;
|
||||||
|
|
||||||
|
class ButtonImageView extends ButtonView {
|
||||||
|
|
||||||
|
public var image(default, set):BitmapData;
|
||||||
|
private var bitmapSkin:ButtonBitmapSkin = new ButtonBitmapSkin();
|
||||||
|
|
||||||
|
public function new(image:BitmapData = null) {
|
||||||
|
super();
|
||||||
|
if (image != null) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function set_skin(value:SkinSet):SkinSet {
|
||||||
|
value = value.slice(0);
|
||||||
|
value.unshift(bitmapSkin);
|
||||||
|
return super.set_skin(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_image(value:BitmapData):BitmapData {
|
||||||
|
if (image != value) {
|
||||||
|
setContentSize(value.width, value.height, "image");
|
||||||
|
image = value;
|
||||||
|
bitmapSkin.image = image;
|
||||||
|
toRedraw();
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,8 @@ class Root {
|
|||||||
view.height = content.stage.stageHeight;
|
view.height = content.stage.stageHeight;
|
||||||
view.toUpdate();
|
view.toUpdate();
|
||||||
} else {
|
} else {
|
||||||
|
view.width = view.geometry.minWidth;
|
||||||
|
view.height = view.geometry.minHeight;
|
||||||
view.x = (content.stage.stageWidth - view.width) / 2;
|
view.x = (content.stage.stageWidth - view.width) / 2;
|
||||||
view.y = (content.stage.stageHeight - view.height) / 2;
|
view.y = (content.stage.stageHeight - view.height) / 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,13 @@ class View<C:DisplayObject> implements IView<C> {
|
|||||||
if (width != value) {
|
if (width != value) {
|
||||||
width = value;
|
width = value;
|
||||||
toRedraw();
|
toRedraw();
|
||||||
|
if (geometry != null && geometry.size.ratio > -1) {
|
||||||
|
var ratioHeight = value / geometry.size.ratio;
|
||||||
|
var size = geometry.size.content["ratio.height"];
|
||||||
|
if (size == null || size.height != ratioHeight) {
|
||||||
|
this.setContentSize(-1, ratioHeight, "ratio.height");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
@@ -106,6 +113,13 @@ class View<C:DisplayObject> implements IView<C> {
|
|||||||
if (height != value) {
|
if (height != value) {
|
||||||
height = value;
|
height = value;
|
||||||
toRedraw();
|
toRedraw();
|
||||||
|
if (geometry != null && geometry.size.ratio > -1) {
|
||||||
|
var ratioWidth = value * geometry.size.ratio;
|
||||||
|
var size = geometry.size.content["ratio.width"];
|
||||||
|
if (size == null || size.width != ratioWidth) {
|
||||||
|
this.setContentSize(ratioWidth, -1, "ratio.width");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class SizeSet {
|
|||||||
public var percent(default, default):Size;
|
public var percent(default, default):Size;
|
||||||
public var stretch(null, set):Bool;
|
public var stretch(null, set):Bool;
|
||||||
public var empty(get, null):Bool;
|
public var empty(get, null):Bool;
|
||||||
|
public var ratio(default, default):Float = -1;
|
||||||
|
|
||||||
public var width(null, set):ASizeValue;
|
public var width(null, set):ASizeValue;
|
||||||
public var height(null, set):ASizeValue;
|
public var height(null, set):ASizeValue;
|
||||||
@@ -156,4 +157,9 @@ class Geometry {
|
|||||||
this.size.height = height;
|
this.size.height = height;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setRatio(ratio:Float):Geometry {
|
||||||
|
this.size.ratio = ratio;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user