diff --git a/starling/src/starling/display/Button.as b/starling/src/starling/display/Button.as index d868edf4c..ac82ebc94 100644 --- a/starling/src/starling/display/Button.as +++ b/starling/src/starling/display/Button.as @@ -266,6 +266,13 @@ package starling.display _textField.style = value; } + /** Get access to button's TextField object */ + public function get textField():TextField + { + if (_textField == null) createTextField(); + return _textField; + } + /** The style that is used to render the button. * Note that a style instance may only be used on one mesh at a time. */ public function get style():MeshStyle { return _body.style; } @@ -423,4 +430,4 @@ package starling.display public function get abortDistance():Number { return _behavior.abortDistance; } public function set abortDistance(value:Number):void { _behavior.abortDistance = value; } } -} \ No newline at end of file +} diff --git a/starling/src/starling/display/DisplayObject.as b/starling/src/starling/display/DisplayObject.as index 9b91c0675..7a7cca5b4 100644 --- a/starling/src/starling/display/DisplayObject.as +++ b/starling/src/starling/display/DisplayObject.as @@ -287,6 +287,12 @@ package starling.display { throw new AbstractMethodError(); } + + /** Same as getBounds but only for visible objects (visible = true) */ + public function getVisibleBounds(targetSpace:DisplayObject, out:Rectangle=null):Rectangle + { + throw new AbstractMethodError(); + } /** Returns the object that is found topmost beneath a point in local coordinates, or nil * if the test fails. Untouchable and invisible objects will cause the test to fail. */ diff --git a/starling/src/starling/display/DisplayObjectContainer.as b/starling/src/starling/display/DisplayObjectContainer.as index e5e7b1967..15b4739c8 100644 --- a/starling/src/starling/display/DisplayObjectContainer.as +++ b/starling/src/starling/display/DisplayObjectContainer.as @@ -341,6 +341,61 @@ package starling.display return out; } + /** @inheritDoc */ + public override function getVisibleBounds(targetSpace:DisplayObject, resultRect:Rectangle=null):Rectangle + { + if (resultRect == null) resultRect = new Rectangle(); + + var numChildren:int = this.numChildren; + + if (numChildren == 0) + { + getTransformationMatrix(targetSpace, sBoundsMatrix); + MatrixUtil.transformCoords(sBoundsMatrix, 0.0, 0.0, sBoundsPoint); + resultRect.setTo(sBoundsPoint.x, sBoundsPoint.y, 0, 0); + } + else + { + var visibleSizedChildrenCount:uint = 0; + var minX:Number = Number.MAX_VALUE, maxX:Number = -Number.MAX_VALUE; + var minY:Number = Number.MAX_VALUE, maxY:Number = -Number.MAX_VALUE; + + for (var i:int=0; i resultRect.x) minX = resultRect.x; + if (maxX < resultRect.right) maxX = resultRect.right; + if (minY > resultRect.y) minY = resultRect.y; + if (maxY < resultRect.bottom) maxY = resultRect.bottom; + } + } + + // all visible children have no size + if (visibleSizedChildrenCount == 0) + { + getTransformationMatrix(targetSpace, sBoundsMatrix); + MatrixUtil.transformCoords(sBoundsMatrix, 0.0, 0.0, sBoundsPoint); + resultRect.setTo(sBoundsPoint.x, sBoundsPoint.y, 0, 0); + } + // at least one visible child is sized + else + { + resultRect.setTo(minX, minY, maxX - minX, maxY - minY); + } + } + + return resultRect; + } + /** @inheritDoc */ public override function hitTest(localPoint:Point):DisplayObject {