[view] GroupView: add maskEnable; Color: fromString improve

This commit is contained in:
2019-07-29 17:57:02 +03:00
parent f186b08e9f
commit f31b1ce506
2 changed files with 40 additions and 4 deletions

View File

@@ -44,7 +44,25 @@ abstract Color(Int) {
} }
@:from static public inline function fromString(value:String):Color { @:from static public inline function fromString(value:String):Color {
return new Color(Std.parseInt('0x${value.split('#').pop()}')); return new Color(switch value {
case "white": 0xFFFFFF;
case "silver": 0xC0C0C0;
case "gray": 0x808080;
case "black": 0x000000;
case "red": 0xFF0000;
case "maroon": 0x800000;
case "yellow": 0xFFFF00;
case "olive": 0x808000;
case "lime": 0x00FF00;
case "green": 0x008000;
case "aqua": 0x00FFFF;
case "teal": 0x008080;
case "blue": 0x0000FF;
case "navy": 0x000080;
case "fuchsia": 0xFF00FF;
case "purple": 0x800080;
case x: Std.parseInt('0x${x.split('#').pop()}');
});
} }
@:to public inline function toString():String { @:to public inline function toString():String {

View File

@@ -79,6 +79,7 @@ class OverflowControl {
private var _mask:Sprite; private var _mask:Sprite;
private var scrollX(get, null):HScrollBarView; private var scrollX(get, null):HScrollBarView;
private var scrollY(get, null):VScrollBarView; private var scrollY(get, null):VScrollBarView;
private var maskEnable(default, set):Bool;
public var overflowControlX(default, null):OverflowControl; public var overflowControlX(default, null):OverflowControl;
public var overflowControlY(default, null):OverflowControl; public var overflowControlY(default, null):OverflowControl;
@@ -88,8 +89,6 @@ class OverflowControl {
container = new Sprite(); container = new Sprite();
content.addChild(container); content.addChild(container);
_mask = new Sprite(); _mask = new Sprite();
content.addChild(_mask);
container.mask = _mask;
this.layout = layout != null ? layout : new DefaultLayout(); this.layout = layout != null ? layout : new DefaultLayout();
this.overflow = overflow != null ? overflow : new Overflow(); this.overflow = overflow != null ? overflow : new Overflow();
views = []; views = [];
@@ -101,6 +100,21 @@ class OverflowControl {
content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin); content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
} }
private function set_maskEnable(value:Bool):Bool {
if (maskEnable != value) {
maskEnable = value;
if (maskEnable) {
content.addChild(_mask);
container.mask = _mask;
} else {
content.removeChild(_mask);
container.mask = null;
}
}
return value;
}
private function onMouseWheelEvent(event:MouseEvent):Void { private function onMouseWheelEvent(event:MouseEvent):Void {
if (overflowY > 1) { if (overflowY > 1) {
#if flash event.preventDefault(); #end #if flash event.preventDefault(); #end
@@ -157,10 +171,12 @@ class OverflowControl {
} }
public function set_overflowX(value:Float):Float { public function set_overflowX(value:Float):Float {
maskEnable = value > 1;
return overflowX = overflowControlX.overflow = value; return overflowX = overflowControlX.overflow = value;
} }
public function set_overflowY(value:Float):Float { public function set_overflowY(value:Float):Float {
maskEnable = value > 1;
return overflowY = overflowControlY.overflow = value; return overflowY = overflowControlY.overflow = value;
} }
@@ -177,7 +193,9 @@ class OverflowControl {
overflowControlY.size = height; overflowControlY.size = height;
_mask.graphics.clear(); _mask.graphics.clear();
_mask.graphics.beginFill(0, 1); _mask.graphics.beginFill(0, 1);
if (!Math.isNaN(width) && !Math.isNaN(height) && width > 0 && height > 0) {
_mask.graphics.drawRect(0, 0, width, height); _mask.graphics.drawRect(0, 0, width, height);
}
_mask.graphics.endFill(); _mask.graphics.endFill();
} }