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:
parent
77c51088ee
commit
6aacdb1938
8 changed files with 22 additions and 18 deletions
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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."))
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"; }
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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'");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue