The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
SDL_Rect const & location () const
 
virtual void set_location (SDL_Rect const &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::stringid () 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)
 
- 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 ()
 

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 (SDL_Rect const &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 (widget const &o)
 
 widget (CVideo &video, const bool auto_join=true)
 
virtual ~widget ()
 
void bg_register (SDL_Rect const &rect)
 
void bg_restore () const
 
void bg_restore (SDL_Rect const &rect) const
 
void bg_update ()
 
void bg_cancel ()
 
CVideovideo () const
 
virtual void draw ()
 
const SDL_Rect * clip_rect () const
 
virtual sdl_handler_vector member_handlers ()
 
virtual void handle_window_event (SDL_Event const &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)
 
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, SDL_Color 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, intcurr_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 34 of file help_text_area.hpp.

Member Enumeration Documentation

Enumerator
LEFT 
MIDDLE 
RIGHT 
HERE 

Definition at line 51 of file help_text_area.hpp.

Constructor & Destructor Documentation

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

Definition at line 37 of file help_text_area.cpp.

References gui::scrollarea::set_scroll_rate().

Member Function Documentation

void help::help_text_area::add_img_item ( const std::string path,
const std::string alignment,
const bool  floating,
const bool  box 
)
private
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 460 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().

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,
SDL_Color  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 294 of file help_text_area.cpp.

References add_item(), font::BAD_COLOR, curr_loc_, curr_row_height_, down_one_line(), gui::font_size, help::get_first_word(), get_min_x(), get_remaining_width(), font::get_rendered_text(), font::line_width(), help::normal_font_size, surface::null(), help::remove_first_space(), help::split_in_width(), surf, and font::YELLOW_COLOR.

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

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

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

Referenced by down_one_line().

void help::help_text_area::down_one_line ( )
private

Move the current input point to the next line.

Definition at line 494 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().

void help::help_text_area::draw_contents ( )
privatevirtual
int help::help_text_area::get_max_x ( const int  y,
const int  height = 0 
)
private
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 427 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().

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

References curr_loc_, curr_row_height_, and get_max_x().

Referenced by add_text_item().

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 412 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().

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

Definition at line 216 of file help_text_area.cpp.

References add_text_item().

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

Definition at line 234 of file help_text_area.cpp.

References add_text_item(), and help::title2_size.

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

Definition at line 204 of file help_text_area.cpp.

References add_img_item().

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

Definition at line 225 of file help_text_area.cpp.

References add_text_item().

void help::help_text_area::handle_jump_cfg ( const config cfg)
private
void help::help_text_area::handle_ref_cfg ( const config cfg)
private
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 557 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().

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

Implements gui::scrollarea.

Definition at line 545 of file help_text_area.cpp.

References gui::widget::set_dirty().

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

Implements gui::scrollarea.

Definition at line 52 of file help_text_area.cpp.

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

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

Display the topic.

Definition at line 59 of file help_text_area.cpp.

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

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

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

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

Referenced by add_img_item().

Member Data Documentation

int help::help_text_area::contents_height_
private

The height of all items in total.

Definition at line 165 of file help_text_area.hpp.

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

std::pair<int, int> help::help_text_area::curr_loc_
private
unsigned help::help_text_area::curr_row_height_
private
std::list<item> help::help_text_area::items_
private
std::list<item *> help::help_text_area::last_row_
private

Definition at line 156 of file help_text_area.hpp.

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

const unsigned help::help_text_area::min_row_height_
private

Definition at line 162 of file help_text_area.hpp.

Referenced by down_one_line(), and set_items().

topic const* help::help_text_area::shown_topic_
private

Definition at line 158 of file help_text_area.hpp.

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

const int help::help_text_area::title_spacing_
private

Definition at line 159 of file help_text_area.hpp.

Referenced by set_items().

const section& help::help_text_area::toplevel_
private

Definition at line 157 of file help_text_area.hpp.

Referenced by handle_ref_cfg().


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