The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
help_menu.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[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 
15 #ifndef INCLUDED_HELP_MENU
16 #define INCLUDED_HELP_MENU
17 
18 #include <set> // for set
19 #include <string> // for string, basic_string
20 #include <vector> // for vector
21 #include "sdl/utils.hpp" // for surface_restorer
22 #include "widgets/menu.hpp" // for menu
23 class CVideo;
24 namespace help { struct section; }
25 namespace help { struct topic; }
26 
27 namespace help {
28 
29 /// The menu to the left in the help browser, where topics can be
30 /// navigated through and chosen.
31 class help_menu : public gui::menu
32 {
33 public:
34  help_menu(CVideo &video, const section &toplevel, int max_height=-1);
35  int process();
36 
37  /// Make the topic the currently selected one, and expand all
38  /// sections that need to be expanded to show it.
39  void select_topic(const topic &t);
40 
41  /// If a topic has been chosen, return that topic, otherwise
42  /// nullptr. If one topic is returned, it will not be returned again,
43  /// if it is not re-chosen.
44  const topic *chosen_topic();
45 
46 private:
47  /// Information about an item that is visible in the menu.
48  struct visible_item {
49  visible_item(const section *_sec, const std::string &visible_string);
50  visible_item(const topic *_t, const std::string &visible_string);
51  // Invariant, one if these should be nullptr. The constructors
52  // enforce it.
53  const topic *t;
54  const section *sec;
56  bool operator==(const visible_item &vis_item) const;
57  bool operator==(const section &sec) const;
58  bool operator==(const topic &t) const;
59  };
60 
61  /// Regenerate what items are visible by checking what sections are
62  /// expanded.
63  void update_visible_items(const section &top_level, unsigned starting_level=0);
64 
65  /// Return true if the section is expanded.
66  bool expanded(const section &sec);
67 
68  /// Mark a section as expanded. Do not update the visible items or
69  /// anything.
70  void expand(const section &sec);
71 
72  /// Contract (close) a section. That is, mark it as not expanded,
73  /// visible items are not updated.
74  void contract(const section &sec);
75 
76  /// Return the string to use as the prefix for the icon part of the
77  /// menu-string at the specified level.
78  std::string indent_list(const std::string &icon, const unsigned level);
79  /// Return the string to use as the menu-string for sections at the
80  /// specified level.
81  std::string get_string_to_show(const section &sec, const unsigned level);
82  /// Return the string to use as the menu-string for topics at the
83  /// specified level.
84  std::string get_string_to_show(const topic &topic, const unsigned level);
85 
86  /// Draw the currently visible items.
87  void display_visible_items();
88 
89  /// Internal recursive thingie. did_expand will be true if any
90  /// section was expanded, otherwise untouched.
91  bool select_topic_internal(const topic &t, const section &sec);
92 
93  std::vector<visible_item> visible_items_;
95  std::set<const section*> expanded_;
99 };
100 
101 } // end namespace help
102 
103 #endif
void contract(const section &sec)
Contract (close) a section.
Definition: help_menu.cpp:60
surface_restorer restorer_
Definition: help_menu.hpp:96
std::string get_string_to_show(const section &sec, const unsigned level)
Return the string to use as the menu-string for sections at the specified level.
Definition: help_menu.cpp:102
visible_item selected_item_
Definition: help_menu.hpp:98
topic const * chosen_topic_
Definition: help_menu.hpp:97
visible_item(const section *_sec, const std::string &visible_string)
Definition: help_menu.cpp:217
GLint level
Definition: glew.h:1220
A section contains topics and sections along with title and ID.
Definition: help_impl.hpp:143
Definition: video.hpp:58
help::section toplevel
Definition: help_impl.cpp:66
CVideo & video() const
Definition: widget.hpp:83
bool expanded(const section &sec)
Return true if the section is expanded.
Definition: help_menu.cpp:48
GLdouble GLdouble t
Definition: glew.h:1366
void display_visible_items()
Draw the currently visible items.
Definition: help_menu.cpp:204
bool operator==(const visible_item &vis_item) const
Definition: help_menu.cpp:233
const section & toplevel_
Definition: help_menu.hpp:94
std::string indent_list(const std::string &icon, const unsigned level)
Return the string to use as the prefix for the icon part of the menu-string at the specified level...
Definition: help_menu.cpp:92
Information about an item that is visible in the menu.
Definition: help_menu.hpp:48
void expand(const section &sec)
Mark a section as expanded.
Definition: help_menu.cpp:53
help_menu(CVideo &video, const section &toplevel, int max_height=-1)
Definition: help_menu.cpp:32
std::set< const section * > expanded_
Definition: help_menu.hpp:95
std::vector< visible_item > visible_items_
Definition: help_menu.hpp:93
void select_topic(const topic &t)
Make the topic the currently selected one, and expand all sections that need to be expanded to show i...
Definition: help_menu.cpp:139
The menu to the left in the help browser, where topics can be navigated through and chosen...
Definition: help_menu.hpp:31
A topic contains a title, an id and some text.
Definition: help_impl.hpp:111
void update_visible_items(const section &top_level, unsigned starting_level=0)
Regenerate what items are visible by checking what sections are expanded.
Definition: help_menu.cpp:67
const topic * chosen_topic()
If a topic has been chosen, return that topic, otherwise nullptr.
Definition: help_menu.cpp:197
Definition: help.cpp:57
bool select_topic_internal(const topic &t, const section &sec)
Internal recursive thingie.
Definition: help_menu.cpp:118
GLsizei const GLcharARB ** string
Definition: glew.h:4503