The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
old_markup.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
17 namespace gui2
18 {
19 
21  : icon_(), label_(str), desc_(), default_(false)
22 {
23  if(label_.empty()) {
24  return;
25  }
26 
27  // Handle selection.
28  if(label_[0] == '*') {
29  default_ = true;
30  label_.erase(0, 1);
31  }
32 
33  // Handle the special case with an image.
34  std::string::size_type pos = label_.find('=');
35  if(pos != std::string::npos && (label_[0] == '&' || pos == 0)) {
36  if(pos)
37  icon_ = label_.substr(1, pos - 1);
38  label_.erase(0, pos + 1);
39  }
40 
41  // Search for an '=' symbol that is not inside markup.
42  std::string::size_type prev = 0;
43  bool open = false;
44  while((pos = label_.find('=', prev)) != std::string::npos) {
45  for(std::string::size_type i = prev; i != pos; ++i) {
46  switch(label_[i]) {
47  case '<':
48  open = true;
49  break;
50  case '>':
51  open = false;
52  break;
53  }
54  }
55  if(!open)
56  break;
57  prev = pos + 1;
58  }
59  if(pos != std::string::npos) {
60  desc_ = label_.substr(pos + 1);
61  label_.erase(pos);
62  }
63 }
64 }
std::string icon_
The icon for the menu item.
Definition: old_markup.hpp:77
std::string label_
The first text item of the menu item, normally a short string.
Definition: old_markup.hpp:80
bool default_
Is the item the default item and thus initially selected.
Definition: old_markup.hpp:90
int pos
Definition: formula.cpp:800
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
std::string desc_
The second text item of the menu item, normally a longer string.
Definition: old_markup.hpp:83
tlegacy_menu_item(const std::string &str=std::string())
Definition: old_markup.cpp:20
size_t i
Definition: function.cpp:1057
map_location prev
Definition: astarsearch.cpp:67
GLsizei const GLcharARB ** string
Definition: glew.h:4503