Fix context menu position #65

This commit is contained in:
Simon Robertshaw 2012-08-03 17:44:12 +01:00
parent c7dd248ae3
commit 40e5ce5d37
3 changed files with 14 additions and 1 deletions

View File

@ -156,6 +156,17 @@ void Component::SetParent(Panel* new_parent)
this->_parent = new_parent; this->_parent = new_parent;
} }
Point Component::GetScreenPos()
{
Point newPos(0,0);
if(GetParentWindow())
newPos += GetParentWindow()->Position;
if(GetParent())
newPos += GetParent()->Position;
newPos += Position;
return newPos;
}
// ***** OVERRIDEABLES ***** // ***** OVERRIDEABLES *****
// Kept empty. // Kept empty.

View File

@ -50,6 +50,8 @@ namespace ui
virtual void TextPosition(std::string); virtual void TextPosition(std::string);
void Refresh(); void Refresh();
Point GetScreenPos();
/* See the parent of this component. /* See the parent of this component.
* If new_parent is NULL, this component will have no parent. (THIS DOES NOT delete THE COMPONENT. See XComponent::RemoveChild) * If new_parent is NULL, this component will have no parent. (THIS DOES NOT delete THE COMPONENT. See XComponent::RemoveChild)

View File

@ -121,7 +121,7 @@ void Label::OnMouseClick(int x, int y, unsigned button)
if(button == BUTTON_RIGHT) if(button == BUTTON_RIGHT)
{ {
if(menu) if(menu)
menu->Show(GetParentWindow()->Position + Position + ui::Point(x, y)); menu->Show(GetScreenPos() + ui::Point(x, y));
} }
else else
{ {