35 #define WRN_DP LOG_STREAM(warn, log_display)
38 #define ERR_HP LOG_STREAM(err, log_help)
39 #define WRN_HP LOG_STREAM(warn, log_help)
40 #define DBG_HP LOG_STREAM(debug, log_help)
49 shown_topic_(nullptr),
53 curr_row_height_(min_row_height_),
70 DBG_HP <<
"Showing topic: " <<
t.id <<
": " <<
t.title;
75 const std::string& reference_to,
bool _floating,
81 floating(_floating), box(_box),
97 box(_box), align(alignment)
125 std::vector<std::string>::const_iterator it;
126 for (it = parsed_items.begin(); it != parsed_items.end(); ++it) {
127 if (!(*it).empty() && (*it)[0] ==
'[') {
131 std::istringstream stream(*it);
134 #define TRY(name) do { \
135 if (auto child = cfg.optional_child(#name)) \
136 handle_##name##_cfg(*child); \
151 std::stringstream
msg;
152 msg <<
"Error when parsing help markup as WML: '" <<
e.message <<
"'";
169 const std::string dst = cfg[
"dst"];
170 const std::string text = cfg[
"text"];
171 bool force = cfg[
"force"].to_bool();
174 std::stringstream
msg;
175 msg <<
"Ref markup must have dst attribute. Please submit a bug"
176 " report if you have not modified the game files yourself. Erroneous config: ";
198 std::stringstream
msg;
199 msg <<
"Reference to non-existent topic '" << dst
200 <<
"'. Please submit a bug report if you have not"
201 "modified the game files yourself. Erroneous config: ";
213 const std::string src = cfg[
"src"];
214 const std::string align = cfg[
"align"];
215 bool floating = cfg[
"float"].to_bool();
216 bool box = cfg[
"box"].to_bool(
true);
218 throw parse_error(
"Img markup must have src attribute.");
225 const std::string text = cfg[
"text"];
227 throw parse_error(
"Bold markup must have text attribute.");
234 const std::string text = cfg[
"text"];
236 throw parse_error(
"Italic markup must have text attribute.");
243 const std::string text = cfg[
"text"];
245 throw parse_error(
"Header markup must have text attribute.");
252 const std::string amount_str = cfg[
"amount"];
253 const std::string to_str = cfg[
"to"];
254 if (amount_str.empty() && to_str.empty()) {
255 throw parse_error(
"Jump markup must have either a to or an amount attribute.");
258 if (!amount_str.empty()) {
261 amount = lexical_cast<unsigned, std::string>(amount_str);
264 throw parse_error(
"Invalid amount the amount attribute in jump markup.");
268 if (!to_str.empty()) {
271 to = lexical_cast<unsigned, std::string>(to_str);
274 throw parse_error(
"Invalid amount in the to attribute in jump markup.");
290 const std::string text = cfg[
"text"];
292 throw parse_error(
"Format markup must have text attribute.");
294 bool bold = cfg[
"bold"].to_bool();
295 bool italic = cfg[
"italic"].to_bool();
302 bool broken_link,
int _font_size,
bool bold,
bool italic,
312 std::size_t first_word_start = text.find_first_not_of(
" ");
313 if (first_word_start == std::string::npos) {
314 first_word_start = 0;
316 if (text[first_word_start] ==
'\n') {
318 std::string rest_text = text;
319 rest_text.erase(0, first_word_start + 1);
320 add_text_item(rest_text, ref_dst, broken_link, _font_size,
bold, italic, text_color);
336 std::vector<std::string> parts =
split_in_width(text, font_size, remaining_width);
337 std::string first_part = parts.front();
350 if (first_part.empty()) {
358 first_part, ref_dst));
361 if (parts.size() > 1) {
363 std::string&
s = parts.back();
387 const bool floating,
const bool box)
393 if (align ==
HERE && floating) {
394 WRN_DP <<
"Floating image with align HERE, aligning left.";
434 int min_y = desired_y;
435 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
436 const item& itm = *it;
440 min_y = std::max<int>(min_y, itm.
rect_.y + itm.
rect_.h);
450 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
451 const item& itm = *it;
454 min_x = std::max<int>(min_x, itm.
rect_.w + 5);
464 int max_x = text_width;
465 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
466 const item& itm = *it;
470 max_x = std::min<int>(max_x, text_width - itm.
rect_.w - 5);
472 max_x = std::min<int>(max_x, text_width / 2 - itm.
rect_.w / 2 - 5);
500 if (cmp_str ==
"left") {
502 }
else if (cmp_str ==
"middle") {
504 }
else if (cmp_str ==
"right") {
506 }
else if (cmp_str ==
"here" || cmp_str.empty()) {
509 std::stringstream
msg;
510 msg <<
"Invalid alignment string: '" << cmp_str <<
"'";
529 itm.
rect_.y += gap / 2;
543 for(std::list<item>::const_iterator it =
items_.begin(), end =
items_.end(); it != end; ++it) {
544 SDL_Rect dst = it->rect_;
546 if (dst.y <
static_cast<int>(loc.h) && dst.y + it->rect_.h > 0) {
583 if (local_y <
height() && local_y > 0) {
585 const std::list<item>::const_iterator it =
588 if (!(*it).ref_to.empty()) {
589 return ((*it).ref_to);
A config object defines a single node in a WML file, with access to child nodes.
Function object to find an item at the specified coordinates.
bool operator()(const item &) const
const section & toplevel_
const unsigned min_row_height_
void handle_italic_cfg(const config &cfg)
void handle_img_cfg(const config &cfg)
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.
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...
std::string ref_at(const int x, const int y)
Return the ID that is cross-referenced at the (screen) coordinates x, y.
help_text_area(const section &toplevel)
std::list< item * > last_row_
std::pair< int, int > curr_loc_
The current input location when creating items.
int get_remaining_width()
Return the width that remain on the line the current input point is at.
virtual void set_inner_location(const SDL_Rect &rect)
void show_topic(const topic &t)
Display the topic.
void handle_format_cfg(const config &cfg)
void adjust_last_row()
Adjust the heights of the items in the last row to make it look good.
virtual void scroll(unsigned int pos)
void set_items()
Update the vector with the items of the shown topic, creating surfaces for everything and putting thi...
void handle_bold_cfg(const config &cfg)
void handle_ref_cfg(const config &cfg)
unsigned curr_row_height_
void down_one_line()
Move the current input point to the next line.
ALIGNMENT str_to_align(const std::string &s)
Convert a string to an alignment.
void handle_jump_cfg(const config &cfg)
int get_max_x(const int y, const int height=0)
Analogous with get_min_x but return the maximum X.
void add_item(const item &itm)
Add an item to the internal list, update the locations and row height.
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.
void handle_header_cfg(const config &cfg)
int contents_height_
The height of all items in total.
topic const * shown_topic_
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...
const std::vector< std::string > & parsed_text() const
Wrapper class to encapsulate creation and management of an SDL_Texture.
int w() const
The draw-space width of the texture, in pixels.
int h() const
The draw-space height of the texture, in pixels.
Drawing functions, for drawing things on the screen.
static lg::log_domain log_display("display")
static lg::log_domain log_help("help")
New lexcical_cast header.
Standard logging facilities (interface).
clip_setter reduce_clip(const SDL_Rect &clip)
Set the clipping area to the intersection of the current clipping area and the given rectangle.
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
Collection of helper functions relating to Pango formatting.
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.
const color_t YELLOW_COLOR
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.
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 (...)
texture 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 texture containing the rendered text.
const color_t NORMAL_COLOR
std::string get_first_word(const std::string &s)
Return the first word in s, not removing any spaces in the start of it.
std::string bold(const std::string &s)
std::pair< std::string, unsigned > item
const int normal_font_size
std::string remove_first_space(const std::string &text)
std::string jump_to(const unsigned pos)
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.
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.
color_t string_to_color(const std::string &cmp_str)
Return the color the string represents.
std::string jump(const unsigned amount)
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
int font_scaled(int size)
std::string::const_iterator iterator
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Contains the SDL_Rect helper code.
Transitional API for porting SDL_ttf-based code to Pango.
void read(config &cfg, std::istream &in, abstract_validator *validator)
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Thrown when a lexical_cast fails.
The basic class for representing 8-bit RGB or RGBA colour values.
An item that is displayed in the text area.
item(const texture &tex, int x, int y, const std::string &text="", const std::string &reference_to="", bool floating=false, bool box=false, ALIGNMENT alignment=HERE)
rect rect_
Relative coordinates of this item.
Thrown when the help system fails to parse something.
A section contains topics and sections along with title and ID.
A topic contains a title, an id and some text.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
static map_location::DIRECTION s