The Battle for Wesnoth  1.17.8+dev
Classes | Functions
draw Namespace Reference

Classes

class  clip_setter
 A class to manage automatic restoration of the clipping region. More...
 
class  render_target_setter
 A class to manage automatic restoration of the render target. More...
 
class  viewport_setter
 A class to manage automatic restoration of the viewport region. More...
 

Functions

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. More...
 
void fill (const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b)
 
void fill (const SDL_Rect &rect, const color_t &color)
 
void fill (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 
void fill (uint8_t r, uint8_t g, uint8_t b)
 
void fill (const color_t &color)
 
void fill (const SDL_Rect &rect)
 Fill an area. More...
 
void fill ()
 
void set_color (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 Set the drawing colour. More...
 
void set_color (uint8_t r, uint8_t g, uint8_t b)
 
void set_color (const color_t &c)
 
void set_blend_mode (SDL_BlendMode b)
 Set the blend mode used for drawing operations such as fill() and line(). More...
 
void rect (const SDL_Rect &rect)
 Draw a rectangle. More...
 
void rect (const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 Draw a rectangle using the given colour. More...
 
void rect (const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b)
 
void rect (const SDL_Rect &rect, const color_t &color)
 
void line (int from_x, int from_y, int to_x, int to_y)
 Draw a line. More...
 
void line (int from_x, int from_y, int to_x, int to_y, const color_t &c)
 Draw a line of the given colour. More...
 
void points (const std::vector< SDL_Point > &points)
 Draw a set of points. More...
 
void point (int x, int y)
 Draw a single point. More...
 
void circle (int x, int y, int r, const color_t &c, uint8_t octants=0xff)
 Draw a circle of the given colour. More...
 
void circle (int x, int y, int r, uint8_t octants=0xff)
 
void disc (int x, int y, int r, const color_t &c, uint8_t octants=0xff)
 Draw a solid disc of the given colour. More...
 
void disc (int x, int y, int r, uint8_t octants=0xff)
 
void blit (const texture &tex, const SDL_Rect &dst)
 Draws a texture, or part of a texture, at the given location. More...
 
void blit (const texture &tex)
 
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 horizontally and/or vertically. More...
 
void flipped (const texture &tex, bool flip_h=true, bool flip_v=false)
 
void tiled (const texture &tex, const SDL_Rect &dst, bool centered=false, bool mirrored=false)
 Tile a texture to fill a region. More...
 
void tiled_highres (const texture &tex, const SDL_Rect &dst, bool centered=false, bool mirrored=false)
 Tile a texture to fill a region. More...
 
clip_setter override_clip (const SDL_Rect &clip)
 Override the clipping area. More...
 
clip_setter reduce_clip (const SDL_Rect &clip)
 Set the clipping area to the intersection of the current clipping area and the given rectangle. More...
 
void force_clip (const SDL_Rect &clip)
 Set the clipping area, without any provided way of setting it back. More...
 
::rect get_clip ()
 Get the current clipping area, in draw coordinates. More...
 
bool clip_enabled ()
 Whether clipping is enabled. More...
 
void disable_clip ()
 Disable clipping. More...
 
bool null_clip ()
 Whether the current clipping region will disallow drawing. More...
 
viewport_setter set_viewport (const SDL_Rect &viewport)
 Set the viewport. More...
 
void force_viewport (const SDL_Rect &viewport)
 Set the viewport, without any provided way of setting it back. More...
 
SDL_Rect get_viewport ()
 Get the current viewport. More...
 
render_target_setter set_render_target (const texture &t)
 Set the given texture as the active render target. More...
 

Function Documentation

◆ blit() [1/2]

void draw::blit ( const texture tex,
const SDL_Rect &  dst 
)

Draws a texture, or part of a texture, at the given location.

The portion of the texture to be drawn will be scaled to fill the target rectangle.

This version takes coordinates in game-native resolution, which may be lower than the final output resolution in high-dpi contexts or if pixel scaling is used. The texture will be copied in high-resolution if possible.

Parameters
texThe texture to be copied / drawn.
dstThe target location to copy the texture to, in low-resolution game-native drawing coordinates. If null, this fills the entire render target.

Definition at line 301 of file draw.cpp.

References DBG_D, sdl::empty_rect, renderer(), and texture::src().

Referenced by font::floating_label::draw(), gui2::canvas::draw(), gui2::image_shape::draw(), gui2::text_shape::draw(), gui::dialog_frame::draw_background(), gui::dialog_frame::draw_border(), gui::textbox::draw_contents(), gui::scrollbar::draw_contents(), gui::tristate_button::draw_contents(), gui::button::draw_contents(), help::help_text_area::draw_contents(), display::draw_label(), display::draw_minimap(), display::draw_report(), gui::menu::imgsel_style::draw_row(), gui::menu::draw_row(), gui::menu::imgsel_style::draw_row_bg(), display::drawing_buffer_commit(), display::expose(), font::pango_draw_text(), halo::halo_impl::effect::render(), image::render_minimap(), display::scroll(), and tiled().

◆ blit() [2/2]

void draw::blit ( const texture tex)

Definition at line 313 of file draw.cpp.

References DBG_D, renderer(), and texture::src().

◆ circle() [1/2]

void draw::circle ( int  x,
int  y,
int  r,
const color_t c,
uint8_t  octants = 0xff 
)

Draw a circle of the given colour.

Only the outline of the circle is drawn. To draw a filled circle, use draw::disc().

The octants bitfield can be used to draw only certain octants of the circle, resulting in one or more arcs.

If no colour is specified, the current drawing colour will be used.

Parameters
xThe x coordinate of the center of the circle.
yThe y coordinate of the center of the circle.
rThe radius of the circle.
cThe colour of the circle.
octantsA bitfield indicating which octants to draw, starting at twelve o'clock and moving clockwise.

Definition at line 199 of file draw.cpp.

References set_color().

Referenced by gui2::round_rectangle_shape::draw(), and gui2::circle_shape::draw().

◆ circle() [2/2]

void draw::circle ( int  x,
int  y,
int  r,
uint8_t  octants = 0xff 
)

Definition at line 205 of file draw.cpp.

References d, DBG_D, and points().

◆ clip_enabled()

bool draw::clip_enabled ( )

Whether clipping is enabled.

Definition at line 484 of file draw.cpp.

References renderer().

Referenced by reduce_clip().

◆ disable_clip()

void draw::disable_clip ( )

Disable clipping.

To enable clipping, use set_clip() or force_clip().

Definition at line 492 of file draw.cpp.

References DBG_D, and renderer().

Referenced by draw::clip_setter::~clip_setter(), and draw::viewport_setter::~viewport_setter().

◆ disc() [1/2]

void draw::disc ( int  x,
int  y,
int  r,
const color_t c,
uint8_t  octants = 0xff 
)

Draw a solid disc of the given colour.

The octants bitfield can be used to draw only certain octants of the disc, resulting in one or more filled wedges.

If no colour is specified, the current drawing colour will be used.

Parameters
xThe x coordinate of the center of the circle.
yThe y coordinate of the center of the circle.
rThe radius of the circle.
cThe colour of the circle.
octantsA bitfield indicating which octants to draw, starting at twelve o'clock and moving clockwise.

Definition at line 241 of file draw.cpp.

References set_color().

Referenced by gui2::round_rectangle_shape::draw(), and gui2::circle_shape::draw().

◆ disc() [2/2]

void draw::disc ( int  x,
int  y,
int  r,
uint8_t  octants = 0xff 
)

Definition at line 247 of file draw.cpp.

References d, DBG_D, and line().

◆ fill() [1/8]

void draw::fill ( const SDL_Rect &  rect,
uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a 
)

◆ fill() [2/8]

void draw::fill ( const SDL_Rect &  rect,
uint8_t  r,
uint8_t  g,
uint8_t  b 
)

Definition at line 50 of file draw.cpp.

References fill().

◆ fill() [3/8]

void draw::fill ( const SDL_Rect &  rect,
const color_t color 
)

Definition at line 57 of file draw.cpp.

References fill().

◆ fill() [4/8]

void draw::fill ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a 
)

Definition at line 62 of file draw.cpp.

References b, DBG_D, g, and renderer().

◆ fill() [5/8]

void draw::fill ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)

Definition at line 69 of file draw.cpp.

References fill().

◆ fill() [6/8]

void draw::fill ( const color_t color)

Definition at line 74 of file draw.cpp.

References fill().

◆ fill() [7/8]

void draw::fill ( const SDL_Rect &  rect)

Fill an area.

Uses the current drawing colour set by set_draw_color(). Coordinates are given in draw space.

If a fill area is not specified, it will fill the entire render target.

Parameters
rectThe area to fill, in drawing coordinates.

Definition at line 79 of file draw.cpp.

References DBG_D, and renderer().

◆ fill() [8/8]

void draw::fill ( )

Definition at line 85 of file draw.cpp.

References DBG_D, and renderer().

◆ flipped() [1/2]

void draw::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 horizontally and/or vertically.

By default the texture will be flipped horizontally.

Parameters
texThe texture to be copied / drawn.
dstThe target location to copy the texture to, in low-resolution game-native drawing coordinates. If not given, the entire render target will be filled.
flip_hWhether to flip/mirror the texture horizontally.
flip_vWhether to flip/mirror the texture vertically.

Definition at line 331 of file draw.cpp.

References DBG_D, sdl::empty_rect, get_flip(), renderer(), and texture::src().

Referenced by gui2::image_shape::draw(), display::drawing_buffer_commit(), halo::halo_impl::effect::render(), and tiled().

◆ flipped() [2/2]

void draw::flipped ( const texture tex,
bool  flip_h = true,
bool  flip_v = false 
)

Definition at line 349 of file draw.cpp.

References DBG_D, get_flip(), renderer(), and texture::src().

◆ force_clip()

void draw::force_clip ( const SDL_Rect &  clip)

Set the clipping area, without any provided way of setting it back.

Parameters
clipThe clipping area, in draw-space coordinates.

Definition at line 456 of file draw.cpp.

References DBG_D, renderer(), and WRN_D.

Referenced by draw::clip_setter::clip_setter(), draw::viewport_setter::viewport_setter(), draw::clip_setter::~clip_setter(), and draw::viewport_setter::~viewport_setter().

◆ force_viewport()

void draw::force_viewport ( const SDL_Rect &  viewport)

Set the viewport, without any provided way of setting it back.

The new viewport is specified in absolute coordinates, relative to the full drawing surface.

Parameters
viewportThe viewport, in absolute draw-space coordinates. If null, the viewport is reset to the full draw area.

Definition at line 547 of file draw.cpp.

References DBG_D, renderer(), and WRN_D.

Referenced by draw::viewport_setter::viewport_setter(), and draw::viewport_setter::~viewport_setter().

◆ get_clip()

rect draw::get_clip ( )

Get the current clipping area, in draw coordinates.

The clipping area is interpreted relative to the current viewport.

If clipping is disabled, this will return the full drawing area.

Definition at line 468 of file draw.cpp.

References sdl::empty_rect, get_viewport(), and renderer().

Referenced by font::floating_label::draw(), display::draw_label(), display::draw_minimap(), display::draw_panel(), gui2::window::expose(), display::expose(), reduce_clip(), and draw::viewport_setter::viewport_setter().

◆ get_viewport()

SDL_Rect draw::get_viewport ( )

Get the current viewport.

Returns
The current viewport, in the coordinate space of the original drawing surface

Definition at line 558 of file draw.cpp.

References video::draw_area(), sdl::empty_rect, renderer(), and WRN_D.

Referenced by gui2::canvas::draw(), get_clip(), and draw::viewport_setter::viewport_setter().

◆ line() [1/2]

void draw::line ( int  from_x,
int  from_y,
int  to_x,
int  to_y 
)

Draw a line.

Uses the current drawing colour set by set_color(). Coordinates are given in draw space.

Parameters
from_xThe X coordinate of the start point, in draw space.
from_yThe Y coordinate of the start point, in draw space.
to_xThe X coordinate of the end point, in draw space.
to_yThe Y coordinate of the end point, in draw space.

Definition at line 171 of file draw.cpp.

References DBG_D, and renderer().

Referenced by disc(), gui2::line_shape::draw(), gui2::round_rectangle_shape::draw(), draw_rect_as_lines(), wfl::formula_error::formula_error(), font::pango_text::get_column_line(), font::pango_text::get_cursor_position(), gui2::text_box_base::get_cursor_position(), gui2::get_hp_tooltip(), utils::indent(), intf_describe_plugins(), intf_object_dir(), lineno_string(), font::pango_word_wrap(), read_ignore_patterns(), unit_hp(), unit_weapons(), and preferences::manager::~manager().

◆ line() [2/2]

void draw::line ( int  from_x,
int  from_y,
int  to_x,
int  to_y,
const color_t c 
)

Draw a line of the given colour.

Parameters
from_xThe X coordinate of the start point, in draw space.
from_yThe Y coordinate of the start point, in draw space.
to_xThe X coordinate of the end point, in draw space.
to_yThe Y coordinate of the end point, in draw space.
cThe RGBA colour of the line.

Definition at line 178 of file draw.cpp.

References c, DBG_D, and renderer().

◆ null_clip()

bool draw::null_clip ( )

Whether the current clipping region will disallow drawing.

This returns true for any clipping region with negative or zero width or height.

Definition at line 501 of file draw.cpp.

References renderer().

◆ override_clip()

draw::clip_setter draw::override_clip ( const SDL_Rect &  clip)

Override the clipping area.

All draw calls will be clipped to this region.

The clipping area is specified in draw-space coordinates.

The returned object will reset the clipping area when it is destroyed, so it should be kept in scope until drawing is complete.

Parameters
clipThe clipping region in draw-space coordinates.
Returns
A clip_setter object. When this object is destroyed the clipping region will be restored to whatever it was before this call.

Definition at line 443 of file draw.cpp.

Referenced by draw_manager::expose(), and display::screenshot().

◆ point()

void draw::point ( int  x,
int  y 
)

Draw a single point.

Definition at line 193 of file draw.cpp.

References DBG_D, and renderer().

Referenced by gui2::tree_view_node::add_child_impl(), gui2::panel::border_space(), gui2::toggle_panel::border_space(), gui2::container_base::border_space(), gui2::implementation::builder_drawing::build(), gui2::spacer::calculate_best_size(), gui2::size_lock::calculate_best_size(), gui2::drawing::calculate_best_size(), gui2::scrollbar_container::calculate_best_size(), gui2::policy::placement::table::calculate_best_size(), gui2::widget::clear_layout_size(), gui2::scrollbar_container::content_resize_request(), video::current_resolution(), game_launcher::game_launcher(), gui2::widget::get_best_size(), gui2::grid::child::get_best_size(), gui2::styled_widget::get_best_text_size(), font::pango_text::get_column_line(), gui2::get_control(), gui2::tree_view_node::get_current_size(), font::pango_text::get_cursor_position(), gui2::window::get_linked_size(), gui2::dialogs::get_modeless_dialog_id(), gui2::implementation::placer_vertical_list::get_origin(), gui2::implementation::placer_horizontal_list::get_origin(), gui2::widget::get_origin(), gui2::implementation::placer_vertical_list::get_size(), gui2::implementation::placer_horizontal_list::get_size(), gui2::widget::get_size(), gui2::get_window_builder(), gui2::event::sdl_event_handler::handle_event(), gui2::text_box::handle_mouse_selection(), gui2::widget::layout_initialize(), gui2::viewport::place(), gui2::tree_view_node::place(), gui2::grid::child::place(), gui2::tree_view::remove_node(), gui2::tree_view_node::replace_children(), gui2::drawing::request_reduce_height(), gui2::drawing::request_reduce_width(), gui2::styled_widget::request_reduce_width(), preferences::resolution(), gui2::scroll_label::set_label(), gui2::styled_widget::set_label(), gui2::grid::set_origin(), gui2::widget::set_visible(), gui2::event::mouse_motion::show_tooltip(), gui2::pane::signal_handler_request_placement(), gui2::event::mouse_motion::stop_hover_timer(), tiled_highres(), and gui2::listbox::update_content_size().

◆ points()

void draw::points ( const std::vector< SDL_Point > &  points)

Draw a set of points.

Definition at line 187 of file draw.cpp.

References DBG_D, and renderer().

Referenced by circle().

◆ rect() [1/4]

void draw::rect ( const SDL_Rect &  rect)

◆ rect() [2/4]

void draw::rect ( const SDL_Rect &  rect,
uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a 
)

Draw a rectangle using the given colour.

Parameters
rectThe rectangle to draw, in drawing coordinates.
rThe red component of the drawing colour, 0-255.
gThe green component of the drawing colour, 0-255.
bThe blue component of the drawing colour, 0-255.
aThe alpha component of the drawing colour, 0-255.

Definition at line 150 of file draw.cpp.

References b, DBG_D, draw_rect_as_lines(), g, renderer(), and sdl_bad_at_rects().

◆ rect() [3/4]

void draw::rect ( const SDL_Rect &  rect,
uint8_t  r,
uint8_t  g,
uint8_t  b 
)

Definition at line 161 of file draw.cpp.

References rect().

◆ rect() [4/4]

void draw::rect ( const SDL_Rect &  rect,
const color_t color 
)

Definition at line 166 of file draw.cpp.

References rect().

◆ reduce_clip()

draw::clip_setter draw::reduce_clip ( const SDL_Rect &  clip)

◆ set_blend_mode()

void draw::set_blend_mode ( SDL_BlendMode  b)

Set the blend mode used for drawing operations such as fill() and line().

This does not affect texture drawing operations such as blit(). For those, use texture::set_blend_mode() on the texture before blitting.

Definition at line 109 of file draw.cpp.

References renderer().

Referenced by image::render_minimap().

◆ set_color() [1/3]

void draw::set_color ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a 
)

