The Battle for Wesnoth  1.19.0-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:

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 (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 (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_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 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
 
- 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...
 

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 ()
 
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 &&)
 

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_
 The current input location when creating items. More...
 
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 33 of file help_text_area.hpp.

Member Enumeration Documentation

◆ ALIGNMENT

Enumerator
LEFT 
MIDDLE 
RIGHT 
HERE 

Definition at line 52 of file help_text_area.hpp.

Constructor & Destructor Documentation

◆ help_text_area()

help::help_text_area::help_text_area ( const section toplevel)

Definition at line 44 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 480 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 301 of file help_text_area.cpp.

References add_item(), font::BAD_COLOR, help::bold(), curr_loc_, curr_row_height_, down_one_line(), preferences::font_scaled(), help::get_first_word(), get_min_x(), get_remaining_width(), help::normal_font_size, font::pango_line_width(), font::pango_render_text(), help::remove_first_space(), s, help::split_in_width(), font::pango_text::STYLE_BOLD, font::pango_text::STYLE_ITALIC, font::pango_text::STYLE_NORMAL, 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 524 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 514 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 447 of file help_text_area.cpp.

References help::help_text_area::item::align, help::help_text_area::item::floating, gui::widget::height(), items_, LEFT, help::help_text_area::item::rect_, and gui::scrollarea::y.

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 533 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 432 of file help_text_area.cpp.

References help::help_text_area::item::floating, items_, help::help_text_area::item::rect_, gui::widget::width(), and gui::scrollarea::x.

Referenced by add_img_item().

◆ handle_bold_cfg()

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

Definition at line 223 of file help_text_area.cpp.

References add_text_item().

◆ 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

Definition at line 241 of file help_text_area.cpp.

References add_text_item(), and help::title2_size.

◆ handle_img_cfg()

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

Definition at line 211 of file help_text_area.cpp.

References add_img_item().

◆ handle_italic_cfg()

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

Definition at line 232 of file help_text_area.cpp.

References add_text_item().

◆ 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 579 of file help_text_area.cpp.

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

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 567 of file help_text_area.cpp.

References gui::widget::queue_redraw().

◆ set_inner_location()

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

Implements gui::scrollarea.

Definition at line 59 of file help_text_area.cpp.

References 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 65 of file help_text_area.cpp.

References DBG_HP, gui::widget::queue_redraw(), set_items(), shown_topic_, and t.

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 498 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 173 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

The current input location when creating items.

Definition at line 169 of file help_text_area.hpp.

Referenced by add_img_item(), add_item(), add_text_item(), down_one_line(), get_remaining_width(), handle_jump_cfg(), and set_items().

◆ 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 164 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 170 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 166 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 167 of file help_text_area.hpp.

Referenced by set_items().

◆ toplevel_

const section& help::help_text_area::toplevel_
private

Definition at line 165 of file help_text_area.hpp.

Referenced by handle_ref_cfg().


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