diff options
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemlinkhandler.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/popup.cpp | 16 | ||||
-rw-r--r-- | src/gui/widgets/popup.h | 8 | ||||
-rw-r--r-- | src/gui/widgets/shoplistbox.cpp | 2 |
6 files changed, 28 insertions, 4 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 4f5d417d..f801822c 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -320,7 +320,7 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event) if (item) { mItemPopup->setItem(item->getInfo()); - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index 0baa4d1e..0c51aeb3 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -56,6 +56,6 @@ void ItemLinkHandler::handleLink(const std::string &link) if (mItemPopup->isVisible()) mItemPopup->setVisible(false); else - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } } diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 7a81c097..b2ddcf0c 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -239,7 +239,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) if (item) { mItemPopup->setItem(item->getInfo()); - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 6f551317..391b0eed 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -170,3 +170,19 @@ void Popup::scheduleDelete() windowContainer->scheduleDelete(this); } +void Popup::position(int x, int y) +{ + const int distance = 20; + + int posX = std::max(0, x - getWidth() / 2); + int posY = y + distance; + + if (posX > graphics->getWidth() - getWidth()) + posX = graphics->getWidth() - getWidth(); + if (posY > graphics->getHeight() - getHeight()) + posY = y - getHeight() - distance; + + setPosition(posX, posY); + setVisible(true); + requestMoveToTop(); +} diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index a77ec2c8..449c2f7b 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -152,6 +152,14 @@ class Popup : public Container virtual gcn::Rectangle getChildrenArea(); + /** + * Sets the location to display the popup. Tries to horizontally center + * the popup and provide a vertical buffer between the given point and + * the popup. Prevents the popup from extending off-screen, if + * possible. + */ + void position(int x, int y); + private: std::string mPopupName; /**< Name of the popup */ std::string mDefaultSkinPath; /**< Default skin path for this popup */ diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 1f735feb..fc9fc4d4 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -159,7 +159,7 @@ void ShopListBox::mouseMoved(gcn::MouseEvent &event) if (item) { mItemPopup->setItem(item->getInfo()); - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } else { |