diff --git a/src/gui/ToolTip.cxx b/src/gui/ToolTip.cxx index 72ecb47ad..30100009a 100644 --- a/src/gui/ToolTip.cxx +++ b/src/gui/ToolTip.cxx @@ -16,11 +16,10 @@ //============================================================================ #include "OSystem.hxx" +#include "Dialog.hxx" +#include "Font.hxx" #include "FrameBuffer.hxx" #include "FBSurface.hxx" - -#include "Font.hxx" -#include "Dialog.hxx" #include "Widget.hxx" #include "ToolTip.hxx" @@ -36,7 +35,8 @@ ToolTip::ToolTip(OSystem& instance, Dialog& dialog, const GUI::Font& font) myTextXOfs = fontHeight < 24 ? 5 : 8; //3 : 5; myWidth = myTextXOfs * 2 + fontWidth * MAX_LEN; myHeight = fontHeight + TEXT_Y_OFS * 2; - mySurface = instance.frameBuffer().allocateSurface(myWidth, myHeight); + mySurface = myDialog.instance().frameBuffer().allocateSurface(myWidth, myHeight); + myScale = myDialog.instance().frameBuffer().hidpiScaleFactor(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -48,15 +48,31 @@ void ToolTip::request(Widget* widget) } if(myTimer == DELAY_TIME) { + const uInt32 VGAP = 1; + const uInt32 hCursor = 19; // TODO: query cursor height string text = widget->getToolTip(); - int width = std::min(myWidth, myFont.getStringWidth(text) + myTextXOfs * 2); - int yOffset = 20; // TODO: query cursor height + uInt32 width = std::min(myWidth, myFont.getStringWidth(text) + myTextXOfs * 2); + // Note: These include HiDPI scaling: + const Common::Rect imageRect = myDialog.instance().frameBuffer().imageRect(); + const Common::Rect dialogRect = myDialog.surface().dstRect(); + // Limit to app or screen size and adjust position + const Int32 xAbs = myPos.x + dialogRect.x() / myScale; + const uInt32 yAbs = myPos.y + dialogRect.y() / myScale; + Int32 x = std::min(xAbs, Int32(imageRect.w() / myScale - width)); + const uInt32 y = (yAbs + myHeight + hCursor > imageRect.h() / myScale) + ? yAbs - myHeight - VGAP + : yAbs + hCursor / myScale + VGAP; + + if(x < 0) + { + x = 0; + width = imageRect.w() / myScale; + } myWidget = widget; - // TODO: limit to app or screen size mySurface->setSrcSize(width, myHeight); - mySurface->setDstSize(width, myHeight); - mySurface->setDstPos(myPos.x, myPos.y + yOffset); + mySurface->setDstSize(width * myScale, myHeight * myScale); + mySurface->setDstPos(x * myScale, y * myScale); mySurface->frameRect(0, 0, width, myHeight, kColor); mySurface->fillRect(1, 1, width - 2, myHeight - 2, kWidColor); diff --git a/src/gui/ToolTip.hxx b/src/gui/ToolTip.hxx index 7ba4dc044..d3164a09d 100644 --- a/src/gui/ToolTip.hxx +++ b/src/gui/ToolTip.hxx @@ -25,8 +25,9 @@ */ class OSystem; -class FBSurface; +class Dialog; class Widget; +class FBSurface; #include "Rect.hxx" @@ -34,7 +35,7 @@ class ToolTip { public: // Maximum tooltip length - static constexpr int MAX_LEN = 60; + static constexpr uInt32 MAX_LEN = 80; ToolTip(OSystem& instance, Dialog& dialog, const GUI::Font& font); ~ToolTip() = default; @@ -64,15 +65,16 @@ private: static constexpr uInt32 DELAY_TIME = 45; // display delay static constexpr int TEXT_Y_OFS = 2; - const GUI::Font& myFont; Dialog& myDialog; + const GUI::Font& myFont; Widget* myWidget{nullptr}; uInt32 myTimer{0}; Common::Point myPos; - int myWidth{0}; - int myHeight{0}; - int myTextXOfs{0}; + uInt32 myWidth{0}; + uInt32 myHeight{0}; + uInt32 myScale{1}; + uInt32 myTextXOfs{0}; shared_ptr mySurface; }; diff --git a/src/gui/VideoAudioDialog.cxx b/src/gui/VideoAudioDialog.cxx index 86db273b9..8d2c3be6d 100644 --- a/src/gui/VideoAudioDialog.cxx +++ b/src/gui/VideoAudioDialog.cxx @@ -122,6 +122,7 @@ void VideoAudioDialog::addDisplayTab() myRenderer = new PopUpWidget(myTab, _font, xpos, ypos, pwidth, lineHeight, instance().frameBuffer().supportedRenderers(), "Renderer ", lwidth); + myRenderer->setToolTip("Select renderer used for displaying screen."); wid.push_back(myRenderer); const int swidth = myRenderer->getWidth() - lwidth; ypos += lineHeight + VGAP;