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
This commit is contained in:
@@ -25,6 +25,7 @@ import flash.display.DisplayObject;
|
|||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import flash.events.IEventDispatcher;
|
import flash.events.IEventDispatcher;
|
||||||
|
|
||||||
|
import flash.geom.Point;
|
||||||
import flash.geom.Rectangle;
|
import flash.geom.Rectangle;
|
||||||
|
|
||||||
import mx.controls.Menu;
|
import mx.controls.Menu;
|
||||||
@@ -49,6 +50,8 @@ import flexlib.controls.ScrollableArrowMenu;
|
|||||||
|
|
||||||
import com.threerings.util.CommandEvent;
|
import com.threerings.util.CommandEvent;
|
||||||
|
|
||||||
|
import com.threerings.flex.PopUpUtil;
|
||||||
|
|
||||||
import com.threerings.flex.menuClasses.CommandMenuItemRenderer;
|
import com.threerings.flex.menuClasses.CommandMenuItemRenderer;
|
||||||
import com.threerings.flex.menuClasses.CommandListData;
|
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);
|
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.
|
* Shows the menu at the specified mouse coordinates.
|
||||||
*/
|
*/
|
||||||
@@ -168,9 +138,21 @@ public class CommandMenu extends Menu
|
|||||||
show(mx, my);
|
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
|
* 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.
|
* 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
|
override public function show (xShow :Object = null, yShow :Object = null) :void
|
||||||
{
|
{
|
||||||
@@ -190,6 +172,8 @@ public class CommandMenu extends Menu
|
|||||||
if (_upping) {
|
if (_upping) {
|
||||||
y = y - getExplicitOrMeasuredHeight();
|
y = y - getExplicitOrMeasuredHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PopUpUtil.fit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user