From c31a9d36ed570fa1c93c206e1d57713016e4117f Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Mon, 15 Nov 2010 19:19:18 +0000 Subject: [PATCH] Add missing files from 2010-11-15T03:41:42Z!shadowm@wesnoth.org so Wesnoth compiles again --- src/gui/auxiliary/old_markup.cpp | 56 ++++++++++++++++++++++++++ src/gui/auxiliary/old_markup.hpp | 69 ++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/gui/auxiliary/old_markup.cpp create mode 100644 src/gui/auxiliary/old_markup.hpp diff --git a/src/gui/auxiliary/old_markup.cpp b/src/gui/auxiliary/old_markup.cpp new file mode 100644 index 00000000000..a4578e5eeab --- /dev/null +++ b/src/gui/auxiliary/old_markup.cpp @@ -0,0 +1,56 @@ +/* $Id$ */ +/* + Copyright (C) 2008 - 2010 by Mark de Wever + 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); + } + +} + +} diff --git a/src/gui/auxiliary/old_markup.hpp b/src/gui/auxiliary/old_markup.hpp new file mode 100644 index 00000000000..7c59368b984 --- /dev/null +++ b/src/gui/auxiliary/old_markup.hpp @@ -0,0 +1,69 @@ +/* $Id$ */ +/* + Copyright (C) 2008 - 2010 by Mark de Wever + 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 + +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