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;
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);
}

View File

@ -132,7 +132,7 @@ void PNGLibrary::saveImage(const string& filename, const VariantList& comments)
const FrameBuffer& fb = myOSystem.frameBuffer();
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)
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");
// 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())
{
width = surface.width();

View File

@ -105,75 +105,78 @@ struct Size
*/
struct 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).
private:
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).
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& operator=(const Rect&) = default;
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(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top(y1), left(x1), bottom(y2), right(x2) { assert(valid()); }
public:
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 Size& s) : top(0), left(0), bottom(s.h), right(s.w) { assert(valid()); }
Rect& operator=(const Rect&) = default;
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(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top(y1), left(x1), bottom(y2), right(x2) { assert(valid()); }
uInt32 x() const { return left; }
uInt32 y() const { return top; }
Point point() const { return Point(x(), y()); }
uInt32 x() const { return left; }
uInt32 y() const { return top; }
Point point() const { return Point(x(), y()); }
uInt32 width() const { return right - left; }
uInt32 height() const { return bottom - top; }
Size size() const { return Size(width(), height()); }
uInt32 w() const { return right - left; }
uInt32 h() const { return bottom - top; }
Size size() const { return Size(w(), h()); }
void setWidth(uInt32 aWidth) { right = left + aWidth; }
void setHeight(uInt32 aHeight) { bottom = top + aHeight; }
void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); }
void setWidth(uInt32 aWidth) { right = left + aWidth; }
void setHeight(uInt32 aHeight) { bottom = top + aHeight; }
void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); }
void setBounds(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) {
top = y1;
left = x1;
bottom = y2;
right = x2;
assert(valid());
}
void setBounds(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) {
top = y1;
left = x1;
bottom = y2;
right = x2;
assert(valid());
}
bool valid() const {
return (left <= right && top <= bottom);
}
bool valid() const {
return (left <= right && top <= bottom);
}
bool empty() const {
return top == 0 && left == 0 && bottom == 0 && right == 0;
}
bool empty() const {
return top == 0 && left == 0 && bottom == 0 && right == 0;
}
void moveTo(uInt32 x, uInt32 y) {
bottom += y - top;
right += x - left;
top = y;
left = x;
}
void moveTo(uInt32 x, uInt32 y) {
bottom += y - top;
right += x - left;
top = y;
left = x;
}
void moveTo(const Point& p) {
moveTo(p.x, p.y);
}
void moveTo(const Point& p) {
moveTo(p.x, p.y);
}
bool contains(uInt32 x, uInt32 y) const {
return x >= left && y >= top && x < right && y < bottom;
}
bool contains(uInt32 x, uInt32 y) const {
return x >= left && y >= top && x < right && y < bottom;
}
// Tests whether 'r' is completely contained within this rectangle.
// If it isn't, then set 'x' and 'y' such that moving 'r' to this
// position will make it be contained.
bool contains(uInt32& x, uInt32& y, const Rect& r) const {
if(r.left < left) x = left;
else if(r.right > right) x = r.left - (r.right - right);
if(r.top < top) y = top;
else if(r.bottom > bottom) y = r.top - (r.bottom - bottom);
// Tests whether 'r' is completely contained within this rectangle.
// If it isn't, then set 'x' and 'y' such that moving 'r' to this
// position will make it be contained.
bool contains(uInt32& x, uInt32& y, const Rect& r) const {
if(r.left < left) x = left;
else if(r.right > right) x = r.left - (r.right - right);
if(r.top < top) y = top;
else if(r.bottom > bottom) y = r.top - (r.bottom - bottom);
return r.left != x || r.top != y;
}
return r.left != x || r.top != y;
}
friend ostream& operator<<(ostream& os, const Rect& r) {
os << r.point() << "," << r.size();
return os;
}
friend ostream& operator<<(ostream& os, const Rect& r) {
os << r.point() << "," << r.size();
return os;
}
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -670,15 +670,11 @@ void DataGridWidget::drawWidget(bool hilite)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect DataGridWidget::getEditRect() const
{
Common::Rect r(1, 0, _colWidth, _rowHeight);
const int rowoffset = _currentRow * _rowHeight;
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();
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
// Since there are two tab widgets in this dialog, we specifically
// assign an ID of 0
myTab = new TabWidget(this, *myLFont, r.left, r.top + vBorder,
r.width(), r.height() - vBorder);
myTab = new TabWidget(this, *myLFont, r.x(), r.y() + vBorder,
r.w(), r.h() - vBorder);
myTab->setID(0);
addTabWidget(myTab);
const int widWidth = r.width() - vBorder;
const int widHeight = r.height() - myTab->getTabHeight() - vBorder - 4;
const int widWidth = r.w() - vBorder;
const int widHeight = r.h() - myTab->getTabHeight() - vBorder - 4;
int tabID;
// The Prompt/console tab
@ -462,12 +462,12 @@ void DebuggerDialog::addStatusArea()
const Common::Rect& r = getStatusBounds();
int xpos, ypos;
xpos = r.left; ypos = r.top;
myTiaInfo = new TiaInfoWidget(this, *myLFont, *myNFont, xpos, ypos, r.width());
xpos = r.x(); ypos = r.y();
myTiaInfo = new TiaInfoWidget(this, *myLFont, *myNFont, xpos, ypos, r.w());
ypos += myTiaInfo->getHeight() + 10;
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());
xpos += 10; ypos += myTiaZoom->getHeight() + 10;
@ -518,7 +518,7 @@ void DebuggerDialog::addRomArea()
int bwidth = myLFont->getStringWidth("Frame +1 "),
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,
bwidth, bheight, "Step", kDDStepCmd, true);
@ -543,7 +543,7 @@ void DebuggerDialog::addRomArea()
bwidth = bheight; // 7 + 12;
bheight = bheight * 3 + 4 * 2;
buttonX -= (bwidth + 5);
buttonY = r.top + 5;
buttonY = r.y() + 5;
myRewindButton =
new ButtonWidget(this, *myLFont, buttonX, buttonY,
@ -563,7 +563,7 @@ void DebuggerDialog::addRomArea()
bwidth = myLFont->getStringWidth("Options " + ELLIPSIS);
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);
wid1.push_back(b);
wid1.push_back(myRewindButton);
@ -571,16 +571,16 @@ void DebuggerDialog::addRomArea()
DataGridOpsWidget* ops = new DataGridOpsWidget(this, *myLFont, xpos, ypos);
int max_w = xpos - r.left - 10;
xpos = r.left + 10; ypos = 10;
int max_w = xpos - r.x() - 10;
xpos = r.x() + 10; ypos = 10;
myCpu = new CpuWidget(this, *myLFont, *myNFont, xpos, ypos, max_w);
addToFocusList(myCpu->getFocusList());
addToFocusList(wid1);
addToFocusList(wid2);
xpos = r.left + 10; ypos += myCpu->getHeight() + 10;
myRam = new RiotRamWidget(this, *myLFont, *myNFont, xpos, ypos, r.width() - 10);
xpos = r.x() + 10; ypos += myCpu->getHeight() + 10;
myRam = new RiotRamWidget(this, *myLFont, *myNFont, xpos, ypos, r.w() - 10);
addToFocusList(myRam->getFocusList());
// Add the DataGridOpsWidget to any widgets which contain a
@ -591,9 +591,9 @@ void DebuggerDialog::addRomArea()
////////////////////////////////////////////////////////////////////
// Disassembly area
xpos = r.left + VBORDER; ypos += myRam->getHeight() + 5;
const int tabWidth = r.width() - VBORDER - 1;
const int tabHeight = r.height() - ypos - 1;
xpos = r.x() + VBORDER; ypos += myRam->getHeight() + 5;
const int tabWidth = r.w() - VBORDER - 1;
const int tabHeight = r.h() - ypos - 1;
int tabID;
// 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
const Common::Rect& status = getStatusBounds();
Common::Rect r(status.right + 1, 0, _w, _h);
return r;
return Common::Rect(status.x() + status.w() + 1, 0, _w, _h);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -677,13 +675,12 @@ Common::Rect DebuggerDialog::getStatusBounds() const
// 30% of any space above 1030 pixels will be allocated to this area
const Common::Rect& tia = getTiaBounds();
int x1 = tia.right + 1;
int x1 = tia.x() + tia.w() + 1;
int y1 = 0;
int x2 = tia.right + 225 + (_w > 1030 ? int(0.35 * (_w - 1030)) : 0);
int y2 = tia.bottom;
Common::Rect r(x1, y1, x2, y2);
int x2 = tia.x() + tia.w() + 225 + (_w > 1030 ? int(0.35 * (_w - 1030)) : 0);
int y2 = tia.y() + tia.h();
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
const Common::Rect& tia = getTiaBounds();
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
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(!instance().frameBuffer().imageRect().contains(
if(!instance().frameBuffer().screenRect().contains(
_xorig, _yorig, surface().dstRect()))
surface().setDstPos(_xorig, _yorig);
}

View File

@ -480,7 +480,7 @@ void RomListWidget::drawWidget(bool hilite)
// Draw the list items
int cycleCountW = _fontWidth * 8,
noTypeDisasmW = _w - l.x() - _labelWidth,
noCodeDisasmW = noTypeDisasmW - r.width(),
noCodeDisasmW = noTypeDisasmW - r.w(),
codeDisasmW = noCodeDisasmW - cycleCountW,
actualWidth = myDisasm->fieldwidth * _fontWidth;
if(actualWidth < codeDisasmW)
@ -505,11 +505,11 @@ void RomListWidget::drawWidget(bool hilite)
{
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;
}
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
@ -548,14 +548,14 @@ void RomListWidget::drawWidget(bool hilite)
if (_selectedItem == pos && _editMode)
{
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);
drawCaret();
}
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 r(2, 1, _w, _fontHeight);
const int yoffset = (_selectedItem - _currentPos) * _fontHeight,
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 r(2, 1, _w, _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);
else
{
uInt32 w = std::min(rect.width(), width());
uInt32 h = std::min(rect.height(), height());
uInt32 w = std::min(rect.w(), width());
uInt32 h = std::min(rect.h(), height());
// Copy 'height' lines of width 'pitch' (in bytes for both)
uInt8* dst = buffer;

View File

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

View File

@ -185,6 +185,7 @@ class FrameBuffer
'unusable' area.
*/
const Common::Size& screenSize() const { return myScreenSize; }
const Common::Rect& screenRect() const { return myScreenRect; }
/**
Returns the current dimensions of the users' desktop.
@ -538,7 +539,10 @@ class FrameBuffer
Common::Rect myImageRect;
// 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::Rect myScreenRect;
// Maximum dimensions of the desktop area
// 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());
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->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
int p_blend = 0;
@ -97,8 +97,8 @@ void TIASurface::initialize(const Console& console,
// so rounding is performed to eliminate it
// This won't be 100% accurate, but non-integral scaling isn't 100%
// accurate anyway
mySLineSurface->setSrcSize(1, 2 * int(float(mode.image.height()) /
floorf((float(mode.image.height()) / myTIA->height()) + 0.5f)));
mySLineSurface->setSrcSize(1, 2 * int(float(mode.image.h()) /
floorf((float(mode.image.h()) / myTIA->height()) + 0.5f)));
#if 0
cerr << "INITIALIZE:\n"

View File

@ -120,23 +120,23 @@ void CheckListWidget::drawWidget(bool hilite)
{
if(_hasFocus && !_editMode)
{
s.fillRect(_x + r.left - 3, _y + 1 + _fontHeight * i,
_w - r.left, _fontHeight, kTextColorHi);
s.fillRect(_x + r.x() - 3, _y + 1 + _fontHeight * i,
_w - r.x(), _fontHeight, kTextColorHi);
textColor = kTextColorInv;
}
else
s.frameRect(_x + r.left - 3, _y + 1 + _fontHeight * i,
_w - r.left, _fontHeight, onTop ? kTextColorHi : kColor);
s.frameRect(_x + r.x() - 3, _y + 1 + _fontHeight * i,
_w - r.x(), _fontHeight, onTop ? kTextColorHi : kColor);
}
if (_selectedItem == pos && _editMode)
{
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);
}
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);
}
@ -149,15 +149,11 @@ void CheckListWidget::drawWidget(bool hilite)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect CheckListWidget::getEditRect() const
{
Common::Rect r(2, 1, _w, _fontHeight);
const int yoffset = (_selectedItem - _currentPos) * _fontHeight,
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
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(!instance().frameBuffer().imageRect().contains(
if(!instance().frameBuffer().screenRect().contains(
_xorig, _yorig, surface().dstRect()))
surface().setDstPos(_xorig, _yorig);
}
@ -102,7 +102,7 @@ void ContextMenu::recalc(const Common::Rect& image)
{
// Now is the time to adjust the height
// 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)
{
// 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
Int32 hgap = (screen.w >> 6) * _layer + screen.w * overscan;
Int32 vgap = (screen.w >> 6) * _layer + screen.h * overscan;
int top = std::min(std::max(0, Int32(screen.h - dst.height())), vgap);
int btm = std::max(0, Int32(screen.h - dst.height() - vgap));
int left = std::min(std::max(0, Int32(screen.w - dst.width())), hgap);
int right = std::max(0, Int32(screen.w - dst.width() - hgap));
int top = std::min(std::max(0, Int32(screen.h - dst.h())), vgap);
int btm = std::max(0, Int32(screen.h - dst.h() - vgap));
int left = std::min(std::max(0, Int32(screen.w - dst.w())), hgap);
int right = std::max(0, Int32(screen.w - dst.w() - hgap));
switch (pos)
{
@ -199,7 +199,7 @@ void Dialog::positionAt(uInt32 pos)
default:
// 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;
}
}
@ -872,16 +872,16 @@ bool Dialog::getDynamicBounds(uInt32& w, uInt32& h) const
const Common::Rect& r = instance().frameBuffer().imageRect();
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;
h = r.height() / scale;
w = r.w() / scale;
h = r.h() / scale;
return false;
}
else
{
w = uInt32(0.95 * r.width() / scale);
h = uInt32(0.95 * r.height() / scale);
w = uInt32(0.95 * r.w() / scale);
h = uInt32(0.95 * r.h() / scale);
return true;
}
}

View File

@ -122,7 +122,7 @@ int DialogContainer::addDialog(Dialog* d)
const Common::Rect& r = myOSystem.frameBuffer().imageRect();
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(
"Unable to show dialog box; FIX THE CODE");
else

View File

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

View File

@ -58,7 +58,7 @@ void EditableWidget::setText(const string& str, bool)
_caretPos = int(_editString.size());
_editScrollOffset = (_font.getStringWidth(_editString) - (getEditRect().width()));
_editScrollOffset = (_font.getStringWidth(_editString) - (getEditRect().w()));
if (_editScrollOffset < 0)
_editScrollOffset = 0;
@ -203,8 +203,8 @@ void EditableWidget::drawCaret()
return;
const Common::Rect& editRect = getEditRect();
int x = editRect.left;
int y = editRect.top;
int x = editRect.x();
int y = editRect.y();
x += getCaretOffset();
@ -212,7 +212,7 @@ void EditableWidget::drawCaret()
y += _y;
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.
int caretpos = getCaretOffset();
const int editWidth = getEditRect().width();
const int editWidth = getEditRect().w();
if (caretpos < 0)
{

View File

@ -140,9 +140,9 @@ void InputTextDialog::center()
// First set position according to original coordinates
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(!instance().frameBuffer().imageRect().contains(
if(!instance().frameBuffer().screenRect().contains(
myXOrig, myXOrig, surface().dstRect()))
surface().setDstPos(myXOrig, myYOrig);
}

View File

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

View File

@ -87,11 +87,11 @@ void StringListWidget::drawWidget(bool hilite)
{
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);
}
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
@ -103,10 +103,6 @@ void StringListWidget::drawWidget(bool hilite)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Rect StringListWidget::getEditRect() const
{
Common::Rect r(2, 1, _w - 2, _fontHeight);
const int offset = std::max(0, (_selectedItem - _currentPos) * _fontHeight);
r.top += offset;
r.bottom += offset;
return r;
return Common::Rect(2, 1 + offset, _w - 2, _fontHeight + offset);
}

View File

@ -287,7 +287,7 @@ void TimeMachineDialog::center()
// Place on the bottom of the screen, centered horizontally
const Common::Size& screen = instance().frameBuffer().screenSize();
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);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -