From 40e5ce5d37cde6d923d9ca68efd0fe49e4940986 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 3 Aug 2012 17:44:12 +0100 Subject: [PATCH] Fix context menu position #65 --- src/interface/Component.cpp | 11 +++++++++++ src/interface/Component.h | 2 ++ src/interface/Label.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/interface/Component.cpp b/src/interface/Component.cpp index e4c681157..b92543008 100644 --- a/src/interface/Component.cpp +++ b/src/interface/Component.cpp @@ -156,6 +156,17 @@ void Component::SetParent(Panel* 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 ***** // Kept empty. diff --git a/src/interface/Component.h b/src/interface/Component.h index 5ef672d54..c034952b6 100644 --- a/src/interface/Component.h +++ b/src/interface/Component.h @@ -50,6 +50,8 @@ namespace ui virtual void TextPosition(std::string); void Refresh(); + + Point GetScreenPos(); /* 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) diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp index 4be7fb77a..e388e122f 100644 --- a/src/interface/Label.cpp +++ b/src/interface/Label.cpp @@ -121,7 +121,7 @@ void Label::OnMouseClick(int x, int y, unsigned button) if(button == BUTTON_RIGHT) { if(menu) - menu->Show(GetParentWindow()->Position + Position + ui::Point(x, y)); + menu->Show(GetScreenPos() + ui::Point(x, y)); } else {