All widgets and dialogs using 'ContextMenu' now work in hidpi mode.

This commit is contained in:
Stephen Anthony 2019-05-11 19:50:42 -02:30
parent ef93ecfbd6
commit c37e245c7a
9 changed files with 29 additions and 21 deletions

View File

@ -154,6 +154,10 @@ struct Rect
moveTo(p.x, p.y); 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) { friend ostream& operator<<(ostream& os, const Rect& r) {
os << r.point() << "," << r.size(); os << r.point() << "," << r.size();
return os; return os;

View File

@ -90,8 +90,8 @@ RomListSettings::RomListSettings(GuiObject* boss, const GUI::Font& font)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomListSettings::show(uInt32 x, uInt32 y, int data) void RomListSettings::show(uInt32 x, uInt32 y, int data)
{ {
_xorig = x; _xorig = x * instance().frameBuffer().hidpiScaleFactor();
_yorig = y; _yorig = y * instance().frameBuffer().hidpiScaleFactor();
_item = data; _item = data;
open(); open();
@ -103,12 +103,13 @@ void RomListSettings::center()
// Make sure the menu is exactly where it should be, in case the image // Make sure the menu is exactly where it should be, in case the image
// offset has changed // offset has changed
const Common::Rect& image = instance().frameBuffer().imageRect(); const Common::Rect& image = instance().frameBuffer().imageRect();
const uInt32 scale = instance().frameBuffer().hidpiScaleFactor();
uInt32 x = image.x() + _xorig; uInt32 x = image.x() + _xorig;
uInt32 y = image.y() + _yorig; uInt32 y = image.y() + _yorig;
uInt32 tx = image.x() + image.width(); uInt32 tx = image.x() + image.width();
uInt32 ty = image.y() + image.height(); uInt32 ty = image.y() + image.height();
if(x + _w > tx) x -= (x + _w - tx); if(x + _w*scale > tx) x -= (x + _w*scale - tx);
if(y + _h > ty) y -= (y + _h - ty); if(y + _h*scale > ty) y -= (y + _h*scale - ty);
surface().setDstPos(x, y); surface().setDstPos(x, y);
} }

View File

@ -109,7 +109,7 @@ void TiaOutputWidget::handleMouseDown(int x, int y, MouseButton b, int clickCoun
myClickY = y; myClickY = y;
// Add menu at current x,y mouse location // Add menu at current x,y mouse location
myMenu->show(x + getAbsX(), y + getAbsY()); myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect());
} }
} }

View File

@ -116,7 +116,7 @@ void TiaZoomWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount)
else if(b == MouseButton::RIGHT) else if(b == MouseButton::RIGHT)
{ {
// Add menu at current x,y mouse location // Add menu at current x,y mouse location
myMenu->show(x + getAbsX(), y + getAbsY()); myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect());
} }
} }

View File

@ -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; const Common::Rect& image = instance().frameBuffer().imageRect();
_yorig = y; 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()); recalc(instance().frameBuffer().imageRect());
open(); open();

View File

@ -49,7 +49,7 @@ class ContextMenu : public Dialog, public CommandSender
void addItems(const VariantList& items); void addItems(const VariantList& items);
/** Show context menu onscreen at the specified coordinates */ /** 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. */ /** Select the first entry matching the given tag. */
void setSelected(const Variant& tag, const Variant& defaultTag); void setSelected(const Variant& tag, const Variant& defaultTag);

View File

@ -100,8 +100,9 @@ void Dialog::open()
_surface = instance().frameBuffer().allocateSurface(_w, _h); _surface = instance().frameBuffer().allocateSurface(_w, _h);
_layer = parent().addDialog(this); _layer = parent().addDialog(this);
if(instance().frameBuffer().hidpiEnabled()) // Take hidpi scaling into account
_surface->setDstSize(_w*2, _h*2); const uInt32 scale = instance().frameBuffer().hidpiScaleFactor();
_surface->setDstSize(_w * scale, _h * scale);
center(); center();
@ -129,7 +130,7 @@ void Dialog::open()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::close() void Dialog::close()
{ {
if (_mouseWidget) if(_mouseWidget)
{ {
_mouseWidget->handleMouseLeft(); _mouseWidget->handleMouseLeft();
_mouseWidget = nullptr; _mouseWidget = nullptr;

View File

@ -31,6 +31,7 @@
#include "MessageBox.hxx" #include "MessageBox.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "FBSurface.hxx"
#include "EventHandler.hxx" #include "EventHandler.hxx"
#include "StellaKeys.hxx" #include "StellaKeys.hxx"
#include "Props.hxx" #include "Props.hxx"
@ -539,7 +540,7 @@ void LauncherDialog::handleMouseDown(int x, int y, MouseButton b, int clickCount
if(b == MouseButton::RIGHT) if(b == MouseButton::RIGHT)
{ {
// Add menu at current x,y mouse location // Add menu at current x,y mouse location
myMenu->show(x + getAbsX(), y + getAbsY()); myMenu->show(x + getAbsX(), y + getAbsY(), surface().dstRect());
} }
else else
Dialog::handleMouseDown(x, y, b, clickCount); Dialog::handleMouseDown(x, y, b, clickCount);

View File

@ -119,13 +119,8 @@ void PopUpWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount)
if(isEnabled() && !myMenu->isVisible()) if(isEnabled() && !myMenu->isVisible())
{ {
// Add menu just underneath parent widget // Add menu just underneath parent widget
const Common::Rect& image = instance().frameBuffer().imageRect(); myMenu->show(getAbsX() + _labelWidth, getAbsY() + getHeight(),
const Common::Rect& srect = dialog().surface().dstRect(); dialog().surface().dstRect(), myMenu->getSelected());
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());
} }
} }