The Battle for Wesnoth  1.17.12+dev
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
help::help_menu Class Reference

The menu to the left in the help browser, where topics can be navigated through and chosen. More...

#include <help_menu.hpp>

Inheritance diagram for help::help_menu:

Classes

struct  visible_item
 Information about an item that is visible in the menu. More...
 

Public Member Functions

 help_menu (const section &toplevel, int max_height=-1)
 
int process ()
 
void select_topic (const topic &t)
 Make the topic the currently selected one, and expand all sections that need to be expanded to show it. More...
 
const topicchosen_topic ()
 If a topic has been chosen, return that topic, otherwise nullptr. More...
 
- Public Member Functions inherited from gui::menu
 menu (const std::vector< std::string > &items, bool click_selects=false, int max_height=-1, int max_width=-1, const sorter *sorter_obj=nullptr, style *menu_style=nullptr, const bool auto_join=true)
 
 ~menu ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
int selection () const
 
void move_selection (std::size_t id)
 
void move_selection_keeping_viewport (std::size_t id)
 
void reset_selection ()
 
void change_item (int pos1, int pos2, const std::string &str)
 
virtual void erase_item (std::size_t index)
 
void set_heading (const std::vector< std::string > &heading)
 
virtual void set_items (const std::vector< std::string > &items, bool strip_spaces=true, bool keep_viewport=false)
 Set new items to show and redraw/recalculate everything. More...
 
void set_max_height (const int new_max_height)
 Set a new max height for this menu. More...
 
void set_max_width (const int new_max_width)
 
int get_max_height () const
 
int get_max_width () const
 
std::size_t number_of_items () const
 
int process ()
 
bool double_clicked ()
 
void set_click_selects (bool value)
 
void set_numeric_keypress_selection (bool value)
 
void scroll (unsigned int pos) override
 
void set_sorter (sorter *s)
 
void sort_by (int column)
 
int get_sort_by () const
 
bool get_sort_reversed () const
 
- Public Member Functions inherited from gui::scrollarea
 scrollarea (bool auto_join=true)
 Create a zone with automatic handling of scrollbar. More...
 
virtual void hide (bool value=true)
 
- Public Member Functions inherited from gui::widget
const rectlocation () const
 
virtual void set_location (const SDL_Rect &rect)
 
void set_location (int x, int y)
 
void set_width (int w)
 
void set_height (int h)
 
void set_measurements (int w, int h)
 
int width () const
 
int height () const
 
bool focus (const SDL_Event *event)
 
void set_focus (bool focus)
 
bool hidden () const
 
virtual void enable (bool new_val=true)
 
bool enabled () const
 
void set_clip_rect (const SDL_Rect &rect)
 
void queue_redraw ()
 Indicate that the widget should be redrawn. More...
 
void queue_redraw (const rect &)
 Indicate that a specific region of the screen should be redrawn. More...
 
void set_dirty (bool dirty=true)
 
bool dirty () const
 
const std::string & id () const
 
void set_id (const std::string &id)
 
void set_help_string (const std::string &str)
 
void set_tooltip_string (const std::string &str)
 
virtual void process_tooltip_string (int mousex, int mousey) override
 
virtual void layout () override
 Called by draw_manager to validate layout. More...
 
virtual bool expose (const rect &region) override
 Called by draw_manager when it believes a redraw is necessary. More...
 
virtual rect screen_location () override
 The current draw location of the display, on the screen. More...
 
- Public Member Functions inherited from events::sdl_handler
virtual void handle_window_event (const SDL_Event &)
 
virtual void join ()
 
virtual void join (context &c)
 
virtual void join_same (sdl_handler *parent)
 
virtual void leave ()
 
virtual void join_global ()
 
virtual void leave_global ()
 
virtual bool has_joined ()
 
virtual bool has_joined_global ()
 
sdl_handleroperator= (sdl_handler &&)=delete
 Moving would require two instances' context membership to be handled, it's simpler to delete these and require the two instances to be separately constructed / destructed. More...
 
 sdl_handler (sdl_handler &&)=delete
 
- Public Member Functions inherited from gui2::top_level_drawable
virtual void update ()
 Update state and any parameters that may effect layout, or any of the later stages. More...
 
virtual void render ()
 Perform any internal rendering necessary to prepare the drawable. More...
 

Private Member Functions

void update_visible_items (const section &top_level, unsigned starting_level=0)
 Regenerate what items are visible by checking what sections are expanded. More...
 
bool expanded (const section &sec)
 Return true if the section is expanded. More...
 
void expand (const section &sec)
 Mark a section as expanded. More...
 
void contract (const section &sec)
 Contract (close) a section. More...
 
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. More...
 
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. More...
 
std::string get_string_to_show (const topic &topic, const unsigned level)
 Return the string to use as the menu-string for topics at the specified level. More...
 
void display_visible_items ()
 Draw the currently visible items. More...
 
bool select_topic_internal (const topic &t, const section &sec)
 Internal recursive thingie. More...
 

Private Attributes

std::vector< visible_itemvisible_items_
 
const sectiontoplevel_
 
std::set< const section * > expanded_
 
topic const * chosen_topic_
 
visible_item selected_item_
 

Additional Inherited Members

- Public Types inherited from gui::menu
enum  ROW_TYPE { NORMAL_ROW, SELECTED_ROW, HEADING_ROW }
 
- Static Public Attributes inherited from gui::menu
static styledefault_style = menu::bluebg_style
 
static imgsel_style bluebg_style
 
- Protected Member Functions inherited from gui::menu
bool item_ends_with_image (const std::string &item) const
 
virtual void handle_event (const SDL_Event &event) override
 
void set_inner_location (const SDL_Rect &rect) override
 
bool requires_event_focus (const SDL_Event *event=nullptr) const override
 
const std::vector< int > & column_widths () const
 
virtual void draw_row (const std::size_t row_index, const SDL_Rect &rect, ROW_TYPE type)
 
int hit (int x, int y) const
 
std::pair< int, int > hit_cell (int x, int y) const
 
int hit_column (int x) const
 
int hit_heading (int x, int y) const
 
void invalidate_row (std::size_t id)
 
void invalidate_row_pos (std::size_t pos)
 
void invalidate_heading ()
 
- Protected Member Functions inherited from gui::scrollarea
virtual sdl_handler_vector handler_members ()
 
virtual void update_location (const SDL_Rect &rect)
 
virtual void process_event ()
 
rect inner_location () const
 
unsigned scrollbar_width () const
 
unsigned get_position () const
 
unsigned get_max_position () const
 
void set_position (unsigned pos)
 
void adjust_position (unsigned pos)
 
void move_position (int dep)
 
void set_shown_size (unsigned h)
 
void set_full_size (unsigned h)
 
void set_scroll_rate (unsigned r)
 
bool has_scrollbar () const
 
- Protected Member Functions inherited from gui::widget
 widget (const bool auto_join=true)
 
virtual ~widget ()
 
bool mouse_locked () const
 
void aquire_mouse_lock ()
 
void free_mouse_lock ()
 
- Protected Member Functions inherited from events::sdl_handler
 sdl_handler (const bool auto_join=true)
 
 sdl_handler (const sdl_handler &)
 
sdl_handleroperator= (const sdl_handler &)
 
virtual ~sdl_handler ()
 
- Protected Member Functions inherited from gui2::top_level_drawable
 top_level_drawable ()
 
virtual ~top_level_drawable ()
 
 top_level_drawable (const top_level_drawable &)
 
top_level_drawableoperator= (const top_level_drawable &)
 
 top_level_drawable (top_level_drawable &&)
 
top_level_drawableoperator= (top_level_drawable &&)
 
- Protected Attributes inherited from gui::menu
stylestyle_
 
bool silent_
 
- Protected Attributes inherited from gui::widget
bool focus_
 

Detailed Description

The menu to the left in the help browser, where topics can be navigated through and chosen.

Definition at line 32 of file help_menu.hpp.

Constructor & Destructor Documentation

◆ help_menu()

help::help_menu::help_menu ( const section toplevel,
int  max_height = -1 
)

Member Function Documentation

◆ chosen_topic()

const topic * help::help_menu::chosen_topic ( )

If a topic has been chosen, return that topic, otherwise nullptr.

If one topic is returned, it will not be returned again, if it is not re-chosen.

Definition at line 196 of file help_menu.cpp.

References chosen_topic_.

Referenced by help::help_browser::process_event().

◆ contract()

void help::help_menu::contract ( const section sec)
private

Contract (close) a section.

That is, mark it as not expanded, visible items are not updated.

Definition at line 58 of file help_menu.cpp.

References expanded_, game_config::sounds::menu_contract, and sound::play_UI_sound().

Referenced by process().

◆ display_visible_items()

void help::help_menu::display_visible_items ( )
private

Draw the currently visible items.

Definition at line 203 of file help_menu.cpp.

References selected_item_, gui::menu::set_items(), and visible_items_.

Referenced by help_menu(), process(), and select_topic().

◆ expand()

void help::help_menu::expand ( const section sec)
private

Mark a section as expanded.

Do not update the visible items or anything.

Definition at line 51 of file help_menu.cpp.

References expanded_, help::section::id, game_config::sounds::menu_expand, and sound::play_UI_sound().

Referenced by process(), and select_topic_internal().

◆ expanded()

bool help::help_menu::expanded ( const section sec)
private

Return true if the section is expanded.

Definition at line 46 of file help_menu.cpp.

References expanded_.

Referenced by get_string_to_show(), process(), and update_visible_items().

◆ get_string_to_show() [1/2]

std::string help::help_menu::get_string_to_show ( const section sec,
const unsigned  level 
)
private

Return the string to use as the menu-string for sections at the specified level.

Definition at line 98 of file help_menu.cpp.

References help::closed_section_img, expanded(), IMG_TEXT_SEPARATOR, indent_list(), help::open_section_img, and help::section::title.

Referenced by update_visible_items().

◆ get_string_to_show() [2/2]

std::string help::help_menu::get_string_to_show ( const topic topic,
const unsigned  level 
)
private

Return the string to use as the menu-string for topics at the specified level.

Definition at line 106 of file help_menu.cpp.

References IMG_TEXT_SEPARATOR, indent_list(), help::topic::title, and help::topic_img.

◆ indent_list()

std::string help::help_menu::indent_list ( const std::string &  icon,
const unsigned  level 
)
private

Return the string to use as the prefix for the icon part of the menu-string at the specified level.

Definition at line 88 of file help_menu.cpp.

References i, IMAGE_PREFIX, IMG_TEXT_SEPARATOR, and game_config::images::level.

Referenced by get_string_to_show(), and process().

◆ process()

int help::help_menu::process ( )

◆ select_topic()

void help::help_menu::select_topic ( const topic t)

Make the topic the currently selected one, and expand all sections that need to be expanded to show it.

Definition at line 134 of file help_menu.cpp.

References display_visible_items(), select_topic_internal(), selected_item_, toplevel_, update_visible_items(), and visible_items_.

Referenced by help::help_browser::show_topic().

◆ select_topic_internal()

bool help::help_menu::select_topic_internal ( const topic t,
const section sec 
)
private

Internal recursive thingie.

did_expand will be true if any section was expanded, otherwise untouched.

Definition at line 114 of file help_menu.cpp.

References expand(), help::topic::id, s, help::section::sections, t, and help::section::topics.

Referenced by select_topic().

◆ update_visible_items()

void help::help_menu::update_visible_items ( const section top_level,
unsigned  starting_level = 0 
)
private

Regenerate what items are visible by checking what sections are expanded.

Definition at line 65 of file help_menu.cpp.

References expanded(), get_string_to_show(), help::is_visible_id(), s, help::section::sections, t, help::section::topics, and visible_items_.

Referenced by help_menu(), process(), and select_topic().

Member Data Documentation

◆ chosen_topic_

topic const* help::help_menu::chosen_topic_
private

Definition at line 104 of file help_menu.hpp.

Referenced by chosen_topic(), and process().

◆ expanded_

std::set<const section*> help::help_menu::expanded_
private

Definition at line 103 of file help_menu.hpp.

Referenced by contract(), expand(), and expanded().

◆ selected_item_

visible_item help::help_menu::selected_item_
private

Definition at line 105 of file help_menu.hpp.

Referenced by display_visible_items(), help_menu(), process(), and select_topic().

◆ toplevel_

const section& help::help_menu::toplevel_
private

Definition at line 102 of file help_menu.hpp.

Referenced by help_menu(), process(), and select_topic().

◆ visible_items_

std::vector<visible_item> help::help_menu::visible_items_
private

The documentation for this class was generated from the following files: