Fix PopupWidget/ContextMenu not positioned correctly in fullscreen mode.

Refactored Rect class.
This commit is contained in:
Stephen Anthony 2019-06-03 19:28:56 -02:30
parent 0eb7cd70da
commit 4a8f2f80b6
21 changed files with 165 additions and 178 deletions

View File

@ -415,7 +415,7 @@ void FrameBufferSDL2::readPixels(uInt8* pixels, uInt32 pitch,
SDL_Rect r; SDL_Rect r;
r.x = rect.x(); r.y = rect.y(); r.x = rect.x(); r.y = rect.y();
r.w = rect.width(); r.h = rect.height(); r.w = rect.w(); r.h = rect.h();
SDL_RenderReadPixels(myRenderer, &r, 0, pixels, pitch); SDL_RenderReadPixels(myRenderer, &r, 0, pixels, pitch);
} }

View File

@ -132,7 +132,7 @@ void PNGLibrary::saveImage(const string& filename, const VariantList& comments)
const FrameBuffer& fb = myOSystem.frameBuffer(); const FrameBuffer& fb = myOSystem.frameBuffer();
const Common::Rect& rect = fb.imageRect(); const Common::Rect& rect = fb.imageRect();
png_uint_32 width = rect.width(), height = rect.height(); png_uint_32 width = rect.w(), height = rect.h();
// Get framebuffer pixel data (we get ABGR format) // Get framebuffer pixel data (we get ABGR format)
unique_ptr<png_byte[]> buffer = make_unique<png_byte[]>(width * height * 4); unique_ptr<png_byte[]> buffer = make_unique<png_byte[]>(width * height * 4);
@ -156,7 +156,7 @@ void PNGLibrary::saveImage(const string& filename, const FBSurface& surface,
throw runtime_error("ERROR: Couldn't create snapshot file"); throw runtime_error("ERROR: Couldn't create snapshot file");
// Do we want the entire surface or just a section? // Do we want the entire surface or just a section?
png_uint_32 width = rect.width(), height = rect.height(); png_uint_32 width = rect.w(), height = rect.h();
if(rect.empty()) if(rect.empty())
{ {
width = surface.width(); width = surface.width();

View File

@ -105,11 +105,14 @@ struct Size
*/ */
struct Rect struct Rect
{ {
private:
uInt32 top, left; //!< The point at the top left of the rectangle (part of the rect). uInt32 top, left; //!< The point at the top left of the rectangle (part of the rect).
uInt32 bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect). uInt32 bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect).
public:
Rect() : top(0), left(0), bottom(0), right(0) { assert(valid()); } Rect() : top(0), left(0), bottom(0), right(0) { assert(valid()); }
Rect(const Rect& s) : top(s.top), left(s.left), bottom(s.bottom), right(s.right) { assert(valid()); } Rect(const Rect& s) : top(s.top), left(s.left), bottom(s.bottom), right(s.right) { assert(valid()); }
Rect(const Size& s) : top(0), left(0), bottom(s.h), right(s.w) { assert(valid()); }
Rect& operator=(const Rect&) = default; Rect& operator=(const Rect&) = default;
Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) { assert(valid()); } Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) { assert(valid()); }
Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) { assert(valid()); } Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) { assert(valid()); }
@ -119,9 +122,9 @@ struct Rect
uInt32 y() const { return top; } uInt32 y() const { return top; }
Point point() const { return Point(x(), y()); } Point point() const { return Point(x(), y()); }
uInt32 width() const { return right - left; } uInt32 w() const { return right - left; }
uInt32 height() const { return bottom - top; } uInt32 h() const { return bottom - top; }
Size size() const { return Size(width(), height()); } Size size() const { return Size(w(), h()); }
void setWidth(uInt32 aWidth) { right = left + aWidth; } void setWidth(uInt32 aWidth) { right = left + aWidth; }
void setHeight(uInt32 aHeight) { bottom = top + aHeight; } void setHeight(uInt32 aHeight) { bottom = top + aHeight; }

View File

