The Battle for Wesnoth
1.15.11+dev
help
help_menu.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3
Part of the Battle for Wesnoth Project https://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
#pragma once
16
17
#include <set>
// for set
18
#include <string>
// for string, basic_string
19
#include <vector>
// for vector
20
#include "
widgets/menu.hpp
"
// for menu
21
22
class
CVideo
;
23
struct
surface_restorer
;
24
25
namespace
help
{
struct
section; }
26
namespace
help
{
struct
topic; }
27
28
namespace
help
{
29
30
/**
31
* The menu to the left in the help browser, where topics can be
32
* navigated through and chosen.
33
*/
34
class
help_menu
:
public
gui::menu
35
{
36
public
:
37
help_menu
(
CVideo
&
video
,
const
section
&toplevel,
int
max_height=-1);
38
int
process
();
39
40
/**
41
* Make the topic the currently selected one, and expand all
42
* sections that need to be expanded to show it.
43
*/
44
void
select_topic
(
const
topic
&
t
);
45
46
/**
47
* If a topic has been chosen, return that topic, otherwise
48
* nullptr. If one topic is returned, it will not be returned again,
49
* if it is not re-chosen.
50
*/
51
const
topic
*
chosen_topic
();
52
53
private
:
54
/** Information about an item that is visible in the menu. */
55
struct
visible_item
{
56
visible_item
(
const
section
*_sec,
const
std::string &
visible_string
,
int
level
);
57
visible_item
(
const
topic
*_t,
const
std::string &visible_string,
int
level);
58
// Invariant, one if these should be nullptr. The constructors
59
// enforce it.
60
const
topic
*
t
;
61
const
section
*
sec
;
62
std::string
visible_string
;
63
int
level
;
64
bool
operator==
(
const
visible_item
&vis_item)
const
;
65
bool
operator==
(
const
section
&sec)
const
;
66
bool
operator==
(
const
topic
&t)
const
;
67
};
68
69
/** Regenerate what items are visible by checking what sections are expanded. */
70
void
update_visible_items
(
const
section
&top_level,
unsigned
starting_level=0);
71
72
/** Return true if the section is expanded. */
73
bool
expanded
(
const
section
&
sec
);
74
75
/** Mark a section as expanded. Do not update the visible items or anything. */
76
void
expand
(
const
section
&
sec
);
77
78
/**
79
* Contract (close) a section. That is, mark it as not expanded,
80
* visible items are not updated.
81
*/
82
void
contract
(
const
section
&
sec
);
83
84
/**
85
* Return the string to use as the prefix for the icon part of the
86
* menu-string at the specified level.
87
*/
88
std::string
indent_list
(
const
std::string &icon,
const
unsigned
level
);
89
/** Return the string to use as the menu-string for sections at the specified level. */
90
std::string
get_string_to_show
(
const
section
&
sec
,
const
unsigned
level
);
91
/** Return the string to use as the menu-string for topics at the specified level. */
92
std::string
get_string_to_show
(
const
topic
&
topic
,
const
unsigned
level
);
93
94
/** Draw the currently visible items. */
95
void
display_visible_items
();
96
97
/**
98
* Internal recursive thingie. did_expand will be true if any
99
* section was expanded, otherwise untouched.
100
*/
101
bool
select_topic_internal
(
const
topic
&t,
const
section
&
sec
);
102
103
std::vector<visible_item>
visible_items_
;
104
const
section
&
toplevel_
;
105
std::set<const section*>
expanded_
;
106
surface_restorer
restorer_
;
107
topic
const
*
chosen_topic_
;
108
visible_item
selected_item_
;
109
};
110
111
}
// end namespace help
help::help_menu::contract
void contract(const section &sec)
Contract (close) a section.
Definition:
help_menu.cpp:60
help::help_menu::restorer_
surface_restorer restorer_
Definition:
help_menu.hpp:106
help::help_menu::get_string_to_show
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:100
help::help_menu::selected_item_
visible_item selected_item_
Definition:
help_menu.hpp:108
help::help_menu::chosen_topic_
topic const * chosen_topic_
Definition:
help_menu.hpp:107
help::section
A section contains topics and sections along with title and ID.
Definition:
help_impl.hpp:145
CVideo
Definition:
video.hpp:31
surface_restorer
Definition:
surface.hpp:119
help::help_menu::process
int process()
Definition:
help_menu.cpp:155
help::help_menu::expanded
bool expanded(const section &sec)
Return true if the section is expanded.
Definition:
help_menu.cpp:48
help::help_menu::visible_item::visible_item
visible_item(const section *_sec, const std::string &visible_string, int level)
Definition:
help_menu.cpp:218
help::help_menu::display_visible_items
void display_visible_items()
Draw the currently visible items.
Definition:
help_menu.cpp:205
help::help_menu::toplevel_
const section & toplevel_
Definition:
help_menu.hpp:104
help::help_menu::indent_list
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:90
help::help_menu::visible_item
Information about an item that is visible in the menu.
Definition:
help_menu.hpp:55
help::help_menu::expand
void expand(const section &sec)
Mark a section as expanded.
Definition:
help_menu.cpp:53
help::help_menu::help_menu
help_menu(CVideo &video, const section &toplevel, int max_height=-1)
Definition:
help_menu.cpp:32
help::help_menu::expanded_
std::set< const section * > expanded_
Definition:
help_menu.hpp:105
help::help_menu::visible_item::level
int level
Definition:
help_menu.hpp:63
help::help_menu::visible_items_
std::vector< visible_item > visible_items_
Definition:
help_menu.hpp:103
help::help_menu::visible_item::operator==
bool operator==(const visible_item &vis_item) const
Definition:
help_menu.cpp:234
help::help_menu::select_topic
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:136
gui::widget::video
CVideo & video() const
Definition:
widget.hpp:83
t
double t
Definition:
astarsearch.cpp:64
gui::menu
Definition:
menu.hpp:28
help::help_menu
The menu to the left in the help browser, where topics can be navigated through and chosen...
Definition:
help_menu.hpp:34
help::help_menu::visible_item::visible_string
std::string visible_string
Definition:
help_menu.hpp:62
help::topic
A topic contains a title, an id and some text.
Definition:
help_impl.hpp:111
help::help_menu::update_visible_items
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
help::help_menu::chosen_topic
const topic * chosen_topic()
If a topic has been chosen, return that topic, otherwise nullptr.
Definition:
help_menu.cpp:198
help
Definition:
help.cpp:55
help::help_menu::select_topic_internal
bool select_topic_internal(const topic &t, const section &sec)
Internal recursive thingie.
Definition:
help_menu.cpp:116
menu.hpp
help::help_menu::visible_item::t
const topic * t
Definition:
help_menu.hpp:60
help::help_menu::visible_item::sec
const section * sec
Definition:
help_menu.hpp:61
Generated by
1.8.13