The area where the content is shown in the help browser. More...
#include <help_text_area.hpp>
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 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 | 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 ®ion) 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_handler & | operator= (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_handler & | operator= (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_drawable & | operator= (const top_level_drawable &) |
top_level_drawable (top_level_drawable &&) | |
top_level_drawable & | operator= (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< item > | items_ |
std::list< item * > | last_row_ |
const section & | toplevel_ |
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_ |
The area where the content is shown in the help browser.
Definition at line 33 of file help_text_area.hpp.
|
private |
Enumerator | |
---|---|
LEFT | |
MIDDLE | |
RIGHT | |
HERE |
Definition at line 52 of file help_text_area.hpp.
help::help_text_area::help_text_area | ( | const section & | toplevel | ) |
Definition at line 45 of file help_text_area.cpp.
References gui::scrollarea::set_scroll_rate().
|
private |
Add an image item with the specified attributes.
Definition at line 387 of file help_text_area.cpp.
References add_item(), help::box_width, curr_loc_, curr_row_height_, down_one_line(), get_min_x(), image::get_texture(), get_y_for_floating_img(), HERE, gui::scrollarea::inner_location(), LEFT, MIDDLE, game_config::path, RIGHT, str_to_align(), texture::w(), gui::widget::width(), and WRN_DP.
Referenced by handle_img_cfg().
|
private |
Add an item to the internal list, update the locations and row height.
Definition at line 481 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().
|
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 302 of file help_text_area.cpp.
References add_item(), font::BAD_COLOR, help::bold(), curr_loc_, curr_row_height_, down_one_line(), prefs::font_scaled(), prefs::get(), 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().
|
private |
Adjust the heights of the items in the last row to make it look good.
Definition at line 525 of file help_text_area.cpp.
References curr_row_height_, last_row_, and help::help_text_area::item::rect_.
Referenced by down_one_line().
|
private |
Move the current input point to the next line.
Definition at line 515 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().
|
privatevirtual |
Reimplemented from gui::widget.
Definition at line 540 of file help_text_area.cpp.
References draw::blit(), help::box_width, dst, draw::fill(), gui::scrollarea::get_position(), i, gui::scrollarea::inner_location(), items_, and draw::reduce_clip().
|
private |
Analogous with get_min_x but return the maximum X.
Definition at line 462 of file help_text_area.cpp.
References help::help_text_area::item::align, help::help_text_area::item::floating, gui::widget::height(), gui::scrollarea::inner_location(), items_, MIDDLE, help::help_text_area::item::rect_, RIGHT, and gui::scrollarea::y.
Referenced by get_remaining_width(), and handle_jump_cfg().
|
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 448 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().
|
private |
Return the width that remain on the line the current input point is at.
Definition at line 534 of file help_text_area.cpp.
References curr_loc_, curr_row_height_, and get_max_x().
Referenced by add_text_item().
|
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 433 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().
|
private |
Definition at line 224 of file help_text_area.cpp.
References add_text_item().
|
private |
Definition at line 289 of file help_text_area.cpp.
References add_text_item(), help::bold(), help::normal_font_size, and font::string_to_color().
|
private |
Definition at line 242 of file help_text_area.cpp.
References add_text_item(), and help::title2_size.
|
private |
Definition at line 212 of file help_text_area.cpp.
References add_img_item(), rect::empty(), and src.
|
private |
Definition at line 233 of file help_text_area.cpp.
References add_text_item().
|
private |
Definition at line 251 of file help_text_area.cpp.
References curr_loc_, curr_row_height_, down_one_line(), get_max_x(), and help::jump_to().
|
private |
Definition at line 168 of file help_text_area.cpp.
References add_text_item(), game_config::debug, dst, rect::empty(), help::find_topic(), wfl::msg(), toplevel_, and write().
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 580 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().
|
protectedvirtual |
Implements gui::scrollarea.
Definition at line 568 of file help_text_area.cpp.
References gui::widget::queue_redraw().
|
protectedvirtual |
Implements gui::scrollarea.
Definition at line 60 of file help_text_area.cpp.
References set_items(), and shown_topic_.
|
private |
Update the vector with the items of the shown topic, creating surfaces for everything and putting things where they belong.
Definition at line 106 of file help_text_area.cpp.
References add_item(), add_text_item(), help::bold(), contents_height_, curr_loc_, curr_row_height_, down_one_line(), e, h, gui::widget::height(), gui::scrollarea::inner_location(), items_, help::jump(), last_row_, min_row_height_, wfl::msg(), font::NORMAL_COLOR, font::pango_line_ellipsize(), font::pango_render_text(), help::topic_text::parsed_text(), read(), gui::scrollarea::set_full_size(), gui::scrollarea::set_position(), gui::scrollarea::set_shown_size(), shown_topic_, font::pango_text::STYLE_BOLD, help::topic::text, help::topic::title, help::title_size, title_spacing_, TRY, and w.
Referenced by set_inner_location(), and show_topic().
void help::help_text_area::show_topic | ( | const topic & | t | ) |
Display the topic.
Definition at line 66 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().
|
private |
Convert a string to an alignment.
Throw parse_error if unsuccessful.
Definition at line 499 of file help_text_area.cpp.
References HERE, LEFT, MIDDLE, wfl::msg(), and RIGHT.
Referenced by add_img_item().
|
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().
|
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().
|
private |
Definition at line 171 of file help_text_area.hpp.
Referenced by add_img_item(), add_item(), add_text_item(), adjust_last_row(), down_one_line(), get_remaining_width(), handle_jump_cfg(), and set_items().
|
private |
Definition at line 163 of file help_text_area.hpp.
Referenced by add_item(), draw_contents(), get_max_x(), get_min_x(), get_y_for_floating_img(), ref_at(), and set_items().
|
private |
Definition at line 164 of file help_text_area.hpp.
Referenced by add_item(), adjust_last_row(), down_one_line(), and set_items().
|
private |
Definition at line 170 of file help_text_area.hpp.
Referenced by down_one_line(), and set_items().
|
private |
Definition at line 166 of file help_text_area.hpp.
Referenced by set_inner_location(), set_items(), and show_topic().
|
private |
Definition at line 167 of file help_text_area.hpp.
Referenced by set_items().
|
private |
Definition at line 165 of file help_text_area.hpp.
Referenced by handle_ref_cfg().