GUI: Normalize width/height parameters

The fact that ThemeLayout had them int, and GuiObject as uint, was
leading to number of unexpected overflows.
This commit is contained in:
Eugene Sandulenko 2020-05-09 21:04:53 +02:00
parent 77c51088ee
commit 6aacdb1938
8 changed files with 22 additions and 18 deletions

View file

@ -305,7 +305,7 @@ void HelpDialog::reflowLayout() {
int lineHeight = g_gui.getFontHeight(); int lineHeight = g_gui.getFontHeight();
int16 x, y; int16 x, y;
uint16 w, h; int16 w, h;
assert(lineHeight); assert(lineHeight);

View file

@ -50,7 +50,7 @@ void ThemeEval::reset() {
_layouts.clear(); _layouts.clear();
} }
bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) { bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, int16 &w, int16 &h) {
Common::StringTokenizer tokenizer(widget, "."); Common::StringTokenizer tokenizer(widget, ".");
if (widget.hasPrefix("Dialog.")) if (widget.hasPrefix("Dialog."))

View file

@ -88,7 +88,7 @@ public:
bool hasDialog(const Common::String &name); bool hasDialog(const Common::String &name);
void reflowDialogLayout(const Common::String &name, Widget *widgetChain); void reflowDialogLayout(const Common::String &name, Widget *widgetChain);
bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h); bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, int16 &w, int16 &h);
Graphics::TextAlign getWidgetTextHAlign(const Common::String &widget); Graphics::TextAlign getWidgetTextHAlign(const Common::String &widget);

View file

@ -71,7 +71,7 @@ void ThemeLayout::resetLayout() {
_children[i]->resetLayout(); _children[i]->resetLayout();
} }
bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) { bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) {
if (name.empty()) { if (name.empty()) {
assert(getLayoutType() == kLayoutMain); assert(getLayoutType() == kLayoutMain);
x = _x; y = _y; x = _x; y = _y;
@ -158,7 +158,7 @@ void ThemeLayout::debugDraw(Graphics::Surface *screen, const Graphics::Font *fon
#endif #endif
bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) { bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) {
if (name == _name) { if (name == _name) {
x = _x; y = _y; x = _x; y = _y;
w = _w; h = _h; w = _w; h = _h;
@ -229,7 +229,7 @@ void ThemeLayoutMain::reflowLayout(Widget *widgetChain) {
_w = _defaultW > 0 ? MIN(_defaultW, g_system->getOverlayWidth()) : -1; _w = _defaultW > 0 ? MIN(_defaultW, g_system->getOverlayWidth()) : -1;
_h = _defaultH > 0 ? MIN(_defaultH, g_system->getOverlayHeight()) : -1; _h = _defaultH > 0 ? MIN(_defaultH, g_system->getOverlayHeight()) : -1;
} else { } else {
if (!g_gui.xmlEval()->getWidgetData(_overlays, _x, _y, (uint16 &) _w, (uint16 &) _h)) { if (!g_gui.xmlEval()->getWidgetData(_overlays, _x, _y, _w, _h)) {
warning("Unable to retrieve overlayed dialog position %s", _overlays.c_str()); warning("Unable to retrieve overlayed dialog position %s", _overlays.c_str());
} }

View file

@ -114,7 +114,7 @@ protected:
virtual ThemeLayout *makeClone(ThemeLayout *newParent) = 0; virtual ThemeLayout *makeClone(ThemeLayout *newParent) = 0;
public: public:
virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h); virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h);
virtual Graphics::TextAlign getWidgetTextHAlign(const Common::String &name); virtual Graphics::TextAlign getWidgetTextHAlign(const Common::String &name);
@ -226,7 +226,7 @@ public:
setTextHAlign(align); setTextHAlign(align);
} }
bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) override; bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override;
Graphics::TextAlign getWidgetTextHAlign(const Common::String &name) override; Graphics::TextAlign getWidgetTextHAlign(const Common::String &name) override;
void reflowLayout(Widget *widgetChain) override; void reflowLayout(Widget *widgetChain) override;
@ -263,7 +263,7 @@ public:
} }
} }
bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) override { bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override {
if (ThemeLayoutWidget::getWidgetData(name, x, y, w, h)) { if (ThemeLayoutWidget::getWidgetData(name, x, y, w, h)) {
h -= _tabHeight; h -= _tabHeight;
return true; return true;
@ -294,7 +294,7 @@ public:
} }
} }
bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) override { return false; } bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override { return false; }
void reflowLayout(Widget *widgetChain) override {} void reflowLayout(Widget *widgetChain) override {}
#ifdef LAYOUT_DEBUG_DIALOG #ifdef LAYOUT_DEBUG_DIALOG
const char *getName() const { return "SPACE"; } const char *getName() const { return "SPACE"; }

