33 #define WRN_DP LOG_STREAM(warn, log_display)
38 gui::scrollarea(video),
42 shown_topic_(nullptr),
46 curr_row_height_(min_row_height_),
74 floating(_floating), box(_box),
90 box(_box), align(alignment)
110 if (surf !=
nullptr) {
118 std::vector<std::string>::const_iterator it;
119 for (it = parsed_items.begin(); it != parsed_items.end(); ++it) {
120 if (*it !=
"" && (*it)[0] ==
'[') {
124 std::istringstream
stream(*it);
127 #define TRY(name) do { \
128 if (config &child = cfg.child(#name)) \
129 handle_##name##_cfg(child); \
144 std::stringstream
msg;
145 msg <<
"Error when parsing help markup as WML: '" << e.
message <<
"'";
164 bool force = cfg[
"force"].to_bool();
167 std::stringstream
msg;
168 msg <<
"Ref markup must have dst attribute. Please submit a bug"
169 " report if you have not modified the game files yourself. Erroneous config: ";
191 std::stringstream
msg;
192 msg <<
"Reference to non-existent topic '" << dst
193 <<
"'. Please submit a bug report if you have not"
194 "modified the game files yourself. Erroneous config: ";
208 bool floating = cfg[
"float"].to_bool();
209 bool box = cfg[
"box"].to_bool(
true);
211 throw parse_error(
"Img markup must have src attribute.");
220 throw parse_error(
"Bold markup must have text attribute.");
229 throw parse_error(
"Italic markup must have text attribute.");
238 throw parse_error(
"Header markup must have text attribute.");
247 if (amount_str ==
"" && to_str ==
"") {
248 throw parse_error(
"Jump markup must have either a to or an amount attribute.");
251 if (amount_str !=
"") {
257 throw parse_error(
"Invalid amount the amount attribute in jump markup.");
267 throw parse_error(
"Invalid amount in the to attribute in jump markup.");
274 if (jump_to != 0 && static_cast<int>(jump_to) <
285 throw parse_error(
"Format markup must have text attribute.");
287 bool bold = cfg[
"bold"].to_bool();
288 bool italic = cfg[
"italic"].to_bool();
291 add_text_item(text,
"",
false, font_size, bold, italic, color);
295 bool broken_link,
int _font_size,
bool bold,
bool italic,
303 size_t first_word_start = text.find_first_not_of(
" ");
304 if (first_word_start == std::string::npos) {
305 first_word_start = 0;
307 if (text[first_word_start] ==
'\n') {
310 rest_text.erase(0, first_word_start + 1);
311 add_text_item(rest_text, ref_dst, broken_link, _font_size, bold, italic, text_color);
316 state |= bold ? TTF_STYLE_BOLD : 0;
317 state |= italic ? TTF_STYLE_ITALIC : 0;
324 add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color);
327 std::vector<std::string> parts =
split_in_width(text, font_size, remaining_width);
341 if (parts.size() > 1) {
360 add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color);
367 const bool floating,
const bool box)
373 if (align ==
HERE && floating) {
374 WRN_DP <<
"Floating image with align HERE, aligning left." << std::endl;
390 xpos = text_width / 2 - width / 2 - (box ?
box_width : 0);
393 xpos = text_width - width - (box ?
box_width * 2 : 0);
397 && (xpos <
curr_loc_.first || xpos + width > text_width)) {
414 int min_y = desired_y;
415 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
416 const item& itm = *it;
418 if ((itm.
rect.x + itm.
rect.w > x && itm.
rect.x < x + width)
420 min_y = std::max<int>(min_y, itm.
rect.y + itm.
rect.h);
430 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
431 const item& itm = *it;
434 min_x = std::max<int>(min_x, itm.
rect.w + 5);
444 int max_x = text_width;
445 for (std::list<item>::const_iterator it =
items_.begin(); it !=
items_.end(); ++it) {
446 const item& itm = *it;
448 if (itm.
rect.y < y + height && itm.
rect.y + itm.
rect.h > y) {
450 max_x = std::min<int>(max_x, text_width - itm.
rect.w - 5);
452 max_x = std::min<int>(max_x, text_width / 2 - itm.
rect.w / 2 - 5);
480 if (cmp_str ==
"left") {
482 }
else if (cmp_str ==
"middle") {
484 }
else if (cmp_str ==
"right") {
486 }
else if (cmp_str ==
"here" || cmp_str ==
"") {
489 std::stringstream
msg;
490 msg <<
"Invalid alignment string: '" << cmp_str <<
"'";
509 itm.
rect.y += gap / 2;
525 for(std::list<item>::const_iterator it =
items_.begin(),
end =
items_.end(); it !=
end; ++it) {
526 SDL_Rect
dst = it->rect;
528 if (dst.y < static_cast<int>(loc.h) && dst.y + it->rect.h > 0) {
539 sdl_blit(it->surf,
nullptr, screen, &dst);
559 const int local_x = x -
location().x;
560 const int local_y = y -
location().y;
561 if (local_y < static_cast<int>(
height()) && local_y > 0) {
563 const std::list<item>::const_iterator it =
566 if ((*it).ref_to !=
"") {
567 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)
function to get the surface corresponding to an image.
tformula< unsigned > x_
The x coordinate of the rectangle.
help_text_area(CVideo &video, const section &toplevel)
virtual void set_inner_location(const SDL_Rect &rect)
const std::vector< std::string > & parsed_text() const
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...
Thrown when the help system fails to parse something.
std::list< item * > last_row_
GLint GLint GLint GLint GLint GLint y
const int normal_font_size
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, SDL_Color color=font::NORMAL_COLOR)
Add an item with text.
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.
const SDL_Color NORMAL_COLOR
Definitions for the interface to Wesnoth Markup Language (WML).
std::string bold(const std::string &s)
topic const * shown_topic_
GLsizei const char ** path
const SDL_Color BAD_COLOR
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.
GLubyte GLubyte GLubyte GLubyte w
virtual void scroll(unsigned int pos)
const section & toplevel_
void handle_ref_cfg(const config &cfg)
const unsigned min_row_height_
Templates and utility-routines for strings and numbers.
void handle_img_cfg(const config &cfg)
int get_max_height(int size)
const std::string ¶meters float amount
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 .
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
std::pair< int, int > curr_loc_
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)
GLfloat GLfloat GLfloat GLfloat h
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
GLint GLint GLint GLint GLint x
tformula< unsigned > y_
The y coordinate of the rectangle.
void read(config &cfg, std::istream &in, abstract_validator *validator)
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.
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
std::string make_text_ellipsis(const std::string &text, int font_size, int max_width, int style)
If the text exceeds the specified max width, end it with an ellipsis (...)
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.
Standard logging facilities (interface).
bool operator()(const item &) const
A topic contains a title, an id and some text.
ALIGNMENT str_to_align(const std::string &s)
Convert a string to an alignment.
GLint GLint GLint GLint GLint GLint GLsizei width
SDL_Rect rect
Relative coordinates of this item.
SDL_Color string_to_color(const std::string &cmp_str)
Return the color the string represents.
const SDL_Color YELLOW_COLOR
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.
surface get_rendered_text(const std::string &str, int size, const SDL_Color &color, int style)
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.
void update_rect(const SDL_Rect &)
int contents_height_
The height of all items in total.
void write(std::ostream &out, configr_of const &cfg, unsigned int level)
Thrown when a lexical_cast fails.
GLsizei const GLcharARB ** string
int line_width(const std::string &line, int font_size, int style)
Determine the width of a line of text given a certain font size.
void draw_rectangle(int x, int y, int w, int h, Uint32 color, surface target)
Draw a colored rectangle on a surface.
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. All parts are less than width.
unsigned curr_row_height_
Function object to find an item at the specified coordinates.