Added avoidOtherPopups. A hole was rabbitted while I debugged

that assigning to Rectangle.topLeft sets x and y and width! and height!
Gah.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@729 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2008-12-04 00:55:18 +00:00
parent 8b899014ef
commit 22603206cd
+42 -2
View File
@@ -47,12 +47,46 @@ public class PopUpUtil
*/
public static function fitInRect (popup :UIComponent, rect :Rectangle) :void
{
var p :Point = DisplayUtil.fitRectInRect(new Rectangle(popup.x, popup.y,
popup.getExplicitOrMeasuredWidth(), popup.getExplicitOrMeasuredHeight()), rect);
var p :Point = DisplayUtil.fitRectInRect(createPopupRect(popup), rect);
popup.x = p.x;
popup.y = p.y;
}
/**
* Try to fit inside the specified rectangle, also avoiding other popups.
*
* @param popup the popup we'll try to move.
* @param bounds the boundary within which to place the popup.
* @param padding extra padding to place between popups (but not around the inside of
* the bounds, do that yourself if you want it).
*/
public static function avoidOtherPopups (
popup :UIComponent, bounds :Rectangle, padding :int = 0) :void
{
var avoid :Array = [];
var r :Rectangle;
// find the other popups we need to avoid
for (var ii :int = popup.parent.numChildren - 1; ii >= 0; ii--) {
var comp :UIComponent = popup.parent.getChildAt(ii) as UIComponent;
if (comp != null && comp.isPopUp && comp.visible && comp != popup) {
r = createPopupRect(comp);
r.inflate(padding, padding);
avoid.push(r);
}
}
r = createPopupRect(popup);
// put the rectangle in-bounds, so that even if avoiding the others fails, we're
// at least in-bounds when fitRectInRect resets to the original position.
var p :Point = DisplayUtil.fitRectInRect(r, bounds);
r.x = p.x;
r.y = p.y; // assigning to topLeft adjusts width/height too, so don't do it!
DisplayUtil.positionRect(r, bounds, avoid);
popup.x = r.x;
popup.y = r.y;
}
/**
* Wee utility method.
*/
@@ -60,5 +94,11 @@ public class PopUpUtil
{
return new Rectangle(0, 0, popup.stage.stageWidth, popup.stage.stageHeight);
}
protected static function createPopupRect (popup :UIComponent) :Rectangle
{
return new Rectangle(popup.x, popup.y,
popup.getExplicitOrMeasuredWidth(), popup.getExplicitOrMeasuredHeight());
}
}
}