Set the drawing colour.

This is the colour used by fill(), line(), points(), etc..

If the alpha component is not specified, it defaults to fully opaque.

Parameters
rThe red component of the drawing colour, 0-255.
gThe green component of the drawing colour, 0-255.
bThe blue component of the drawing colour, 0-255.
aThe alpha component of the drawing colour, 0-255.

Definition at line 91 of file draw.cpp.

References b, DBG_D, g, and renderer().

Referenced by circle(), disc(), gui2::rectangle_shape::draw(), and gui2::round_rectangle_shape::draw().

◆ set_color() [2/3]

void draw::set_color ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)

Definition at line 97 of file draw.cpp.

References DBG_D, g, and renderer().

◆ set_color() [3/3]

void draw::set_color ( const color_t c)

Definition at line 103 of file draw.cpp.

References c, DBG_D, and renderer().

◆ set_render_target()

draw::render_target_setter draw::set_render_target ( const texture t)

Set the given texture as the active render target.

The current viewport will also be cached and restored along with the render target.

All draw calls will draw to this texture until the returned object goes out of scope. Do not retain the render_target_setter longer than necessary.

The provided texture must have been created with the SDL_TEXTUREACCESS_TARGET access mode.

Parameters
tThe new render target. This must be a texture created with SDL_TEXTUREACCESS_TARGET.
Returns
A render_target_setter object. When this object is destroyed the render target will be restored to whatever it was before this call.

