34 #define WRN_DP LOG_STREAM(warn, log_display) 37 #define ERR_HP LOG_STREAM(err, log_help) 38 #define WRN_HP LOG_STREAM(warn, log_help) 39 #define DBG_HP LOG_STREAM(debug, log_help) 44 gui::scrollarea(video),
48 shown_topic_(nullptr),
52 curr_row_height_(min_row_height_),
70 DBG_HP <<
"Showing topic: " << t.
id <<
": " << t.
title << std::endl;
75 const std::string& reference_to,
bool _floating,
81 floating(_floating), box(_box),
113 const std::string show_title =
116 if (surf !=
nullptr) {
124 std::vector<std::string>::const_iterator it;
125 for (it = parsed_items.begin(); it != parsed_items.end(); ++it) {
126 if (!(*it).empty() && (*it)[0] ==
'[') {
130 std::istringstream stream(*it);
133 #define TRY(name) do { \ 134 if (config &child = cfg.child(#name)) \ 135 handle_##name##_cfg(child); \ 150 std::stringstream
msg;
151 msg <<
"Error when parsing help markup as WML: '" << e.
message <<
"'";
168 const std::string dst = cfg[
"dst"];
169 const std::string
text = cfg[
"text"];
170 bool force = cfg[
"force"].to_bool();
173 std::stringstream
msg;
174 msg <<
"Ref markup must have dst attribute. Please submit a bug" 175 " report if you have not modified the game files yourself. Erroneous config: ";
197 std::stringstream
msg;
198 msg <<
"Reference to non-existent topic '" << dst
199 <<
"'. Please submit a bug report if you have not" 200 "modified the game files yourself. Erroneous config: ";
212 const std::string src = cfg[
"src"];
213 const std::string
align = cfg[
"align"];
214 bool floating = cfg[
"float"].to_bool();
215 bool box = cfg[
"box"].to_bool(
true);
217 throw parse_error(
"Img markup must have src attribute.");
224 const std::string
text = cfg[
"text"];
226 throw parse_error(
"Bold markup must have text attribute.");
233 const std::string
text = cfg[
"text"];
235 throw parse_error(
"Italic markup must have text attribute.");
242 const std::string
text = cfg[
"text"];
244 throw parse_error(
"Header markup must have text attribute.");
251 const std::string amount_str = cfg[
"amount"];
252 const std::string to_str = cfg[
"to"];
253 if (amount_str.empty() && to_str.empty()) {
254 throw parse_error(
"Jump markup must have either a to or an amount attribute.");
257 if (!amount_str.empty()) {
260 amount =
lexical_cast<unsigned, std::string>(amount_str);
263 throw parse_error(
"Invalid amount the amount attribute in jump markup.");
267 if (!to_str.empty()) {
273 throw parse_error(
"Invalid amount in the to attribute in jump markup.");
280 if (jump_to != 0 && static_cast<int>(jump_to) <
289 const std::string
text = cfg[
"text"];
291 throw parse_error(
"Format markup must have text attribute.");
293 bool bold = cfg[
"bold"].to_bool();
294 bool italic = cfg[
"italic"].to_bool();
297 add_text_item(text,
"",
false, font_size, bold, italic, color);
301 bool broken_link,
int _font_size,
bool bold,
bool italic,
311 std::size_t first_word_start = text.find_first_not_of(
" ");
312 if (first_word_start == std::string::npos) {
313 first_word_start = 0;
315 if (text[first_word_start] ==
'\n') {
317 std::string rest_text =
text;
318 rest_text.erase(0, first_word_start + 1);
319 add_text_item(rest_text, ref_dst, broken_link, _font_size, bold, italic, text_color);
332 add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color);
335 std::vector<std::string> parts =
split_in_width(text, font_size, remaining_width);
336 std::string first_part = parts.front();
349 if (first_part.empty()) {
357 if (parts.size() > 1) {
359 std::string&
s = parts.back();
376 add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color);
389 if (align ==
HERE && floating) {
390 WRN_DP <<
"Floating image with align HERE, aligning left." << std::endl;
406 xpos = text_width / 2 - width / 2 - (box ?
box_width : 0);
409 xpos = text_width - width - (box ?
box_width * 2 : 0);
413 && (xpos <
curr_loc_.first || xpos + width > text_width)) {
430 int min_y = desired_y;
431 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
432 const item& itm = *it;
434 if ((itm.
rect.x + itm.
rect.w > x && itm.
rect.x < x + width)
436 min_y = std::max<int>(min_y, itm.
rect.y + itm.
rect.h);
446 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
447 const item& itm = *it;
450 min_x = std::max<int>(min_x, itm.
rect.w + 5);
460 int max_x = text_width;
461 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
462 const item& itm = *it;
464 if (itm.
rect.y < y + height && itm.
rect.y + itm.
rect.h > y) {
466 max_x = std::min<int>(max_x, text_width - itm.
rect.w - 5);
468 max_x = std::min<int>(max_x, text_width / 2 - itm.
rect.w / 2 - 5);
496 if (cmp_str ==
"left") {
498 }
else if (cmp_str ==
"middle") {
500 }
else if (cmp_str ==
"right") {
502 }
else if (cmp_str ==
"here" || cmp_str.empty()) {
505 std::stringstream
msg;
506 msg <<
"Invalid alignment string: '" << cmp_str <<
"'";
525 itm.
rect.y += gap / 2;
541 for(std::list<item>::const_iterator it =
items_.begin(), end =
items_.end(); it != end; ++it) {
542 SDL_Rect dst = it->rect;
544 if (dst.y < static_cast<int>(loc.h) && dst.y + it->rect.h > 0) {
560 SDL_FillRect(screen, &draw_rect, 0);
565 sdl_blit(it->surf,
nullptr, screen, &dst);
584 const int local_x = x -
location().x;
585 const int local_y = y -
location().y;
586 if (local_y <
height() && local_y > 0) {
588 const std::list<item>::const_iterator it =
591 if (!(*it).ref_to.empty()) {
592 return ((*it).ref_to);
std::string jump_to(const unsigned pos)
int get_max_x(const int y, const int height=0)
Analogous with get_min_x but return the maximum X.
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
std::string pango_line_ellipsize(const std::string &text, int font_size, int max_width, font::pango_text::FONT_STYLE font_style)
If the text exceeds the specified max width, end it with an ellipsis (...)
help_text_area(CVideo &video, const section &toplevel)
virtual void set_inner_location(const SDL_Rect &rect)
Collection of helper functions relating to Pango formatting.
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.
std::string remove_first_space(const std::string &text)
A section contains topics and sections along with title and ID.
int get_remaining_width()
Return the width that remain on the line the current input point is at.
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 coord...
New lexcical_cast header.
Thrown when the help system fails to parse something.
std::list< item * > last_row_
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
const int normal_font_size
void set_items()
Update the vector with the items of the shown topic, creating surfaces for everything and putting thi...
To lexical_cast(From value)
Lexical cast converts one type to another.
int get_max_height(unsigned size, font::family_class fclass, pango_text::FONT_STYLE style)
Returns the maximum glyph height of a font, in pixels.
color_t string_to_color(const std::string &cmp_str)
Return the color the string represents.
Definitions for the interface to Wesnoth Markup Language (WML).
surface & getSurface()
Returns a reference to the framebuffer.
std::string bold(const std::string &s)
topic const * shown_topic_
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
void read(config &cfg, std::istream &in, abstract_validator *validator)
void add_item(const item &itm)
Add an item to the internal list, update the locations and row height.
std::string ref_at(const int x, const int y)
Return the ID that is cross-referenced at the (screen) coordinates x, y.
int font_scaled(int size)
virtual void scroll(unsigned int pos)
const section & toplevel_
void handle_ref_cfg(const config &cfg)
const unsigned min_row_height_
const color_t YELLOW_COLOR
void handle_img_cfg(const config &cfg)
const color_t NORMAL_COLOR
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
void handle_header_cfg(const config &cfg)
An item that is displayed in the text area.
void handle_italic_cfg(const config &cfg)
void handle_bold_cfg(const config &cfg)
void show_topic(const topic &t)
Display the topic.
void adjust_last_row()
Adjust the heights of the items in the last row to make it look good.
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.
static map_location::DIRECTION s
std::pair< int, int > curr_loc_
The current input location when creating items.
item(surface surface, int x, int y, const std::string &text="", const std::string &reference_to="", bool floating=false, bool box=false, ALIGNMENT alignment=HERE)
static lg::log_domain log_help("help")
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 specifie...
void down_one_line()
Move the current input point to the next line.
std::string jump(const unsigned amount)
Contains the SDL_Rect helper code.
void handle_format_cfg(const config &cfg)
const topic * find_topic(const section &sec, const std::string &id)
Search for the topic with the specified identifier in the section and its subsections.
const std::vector< std::string > & parsed_text() const
Standard logging facilities (interface).
surface pango_render_text(const std::string &text, int size, const color_t &color, font::pango_text::FONT_STYLE style, bool use_markup, int max_width)
Returns a SDL surface containing the rendered text.
A topic contains a title, an id and some text.
ALIGNMENT str_to_align(const std::string &s)
Convert a string to an alignment.
bool operator()(const item &) const
SDL_Rect rect
Relative coordinates of this item.
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
A config object defines a single node in a WML file, with access to child nodes.
static lg::log_domain log_display("display")
std::string get_first_word(const std::string &s)
Return the first word in s, not removing any spaces in the start of it.
int contents_height_
The height of all items in total.
Thrown when a lexical_cast fails.
Transitional API for porting SDL_ttf-based code to Pango.
std::string::const_iterator iterator
void handle_jump_cfg(const config &cfg)
std::vector< std::string > split_in_width(const std::string &s, const int font_size, const unsigned width)
Make a best effort to word wrap s.
unsigned curr_row_height_
Function object to find an item at the specified coordinates.
int pango_line_width(const std::string &line, int font_size, font::pango_text::FONT_STYLE font_style=font::pango_text::STYLE_NORMAL)
Determine the width of a line of text given a certain font size.