[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;
|
||||
|
||||
override private function internalRequest(url:String):Void {
|
||||
L.d("BaseMediaLoader", "request: " + url);
|
||||
//L.d("BaseMediaLoader", "request: " + url);
|
||||
cockTimeout();
|
||||
loader = buildLoader();
|
||||
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.toUpdate();
|
||||
} else {
|
||||
view.width = view.geometry.minWidth;
|
||||
view.height = view.geometry.minHeight;
|
||||
view.x = (content.stage.stageWidth - view.width) / 2;
|
||||
view.y = (content.stage.stageHeight - view.height) / 2;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,13 @@ class View<C:DisplayObject> implements IView<C> {
|
||||
if (width != value) {
|
||||
width = value;
|
||||
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;
|
||||
}
|
||||
@@ -106,6 +113,13 @@ class View<C:DisplayObject> implements IView<C> {
|
||||
if (height != value) {
|
||||
height = value;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ class SizeSet {
|
||||
public var percent(default, default):Size;
|
||||
public var stretch(null, set):Bool;
|
||||
public var empty(get, null):Bool;
|
||||
public var ratio(default, default):Float = -1;
|
||||
|
||||
public var width(null, set):ASizeValue;
|
||||
public var height(null, set):ASizeValue;
|
||||
@@ -156,4 +157,9 @@ class Geometry {
|
||||
this.size.height = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public function setRatio(ratio:Float):Geometry {
|
||||
this.size.ratio = ratio;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user