Definition at line 603 of file draw.cpp.

References DBG_D, texture::h(), and texture::w().

Referenced by display::render(), display::render_map_outside_area(), display::screenshot(), display::scroll(), and display::update_render_textures().

◆ set_viewport()

draw::viewport_setter draw::set_viewport ( const SDL_Rect &  viewport)

Set the viewport.

Drawing operations will have their coordinates adjusted to the viewport.

The top-left corner of the viewport will be interpreted as (0,0) in draw space coordinates while the returned object is in scope.

The new viewport is specified in absolute coordinates, relative to the full drawing surface.

The returned object will reset the viewport when it is destroyed, so it should be kept in scope until viewport-relative drawing is complete.

Parameters
viewportThe new viewport region, relative to the current viewport.
Returns
A viewport_setter object. When this object is destroyed the viewport will be restored to whatever it was before this call.

Definition at line 542 of file draw.cpp.

Referenced by gui2::widget::draw_background(), gui2::widget::draw_children(), and gui2::widget::draw_foreground().

◆ tiled()

void draw::tiled ( const texture tex,
const SDL_Rect &  dst,
bool  centered = false,
bool  mirrored = false 
)

Tile a texture to fill a region.

This function tiles the texture in draw-space.

The texture may be aligned either with its center at the center of the region, or with its top-left corner at the top-left corner of the region.

Parameters
texThe texture to use to fill the region.
dstThe region to fill, in draw space.
centeredIf true the tiled texture will be centered. If false, it will align at the top-left.
mirroredIf true the texture will be mirrored in such a way that adjacent tiles always share a common edge. This can look better for images that are not perfect tiles.

Definition at line 360 of file draw.cpp.

References blit(), DBG_D, flipped(), texture::h(), reduce_clip(), t, and texture::w().

Referenced by gui2::image_shape::draw(), display::draw_panel(), and display::render_map_outside_area().

◆ tiled_highres()

void draw::tiled_highres ( const texture tex,
const SDL_Rect &  dst,
bool  centered = false,
bool  mirrored = false 
)

Tile a texture to fill a region.

This function tiles the texture in output space. It is otherwise identical to draw::tiled().

Definition at line 388 of file draw.cpp.

References DBG_D, f, get_flip(), video::get_pixel_scale(), texture::get_raw_size(), h, preferences::pixel_scale(), point(), reduce_clip(), renderer(), utf8::size(), t, and w.

Referenced by gui2::image_shape::draw().