36 #define WRN_DP LOG_STREAM(warn, log_display)
39 #define ERR_HP LOG_STREAM(err, log_help)
40 #define WRN_HP LOG_STREAM(warn, log_help)
41 #define DBG_HP LOG_STREAM(debug, log_help)
50 shown_topic_(nullptr),
54 curr_row_height_(min_row_height_),
71 DBG_HP <<
"Showing topic: " <<
t.id <<
": " <<
t.title;
76 const std::string& reference_to,
bool _floating,
82 floating(_floating), box(_box),
98 box(_box), align(alignment)
126 std::vector<std::string>::const_iterator it;
127 for (it = parsed_items.begin(); it != parsed_items.end(); ++it) {
128 if (!(*it).empty() && (*it)[0] ==
'[') {
132 std::istringstream stream(*it);
135 #define TRY(name) do { \
136 if (auto child = cfg.optional_child(#name)) \
137 handle_##name##_cfg(*child); \
152 std::stringstream
msg;
153 msg <<
"Error when parsing help markup as WML: '" <<
e.message <<
"'";
170 const std::string
dst = cfg[
"dst"];
171 const std::string text = cfg[
"text"];
172 bool force = cfg[
"force"].to_bool();
175 std::stringstream
msg;
176 msg <<
"Ref markup must have dst attribute. Please submit a bug"
177 " report if you have not modified the game files yourself. Erroneous config: ";
199 std::stringstream
msg;
200 msg <<
"Reference to non-existent topic '" <<
dst
201 <<
"'. Please submit a bug report if you have not"
202 "modified the game files yourself. Erroneous config: ";
214 const std::string
src = cfg[
"src"];
215 const std::string align = cfg[
"align"];
216 bool floating = cfg[
"float"].to_bool();
217 bool box = cfg[
"box"].to_bool(
true);
219 throw parse_error(
"Img markup must have src attribute.");
226 const std::string text = cfg[
"text"];
228 throw parse_error(
"Bold markup must have text attribute.");
235 const std::string text = cfg[
"text"];
237 throw parse_error(
"Italic markup must have text attribute.");
244 const std::string text = cfg[
"text"];
246 throw parse_error(
"Header markup must have text attribute.");
253 const std::string amount_str = cfg[
"amount"];
254 const std::string to_str = cfg[
"to"];
255 if (amount_str.empty() && to_str.empty()) {
256 throw parse_error(
"Jump markup must have either a to or an amount attribute.");
259 if (!amount_str.empty()) {
262 amount = lexical_cast<unsigned, std::string>(amount_str);
265 throw parse_error(
"Invalid amount the amount attribute in jump markup.");
269 if (!to_str.empty()) {
272 to = lexical_cast<unsigned, std::string>(to_str);
275 throw parse_error(
"Invalid amount in the to attribute in jump markup.");
291 const std::string text = cfg[
"text"];
293 throw parse_error(
"Format markup must have text attribute.");
295 bool bold = cfg[
"bold"].to_bool();
296 bool italic = cfg[
"italic"].to_bool();
303 bool broken_link,
int _font_size,
bool bold,
bool italic,
313 std::size_t first_word_start = text.find_first_not_of(
" ");
314 if (first_word_start == std::string::npos) {
315 first_word_start = 0;
317 if (text[first_word_start] ==
'\n') {
319 std::string rest_text = text;
320 rest_text.erase(0, first_word_start + 1);
321 add_text_item(rest_text, ref_dst, broken_link, _font_size,
bold, italic, text_color);
337 std::vector<std::string> parts =
split_in_width(text, font_size, remaining_width);
338 std::string first_part = parts.front();
351 if (first_part.empty()) {
359 first_part, ref_dst));
362 if (parts.size() > 1) {
364 std::string&
s = parts.back();
388 const bool floating,
const bool box)
394 if (align ==
HERE && floating) {
395 WRN_DP <<
"Floating image with align HERE, aligning left.";
435 int min_y = desired_y;
436 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
437 const item& itm = *it;
441 min_y = std::max<int>(min_y, itm.
rect_.y + itm.
rect_.h);
451 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
452 const item& itm = *it;
455 min_x = std::max<int>(min_x, itm.
rect_.w + 5);
465 int max_x = text_width;
466 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
467 const item& itm = *it;
471 max_x = std::min<int>(max_x, text_width - itm.
rect_.w - 5);
473 max_x = std::min<int>(max_x, text_width / 2 - itm.
rect_.w / 2 - 5);
501 if (cmp_str ==
"left") {
503 }
else if (cmp_str ==
"middle") {
505 }
else if (cmp_str ==
"right") {
507 }
else if (cmp_str ==
"here" || cmp_str.empty()) {
510 std::stringstream
msg;
511 msg <<
"Invalid alignment string: '" << cmp_str <<
"'";
530 itm.
rect_.y += gap / 2;
544 for(std::list<item>::const_iterator it =
items_.begin(), end =
items_.end(); it != end; ++it) {
545 SDL_Rect
dst = it->rect_;
547 if (
dst.y <
static_cast<int>(loc.h) &&
dst.y + it->rect_.h > 0) {
584 if (local_y <
height() && local_y > 0) {
586 const std::list<item>::const_iterator it =
589 if (!(*it).ref_to.empty()) {
590 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
int font_scaled(int size)
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.
Definitions for the interface to Wesnoth Markup Language (WML).
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 (...)
color_t string_to_color(const std::string &cmp_str)
Return the color the string represents.
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.
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.
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)
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
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 empty() const
False if both w and h are > 0, true otherwise.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
static map_location::DIRECTION s