Look, the launcher is rendered with the new layout parser.

svn-id: r33641
This commit is contained in:
Vicent Marti 2008-08-05 16:23:17 +00:00
parent fdf485ea9b
commit eb3d163439
9 changed files with 85 additions and 52 deletions

View file

@ -36,7 +36,7 @@
namespace GUI { namespace GUI {
bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) { bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
if (name == _name) { if (name == _name) {
x = _x; y = _y; x = _x; y = _y;
w = _w; h = _h; w = _w; h = _h;
@ -46,7 +46,7 @@ bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int1
return false; return false;
} }
bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) { bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
for (uint i = 0; i < _children.size(); ++i) { for (uint i = 0; i < _children.size(); ++i) {
if (_children[i]->getWidgetData(name, x, y, w, h)) if (_children[i]->getWidgetData(name, x, y, w, h))
return true; return true;
@ -83,15 +83,19 @@ void ThemeLayoutVertical::reflowLayout() {
if (i == 0) if (i == 0)
assert(_children[i]->getWidth() != -1); assert(_children[i]->getWidth() != -1);
_children[i]->setX(curX);
_children[i]->setY(curY);
if (_children[i]->getWidth() == -1) if (_children[i]->getWidth() == -1)
_children[i]->setWidth(_w - _paddingLeft - _paddingRight); _children[i]->setWidth(_w - _paddingLeft - _paddingRight);
if (_children[i]->getHeight() == -1) if (_children[i]->getHeight() == -1)
_children[i]->setHeight(getParentH() - _h - _spacing); _children[i]->setHeight(getParentH() - _h - _spacing);
_children[i]->setY(curY);
if (_centered)
_children[i]->setX((_w >> 1) - (_children[i]->getWidth() >> 1));
else
_children[i]->setX(curX);
if (_reverse) { if (_reverse) {
for (int j = i - 1; j >= 0; --j) for (int j = i - 1; j >= 0; --j)
_children[j]->setY(_children[i]->getHeight() + _spacing); _children[j]->setY(_children[i]->getHeight() + _spacing);
@ -122,15 +126,15 @@ void ThemeLayoutHorizontal::reflowLayout() {
if (i == 0) if (i == 0)
assert(_children[i]->getHeight() != -1); assert(_children[i]->getHeight() != -1);
_children[i]->setX(curX);
_children[i]->setY(curY);
if (_children[i]->getHeight() == -1) if (_children[i]->getHeight() == -1)
_children[i]->setHeight(_h - _paddingTop - _paddingBottom); _children[i]->setHeight(_h - _paddingTop - _paddingBottom);
if (_children[i]->getWidth() == -1) if (_children[i]->getWidth() == -1)
_children[i]->setWidth(getParentW() - _w - _spacing); _children[i]->setWidth(getParentW() - _w - _spacing);
_children[i]->setX(curX);
_children[i]->setY(curY);
if (_reverse) { if (_reverse) {
for (int j = i - 1; j >= 0; --j) for (int j = i - 1; j >= 0; --j)
_children[j]->setX(_children[i]->getWidth() + _spacing); _children[j]->setX(_children[i]->getWidth() + _spacing);
@ -172,13 +176,13 @@ void ThemeEval::addDialog(const Common::String &name) {
_curLayout.push(layout); _curLayout.push(layout);
} }
void ThemeEval::addLayout(ThemeLayout::LayoutType type, bool reverse) { void ThemeEval::addLayout(ThemeLayout::LayoutType type, bool reverse, bool center) {
ThemeLayout *layout = 0; ThemeLayout *layout = 0;
if (type == ThemeLayout::kLayoutVertical) if (type == ThemeLayout::kLayoutVertical)
layout = new ThemeLayoutVertical(_curLayout.top(), getVar("Globals.Layout.Spacing", 4), reverse); layout = new ThemeLayoutVertical(_curLayout.top(), getVar("Globals.Layout.Spacing", 4), reverse, center);
else if (type == ThemeLayout::kLayoutHorizontal) else if (type == ThemeLayout::kLayoutHorizontal)
layout = new ThemeLayoutHorizontal(_curLayout.top(), getVar("Globals.Layout.Spacing", 4), reverse); layout = new ThemeLayoutHorizontal(_curLayout.top(), getVar("Globals.Layout.Spacing", 4), reverse, center);
layout->setPadding( layout->setPadding(
getVar("Globals.Padding.Left", 0), getVar("Globals.Padding.Left", 0),
@ -187,8 +191,6 @@ void ThemeEval::addLayout(ThemeLayout::LayoutType type, bool reverse) {
getVar("Globals.Padding.Bottom", 0) getVar("Globals.Padding.Bottom", 0)
); );
layout->setSpacing(4);
_curLayout.top()->addChild(layout); _curLayout.top()->addChild(layout);
_curLayout.push(layout); _curLayout.push(layout);
} }

View file

@ -51,7 +51,8 @@ public:
ThemeLayout(ThemeLayout *p, const Common::String &name) : ThemeLayout(ThemeLayout *p, const Common::String &name) :
_parent(p), _name(name), _x(0), _y(0), _w(-1), _h(-1), _reverse(false), _parent(p), _name(name), _x(0), _y(0), _w(-1), _h(-1), _reverse(false),
_paddingLeft(0), _paddingRight(0), _paddingTop(0), _paddingBottom(0) { } _paddingLeft(0), _paddingRight(0), _paddingTop(0), _paddingBottom(0),
_centered(false) { }
virtual ~ThemeLayout() { virtual ~ThemeLayout() {
_children.clear(); _children.clear();
@ -144,7 +145,7 @@ public:
virtual LayoutType getLayoutType() = 0; virtual LayoutType getLayoutType() = 0;
virtual const char *getName() { return _name.c_str(); } virtual const char *getName() { return _name.c_str(); }
virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h); virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
protected: protected:
int16 _x, _y, _w, _h; int16 _x, _y, _w, _h;
@ -153,6 +154,7 @@ protected:
Common::Array<ThemeLayout*> _children; Common::Array<ThemeLayout*> _children;
ThemeLayout *_parent; ThemeLayout *_parent;
bool _reverse; bool _reverse;
bool _centered;
Common::String _name; Common::String _name;
}; };
@ -166,9 +168,11 @@ public:
class ThemeLayoutVertical : public ThemeLayout { class ThemeLayoutVertical : public ThemeLayout {
public: public:
ThemeLayoutVertical(ThemeLayout *p, int spacing, bool reverse) : ThemeLayout(p, "") { ThemeLayoutVertical(ThemeLayout *p, int spacing, bool reverse, bool center) :
ThemeLayout(p, "") {
_spacing = spacing; _spacing = spacing;
_reverse = reverse; _reverse = reverse;
_centered = center;
} }
void reflowLayout(); void reflowLayout();
@ -178,10 +182,11 @@ public:
class ThemeLayoutHorizontal : public ThemeLayout { class ThemeLayoutHorizontal : public ThemeLayout {
public: public:
ThemeLayoutHorizontal(ThemeLayout *p, int spacing, bool reverse) : ThemeLayoutHorizontal(ThemeLayout *p, int spacing, bool reverse, bool center) :
ThemeLayout(p, "") { ThemeLayout(p, "") {
_spacing = spacing; _spacing = spacing;
_reverse = reverse; _reverse = reverse;
_centered = center;
} }
void reflowLayout(); void reflowLayout();
@ -192,7 +197,7 @@ public:
class ThemeLayoutWidget : public ThemeLayout { class ThemeLayoutWidget : public ThemeLayout {
public: public:
ThemeLayoutWidget(ThemeLayout *p, const Common::String &name) : ThemeLayout(p, name) {} ThemeLayoutWidget(ThemeLayout *p, const Common::String &name) : ThemeLayout(p, name) {}
bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h); bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
void reflowLayout() {} void reflowLayout() {}
LayoutType getLayoutType() { return kLayoutWidget; } LayoutType getLayoutType() { return kLayoutWidget; }
}; };
@ -209,7 +214,7 @@ public:
} }
} }
bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) { return false; } bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) { return false; }
void reflowLayout() {} void reflowLayout() {}
LayoutType getLayoutType() { return kLayoutWidget; } LayoutType getLayoutType() { return kLayoutWidget; }
const char *getName() { return "SPACE"; } const char *getName() { return "SPACE"; }
@ -242,14 +247,27 @@ public:
bool hasVar(const Common::String &name) { return _vars.contains(name); } bool hasVar(const Common::String &name) { return _vars.contains(name); }
void addDialog(const Common::String &name); void addDialog(const Common::String &name);
void addLayout(ThemeLayout::LayoutType type, bool reverse); void addLayout(ThemeLayout::LayoutType type, bool reverse, bool center = false);
void addWidget(const Common::String &name, int w, int h); void addWidget(const Common::String &name, int w, int h);
void addSpacing(int size); void addSpacing(int size);
void addPadding(int16 l, int16 r, int16 t, int16 b) {
_curLayout.top()->setPadding(l, r, t, b);
}
void closeLayout() { _curLayout.pop(); } void closeLayout() { _curLayout.pop(); }
void closeDialog() { _curLayout.pop()->reflowLayout(); } void closeDialog() { _curLayout.pop()->reflowLayout(); }
bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) {
Common::StringTokenizer tokenizer(widget, ".");
Common::String dialogName = "Dialog." + tokenizer.nextToken();
Common::String widgetName = tokenizer.nextToken();
if (!_layouts.contains(dialogName))
return false;
return _layouts[dialogName]->getWidgetData(widgetName, x, y, w, h);
}
void debugPrint() { void debugPrint() {
printf("Debug variable list:\n"); printf("Debug variable list:\n");

View file

@ -501,9 +501,23 @@ bool ThemeParser::parserCallback_dialog(ParserNode *node) {
bool ThemeParser::parserCallback_layout(ParserNode *node) { bool ThemeParser::parserCallback_layout(ParserNode *node) {
if (node->values["type"] == "vertical") if (node->values["type"] == "vertical")
_theme->themeEval()->addLayout(GUI::ThemeLayout::kLayoutVertical, node->values["direction"] == "bottom2top"); _theme->themeEval()->addLayout(GUI::ThemeLayout::kLayoutVertical,
node->values["direction"] == "bottom2top",
node->values["center"] == "true");
else if (node->values["type"] == "horizontal") else if (node->values["type"] == "horizontal")
_theme->themeEval()->addLayout(GUI::ThemeLayout::kLayoutHorizontal, node->values["direction"] == "right2left"); _theme->themeEval()->addLayout(GUI::ThemeLayout::kLayoutHorizontal,
node->values["direction"] == "right2left",
node->values["center"] == "true");
if (node->values.contains("padding")) {
int paddingL, paddingR, paddingT, paddingB;
if (!parseIntegerKey(node->values["padding"].c_str(), 4, &paddingL, &paddingR, &paddingT, &paddingB))
return false;
_theme->themeEval()->addPadding(paddingL, paddingR, paddingT, paddingB);
}
return true; return true;
} }

View file

@ -437,7 +437,7 @@ protected:
XML_PROP(name, true) XML_PROP(name, true)
XML_KEY(layout) XML_KEY(layout)
XML_PROP(type, true) XML_PROP(type, true)
XML_PROP(align, false) XML_PROP(center, false)
XML_PROP(direction, false) XML_PROP(direction, false)
XML_PROP(padding, false) XML_PROP(padding, false)
XML_PROP(spacing, false) XML_PROP(spacing, false)

View file

@ -693,11 +693,11 @@ void ThemeRenderer::updateScreen() {
_textQueue.clear(); _textQueue.clear();
} }
// renderDirtyScreen(); renderDirtyScreen();
_vectorRenderer->fillSurface(); // _vectorRenderer->fillSurface();
themeEval()->debugDraw(_screen, _font); // themeEval()->debugDraw(_screen, _font);
_vectorRenderer->copyWholeFrame(_system); // _vectorRenderer->copyWholeFrame(_system);
} }
void ThemeRenderer::renderDirtyScreen() { void ThemeRenderer::renderDirtyScreen() {

View file

@ -481,35 +481,35 @@ LauncherDialog::LauncherDialog()
#ifndef DISABLE_FANCY_THEMES #ifndef DISABLE_FANCY_THEMES
_logo = 0; _logo = 0;
if (g_gui.evaluator()->getVar("launcher_logo.visible") == 1 && g_gui.theme()->supportsImages()) { if (g_gui.evaluator()->getVar("launcher_logo.visible") == 1 && g_gui.theme()->supportsImages()) {
_logo = new GraphicsWidget(this, "launcher_logo"); _logo = new GraphicsWidget(this, "Launcher.Logo");
_logo->useThemeTransparency(true); _logo->useThemeTransparency(true);
_logo->setGfx(g_gui.theme()->getImageSurface(Theme::kImageLogo)); _logo->setGfx(g_gui.theme()->getImageSurface(Theme::kImageLogo));
new StaticTextWidget(this, "launcher_version", gScummVMVersionDate); new StaticTextWidget(this, "Launcher.Version", gScummVMVersionDate);
} else } else
new StaticTextWidget(this, "launcher_version", gScummVMFullVersion); new StaticTextWidget(this, "Launcher.Version", gScummVMFullVersion);
#else #else
// Show ScummVM version // Show ScummVM version
new StaticTextWidget(this, "launcher_version", gScummVMFullVersion); new StaticTextWidget(this, "Launcher.Version", gScummVMFullVersion);
#endif #endif
new ButtonWidget(this, "launcher_quit_button", "Quit", kQuitCmd, 'Q'); new ButtonWidget(this, "Launcher.QuitButton", "Quit", kQuitCmd, 'Q');
new ButtonWidget(this, "launcher_about_button", "About", kAboutCmd, 'B'); new ButtonWidget(this, "Launcher.AboutButton", "About", kAboutCmd, 'B');
new ButtonWidget(this, "launcher_options_button", "Options", kOptionsCmd, 'O'); new ButtonWidget(this, "Launcher.OptionsButton", "Options", kOptionsCmd, 'O');
_startButton = _startButton =
new ButtonWidget(this, "launcher_start_button", "Start", kStartCmd, 'S'); new ButtonWidget(this, "Launcher.StartButton", "Start", kStartCmd, 'S');
// Above the lowest button rows: two more buttons (directly below the list box) // Above the lowest button rows: two more buttons (directly below the list box)
_addButton = _addButton =
new ButtonWidget(this, "launcher_addGame_button", "Add Game...", kAddGameCmd, 'A'); new ButtonWidget(this, "Launcher.AddGameButton", "Add Game...", kAddGameCmd, 'A');
_editButton = _editButton =
new ButtonWidget(this, "launcher_editGame_button", "Edit Game...", kEditGameCmd, 'E'); new ButtonWidget(this, "Launcher.EditGameButton", "Edit Game...", kEditGameCmd, 'E');
_removeButton = _removeButton =
new ButtonWidget(this, "launcher_removeGame_button", "Remove Game", kRemoveGameCmd, 'R'); new ButtonWidget(this, "Launcher.RemoveGameButton", "Remove Game", kRemoveGameCmd, 'R');
// Add list with game titles // Add list with game titles
_list = new ListWidget(this, "launcher_list"); _list = new ListWidget(this, "Launcher.GameList");
_list->setEditable(false); _list->setEditable(false);
_list->setNumberingMode(kListNumberingOff); _list->setNumberingMode(kListNumberingOff);

View file

@ -58,15 +58,11 @@ enum {
void GuiObject::reflowLayout() { void GuiObject::reflowLayout() {
if (!_name.empty()) { if (!_name.empty()) {
if ((_x = g_gui.evaluator()->getVar(_name + ".x")) == EVAL_UNDEF_VAR) if (!g_gui.xmlEval()->getWidgetData(_name, _x, _y, _w, _h))
error("Undefined variable %s.x", _name.c_str()); error("Could not load widget position for '%s'", _name.c_str());
if ((_y = g_gui.evaluator()->getVar(_name + ".y")) == EVAL_UNDEF_VAR)
error("Undefined variable %s.y", _name.c_str());
_w = g_gui.evaluator()->getVar(_name + ".w");
_h = g_gui.evaluator()->getVar(_name + ".h");
if (_x < 0) if (_x < 0)
error("Widget <%s> has x < 0", _name.c_str()); error("Widget <%s> has x < 0: %d", _name.c_str(), _x);
if (_x >= g_system->getOverlayWidth()) if (_x >= g_system->getOverlayWidth())
error("Widget <%s> has x > %d", _name.c_str(), g_system->getOverlayWidth()); error("Widget <%s> has x > %d", _name.c_str(), g_system->getOverlayWidth());
if (_x + _w > g_system->getOverlayWidth()) if (_x + _w > g_system->getOverlayWidth())

File diff suppressed because one or more lines are too long

View file

@ -465,7 +465,7 @@
</globals> </globals>
<dialog name = 'Launcher'> <dialog name = 'Launcher'>
<layout type = 'vertical' align = 'center'> <layout type = 'vertical' center = 'true' padding = '23, 23, 8, 23'>
<widget name = 'Version' <widget name = 'Version'
width = '247' width = '247'
height = 'Globals.Line.Height' height = 'Globals.Line.Height'
@ -474,12 +474,13 @@
width = '283' width = '283'
height = '80' height = '80'
/> />
<layout type = 'horizontal' direction = 'right2left'> <layout type = 'horizontal' direction = 'right2left' padding = '0, 0, 0, 0'>
<layout type = 'vertical'> <layout type = 'vertical' padding = '16, 0, 0, 0'>
<widget name = 'StartButton' <widget name = 'StartButton'
width = 'Globals.Button.Width' width = 'Globals.Button.Width'
height = 'Globals.Button.Height' height = 'Globals.Button.Height'
/> />
<space size = '16' />
<widget name = 'AddGameButton' <widget name = 'AddGameButton'
width = 'Globals.Button.Width' width = 'Globals.Button.Width'
height = 'Globals.Button.Height' height = 'Globals.Button.Height'
@ -492,6 +493,7 @@
width = 'Globals.Button.Width' width = 'Globals.Button.Width'
height = 'Globals.Button.Height' height = 'Globals.Button.Height'
/> />
<space size = '16' />
<widget name = 'OptionsButton' <widget name = 'OptionsButton'
width = 'Globals.Button.Width' width = 'Globals.Button.Width'
height = 'Globals.Button.Height' height = 'Globals.Button.Height'
@ -500,7 +502,8 @@
width = 'Globals.Button.Width' width = 'Globals.Button.Width'
height = 'Globals.Button.Height' height = 'Globals.Button.Height'
/> />
<widget name = 'QuittButton' <space size = '16' />
<widget name = 'QuitButton'
width = 'Globals.Button.Width' width = 'Globals.Button.Width'
height = 'Globals.Button.Height' height = 'Globals.Button.Height'
/> />