diff options
author | Kodexky <kodexky@gmail.com> | 2014-12-01 23:02:41 -0430 |
---|---|---|
committer | Craig Robbins <kde.psych@gmail.com> | 2014-12-13 00:43:37 +1000 |
commit | 6ba50aa8f9ea086177384e6ded8cc753d5d429f7 (patch) | |
tree | e16e057e93ad72255c459771d6614fa47b951d25 | |
parent | 9f65fd68194c5f06eac4d8696de518ced192dd3b (diff) | |
download | minetest-6ba50aa8f9ea086177384e6ded8cc753d5d429f7.tar.gz minetest-6ba50aa8f9ea086177384e6ded8cc753d5d429f7.tar.bz2 minetest-6ba50aa8f9ea086177384e6ded8cc753d5d429f7.zip |
Responsive tooltip offset for Android.
Signed-off-by: Craig Robbins <kde.psych@gmail.com>
-rw-r--r-- | src/guiFormSpecMenu.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index d3c2a0b88..bd4a7c0d5 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -2234,10 +2234,23 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase) m_tooltip_element->setVisible(true); this->bringToFront(m_tooltip_element); m_tooltip_element->setText(narrow_to_wide(tooltip_text).c_str()); - s32 tooltip_x = m_pointer.X + m_btn_height; - s32 tooltip_y = m_pointer.Y + m_btn_height; s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height; s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5; + v2u32 screenSize = driver->getScreenSize(); + int tooltip_offset_x = m_btn_height; + int tooltip_offset_y = m_btn_height; +#ifdef __ANDROID__ + tooltip_offset_x *= 3; + tooltip_offset_y = 0; + if (m_pointer.X > (s32)screenSize.X / 2) + tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1; +#endif + s32 tooltip_x = m_pointer.X + tooltip_offset_x; + s32 tooltip_y = m_pointer.Y + tooltip_offset_y; + if (tooltip_x + tooltip_width > (s32)screenSize.X) + tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height; + if (tooltip_y + tooltip_height > (s32)screenSize.Y) + tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height; m_tooltip_element->setRelativePosition(core::rect<s32>( core::position2d<s32>(tooltip_x, tooltip_y), core::dimension2d<s32>(tooltip_width, tooltip_height))); @@ -2453,13 +2466,23 @@ void GUIFormSpecMenu::drawMenu() if (m_old_tooltip != m_tooltips[iter->fname].tooltip) { m_old_tooltip = m_tooltips[iter->fname].tooltip; m_tooltip_element->setText(narrow_to_wide(m_tooltips[iter->fname].tooltip).c_str()); - s32 tooltip_x = m_pointer.X + m_btn_height; - s32 tooltip_y = m_pointer.Y + m_btn_height; - s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height; - if (tooltip_x + tooltip_width > (s32)screenSize.X) - tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height; std::vector<std::string> tt_rows = str_split(m_tooltips[iter->fname].tooltip, '\n'); + s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height; s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5; + int tooltip_offset_x = m_btn_height; + int tooltip_offset_y = m_btn_height; +#ifdef __ANDROID__ + tooltip_offset_x *= 3; + tooltip_offset_y = 0; + if (m_pointer.X > (s32)screenSize.X / 2) + tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1; +#endif + s32 tooltip_x = m_pointer.X + tooltip_offset_x; + s32 tooltip_y = m_pointer.Y + tooltip_offset_y; + if (tooltip_x + tooltip_width > (s32)screenSize.X) + tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height; + if (tooltip_y + tooltip_height > (s32)screenSize.Y) + tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height; m_tooltip_element->setRelativePosition(core::rect<s32>( core::position2d<s32>(tooltip_x, tooltip_y), core::dimension2d<s32>(tooltip_width, tooltip_height))); |