Add missing files from 2010-11-15T03:41:42Z!shadowm@wesnoth.org so Wesnoth compiles again

This commit is contained in:
Ignacio R. Morelle 2010-11-15 19:19:18 +00:00
parent 28768c71ef
commit c31a9d36ed
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,56 @@
/* $Id$ */
/*
Copyright (C) 2008 - 2010 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "gui/auxiliary/old_markup.hpp"
namespace gui2 {
legacy_menu_item::legacy_menu_item(const std::string& str)
: icon_(), label_(str), desc_(), default_(false)
{
// Handle selection.
if(!label_.empty() && label_[0] == '*') {
default_ = true;
label_.erase(0, 1);
}
// Handle the special case with an image.
std::string::size_type pos = label_.find('=');
if (pos != std::string::npos && (label_[0] == '&' || pos == 0)) {
if (pos) icon_ = label_.substr(1, pos - 1);
label_.erase(0, pos + 1);
}
// Search for an '=' symbol that is not inside markup.
std::string::size_type prev = 0;
bool open = false;
while ((pos = label_.find('=', prev)) != std::string::npos) {
for (std::string::size_type i = prev; i != pos; ++i) {
switch (label_[i]) {
case '<': open = true; break;
case '>': open = false; break;
}
}
if (!open) break;
prev = pos + 1;
}
if (pos != std::string::npos) {
desc_ = label_.substr(pos + 1);
label_.erase(pos);
}
}
}

View File

@ -0,0 +1,69 @@
/* $Id$ */
/*
Copyright (C) 2008 - 2010 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_AUXILIARY_OLD_MARKUP_INCLUDED
#define GUI_AUXILIARY_OLD_MARKUP_INCLUDED
#include <string>
namespace gui2
{
/**
* Implements simple parsing of legacy GUI1 item markup.
*/
class legacy_menu_item
{
/*
* Legacy options/menu items have some special markup:
* A line starting with a * is selected by default.
* A line starting with a & enables the following markup:
* - The part until the = is the name of an image.
* - The part until the second = is the first column.
* - The rest is the third column (the wiki only specifies two columns
* so only two of them are implemented).
*/
/**
* @todo This syntax looks like a bad hack, it would be nice to write
* a new syntax which doesn't use those hacks (also avoids the problem
* with special meanings for certain characters.
*/
public:
legacy_menu_item(const std::string& str);
const std::string& icon() const {
return icon_;
}
const std::string& label() const {
return label_;
}
const std::string& description() const {
return desc_;
}
bool is_default() const {
return default_;
}
private:
std::string icon_, label_, desc_;
bool default_;
};
}
#endif