From d28031c91e4299c4cf92b5093f507488c65166e6 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 17 Mar 2008 23:02:04 +0000 Subject: [PATCH] Removed popUpIn(). Added popUpAtMouse(), which is like our show() (which shows at the mouse) only also allows specifying popLeftwards and popUpwards. Also, in our show(), just fit the damn menu onto the stage. Always. Why have a special method for doing what should be the common case? I suppose the old code was trying to fit the menu into the roomview bounds, which might've been nice if it actually worked. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@452 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/CommandMenu.as | 50 ++++++++--------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/src/as/com/threerings/flex/CommandMenu.as b/src/as/com/threerings/flex/CommandMenu.as index 28543914..dac41a79 100644 --- a/src/as/com/threerings/flex/CommandMenu.as +++ b/src/as/com/threerings/flex/CommandMenu.as @@ -25,6 +25,7 @@ import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import flash.events.IEventDispatcher; +import flash.geom.Point; import flash.geom.Rectangle; import mx.controls.Menu; @@ -49,6 +50,8 @@ import flexlib.controls.ScrollableArrowMenu; import com.threerings.util.CommandEvent; +import com.threerings.flex.PopUpUtil; + import com.threerings.flex.menuClasses.CommandMenuItemRenderer; import com.threerings.flex.menuClasses.CommandListData; @@ -123,39 +126,6 @@ public class CommandMenu extends Menu show(_lefting ? r.left : r.right, _upping ? r.top : r.bottom); } - /** - * Shows the menu at the current mouse coordinates, popping upwards or leftwards as necessary - * to fit the menu into the supplied bounds. - */ - public function popUpIn (bounds :Rectangle) :void - { - var mx :int = DisplayObject(Application.application).mouseX; - var my :int = DisplayObject(Application.application).mouseY; - - // show it at zero zero so that it is layed out and measured - show(0, 0); - _fitting = bounds; - - // then determine if we need to point it leftwards or upwards - if (mx + getExplicitOrMeasuredWidth() > bounds.right) { - mx -= getExplicitOrMeasuredWidth(); - } - if (mx < bounds.left) { - mx = Math.max(bounds.right - getExplicitOrMeasuredWidth(), bounds.left); - } - // if we've poped out of the boundaries, just snap it to the lower right corner - if (my + getExplicitOrMeasuredHeight() > bounds.bottom) { - my -= getExplicitOrMeasuredHeight(); - } - if (my < bounds.top) { - my = Math.max(bounds.bottom - getExplicitOrMeasuredHeight(), bounds.top); - } - - // finally move it to the correct position - x = mx; - y = my; - } - /** * Shows the menu at the specified mouse coordinates. */ @@ -168,9 +138,21 @@ public class CommandMenu extends Menu show(mx, my); } + /** + * Shows the menu at the current mouse location. + */ + public function popUpAtMouse (popUpwards :Boolean = false, popLeftwards :Boolean = false) :void + { + _upping = popUpwards; + _lefting = popLeftwards; + _fitting = null; + show(); // our show, with no args, pops at the mouse + } + /** * Just like our superclass's show(), except that when invoked with no args, causes the menu to * show at the current mouse location instead of the top-left corner of the application. + * Also, we ensure that the resulting menu is in-bounds. */ override public function show (xShow :Object = null, yShow :Object = null) :void { @@ -190,6 +172,8 @@ public class CommandMenu extends Menu if (_upping) { y = y - getExplicitOrMeasuredHeight(); } + + PopUpUtil.fit(this); } /**