From 7072afdf1f6cc3b5ed67bd3ce0102442fd35625d Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 11 May 2019 19:50:42 -0230 Subject: [PATCH] All widgets and dialogs using 'ContextMenu' now work in hidpi mode. --- src/common/Rect.hxx | 4 ++++ src/debugger/gui/RomListSettings.cxx | 9 +++++---- src/debugger/gui/TiaOutputWidget.cxx | 2 +- src/debugger/gui/TiaZoomWidget.cxx | 2 +- src/gui/ContextMenu.cxx | 12 +++++++++--- src/gui/ContextMenu.hxx | 2 +- src/gui/Dialog.cxx | 7 ++++--- src/gui/LauncherDialog.cxx | 3 ++- src/gui/PopUpWidget.cxx | 9 ++------- 9 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/common/Rect.hxx b/src/common/Rect.hxx index 44510d88c..bb3186548 100644 --- a/src/common/Rect.hxx +++ b/src/common/Rect.hxx @@ -154,6 +154,10 @@ struct Rect moveTo(p.x, p.y); } + bool contains(uInt32 x, uInt32 y) const { + return x >= left && y >= top && x < right && y < bottom; + } + friend ostream& operator<<(ostream& os, const Rect& r) { os << r.point() << "," << r.size(); return os; diff --git a/src/debugger/gui/RomListSettings.cxx b/src/debugger/gui/RomListSettings.cxx index 49c822540..054143485 100644 --- a/src/debugger/gui/RomListSettings.cxx +++ b/src/debugger/gui/RomListSettings.cxx @@ -90,8 +90,8 @@ RomListSettings::RomListSettings(GuiObject* boss, const GUI::Font& font) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RomListSettings::show(uInt32 x, uInt32 y, int data) { - _xorig = x; - _yorig = y; + _xorig = x * instance().frameBuffer().hidpiScaleFactor(); + _yorig = y * instance().frameBuffer().hidpiScaleFactor(); _item = data; open(); @@ -103,12 +103,13 @@ void RomListSettings::center() // Make sure the menu is exactly where it should be, in case the image // offset has changed const Common::Rect& image = instance().frameBuffer().imageRect(); + const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); uInt32 x = image.x() + _xorig; uInt32 y = image.y() + _yorig; uInt32 tx = image.x() + image.width(); uInt32 ty = image.y() + image.height(); - if(x + _w > tx) x -= (x + _w - tx); - if(y + _h > ty) y -= (y + _h - ty); + if(x + _w*scale > tx) x -= (x + _w*scale - tx); + if(y + _h*scale > ty) y -= (y + _h*scale - ty); surface().setDstPos(x, y); } diff --git a/src/debugger/gui/TiaOutputWidget.cxx b/src/debugger/gui/TiaOutputWidget.cxx index d767fa5db..b70295770 100644 --- a/src/debugger/gui/TiaOutputWidget.cxx +++ b/src/debugger/gui/TiaOutputWidget.cxx @@ -109,7 +109,7 @@ void TiaOutputWidget::handleMouseDown(int x, int y, MouseButton b, int clickCoun myClickY = y; // Add menu at current x,y mouse location - myMenu->show(x + getAbsX(), y + getAbsY()); + myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect()); } } diff --git a/src/debugger/gui/TiaZoomWidget.cxx b/src/debugger/gui/TiaZoomWidget.cxx index 0c4fb7256..2c3a0e41c 100644 --- a/src/debugger/gui/TiaZoomWidget.cxx +++ b/src/debugger/gui/TiaZoomWidget.cxx @@ -116,7 +116,7 @@ void TiaZoomWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) else if(b == MouseButton::RIGHT) { // Add menu at current x,y mouse location - myMenu->show(x + getAbsX(), y + getAbsY()); + myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect()); } } diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index a6c1f1ab6..d60a96ce8 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -68,10 +68,16 @@ void ContextMenu::addItems(const VariantList& items) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ContextMenu::show(uInt32 x, uInt32 y, int item) +void ContextMenu::show(uInt32 x, uInt32 y, const Common::Rect& bossRect, int item) { - _xorig = x; - _yorig = y; + const Common::Rect& image = instance().frameBuffer().imageRect(); + uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); + _xorig = bossRect.x() + scale * x - image.x(); + _yorig = bossRect.y() + scale * y - image.y(); + + // Only show if we're inside the visible area + if(!bossRect.contains(_xorig, _yorig)) + return; recalc(instance().frameBuffer().imageRect()); open(); diff --git a/src/gui/ContextMenu.hxx b/src/gui/ContextMenu.hxx index 36b82aabd..d0f6bb64a 100644 --- a/src/gui/ContextMenu.hxx +++ b/src/gui/ContextMenu.hxx @@ -49,7 +49,7 @@ class ContextMenu : public Dialog, public CommandSender void addItems(const VariantList& items); /** Show context menu onscreen at the specified coordinates */ - void show(uInt32 x, uInt32 y, int item = -1); + void show(uInt32 x, uInt32 y, const Common::Rect& bossRect, int item = -1); /** Select the first entry matching the given tag. */ void setSelected(const Variant& tag, const Variant& defaultTag); diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 0574ed1fa..256d432cc 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -100,8 +100,9 @@ void Dialog::open() _surface = instance().frameBuffer().allocateSurface(_w, _h); _layer = parent().addDialog(this); - if(instance().frameBuffer().hidpiEnabled()) - _surface->setDstSize(_w*2, _h*2); + // Take hidpi scaling into account + const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); + _surface->setDstSize(_w * scale, _h * scale); center(); @@ -129,7 +130,7 @@ void Dialog::open() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::close() { - if (_mouseWidget) + if(_mouseWidget) { _mouseWidget->handleMouseLeft(); _mouseWidget = nullptr; diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 7636f6bb7..86c819ac0 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -31,6 +31,7 @@ #include "MessageBox.hxx" #include "OSystem.hxx" #include "FrameBuffer.hxx" +#include "FBSurface.hxx" #include "EventHandler.hxx" #include "StellaKeys.hxx" #include "Props.hxx" @@ -539,7 +540,7 @@ void LauncherDialog::handleMouseDown(int x, int y, MouseButton b, int clickCount if(b == MouseButton::RIGHT) { // Add menu at current x,y mouse location - myMenu->show(x + getAbsX(), y + getAbsY()); + myMenu->show(x + getAbsX(), y + getAbsY(), surface().dstRect()); } else Dialog::handleMouseDown(x, y, b, clickCount); diff --git a/src/gui/PopUpWidget.cxx b/src/gui/PopUpWidget.cxx index d18c59ef7..f78e0a581 100644 --- a/src/gui/PopUpWidget.cxx +++ b/src/gui/PopUpWidget.cxx @@ -119,13 +119,8 @@ void PopUpWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) if(isEnabled() && !myMenu->isVisible()) { // Add menu just underneath parent widget - const Common::Rect& image = instance().frameBuffer().imageRect(); - const Common::Rect& srect = dialog().surface().dstRect(); - uInt32 tx = srect.x(), ty = srect.y(); - uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); - tx += scale * (getAbsX() + _labelWidth) - image.x(); - ty += scale * (getAbsY() + getHeight()) - image.y(); - myMenu->show(tx, ty, myMenu->getSelected()); + myMenu->show(getAbsX() + _labelWidth, getAbsY() + getHeight(), + dialog().surface().dstRect(), myMenu->getSelected()); } }