View file

@ -40,9 +40,13 @@ GuiObject::~GuiObject() {
void GuiObject::reflowLayout() { void GuiObject::reflowLayout() {
if (!_name.empty()) { if (!_name.empty()) {
if (!g_gui.xmlEval()->getWidgetData(_name, _x, _y, _w, _h)) { int16 w, h;
if (!g_gui.xmlEval()->getWidgetData(_name, _x, _y, w, h) || w == -1 || h == -1) {
error("Could not load widget position for '%s'", _name.c_str()); error("Could not load widget position for '%s'", _name.c_str());
} }
_w = w;
_h = h;
} }
} }

View file

@ -1133,7 +1133,7 @@ void OptionsDialog::addAchievementsControls(GuiObject *boss, const Common::Strin
for (int16 viewAchieved = 1; viewAchieved >= 0; viewAchieved--) { for (int16 viewAchieved = 1; viewAchieved >= 0; viewAchieved--) {
// run this twice, first view all achieved, then view all non-hidden & non-achieved // run this twice, first view all achieved, then view all non-hidden & non-achieved
for (uint16 idx = 0; idx < nMax ; idx++) { for (uint16 idx = 0; idx < nMax ; idx++) {
bool isAchieved = AchMan.isAchieved(info.descriptions[idx].id); bool isAchieved = AchMan.isAchieved(info.descriptions[idx].id);
@ -1144,7 +1144,7 @@ void OptionsDialog::addAchievementsControls(GuiObject *boss, const Common::Strin
if (isAchieved) { if (isAchieved) {
nAchieved++; nAchieved++;
} }
if (!isAchieved && info.descriptions[idx].isHidden) { if (!isAchieved && info.descriptions[idx].isHidden) {
nHidden++; nHidden++;
continue; continue;
@ -2773,7 +2773,7 @@ void GlobalOptionsDialog::setupCloudTab() {
// calculate shift // calculate shift
int16 x, y; int16 x, y;
uint16 w, h; int16 w, h;
int16 shiftUp = 0; int16 shiftUp = 0;
if (!showingCurrentStorage || enabled) { if (!showingCurrentStorage || enabled) {
// "storage is disabled" hint is not shown, shift everything up // "storage is disabled" hint is not shown, shift everything up
@ -2902,7 +2902,7 @@ void GlobalOptionsDialog::shiftWidget(Widget *widget, const char *widgetName, in
if (!widget) return; if (!widget) return;
int16 x, y; int16 x, y;
uint16 w, h; int16 w, h;
if (!g_gui.xmlEval()->getWidgetData(widgetName, x, y, w, h)) if (!g_gui.xmlEval()->getWidgetData(widgetName, x, y, w, h))
warning("%s's position is undefined", widgetName); warning("%s's position is undefined", widgetName);

View file

@ -489,7 +489,7 @@ void SaveLoadChooserSimple::reflowLayout() {
if (g_gui.xmlEval()->getVar("Globals.SaveLoadChooser.ExtInfo.Visible") == 1 && (_thumbnailSupport || _saveDateSupport || _playTimeSupport)) { if (g_gui.xmlEval()->getVar("Globals.SaveLoadChooser.ExtInfo.Visible") == 1 && (_thumbnailSupport || _saveDateSupport || _playTimeSupport)) {
int16 x, y; int16 x, y;
uint16 w, h; int16 w, h;
if (!g_gui.xmlEval()->getWidgetData("SaveLoadChooser.Thumbnail", x, y, w, h)) if (!g_gui.xmlEval()->getWidgetData("SaveLoadChooser.Thumbnail", x, y, w, h))
error("Error when loading position data for Save/Load Thumbnails"); error("Error when loading position data for Save/Load Thumbnails");
@ -919,10 +919,10 @@ void SaveLoadChooserGrid::reflowLayout() {
// HACK: The whole code below really works around the fact, that we have // HACK: The whole code below really works around the fact, that we have
// no easy way to dynamically layout widgets. // no easy way to dynamically layout widgets.
const uint16 availableWidth = getWidth() - 20; const uint16 availableWidth = getWidth() - 20;
uint16 availableHeight; int16 availableHeight;
int16 x, y; int16 x, y;
uint16 w; int16 w;
if (!g_gui.xmlEval()->getWidgetData("SaveLoadChooser.List", x, y, w, availableHeight)) if (!g_gui.xmlEval()->getWidgetData("SaveLoadChooser.List", x, y, w, availableHeight))
error("Could not load widget position for 'SaveLoadChooser.List'"); error("Could not load widget position for 'SaveLoadChooser.List'");