21 #define GETTEXT_DOMAIN "wesnoth-lib"
52 , color_(cfg[
"color"])
53 , thickness_(cfg[
"thickness"])
55 const std::string&
debug = (cfg[
"debug"]);
69 const unsigned x1 =
x1_(variables);
70 const unsigned y1 =
y1_(variables);
71 const unsigned x2 =
x2_(variables);
72 const unsigned y2 =
y2_(variables);
74 DBG_GUI_D <<
"Line: draw from " << x1 <<
',' << y1 <<
" to " << x2 <<
',' << y2 <<
".";
85 , border_thickness_(cfg[
"border_thickness"])
86 , border_color_(cfg[
"border_color"],
color_t::null_color())
87 , fill_color_(cfg[
"fill_color"],
color_t::null_color())
94 const std::string&
debug = (cfg[
"debug"]);
102 const int x =
x_(variables);
103 const int y =
y_(variables);
104 const int w =
w_(variables);
105 const int h =
h_(variables);
110 if(!fill_color.
null()) {
114 const SDL_Rect area {
129 <<
", colour " << border_color;
131 const SDL_Rect dimensions {
146 , r_(cfg[
"corner_radius"])
147 , border_thickness_(cfg[
"border_thickness"])
148 , border_color_(cfg[
"border_color"],
color_t::null_color())
149 , fill_color_(cfg[
"fill_color"],
color_t::null_color())
156 const std::string&
debug = (cfg[
"debug"]);
158 DBG_GUI_P <<
"Rounded Rectangle: found debug message '" <<
debug <<
"'.";
164 const int x =
x_(variables);
165 const int y =
y_(variables);
166 const int w =
w_(variables);
167 const int h =
h_(variables);
168 const int r =
r_(variables);
170 DBG_GUI_D <<
"Rounded Rectangle: draw from " << x <<
',' << y <<
" width " <<
w <<
" height " <<
h <<
".";
175 if(!fill_color.
null() &&
w &&
h) {
213 , radius_(cfg[
"radius"])
214 , border_color_(cfg[
"border_color"])
215 , fill_color_(cfg[
"fill_color"])
216 , border_thickness_(cfg[
"border_thickness"].to_int(1))
218 const std::string&
debug = (cfg[
"debug"]);
232 const int x =
x_(variables);
233 const int y =
y_(variables);
234 const unsigned radius =
radius_(variables);
236 DBG_GUI_D <<
"Circle: drawn at " << x <<
',' << y <<
" radius " << radius <<
".";
239 if(!fill_color.
null() && radius) {
257 , image_name_(cfg[
"name"])
258 , resize_mode_(get_resize_mode(cfg[
"resize_mode"]))
259 , mirror_(cfg.get_old_attribute(
"mirror",
"vertical_mirror",
"image"))
260 , actions_formula_(cfg[
"actions"], &functions)
262 const std::string&
debug = (cfg[
"debug"]);
270 const int as_int =
static_cast<int>(value);
273 formatter() <<
"Image '" << name <<
"', " << key <<
" = " << as_int <<
"."
289 DBG_GUI_D <<
"Image: formula returned no value, will not be drawn.";
304 ERR_GUI_D <<
"Image: '" << name <<
"' not found and won't be drawn.";
312 int w =
w_(local_variables);
315 int h =
h_(local_variables);
321 const int x =
x_(local_variables);
322 const int y =
y_(local_variables);
332 if (!
w) {
w = tex.
w(); }
333 if (!
h) {
h = tex.
h(); }
335 const SDL_Rect dst_rect { x, y,
w,
h };
362 ERR_GUI_D <<
"Image: unrecognized resize mode.";
400 , font_size_(cfg[
"font_size"])
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"])
410 , maximum_height_(cfg[
"maximum_height"], -1)
416 const std::string&
debug = (cfg[
"debug"]);
424 assert(variables.
has_key(
"text"));
432 DBG_GUI_D <<
"Text: no text to render, leave.";
451 ?
static_cast<PangoEllipsizeMode
>(variables.
query_value(
"text_wrap_mode").
as_int())
452 : PANGO_ELLIPSIZE_END)
456 const auto [tw, th] = text_renderer.
get_size();
462 const int x =
x_(local_variables);
463 const int y =
y_(local_variables);
464 const int w =
w_(local_variables);
465 const int h =
h_(local_variables);
466 rect dst_rect{x, y,
w,
h};
470 DBG_GUI_D <<
"Text: Rendering '" << text <<
"' resulted in an empty canvas, leave.";
474 dst_rect.w = std::min(dst_rect.w, tex.
w());
475 dst_rect.h = std::min(dst_rect.h, tex.
h());
493 : shapes_(std::move(
c.shapes_))
494 , blur_depth_(
c.blur_depth_)
497 , variables_(
c.variables_)
498 , functions_(
c.functions_)
507 DBG_GUI_D <<
"Canvas: empty (no shapes to draw).";
542 DBG_GUI_P <<
"Canvas: found shape of the type " <<
type <<
".";
545 shapes_.emplace_back(std::make_unique<line_shape>(
data));
546 }
else if(
type ==
"rectangle") {
547 shapes_.emplace_back(std::make_unique<rectangle_shape>(
data));
548 }
else if(
type ==
"round_rectangle") {
549 shapes_.emplace_back(std::make_unique<round_rectangle_shape>(
data));
550 }
else if(
type ==
"circle") {
551 shapes_.emplace_back(std::make_unique<circle_shape>(
data));
552 }
else if(
type ==
"image") {
554 }
else if(
type ==
"text") {
555 shapes_.emplace_back(std::make_unique<text_shape>(
data));
556 }
else if(
type ==
"pre_commit") {
559 for(
const auto function :
data.all_children_range())
562 if(
function.key ==
"blur") {
565 ERR_GUI_P <<
"Canvas: found a pre commit function"
566 <<
" of an invalid type " <<
type <<
".";
571 ERR_GUI_P <<
"Canvas: found a shape of an invalid type " <<
type
598 auto conditional = [](
const std::unique_ptr<shape>&
s)->
bool {
return !
s->immutable(); };
600 auto iter = std::remove_if(
shapes_.begin(),
shapes_.end(), conditional);
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.
const_all_children_itors all_children_range() const
In-order iteration over all children.
pango_text & set_font_style(const FONT_STYLE font_style)
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)
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
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.
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)
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.
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.
void parse_cfg(const config &cfg)
Parses a config object.
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.
Class holding common attribute names (for WML) and common implementation (in C++) for shapes placed w...
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.
text_shape(const config &cfg)
Constructor.
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.
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.
typed_formula< unsigned > font_size_
The font size of the text.
unsigned characters_per_line_
The number of characters per line.
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.
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.
variant execute_variant(const variant &to_exec)
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 circle(int x, int y, int r, const color_t &c, uint8_t octants=0xff)
Draw a circle of the given colour.
SDL_Rect get_viewport()
Get the current viewport.
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.
Collection of helper functions relating to Pango formatting.
pango_text & get_text_renderer()
Returns a reference to a static pango_text object.
family_class str_to_family_class(const std::string &str)
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")
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")
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
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
surface blur_surface(const surface &surf, int depth)
Cross-fades a surface.
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)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.