mirror of https://github.com/stella-emu/stella.git
All widgets and dialogs using 'ContextMenu' now work in hidpi mode.
This commit is contained in:
parent
ef93ecfbd6
commit
c37e245c7a
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue