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_),
76 const std::string& reference_to,
bool _floating,
82 floating(_floating), box(_box),
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 (config &child = cfg.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()) {
275 throw parse_error(
"Invalid amount in the to attribute in jump markup.");
282 if (jump_to != 0 && static_cast<int>(jump_to) <
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();
299 add_text_item(text,
"",
false, font_size, bold, italic, color);
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);
334 add_text_item(s, 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();
381 add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color);
394 if (align ==
HERE && floating) {
395 WRN_DP <<
"Floating image with align HERE, aligning left.";
411 xpos = text_width / 2 - width / 2 - (box ?
box_width : 0);
414 xpos = text_width - width - (box ?
box_width * 2 : 0);
418 && (xpos <
curr_loc_.first || xpos + width > text_width)) {
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) {
582 const int local_x = x -
location().x;
583 const int local_y = y -
location().y;
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);
std::string jump_to(const unsigned pos)
Drawing functions, for drawing things on the screen.
int get_max_x(const int y, const int height=0)
Analogous with get_min_x but return the maximum X.
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 (...)
virtual void set_inner_location(const SDL_Rect &rect)
int w() const
The draw-space width of the texture, in pixels.
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.
int h() const
The draw-space height of the texture, in pixels.
help_text_area(const section &toplevel)
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).
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
Wrapper class to encapsulate creation and management of an SDL_Texture.
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.
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)
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)
The basic class for representing 8-bit RGB or RGBA colour values.
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)
rect rect_
Relative coordinates of this item.
const color_t NORMAL_COLOR
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)
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 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.
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 blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
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)
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 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).
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
A config object defines a single node in a WML file, with access to child nodes.
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
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.
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.
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.