@ -670,15 +670,11 @@ void DataGridWidget::drawWidget(bool hilite)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect DataGridWidget::getEditRect() const Common::Rect DataGridWidget::getEditRect() const
{ {
Common::Rect r(1, 0, _colWidth, _rowHeight);
const int rowoffset = _currentRow * _rowHeight; const int rowoffset = _currentRow * _rowHeight;
const int coloffset = _currentCol * _colWidth + 4; const int coloffset = _currentCol * _colWidth + 4;
r.top += rowoffset;
r.bottom += rowoffset;
r.left += coloffset;
r.right += coloffset - 5;
return r; return Common::Rect(1 + coloffset, rowoffset,
_colWidth + coloffset - 5, _rowHeight + rowoffset);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -403,7 +403,7 @@ void DebuggerDialog::addTiaArea()
{ {
const Common::Rect& r = getTiaBounds(); const Common::Rect& r = getTiaBounds();
myTiaOutput = myTiaOutput =
new TiaOutputWidget(this, *myNFont, r.left, r.top, r.width(), r.height()); new TiaOutputWidget(this, *myNFont, r.x(), r.y(), r.w(), r.h());
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -415,13 +415,13 @@ void DebuggerDialog::addTabArea()
// The tab widget // The tab widget
// Since there are two tab widgets in this dialog, we specifically // Since there are two tab widgets in this dialog, we specifically
// assign an ID of 0 // assign an ID of 0
myTab = new TabWidget(this, *myLFont, r.left, r.top + vBorder, myTab = new TabWidget(this, *myLFont, r.x(), r.y() + vBorder,
r.width(), r.height() - vBorder); r.w(), r.h() - vBorder);
myTab->setID(0); myTab->setID(0);
addTabWidget(myTab); addTabWidget(myTab);
const int widWidth = r.width() - vBorder; const int widWidth = r.w() - vBorder;
const int widHeight = r.height() - myTab->getTabHeight() - vBorder - 4; const int widHeight = r.h() - myTab->getTabHeight() - vBorder - 4;
int tabID; int tabID;
// The Prompt/console tab // The Prompt/console tab
@ -462,12 +462,12 @@ void DebuggerDialog::addStatusArea()
const Common::Rect& r = getStatusBounds(); const Common::Rect& r = getStatusBounds();
int xpos, ypos; int xpos, ypos;
xpos = r.left; ypos = r.top; xpos = r.x(); ypos = r.y();
myTiaInfo = new TiaInfoWidget(this, *myLFont, *myNFont, xpos, ypos, r.width()); myTiaInfo = new TiaInfoWidget(this, *myLFont, *myNFont, xpos, ypos, r.w());
ypos += myTiaInfo->getHeight() + 10; ypos += myTiaInfo->getHeight() + 10;
myTiaZoom = new TiaZoomWidget(this, *myNFont, xpos+10, ypos, myTiaZoom = new TiaZoomWidget(this, *myNFont, xpos+10, ypos,
r.width()-10, r.height()-lineHeight-ypos-10); r.w()-10, r.h()-lineHeight-ypos-10);
addToFocusList(myTiaZoom->getFocusList()); addToFocusList(myTiaZoom->getFocusList());
xpos += 10; ypos += myTiaZoom->getHeight() + 10; xpos += 10; ypos += myTiaZoom->getHeight() + 10;
@ -518,7 +518,7 @@ void DebuggerDialog::addRomArea()
int bwidth = myLFont->getStringWidth("Frame +1 "), int bwidth = myLFont->getStringWidth("Frame +1 "),
bheight = myLFont->getLineHeight() + 2; bheight = myLFont->getLineHeight() + 2;
int buttonX = r.right - bwidth - 5, buttonY = r.top + 5; int buttonX = r.x() + r.w() - bwidth - 5, buttonY = r.y() + 5;
b = new ButtonWidget(this, *myLFont, buttonX, buttonY, b = new ButtonWidget(this, *myLFont, buttonX, buttonY,
bwidth, bheight, "Step", kDDStepCmd, true); bwidth, bheight, "Step", kDDStepCmd, true);
@ -543,7 +543,7 @@ void DebuggerDialog::addRomArea()
bwidth = bheight; // 7 + 12; bwidth = bheight; // 7 + 12;
bheight = bheight * 3 + 4 * 2; bheight = bheight * 3 + 4 * 2;
buttonX -= (bwidth + 5); buttonX -= (bwidth + 5);
buttonY = r.top + 5; buttonY = r.y() + 5;
myRewindButton = myRewindButton =
new ButtonWidget(this, *myLFont, buttonX, buttonY, new ButtonWidget(this, *myLFont, buttonX, buttonY,
@ -563,7 +563,7 @@ void DebuggerDialog::addRomArea()
bwidth = myLFont->getStringWidth("Options " + ELLIPSIS); bwidth = myLFont->getStringWidth("Options " + ELLIPSIS);
bheight = myLFont->getLineHeight() + 2; bheight = myLFont->getLineHeight() + 2;
b = new ButtonWidget(this, *myLFont, xpos, r.top + 5, bwidth, bheight, b = new ButtonWidget(this, *myLFont, xpos, r.y() + 5, bwidth, bheight,
"Options" + ELLIPSIS, kDDOptionsCmd); "Options" + ELLIPSIS, kDDOptionsCmd);
wid1.push_back(b); wid1.push_back(b);
wid1.push_back(myRewindButton); wid1.push_back(myRewindButton);
@ -571,16 +571,16 @@ void DebuggerDialog::addRomArea()
DataGridOpsWidget* ops = new DataGridOpsWidget(this, *myLFont, xpos, ypos); DataGridOpsWidget* ops = new DataGridOpsWidget(this, *myLFont, xpos, ypos);
int max_w = xpos - r.left - 10; int max_w = xpos - r.x() - 10;
xpos = r.left + 10; ypos = 10; xpos = r.x() + 10; ypos = 10;
myCpu = new CpuWidget(this, *myLFont, *myNFont, xpos, ypos, max_w); myCpu = new CpuWidget(this, *myLFont, *myNFont, xpos, ypos, max_w);
addToFocusList(myCpu->getFocusList()); addToFocusList(myCpu->getFocusList());
addToFocusList(wid1); addToFocusList(wid1);
addToFocusList(wid2); addToFocusList(wid2);
xpos = r.left + 10; ypos += myCpu->getHeight() + 10; xpos = r.x() + 10; ypos += myCpu->getHeight() + 10;
myRam = new RiotRamWidget(this, *myLFont, *myNFont, xpos, ypos, r.width() - 10); myRam = new RiotRamWidget(this, *myLFont, *myNFont, xpos, ypos, r.w() - 10);
addToFocusList(myRam->getFocusList()); addToFocusList(myRam->getFocusList());
// Add the DataGridOpsWidget to any widgets which contain a // Add the DataGridOpsWidget to any widgets which contain a
@ -591,9 +591,9 @@ void DebuggerDialog::addRomArea()
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Disassembly area // Disassembly area
xpos = r.left + VBORDER; ypos += myRam->getHeight() + 5; xpos = r.x() + VBORDER; ypos += myRam->getHeight() + 5;
const int tabWidth = r.width() - VBORDER - 1; const int tabWidth = r.w() - VBORDER - 1;
const int tabHeight = r.height() - ypos - 1; const int tabHeight = r.h() - ypos - 1;
int tabID; int tabID;
// Since there are two tab widgets in this dialog, we specifically // Since there are two tab widgets in this dialog, we specifically
@ -664,9 +664,7 @@ Common::Rect DebuggerDialog::getRomBounds() const
{ {
// The ROM area is the full area to the right of the tabs // The ROM area is the full area to the right of the tabs
const Common::Rect& status = getStatusBounds(); const Common::Rect& status = getStatusBounds();
Common::Rect r(status.right + 1, 0, _w, _h); return Common::Rect(status.x() + status.w() + 1, 0, _w, _h);
return r;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -677,13 +675,12 @@ Common::Rect DebuggerDialog::getStatusBounds() const
// 30% of any space above 1030 pixels will be allocated to this area // 30% of any space above 1030 pixels will be allocated to this area
const Common::Rect& tia = getTiaBounds(); const Common::Rect& tia = getTiaBounds();
int x1 = tia.right + 1; int x1 = tia.x() + tia.w() + 1;
int y1 = 0; int y1 = 0;
int x2 = tia.right + 225 + (_w > 1030 ? int(0.35 * (_w - 1030)) : 0); int x2 = tia.x() + tia.w() + 225 + (_w > 1030 ? int(0.35 * (_w - 1030)) : 0);
int y2 = tia.bottom; int y2 = tia.y() + tia.h();
Common::Rect r(x1, y1, x2, y2);
return r; return Common::Rect(x1, y1, x2, y2);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -692,7 +689,7 @@ Common::Rect DebuggerDialog::getTabBounds() const
// The tab area is the full area below the TIA image // The tab area is the full area below the TIA image
const Common::Rect& tia = getTiaBounds(); const Common::Rect& tia = getTiaBounds();
const Common::Rect& status = getStatusBounds(); const Common::Rect& status = getStatusBounds();
Common::Rect r(0, tia.bottom + 1, status.right + 1, _h);
return r; return Common::Rect(0, tia.y() + tia.h() + 1,
status.x() + status.w() + 1, _h);
} }

View File

@ -108,9 +108,9 @@ void RomListSettings::center()
// First set position according to original coordinates // First set position according to original coordinates
surface().setDstPos(_xorig, _yorig); surface().setDstPos(_xorig, _yorig);
// Now make sure that the entire menu can fit inside the image bounds // Now make sure that the entire menu can fit inside the screen bounds
// If not, we reset its position // If not, we reset its position
if(!instance().frameBuffer().imageRect().contains( if(!instance().frameBuffer().screenRect().contains(
_xorig, _yorig, surface().dstRect())) _xorig, _yorig, surface().dstRect()))
surface().setDstPos(_xorig, _yorig); surface().setDstPos(_xorig, _yorig);
} }

View File

@ -480,7 +480,7 @@ void RomListWidget::drawWidget(bool hilite)
// Draw the list items // Draw the list items
int cycleCountW = _fontWidth * 8, int cycleCountW = _fontWidth * 8,
noTypeDisasmW = _w - l.x() - _labelWidth, noTypeDisasmW = _w - l.x() - _labelWidth,
noCodeDisasmW = noTypeDisasmW - r.width(), noCodeDisasmW = noTypeDisasmW - r.w(),
codeDisasmW = noCodeDisasmW - cycleCountW, codeDisasmW = noCodeDisasmW - cycleCountW,
actualWidth = myDisasm->fieldwidth * _fontWidth; actualWidth = myDisasm->fieldwidth * _fontWidth;
if(actualWidth < codeDisasmW) if(actualWidth < codeDisasmW)
@ -505,11 +505,11 @@ void RomListWidget::drawWidget(bool hilite)
{ {
if(!_editMode) if(!_editMode)
{ {
s.fillRect(_x + r.x() - 3, ypos - 1, r.width(), _fontHeight, kTextColorHi); s.fillRect(_x + r.x() - 3, ypos - 1, r.w(), _fontHeight, kTextColorHi);
bytesColor = kTextColorInv; bytesColor = kTextColorInv;
} }
else else
s.frameRect(_x + r.x() - 3, ypos - 1, r.width(), _fontHeight, kWidColorHi); s.frameRect(_x + r.x() - 3, ypos - 1, r.w(), _fontHeight, kWidColorHi);
} }
// Draw labels // Draw labels
@ -548,14 +548,14 @@ void RomListWidget::drawWidget(bool hilite)
if (_selectedItem == pos && _editMode) if (_selectedItem == pos && _editMode)
{ {
adjustOffset(); adjustOffset();
s.drawString(_font, editString(), _x + r.x(), ypos, r.width(), textColor, s.drawString(_font, editString(), _x + r.x(), ypos, r.w(), textColor,
TextAlign::Left, -_editScrollOffset, false); TextAlign::Left, -_editScrollOffset, false);
drawCaret(); drawCaret();
} }
else else
{ {
s.drawString(_font, dlist[pos].bytes, _x + r.x(), ypos, r.width(), bytesColor); s.drawString(_font, dlist[pos].bytes, _x + r.x(), ypos, r.w(), bytesColor);
} }
} }
} }
@ -571,28 +571,20 @@ void RomListWidget::drawWidget(bool hilite)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect RomListWidget::getLineRect() const Common::Rect RomListWidget::getLineRect() const
{ {
Common::Rect r(2, 1, _w, _fontHeight);
const int yoffset = (_selectedItem - _currentPos) * _fontHeight, const int yoffset = (_selectedItem - _currentPos) * _fontHeight,
xoffset = CheckboxWidget::boxSize() + 10; xoffset = CheckboxWidget::boxSize() + 10;
r.top += yoffset;
r.bottom += yoffset;
r.left += xoffset;
r.right -= xoffset - 15;
return r; return Common::Rect(2 + xoffset, 1 + yoffset,
_w - (xoffset - 15), _fontHeight + yoffset);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect RomListWidget::getEditRect() const Common::Rect RomListWidget::getEditRect() const
{ {
Common::Rect r(2, 1, _w, _fontHeight);
const int yoffset = (_selectedItem - _currentPos) * _fontHeight; const int yoffset = (_selectedItem - _currentPos) * _fontHeight;
r.top += yoffset;
r.bottom += yoffset;
r.left += _w - _bytesWidth;
r.right = _w;
return r; return Common::Rect(2 + _w - _bytesWidth, 1 + yoffset,
_w, _fontHeight + yoffset);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -48,8 +48,8 @@ void FBSurface::readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect
memcpy(buffer, src, width() * height() * 4); memcpy(buffer, src, width() * height() * 4);
else else
{ {
uInt32 w = std::min(rect.width(), width()); uInt32 w = std::min(rect.w(), width());
uInt32 h = std::min(rect.height(), height()); uInt32 h = std::min(rect.h(), height());
// Copy 'height' lines of width 'pitch' (in bytes for both) // Copy 'height' lines of width 'pitch' (in bytes for both)
uInt8* dst = buffer; uInt8* dst = buffer;

View File

@ -235,6 +235,7 @@ FBInitStatus FrameBuffer::createDisplay(const string& title,
{ {
myImageRect = mode.image; myImageRect = mode.image;
myScreenSize = mode.screen; myScreenSize = mode.screen;
myScreenRect = Common::Rect(mode.screen);
// Inform TIA surface about new mode // Inform TIA surface about new mode
if(myOSystem.eventHandler().state() != EventHandlerState::LAUNCHER && if(myOSystem.eventHandler().state() != EventHandlerState::LAUNCHER &&
@ -581,43 +582,43 @@ inline bool FrameBuffer::drawMessage()
break; break;
case MessagePosition::TopCenter: case MessagePosition::TopCenter:
myMsg.x = (myImageRect.width() - dst.width()) >> 1; myMsg.x = (myImageRect.w() - dst.w()) >> 1;
myMsg.y = 5; myMsg.y = 5;
break; break;
case MessagePosition::TopRight: case MessagePosition::TopRight:
myMsg.x = myImageRect.width() - dst.width() - 5; myMsg.x = myImageRect.w() - dst.w() - 5;
myMsg.y = 5; myMsg.y = 5;
break; break;
case MessagePosition::MiddleLeft: case MessagePosition::MiddleLeft:
myMsg.x = 5; myMsg.x = 5;
myMsg.y = (myImageRect.height() - dst.height()) >> 1; myMsg.y = (myImageRect.h() - dst.h()) >> 1;
break; break;
case MessagePosition::MiddleCenter: case MessagePosition::MiddleCenter:
myMsg.x = (myImageRect.width() - dst.width()) >> 1; myMsg.x = (myImageRect.w() - dst.w()) >> 1;
myMsg.y = (myImageRect.height() - dst.height()) >> 1; myMsg.y = (myImageRect.h() - dst.h()) >> 1;
break; break;
case MessagePosition::MiddleRight: case MessagePosition::MiddleRight:
myMsg.x = myImageRect.width() - dst.width() - 5; myMsg.x = myImageRect.w() - dst.w() - 5;
myMsg.y = (myImageRect.height() - dst.height()) >> 1; myMsg.y = (myImageRect.h() - dst.h()) >> 1;
break; break;
case MessagePosition::BottomLeft: case MessagePosition::BottomLeft:
myMsg.x = 5; myMsg.x = 5;
myMsg.y = myImageRect.height() - dst.height() - 5; myMsg.y = myImageRect.h() - dst.h() - 5;
break; break;
case MessagePosition::BottomCenter: case MessagePosition::BottomCenter:
myMsg.x = (myImageRect.width() - dst.width()) >> 1; myMsg.x = (myImageRect.w() - dst.w()) >> 1;
myMsg.y = myImageRect.height() - dst.height() - 5; myMsg.y = myImageRect.h() - dst.h() - 5;
break; break;
case MessagePosition::BottomRight: case MessagePosition::BottomRight:
myMsg.x = myImageRect.width() - dst.width() - 5; myMsg.x = myImageRect.w() - dst.w() - 5;
myMsg.y = myImageRect.height() - dst.height() - 5; myMsg.y = myImageRect.h() - dst.h() - 5;
break; break;
} }
@ -738,6 +739,7 @@ void FrameBuffer::setFullscreen(bool enable)
{ {
myImageRect = mode.image; myImageRect = mode.image;
myScreenSize = mode.screen; myScreenSize = mode.screen;
myScreenRect = Common::Rect(mode.screen);
// Inform TIA surface about new mode // Inform TIA surface about new mode
if(myOSystem.eventHandler().state() != EventHandlerState::LAUNCHER && if(myOSystem.eventHandler().state() != EventHandlerState::LAUNCHER &&
@ -808,6 +810,7 @@ bool FrameBuffer::changeVidMode(int direction)
{ {
myImageRect = mode.image; myImageRect = mode.image;
myScreenSize = mode.screen; myScreenSize = mode.screen;
myScreenRect = Common::Rect(mode.screen);
// Inform TIA surface about new mode // Inform TIA surface about new mode
myTIASurface->initialize(myOSystem.console(), mode); myTIASurface->initialize(myOSystem.console(), mode);
@ -1038,8 +1041,8 @@ FrameBuffer::VideoMode::VideoMode(uInt32 iw, uInt32 ih, uInt32 sw, uInt32 sh,
screen = Common::Size(sw, sh); screen = Common::Size(sw, sh);
// Now resize based on windowed/fullscreen mode and stretch factor // Now resize based on windowed/fullscreen mode and stretch factor
iw = image.width(); iw = image.w();
ih = image.height(); ih = image.h();
if(fsIndex != -1) if(fsIndex != -1)
{ {

View File

@ -185,6 +185,7 @@ class FrameBuffer
'unusable' area. 'unusable' area.
*/ */
const Common::Size& screenSize() const { return myScreenSize; } const Common::Size& screenSize() const { return myScreenSize; }
const Common::Rect& screenRect() const { return myScreenRect; }
/** /**
Returns the current dimensions of the users' desktop. Returns the current dimensions of the users' desktop.
@ -538,7 +539,10 @@ class FrameBuffer
Common::Rect myImageRect; Common::Rect myImageRect;
// Dimensions of the main window (not always the same as the image) // Dimensions of the main window (not always the same as the image)
// Use 'size' version when only wxh are required
// Use 'rect' version when x/y, wxh are required
Common::Size myScreenSize; Common::Size myScreenSize;
Common::Rect myScreenRect;
// Maximum dimensions of the desktop area // Maximum dimensions of the desktop area
// Note that this takes 'hidpi' mode into account, so in some cases // Note that this takes 'hidpi' mode into account, so in some cases

View File

@ -71,9 +71,9 @@ void TIASurface::initialize(const Console& console,
myTIA = &(console.tia()); myTIA = &(console.tia());
myTiaSurface->setDstPos(mode.image.x(), mode.image.y()); myTiaSurface->setDstPos(mode.image.x(), mode.image.y());
myTiaSurface->setDstSize(mode.image.width(), mode.image.height()); myTiaSurface->setDstSize(mode.image.w(), mode.image.h());
mySLineSurface->setDstPos(mode.image.x(), mode.image.y()); mySLineSurface->setDstPos(mode.image.x(), mode.image.y());
mySLineSurface->setDstSize(mode.image.width(), mode.image.height()); mySLineSurface->setDstSize(mode.image.w(), mode.image.h());
// Phosphor mode can be enabled either globally or per-ROM // Phosphor mode can be enabled either globally or per-ROM
int p_blend = 0; int p_blend = 0;
@ -97,8 +97,8 @@ void TIASurface::initialize(const Console& console,
// so rounding is performed to eliminate it // so rounding is performed to eliminate it
// This won't be 100% accurate, but non-integral scaling isn't 100% // This won't be 100% accurate, but non-integral scaling isn't 100%
// accurate anyway // accurate anyway
mySLineSurface->setSrcSize(1, 2 * int(float(mode.image.height()) / mySLineSurface->setSrcSize(1, 2 * int(float(mode.image.h()) /
floorf((float(mode.image.height()) / myTIA->height()) + 0.5f))); floorf((float(mode.image.h()) / myTIA->height()) + 0.5f)));
#if 0 #if 0
cerr << "INITIALIZE:\n" cerr << "INITIALIZE:\n"

View File

@ -120,23 +120,23 @@ void CheckListWidget::drawWidget(bool hilite)
{ {
if(_hasFocus && !_editMode) if(_hasFocus && !_editMode)
{ {
s.fillRect(_x + r.left - 3, _y + 1 + _fontHeight * i, s.fillRect(_x + r.x() - 3, _y + 1 + _fontHeight * i,
_w - r.left, _fontHeight, kTextColorHi); _w - r.x(), _fontHeight, kTextColorHi);
textColor = kTextColorInv; textColor = kTextColorInv;
} }
else else
s.frameRect(_x + r.left - 3, _y + 1 + _fontHeight * i, s.frameRect(_x + r.x() - 3, _y + 1 + _fontHeight * i,
_w - r.left, _fontHeight, onTop ? kTextColorHi : kColor); _w - r.x(), _fontHeight, onTop ? kTextColorHi : kColor);
} }
if (_selectedItem == pos && _editMode) if (_selectedItem == pos && _editMode)
{ {
adjustOffset(); adjustOffset();
s.drawString(_font, editString(), _x + r.left, y, r.width(), onTop ? kTextColor : kColor, s.drawString(_font, editString(), _x + r.x(), y, r.w(), onTop ? kTextColor : kColor,
TextAlign::Left, -_editScrollOffset, false); TextAlign::Left, -_editScrollOffset, false);
} }
else else
s.drawString(_font, _list[pos], _x + r.left, y, r.width(), s.drawString(_font, _list[pos], _x + r.x(), y, r.w(),
onTop ? textColor : kColor); onTop ? textColor : kColor);
} }
@ -149,15 +149,11 @@ void CheckListWidget::drawWidget(bool hilite)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect CheckListWidget::getEditRect() const Common::Rect CheckListWidget::getEditRect() const
{ {
Common::Rect r(2, 1, _w, _fontHeight);
const int yoffset = (_selectedItem - _currentPos) * _fontHeight, const int yoffset = (_selectedItem - _currentPos) * _fontHeight,
xoffset = CheckboxWidget::boxSize() + 10; xoffset = CheckboxWidget::boxSize() + 10;
r.top += yoffset;
r.bottom += yoffset;
r.left += xoffset;
r.right -= xoffset - 15;
return r; return Common::Rect(2 + xoffset, 1 + yoffset,
_w - (xoffset - 15), _fontHeight + yoffset);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -90,9 +90,9 @@ void ContextMenu::center()
// First set position according to original coordinates // First set position according to original coordinates
surface().setDstPos(_xorig, _yorig); surface().setDstPos(_xorig, _yorig);
// Now make sure that the entire menu can fit inside the image bounds // Now make sure that the entire menu can fit inside the screen bounds
// If not, we reset its position // If not, we reset its position
if(!instance().frameBuffer().imageRect().contains( if(!instance().frameBuffer().screenRect().contains(
_xorig, _yorig, surface().dstRect())) _xorig, _yorig, surface().dstRect()))
surface().setDstPos(_xorig, _yorig); surface().setDstPos(_xorig, _yorig);
} }
@ -102,7 +102,7 @@ void ContextMenu::recalc(const Common::Rect& image)
{ {
// Now is the time to adjust the height // Now is the time to adjust the height
// If it's higher than the screen, we need to scroll through // If it's higher than the screen, we need to scroll through
uInt32 maxentries = std::min(18u, (image.height() - 2) / _rowHeight); uInt32 maxentries = std::min(18u, (image.h() - 2) / _rowHeight);
if(_entries.size() > maxentries) if(_entries.size() > maxentries)
{ {
// We show two less than the max, so we have room for two scroll buttons // We show two less than the max, so we have room for two scroll buttons

View File

@ -174,10 +174,10 @@ void Dialog::positionAt(uInt32 pos)
// shift stacked dialogs // shift stacked dialogs
Int32 hgap = (screen.w >> 6) * _layer + screen.w * overscan; Int32 hgap = (screen.w >> 6) * _layer + screen.w * overscan;
Int32 vgap = (screen.w >> 6) * _layer + screen.h * overscan; Int32 vgap = (screen.w >> 6) * _layer + screen.h * overscan;
int top = std::min(std::max(0, Int32(screen.h - dst.height())), vgap); int top = std::min(std::max(0, Int32(screen.h - dst.h())), vgap);
int btm = std::max(0, Int32(screen.h - dst.height() - vgap)); int btm = std::max(0, Int32(screen.h - dst.h() - vgap));
int left = std::min(std::max(0, Int32(screen.w - dst.width())), hgap); int left = std::min(std::max(0, Int32(screen.w - dst.w())), hgap);
int right = std::max(0, Int32(screen.w - dst.width() - hgap)); int right = std::max(0, Int32(screen.w - dst.w() - hgap));
switch (pos) switch (pos)
{ {
@ -199,7 +199,7 @@ void Dialog::positionAt(uInt32 pos)
default: default:
// center // center
_surface->setDstPos((screen.w - dst.width()) >> 1, (screen.h - dst.height()) >> 1); _surface->setDstPos((screen.w - dst.w()) >> 1, (screen.h - dst.h()) >> 1);
break; break;
} }
} }
@ -872,16 +872,16 @@ bool Dialog::getDynamicBounds(uInt32& w, uInt32& h) const
const Common::Rect& r = instance().frameBuffer().imageRect(); const Common::Rect& r = instance().frameBuffer().imageRect();
const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); const uInt32 scale = instance().frameBuffer().hidpiScaleFactor();
if(r.width() <= FBMinimum::Width || r.height() <= FBMinimum::Height) if(r.w() <= FBMinimum::Width || r.h() <= FBMinimum::Height)
{ {
w = r.width() / scale; w = r.w() / scale;
h = r.height() / scale; h = r.h() / scale;
return false; return false;
} }
else else
{ {
w = uInt32(0.95 * r.width() / scale); w = uInt32(0.95 * r.w() / scale);
h = uInt32(0.95 * r.height() / scale); h = uInt32(0.95 * r.h() / scale);
return true; return true;
} }
} }

View File

@ -122,7 +122,7 @@ int DialogContainer::addDialog(Dialog* d)
const Common::Rect& r = myOSystem.frameBuffer().imageRect(); const Common::Rect& r = myOSystem.frameBuffer().imageRect();
const uInt32 scale = myOSystem.frameBuffer().hidpiScaleFactor(); const uInt32 scale = myOSystem.frameBuffer().hidpiScaleFactor();
if(uInt32(d->getWidth() * scale) > r.width() || uInt32(d->getHeight() * scale) > r.height()) if(uInt32(d->getWidth() * scale) > r.w() || uInt32(d->getHeight() * scale) > r.h())
myOSystem.frameBuffer().showMessage( myOSystem.frameBuffer().showMessage(
"Unable to show dialog box; FIX THE CODE"); "Unable to show dialog box; FIX THE CODE");
else else

View File

@ -93,7 +93,7 @@ void EditTextWidget::drawWidget(bool hilite)
// Draw the text // Draw the text
adjustOffset(); adjustOffset();
s.drawString(_font, editString(), _x + 2, _y + 2, getEditRect().width(), s.drawString(_font, editString(), _x + 2, _y + 2, getEditRect().w(),
_changed && onTop && isEnabled() _changed && onTop && isEnabled()
? kDbgChangedTextColor ? kDbgChangedTextColor
: onTop && isEnabled() ? _textcolor : kColor, : onTop && isEnabled() ? _textcolor : kColor,

View File

@ -58,7 +58,7 @@ void EditableWidget::setText(const string& str, bool)
_caretPos = int(_editString.size()); _caretPos = int(_editString.size());
_editScrollOffset = (_font.getStringWidth(_editString) - (getEditRect().width())); _editScrollOffset = (_font.getStringWidth(_editString) - (getEditRect().w()));
if (_editScrollOffset < 0) if (_editScrollOffset < 0)
_editScrollOffset = 0; _editScrollOffset = 0;
@ -203,8 +203,8 @@ void EditableWidget::drawCaret()
return; return;
const Common::Rect& editRect = getEditRect(); const Common::Rect& editRect = getEditRect();
int x = editRect.left; int x = editRect.x();
int y = editRect.top; int y = editRect.y();
x += getCaretOffset(); x += getCaretOffset();
@ -212,7 +212,7 @@ void EditableWidget::drawCaret()
y += _y; y += _y;
FBSurface& s = _boss->dialog().surface(); FBSurface& s = _boss->dialog().surface();
s.vLine(x, y+2, y + editRect.height() - 2, kTextColorHi); s.vLine(x, y+2, y + editRect.h() - 2, kTextColorHi);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -234,7 +234,7 @@ bool EditableWidget::adjustOffset()
// this method should always return true. // this method should always return true.
int caretpos = getCaretOffset(); int caretpos = getCaretOffset();
const int editWidth = getEditRect().width(); const int editWidth = getEditRect().w();
if (caretpos < 0) if (caretpos < 0)
{ {

View File

@ -140,9 +140,9 @@ void InputTextDialog::center()
// First set position according to original coordinates // First set position according to original coordinates
surface().setDstPos(myXOrig, myYOrig); surface().setDstPos(myXOrig, myYOrig);
// Now make sure that the entire menu can fit inside the image bounds // Now make sure that the entire menu can fit inside the screen bounds
// If not, we reset its position // If not, we reset its position
if(!instance().frameBuffer().imageRect().contains( if(!instance().frameBuffer().screenRect().contains(
myXOrig, myXOrig, surface().dstRect())) myXOrig, myXOrig, surface().dstRect()))
surface().setDstPos(myXOrig, myYOrig); surface().setDstPos(myXOrig, myYOrig);
} }

View File

@ -110,9 +110,9 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node)
// Scale surface to available image area // Scale surface to available image area
const Common::Rect& src = mySurface->srcRect(); const Common::Rect& src = mySurface->srcRect();
float scale = std::min(float(myAvail.w) / src.width(), float(myAvail.h) / src.height()) * float scale = std::min(float(myAvail.w) / src.w(), float(myAvail.h) / src.h()) *
instance().frameBuffer().hidpiScaleFactor(); instance().frameBuffer().hidpiScaleFactor();
mySurface->setDstSize(uInt32(src.width() * scale), uInt32(src.height() * scale)); mySurface->setDstSize(uInt32(src.w() * scale), uInt32(src.h() * scale));
mySurfaceIsValid = true; mySurfaceIsValid = true;
} }
catch(const runtime_error& e) catch(const runtime_error& e)
@ -181,8 +181,8 @@ void RomInfoWidget::drawWidget(bool hilite)
{ {
const Common::Rect& dst = mySurface->dstRect(); const Common::Rect& dst = mySurface->dstRect();
const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); const uInt32 scale = instance().frameBuffer().hidpiScaleFactor();
uInt32 x = _x*scale + ((_w*scale - dst.width()) >> 1); uInt32 x = _x*scale + ((_w*scale - dst.w()) >> 1);
uInt32 y = _y*scale + ((yoff*scale - dst.height()) >> 1); uInt32 y = _y*scale + ((yoff*scale - dst.h()) >> 1);
// Make sure when positioning the snapshot surface that we take // Make sure when positioning the snapshot surface that we take
// the dialog surface position into account // the dialog surface position into account

View File

@ -87,11 +87,11 @@ void StringListWidget::drawWidget(bool hilite)
{ {
adjustOffset(); adjustOffset();
s.drawString(_font, editString(), _x + r.left, y, r.width(), textColor, s.drawString(_font, editString(), _x + r.x(), y, r.w(), textColor,
TextAlign::Left, -_editScrollOffset, false); TextAlign::Left, -_editScrollOffset, false);
} }
else else
s.drawString(_font, _list[pos], _x + r.left, y, r.width(), textColor); s.drawString(_font, _list[pos], _x + r.x(), y, r.w(), textColor);
} }
// Only draw the caret while editing, and if it's in the current viewport // Only draw the caret while editing, and if it's in the current viewport
@ -103,10 +103,6 @@ void StringListWidget::drawWidget(bool hilite)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect StringListWidget::getEditRect() const Common::Rect StringListWidget::getEditRect() const
{ {
Common::Rect r(2, 1, _w - 2, _fontHeight);
const int offset = std::max(0, (_selectedItem - _currentPos) * _fontHeight); const int offset = std::max(0, (_selectedItem - _currentPos) * _fontHeight);
r.top += offset; return Common::Rect(2, 1 + offset, _w - 2, _fontHeight + offset);
r.bottom += offset;
return r;
} }

View File

@ -287,7 +287,7 @@ void TimeMachineDialog::center()
// Place on the bottom of the screen, centered horizontally // Place on the bottom of the screen, centered horizontally
const Common::Size& screen = instance().frameBuffer().screenSize(); const Common::Size& screen = instance().frameBuffer().screenSize();
const Common::Rect& dst = surface().dstRect(); const Common::Rect& dst = surface().dstRect();
surface().setDstPos((screen.w - dst.width()) >> 1, screen.h - dst.height() - 10); surface().setDstPos((screen.w - dst.w()) >> 1, screen.h - dst.h() - 10);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -