The Battle for Wesnoth  1.15.2+dev
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
help::help_text_area Class Reference

The area where the content is shown in the help browser. More...

#include <help_text_area.hpp>

Inheritance diagram for help::help_text_area:
Inheritance graph

Classes

struct  item
 An item that is displayed in the text area. More...
 
class  item_at
 Function object to find an item at the specified coordinates. More...
 

Public Member Functions

 help_text_area (CVideo &video, const section &toplevel)
 
void show_topic (const topic &t)
 Display the topic. More...
 
std::string ref_at (const int x, const int y)
 Return the ID that is cross-referenced at the (screen) coordinates x, y. More...
 
- Public Member Functions inherited from gui::scrollarea
 scrollarea (CVideo &video, 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 SDL_Rect & location () 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 set_volatile (bool val=true)
 
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_help_string (int mousex, int mousey)
 
virtual void process_tooltip_string (int mousex, int mousey)
 
virtual void draw ()
 
- Public Member Functions inherited from events::sdl_handler
virtual bool requires_event_focus (const SDL_Event *=nullptr) const
 
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
 

Protected Member Functions

virtual void scroll (unsigned int pos)
 
virtual void set_inner_location (const SDL_Rect &rect)
 
- Protected Member Functions inherited from gui::scrollarea
virtual sdl_handler_vector handler_members ()
 
virtual void update_location (const SDL_Rect &rect)
 
virtual void handle_event (const SDL_Event &event)
 
virtual void process_event ()
 
SDL_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 (CVideo &video, const bool auto_join=true)
 
virtual ~widget ()
 
void bg_register (const SDL_Rect &rect)
 
void bg_restore () const
 
void bg_restore (const SDL_Rect &rect) const
 
void bg_update ()
 
void bg_cancel ()
 
CVideovideo () const
 
const SDL_Rect * clip_rect () const
 
virtual sdl_handler_vector member_handlers ()
 
virtual void handle_window_event (const SDL_Event &event)
 
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 ()
 

Private Types

enum  ALIGNMENT { LEFT, MIDDLE, RIGHT, HERE }
 

Private Member Functions

ALIGNMENT str_to_align (const std::string &s)
 Convert a string to an alignment. More...
 
void set_items ()
 Update the vector with the items of the shown topic, creating surfaces for everything and putting things where they belong. More...
 
void handle_ref_cfg (const config &cfg)
 
void handle_img_cfg (const config &cfg)
 
void handle_bold_cfg (const config &cfg)
 
void handle_italic_cfg (const config &cfg)
 
void handle_header_cfg (const config &cfg)
 
void handle_jump_cfg (const config &cfg)
 
void handle_format_cfg (const config &cfg)
 
void draw_contents ()
 
void add_text_item (const std::string &text, const std::string &ref_dst="", bool broken_link=false, int font_size=-1, bool bold=false, bool italic=false, color_t color=font::NORMAL_COLOR)
 Add an item with text. More...
 
void add_img_item (const std::string &path, const std::string &alignment, const bool floating, const bool box)
 Add an image item with the specified attributes. More...
 
void down_one_line ()
 Move the current input point to the next line. More...
 
void adjust_last_row ()
 Adjust the heights of the items in the last row to make it look good . More...
 
int get_remaining_width ()
 Return the width that remain on the line the current input point is at. More...
 
int get_min_x (const int y, const int height=0)
 Return the least x coordinate at which something of the specified height can be drawn at the specified y coordinate without interfering with floating images. More...
 
int get_max_x (const int y, const int height=0)
 Analogous with get_min_x but return the maximum X. More...
 
int get_y_for_floating_img (const int width, const int x, const int desired_y)
 Find the lowest y coordinate where a floating img of the specified width and at the specified x coordinate can be placed. More...
 
void add_item (const item &itm)
 Add an item to the internal list, update the locations and row height. More...
 

Private Attributes

std::list< itemitems_
 
std::list< item * > last_row_
 
const sectiontoplevel_
 
topic const * shown_topic_
 
const int title_spacing_
 
std::pair< int, int > curr_loc_
 
const unsigned min_row_height_
 
unsigned curr_row_height_
 
int contents_height_
 The height of all items in total. More...
 

Additional Inherited Members

- Protected Attributes inherited from gui::widget
bool focus_
 

Detailed Description

The area where the content is shown in the help browser.

Definition at line 32 of file help_text_area.hpp.

Member Enumeration Documentation

◆ ALIGNMENT

Enumerator
LEFT 
MIDDLE 
RIGHT 
HERE 

Definition at line 49 of file help_text_area.hpp.

Constructor & Destructor Documentation

◆ help_text_area()

help::help_text_area::help_text_area ( CVideo video,
const section toplevel 
)

Definition at line 41 of file help_text_area.cpp.

References gui::scrollarea::set_scroll_rate().

Member Function Documentation

◆ add_img_item()

void help::help_text_area::add_img_item ( const std::string &  path,
const std::string &  alignment,
const bool  floating,
const bool  box 
)
private

◆ add_item()

void help::help_text_area::add_item ( const item itm)
private

Add an item to the internal list, update the locations and row height.

Definition at line 475 of file help_text_area.cpp.

References help::help_text_area::item::align, contents_height_, curr_loc_, curr_row_height_, help::help_text_area::item::floating, items_, last_row_, LEFT, and help::help_text_area::item::rect.

Referenced by add_img_item(), add_text_item(), and set_items().

◆ add_text_item()

void help::help_text_area::add_text_item ( const std::string &  text,
const std::string &  ref_dst = "",
bool  broken_link = false,
int  font_size = -1,
bool  bold = false,
bool  italic = false,
color_t  color = font::NORMAL_COLOR 
)
private

Add an item with text.

If ref_dst is something else than the empty string, the text item will be underlined to show that it is a cross-reference. The item will also remember what the reference points to. If font_size is below zero, the default will be used.

Definition at line 299 of file help_text_area.cpp.

References add_item(), font::BAD_COLOR, curr_loc_, curr_row_height_, down_one_line(), preferences::font_scaled(), gui::font_size, help::get_first_word(), get_min_x(), get_remaining_width(), font::get_rendered_text(), help::help_text_area::item::item(), font::line_width(), help::normal_font_size, help::remove_first_space(), s, help::split_in_width(), help::help_text_area::item::surf, help::help_text_area::item::text, and font::YELLOW_COLOR.

Referenced by handle_bold_cfg(), handle_format_cfg(), handle_header_cfg(), handle_italic_cfg(), handle_ref_cfg(), and set_items().

◆ adjust_last_row()

void help::help_text_area::adjust_last_row ( )
private

Adjust the heights of the items in the last row to make it look good .

Definition at line 519 of file help_text_area.cpp.

References curr_row_height_, last_row_, and help::help_text_area::item::rect.

Referenced by down_one_line().

◆ down_one_line()

void help::help_text_area::down_one_line ( )
private

Move the current input point to the next line.

Definition at line 509 of file help_text_area.cpp.

References adjust_last_row(), contents_height_, curr_loc_, curr_row_height_, get_min_x(), last_row_, and min_row_height_.

Referenced by add_img_item(), add_text_item(), handle_jump_cfg(), and set_items().

◆ draw_contents()

void help::help_text_area::draw_contents ( )
privatevirtual

◆ get_max_x()

int help::help_text_area::get_max_x ( const int  y,
const int  height = 0 
)
private

◆ get_min_x()

int help::help_text_area::get_min_x ( const int  y,
const int  height = 0 
)
private

Return the least x coordinate at which something of the specified height can be drawn at the specified y coordinate without interfering with floating images.

Definition at line 442 of file help_text_area.cpp.

References help::help_text_area::item::align, help::help_text_area::item::floating, items_, LEFT, and help::help_text_area::item::rect.

Referenced by add_img_item(), add_text_item(), and down_one_line().

◆ get_remaining_width()

int help::help_text_area::get_remaining_width ( )
private

Return the width that remain on the line the current input point is at.

Definition at line 528 of file help_text_area.cpp.

References curr_loc_, curr_row_height_, and get_max_x().

Referenced by add_text_item().

◆ get_y_for_floating_img()

int help::help_text_area::get_y_for_floating_img ( const int  width,
const int  x,
const int  desired_y 
)
private

Find the lowest y coordinate where a floating img of the specified width and at the specified x coordinate can be placed.

Start looking at desired_y and continue downwards. Only check against other floating things, since text and inline images only can be above this place if called correctly.

Definition at line 427 of file help_text_area.cpp.

References help::help_text_area::item::floating, items_, help::help_text_area::item::rect, and gui::widget::width().

Referenced by add_img_item().

◆ handle_bold_cfg()

void help::help_text_area::handle_bold_cfg ( const config cfg)
private

Definition at line 221 of file help_text_area.cpp.

References add_text_item(), and help::help_text_area::item::text.

◆ handle_format_cfg()

void help::help_text_area::handle_format_cfg ( const config cfg)
private

◆ handle_header_cfg()

void help::help_text_area::handle_header_cfg ( const config cfg)
private

◆ handle_img_cfg()

void help::help_text_area::handle_img_cfg ( const config cfg)
private

◆ handle_italic_cfg()

void help::help_text_area::handle_italic_cfg ( const config cfg)
private

Definition at line 230 of file help_text_area.cpp.

References add_text_item(), and help::help_text_area::item::text.

◆ handle_jump_cfg()

void help::help_text_area::handle_jump_cfg ( const config cfg)
private

◆ handle_ref_cfg()

void help::help_text_area::handle_ref_cfg ( const config cfg)
private

◆ ref_at()

std::string help::help_text_area::ref_at ( const int  x,
const int  y 
)

Return the ID that is cross-referenced at the (screen) coordinates x, y.

If no cross-reference is there, return the empty string.

Definition at line 577 of file help_text_area.cpp.

References gui::scrollarea::get_position(), gui::widget::height(), items_, and gui::widget::location().

Referenced by help::help_browser::handle_event(), and help::help_browser::update_cursor().

◆ scroll()

void help::help_text_area::scroll ( unsigned int  pos)
protectedvirtual

Implements gui::scrollarea.

Definition at line 565 of file help_text_area.cpp.

References gui::widget::set_dirty().

◆ set_inner_location()

void help::help_text_area::set_inner_location ( const SDL_Rect &  rect)
protectedvirtual

Implements gui::scrollarea.

Definition at line 56 of file help_text_area.cpp.

References gui::widget::bg_register(), set_items(), and shown_topic_.

◆ set_items()

void help::help_text_area::set_items ( )
private

◆ show_topic()

void help::help_text_area::show_topic ( const topic t)

Display the topic.

Definition at line 63 of file help_text_area.cpp.

References DBG_HP, help::topic::id, gui::widget::set_dirty(), set_items(), shown_topic_, t, and help::topic::title.

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

◆ str_to_align()

help_text_area::ALIGNMENT help::help_text_area::str_to_align ( const std::string &  s)
private

Convert a string to an alignment.

Throw parse_error if unsuccessful.

Definition at line 493 of file help_text_area.cpp.

References HERE, LEFT, MIDDLE, wfl::msg(), and RIGHT.

Referenced by add_img_item().

Member Data Documentation

◆ contents_height_

int help::help_text_area::contents_height_
private

The height of all items in total.

Definition at line 163 of file help_text_area.hpp.

Referenced by add_item(), down_one_line(), and set_items().

◆ curr_loc_

std::pair<int, int> help::help_text_area::curr_loc_
private

◆ curr_row_height_

unsigned help::help_text_area::curr_row_height_
private

◆ items_

std::list<item> help::help_text_area::items_
private

◆ last_row_

std::list<item *> help::help_text_area::last_row_
private

Definition at line 154 of file help_text_area.hpp.

Referenced by add_item(), adjust_last_row(), down_one_line(), and set_items().

◆ min_row_height_

const unsigned help::help_text_area::min_row_height_
private

Definition at line 160 of file help_text_area.hpp.

Referenced by down_one_line(), and set_items().

◆ shown_topic_

topic const* help::help_text_area::shown_topic_
private

Definition at line 156 of file help_text_area.hpp.

Referenced by set_inner_location(), set_items(), and show_topic().

◆ title_spacing_

const int help::help_text_area::title_spacing_
private

Definition at line 157 of file help_text_area.hpp.

Referenced by set_items().

◆ toplevel_

const section& help::help_text_area::toplevel_
private

Definition at line 155 of file help_text_area.hpp.

Referenced by handle_ref_cfg().


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