Skip to content

Commit

Permalink
GUI: Add checks in Widget::getBossClipRect()
Browse files Browse the repository at this point in the history
Prints a warning if clipping area is invalid and fixes it.
  • Loading branch information
Tkachov authored and sev- committed Jul 3, 2016
1 parent 6de5324 commit 846619f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
15 changes: 0 additions & 15 deletions gui/object.cpp
Expand Up @@ -44,21 +44,6 @@ void GuiObject::reflowLayout() {
if (!g_gui.xmlEval()->getWidgetData(_name, _x, _y, _w, _h)) {
error("Could not load widget position for '%s'", _name.c_str());
}

/*
if (_x < 0)
error("Widget <%s> has x < 0 (%d)", _name.c_str(), _x);
if (_x >= g_gui.getWidth())
error("Widget <%s> has x > %d (%d)", _name.c_str(), g_gui.getWidth(), _x);
if (_x + _w > g_gui.getWidth())
error("Widget <%s> has x + w > %d (%d)", _name.c_str(), g_gui.getWidth(), _x + _w);
if (_y < 0)
error("Widget <%s> has y < 0 (%d)", _name.c_str(), _y);
if (_y >= g_gui.getHeight())
error("Widget <%s> has y > %d (%d)", _name.c_str(), g_gui.getHeight(), _y);
if (_y + _h > g_gui.getHeight())
error("Widget <%s> has y + h > %d (%d)", _name.c_str(), g_gui.getHeight(), _y + _h);
*/
}
}

Expand Down
25 changes: 25 additions & 0 deletions gui/widget.cpp
Expand Up @@ -53,6 +53,31 @@ void Widget::init() {
_boss->_firstWidget = this;
}

Common::Rect Widget::getBossClipRect() const {
int bx = _boss->getAbsX();
int by = _boss->getAbsY();
Common::Rect result = Common::Rect(bx, by, bx + _boss->getWidth(), by + _boss->getHeight());
bool needsClipping = false;

//check whether clipping area is inside the screen
if (result.left < 0 && (needsClipping = true))
warning("Widget <%s> has clipping area x < 0 (%d)", _name.c_str(), result.left);
if (result.left >= g_gui.getWidth() && (needsClipping = true))
warning("Widget <%s> has clipping area x > %d (%d)", _name.c_str(), g_gui.getWidth(), result.left);
if (result.right > g_gui.getWidth() && (needsClipping = true))
warning("Widget <%s> has clipping area x + w > %d (%d)", _name.c_str(), g_gui.getWidth(), result.right);
if (result.top < 0 && (needsClipping = true))
warning("Widget <%s> has clipping area y < 0 (%d)", _name.c_str(), result.top);
if (result.top >= g_gui.getHeight() && (needsClipping = true))
warning("Widget <%s> has clipping area y > %d (%d)", _name.c_str(), g_gui.getHeight(), result.top);
if (result.bottom > g_gui.getHeight() && (needsClipping = true))
warning("Widget <%s> has clipping area y + h > %d (%d)", _name.c_str(), g_gui.getHeight(), result.bottom);

if (needsClipping)
result.clip(g_gui.getWidth(), g_gui.getHeight());
return result;
}

Widget::~Widget() {
delete _next;
_next = 0;
Expand Down
6 changes: 1 addition & 5 deletions gui/widget.h
Expand Up @@ -112,11 +112,7 @@ class Widget : public GuiObject {

virtual int16 getAbsX() const { return _x + _boss->getChildX(); }
virtual int16 getAbsY() const { return _y + _boss->getChildY(); }
virtual Common::Rect getBossClipRect() const {
int px = _boss->getAbsX();
int py = _boss->getAbsY();
return Common::Rect(px, py, px + _boss->getWidth(), py + _boss->getHeight());
}
virtual Common::Rect getBossClipRect() const;

virtual void setPos(int x, int y) { _x = x; _y = y; }
virtual void setSize(int w, int h) { _w = w; _h = h; }
Expand Down

0 comments on commit 846619f

Please sign in to comment.