Skip to content

Get access to button's TextField object and add getVisibleBounds() method #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion starling/src/starling/display/Button.as
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
}
}
}
6 changes: 6 additions & 0 deletions starling/src/starling/display/DisplayObject.as
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
55 changes: 55 additions & 0 deletions starling/src/starling/display/DisplayObjectContainer.as
Original file line number Diff line number Diff line change
Expand Up @@ -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<numChildren; ++i)
{
var child:DisplayObject = getChildAt(i);
if (child.visible)
{
child.getBounds(targetSpace, resultRect);

// ignore child with no size
if (resultRect.width == 0 && resultRect.height == 0)
continue;

visibleSizedChildrenCount++;
if (minX > 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
{
Expand Down