21 #define GETTEXT_DOMAIN "wesnoth-lib"
57 , color_(cfg[
"color"])
58 , thickness_(cfg[
"thickness"].to_unsigned())
60 const std::string&
debug = (cfg[
"debug"]);
74 const unsigned x1 =
x1_(variables);
75 const unsigned y1 =
y1_(variables);
76 const unsigned x2 =
x2_(variables);
77 const unsigned y2 =
y2_(variables);
79 DBG_GUI_D <<
"Line: draw from " << x1 <<
',' << y1 <<
" to " << x2 <<
',' << y2 <<
".";
90 , border_thickness_(cfg[
"border_thickness"].to_int())
91 , border_color_(cfg[
"border_color"],
color_t::null_color())
92 , fill_color_(cfg[
"fill_color"],
color_t::null_color())
99 const std::string&
debug = (cfg[
"debug"]);
117 if(!fill_color.
null()) {
137 , r_(cfg[
"corner_radius"])
138 , border_thickness_(cfg[
"border_thickness"].to_int())
139 , border_color_(cfg[
"border_color"],
color_t::null_color())
140 , fill_color_(cfg[
"fill_color"],
color_t::null_color())
147 const std::string&
debug = (cfg[
"debug"]);
149 DBG_GUI_P <<
"Rounded Rectangle: found debug message '" <<
debug <<
"'.";
155 const int x =
x_(variables);
156 const int y =
y_(variables);
157 const int w =
w_(variables);
158 const int h =
h_(variables);
159 const int r =
r_(variables);
161 DBG_GUI_D <<
"Rounded Rectangle: draw from " << x <<
',' << y <<
" width " <<
w <<
" height " <<
h <<
".";
166 if(!fill_color.
null() &&
w &&
h) {
204 , radius_(cfg[
"radius"])
205 , border_color_(cfg[
"border_color"])
206 , fill_color_(cfg[
"fill_color"])
207 , border_thickness_(cfg[
"border_thickness"].to_int(1))
209 const std::string&
debug = (cfg[
"debug"]);
223 const int x =
x_(variables);
224 const int y =
y_(variables);
225 const unsigned radius =
radius_(variables);
227 DBG_GUI_D <<
"Circle: drawn at " << x <<
',' << y <<
" radius " << radius <<
".";
230 if(!fill_color.
null() && radius) {
248 , image_name_(cfg[
"name"])
249 , resize_mode_(get_resize_mode(cfg[
"resize_mode"]))
250 , mirror_(cfg.get_old_attribute(
"mirror",
"vertical_mirror",
"image"))
251 , actions_formula_(cfg[
"actions"], &functions)
253 const std::string&
debug = (cfg[
"debug"]);
261 const int as_int =
static_cast<int>(value);
264 formatter() <<
"Image '" << name <<
"', " << key <<
" = " << as_int <<
"."
280 DBG_GUI_D <<
"Image: formula returned no value, will not be drawn.";
295 ERR_GUI_D <<
"Image: '" << name <<
"' not found and won't be drawn.";
303 int w =
w_(local_variables);
306 int h =
h_(local_variables);
312 const int x =
x_(local_variables);
313 const int y =
y_(local_variables);
331 if (!
w) {
w = tex.
w(); }
332 if (!
h) {
h = tex.
h(); }
334 const SDL_Rect dst_rect { x, y,
w,
h };
361 ERR_GUI_D <<
"Image: unrecognized resize mode.";
402 , text_alignment_(cfg[
"text_alignment"])
403 , color_(cfg[
"color"])
405 , text_markup_(cfg[
"text_markup"], false)
406 , link_aware_(cfg[
"text_link_aware"], false)
407 , link_color_(cfg[
"text_link_color"],
color_t::from_hex_string(
"ffff00"))
408 , maximum_width_(cfg[
"maximum_width"], -1)
409 , characters_per_line_(cfg[
"text_characters_per_line"].to_unsigned())
410 , maximum_height_(cfg[
"maximum_height"], -1)
411 , highlight_start_(cfg[
"highlight_start"])
412 , highlight_end_(cfg[
"highlight_end"])
413 , highlight_color_(cfg[
"highlight_color"],
color_t::from_hex_string(
"215380"))
414 , attr_start_(cfg[
"attr_start"])
415 , attr_end_(cfg[
"attr_end"])
416 , attr_name_(cfg[
"attr_name"])
417 , attr_data_(cfg[
"attr_data"])
418 , outline_(cfg[
"outline"], false)
419 , actions_formula_(cfg[
"actions"], &functions)
421 const std::string&
debug = (cfg[
"debug"]);
429 assert(variables.
has_key(
"text"));
437 DBG_GUI_D <<
"Text: no text to render, leave.";
450 for(
size_t i = 0;
i < std::min(starts.size(), stops.size());
i++) {
460 const std::string& name = attr[
"name"];
466 const unsigned start = attr[
"start"].to_int(0);
467 const unsigned end = attr[
"end"].to_int(text.
size());
469 if (name ==
"color" || name ==
"fgcolor" || name ==
"foreground") {
471 }
else if (name ==
"bgcolor"||name ==
"background") {
473 }
else if (name ==
"font_size"||name ==
"size") {
475 }
else if (name ==
"font_family"||name ==
"face") {
477 }
else if (name ==
"weight") {
479 }
else if (name ==
"style") {
481 }
else if (name ==
"bold" || name ==
"b") {
483 }
else if (name ==
"italic" || name ==
"i") {
485 }
else if (name ==
"underline" || name ==
"u") {
507 ?
static_cast<PangoEllipsizeMode
>(variables.
query_value(
"text_wrap_mode").
as_int())
508 : PANGO_ELLIPSIZE_END)
513 const auto [tw, th] = text_renderer.
get_size();
525 const int x =
x_(local_variables);
526 const int y =
y_(local_variables);
527 const int w =
w_(local_variables);
528 const int h =
h_(local_variables);
529 rect dst_rect{x, y,
w,
h};
536 DBG_GUI_D <<
"Text: Rendering '" << text <<
"' resulted in an empty canvas, leave.";
540 dst_rect.w = std::min(dst_rect.w, tex.
w());
541 dst_rect.h = std::min(dst_rect.h, tex.
h());
561 : shapes_(std::move(
c.shapes_))
562 , blur_depth_(
c.blur_depth_)
563 , blur_region_(
c.blur_region_)
564 , deferred_(
c.deferred_)
567 , variables_(
c.variables_)
568 , functions_(
c.functions_)
583 <<
" to " << screen_region;
611 DBG_GUI_D <<
"Deferring blur at " << screen_region;
620 rect read_region = screen_region;
639 DBG_GUI_D <<
"Canvas: empty (no shapes to draw).";
668 DBG_GUI_P <<
"Canvas: found shape of the type " <<
type <<
".";
671 shapes_.emplace_back(std::make_unique<line_shape>(
data));
672 }
else if(
type ==
"rectangle") {
673 shapes_.emplace_back(std::make_unique<rectangle_shape>(
data));
674 }
else if(
type ==
"round_rectangle") {
675 shapes_.emplace_back(std::make_unique<round_rectangle_shape>(
data));
676 }
else if(
type ==
"circle") {
677 shapes_.emplace_back(std::make_unique<circle_shape>(
data));
678 }
else if(
type ==
"image") {
680 }
else if(
type ==
"text") {
682 }
else if(
type ==
"pre_commit") {
685 for(
const auto [func_key, func_cfg] :
data.all_children_view())
687 if(func_key ==
"blur") {
690 ERR_GUI_P <<
"Canvas: found a pre commit function"
691 <<
" of an invalid type " <<
type <<
".";
696 ERR_GUI_P <<
"Canvas: found a shape of an invalid type " <<
type
This file contains the canvas object which is the part where the widgets draw (temporally) images on.
A config object defines a single node in a WML file, with access to child nodes.
auto all_children_view() const
In-order iteration over all children.
child_itors child_range(config_key_type key)
pango_text & set_font_style(const FONT_STYLE font_style)
void add_attribute_weight(const unsigned start_offset, const unsigned end_offset, PangoWeight weight)
Add pango font weight attribute to a specific portion of text.
point get_size()
Returns the size of the text, in drawing coordinates.
pango_text & set_characters_per_line(const unsigned characters_per_line)
pango_text & set_foreground_color(const color_t &color)
pango_text & set_family_class(font::family_class fclass)
void add_attribute_fg_color(const unsigned start_offset, const unsigned end_offset, const color_t &color)
Add pango fg color attribute to a specific portion of text.
void add_attribute_font_family(const unsigned start_offset, const unsigned end_offset, const std::string &family)
Add pango font family attribute to a specific portion of text.
void add_attribute_size(const unsigned start_offset, const unsigned end_offset, int size)
Add pango font size attribute to a specific portion of text.
pango_text & set_add_outline(bool do_add)
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
void add_attribute_bg_color(const unsigned start_offset, const unsigned end_offset, const color_t &color)
Mark a specific portion of text for highlighting.
void add_attribute_underline(const unsigned start_offset, const unsigned end_offset, PangoUnderline underline)
Add pango underline attribute to a specific portion of text.
pango_text & set_alignment(const PangoAlignment alignment)
pango_text & set_font_size(unsigned font_size)
pango_text & set_link_aware(bool b)
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
void add_attribute_style(const unsigned start_offset, const unsigned end_offset, PangoStyle style)
Add pango font style attribute to a specific portion of text, used to set italic/oblique text.
pango_text & set_maximum_height(int height, bool multiline)
pango_text & set_maximum_width(int width)
texture render_and_get_texture()
Returns the cached texture, or creates a new one otherwise.
pango_text & set_link_color(const color_t &color)
void clear_attribute_list()
Clears all attributes from the global attribute list.
Abstract base class for all other shapes.
virtual void draw(wfl::map_formula_callable &variables)=0
Draws the canvas.
A simple canvas which can be drawn upon.
texture blur_texture_
Blurred background texture.
bool deferred_
Whether we have deferred rendering so we can capture for blur.
wfl::action_function_symbol_table functions_
Action function definitions for the canvas.
void clear_shapes(const bool force)
unsigned blur_depth_
The depth of the blur to use in the pre committing.
wfl::map_formula_callable variables_
The variables of the canvas.
bool update_blur(const rect &screen_region, const bool force=false)
Update the background blur texture, if relevant and necessary.
rect blur_region_
The region of the screen we have blurred (if any).
void parse_cfg(const config &cfg)
Parses a config object.
void queue_reblur()
Clear the cached blur texture, forcing it to regenerate.
std::vector< std::unique_ptr< shape > > shapes_
Vector with the shapes to draw.
unsigned w_
The full width of the canvas.
void update_size_variables()
Update WFL size variables.
unsigned h_
The full height of the canvas.
void draw()
Draw the canvas' shapes onto the screen.
void set_size(const point &size)
typed_formula< color_t > border_color_
The border color of the circle.
typed_formula< unsigned > x_
The center x coordinate of the circle.
typed_formula< unsigned > radius_
The radius of the circle.
unsigned int border_thickness_
The border thickness of the circle.
circle_shape(const config &cfg)
Constructor.
typed_formula< color_t > fill_color_
The fill color of the circle.
typed_formula< unsigned > y_
The center y coordinate of the circle.
void draw(wfl::map_formula_callable &variables) override
Draws the canvas.
typed_formula< std::string > image_name_
Name of the image.
resize_mode
Determines the way an image will be resized.
typed_formula< unsigned > w_
The width of the image.
resize_mode get_resize_mode(const std::string &resize_mode)
Converts a string to a resize mode.
typed_formula< unsigned > x_
The x coordinate of the image.
static void dimension_validation(unsigned value, const std::string &name, const std::string &key)
typed_formula< unsigned > y_
The y coordinate of the image.
typed_formula< unsigned > h_
The height of the image.
resize_mode resize_mode_
The resize mode for an image.
wfl::formula actions_formula_
typed_formula< bool > mirror_
Mirror the image over the vertical axis.
void draw(wfl::map_formula_callable &variables) override
Draws the canvas.
image_shape(const config &cfg, wfl::action_function_symbol_table &functions)
Constructor.
typed_formula< color_t > color_
The color of the line.
typed_formula< unsigned > x1_
The start x coordinate of the line.
typed_formula< unsigned > y1_
The start y coordinate of the line.
typed_formula< unsigned > x2_
The end x coordinate of the line.
line_shape(const config &cfg)
Constructor.
typed_formula< unsigned > y2_
The end y coordinate of the line.
void draw(wfl::map_formula_callable &variables) override
Draws the canvas.
typed_formula< int > x_
The x coordinate of the rectangle.
typed_formula< int > w_
The width of the rectangle.
typed_formula< int > y_
The y coordinate of the rectangle.
typed_formula< int > h_
The height of the rectangle.
rectangle_shape(const config &cfg)
Constructor.
int border_thickness_
Border thickness.
typed_formula< color_t > fill_color_
The border color of the rectangle.
void draw(wfl::map_formula_callable &variables) override
Draws the canvas.
typed_formula< color_t > border_color_
The border color of the rectangle.
typed_formula< color_t > border_color_
The border color of the rounded rectangle.
void draw(wfl::map_formula_callable &variables) override
Draws the canvas.
typed_formula< int > r_
The radius of the corners.
round_rectangle_shape(const config &cfg)
Constructor.
int border_thickness_
Border thickness.
typed_formula< color_t > fill_color_
The border color of the rounded rectangle.
font::pango_text::FONT_STYLE font_style_
The style of the text.
std::string highlight_end_
typed_formula< bool > outline_
Whether to apply a text outline.
typed_formula< color_t > color_
The color of the text.
typed_formula< int > maximum_height_
The maximum height for the text.
typed_formula< bool > link_aware_
The link aware switch of the text.
typed_formula< PangoAlignment > text_alignment_
The alignment of the text.
config cfg_
the source config
typed_formula< color_t > highlight_color_
The color to be used for highlighting.
std::string highlight_start_
Start and end offsets for highlight.
font::family_class font_family_
The text font family.
typed_formula< color_t > link_color_
The link color of the text.
typed_formula< int > maximum_width_
The maximum width for the text.
void draw(wfl::map_formula_callable &variables) override
Draws the canvas.
text_shape(const config &cfg, wfl::action_function_symbol_table &functions)
Constructor.
typed_formula< unsigned > font_size_
The font size of the text.
unsigned characters_per_line_
The number of characters per line.
wfl::formula actions_formula_
Any extra WFL actions to execute.
typed_formula< t_string > text_
The text to draw.
typed_formula< bool > text_markup_
The text markup switch of the text.
Generic locator abstracting the location of an image.
std::string::size_type size() const
Wrapper class to encapsulate creation and management of an SDL_Texture.
int w() const
The draw-space width of the texture, in pixels.
void reset()
Releases ownership of the managed texture and resets the ptr to null.
point draw_size() const
The size of the texture in draw-space.
int h() const
The draw-space height of the texture, in pixels.
variant execute_variant(const variant &to_exec)
bool as_bool() const
Returns a boolean state of the variant value.
Drawing functions, for drawing things on the screen.
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
#define log_scope2(domain, description)
void request_extra_render_pass()
Request an extra render pass.
render_target_setter set_render_target(const texture &t)
Set the given texture as the active render target.
void circle(int x, int y, int r, const color_t &c, uint8_t octants=0xff)
Draw a circle of the given colour.
void tiled(const texture &tex, const SDL_Rect &dst, bool centered=false, bool mirrored=false)
Tile a texture to fill a region.
void disc(int x, int y, int r, const color_t &c, uint8_t octants=0xff)
Draw a solid disc of the given colour.
void set_color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Set the drawing colour.
void flipped(const texture &tex, const SDL_Rect &dst, bool flip_h=true, bool flip_v=false)
Draws a texture, or part of a texture, at the given location, also mirroring/flipping the texture hor...
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.
void tiled_highres(const texture &tex, const SDL_Rect &dst, bool centered=false, bool mirrored=false)
Tile a texture to fill a region.
void rect(const SDL_Rect &rect)
Draw a rectangle.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
pango_text & get_text_renderer()
Returns a reference to a static pango_text object.
color_t string_to_color(const std::string &cmp_str)
Return the color the string represents.
const t_string & get_font_families(family_class fclass)
Returns the currently defined fonts.
family_class str_to_family_class(const std::string &str)
const color_t NORMAL_COLOR
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
lg::log_domain log_gui_draw("gui/draw")
PangoWeight decode_text_weight(const std::string &weight)
Converts a text weight string to a PangoWeight.
font::pango_text::FONT_STYLE decode_font_style(const std::string &style)
Converts a font style string to a font style.
lg::log_domain log_gui_parse("gui/parse")
PangoStyle decode_text_style(const std::string &style)
Converts a text style string to a PangoStyle.
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
constexpr const SDL_Rect empty_rect
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
void erase_if(Container &container, const Predicate &predicate)
Convenience wrapper for using std::remove_if on a container.
std::vector< std::string > split(const config_attribute_value &val)
surface read_pixels_low_res(SDL_Rect *r)
The same as read_pixels, but returns a low-resolution surface suitable for use with the old drawing s...
Contains the SDL_Rect helper code.
The basic class for representing 8-bit RGB or RGBA colour values.
constexpr bool null() const
An abstract description of a rectangle with integer coordinates.
static map_location::direction s
void blur_surface(surface &surf, SDL_Rect rect, int depth)
Cross-fades a surface in place.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message)