The Battle for Wesnoth  1.19.4+dev
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::canvas Class Reference

A simple canvas which can be drawn upon. More...

#include <canvas.hpp>

Classes

class  shape
 Abstract base class for all other shapes. More...
 

Public Member Functions

 canvas ()
 
 canvas (const canvas &)=delete
 
canvasoperator= (const canvas &)=delete
 
 canvas (canvas &&c) noexcept
 
bool update_blur (const rect &screen_region, const bool force=false)
 Update the background blur texture, if relevant and necessary. More...
 
void queue_reblur ()
 Clear the cached blur texture, forcing it to regenerate. More...
 
void draw ()
 Draw the canvas' shapes onto the screen. More...
 
void set_cfg (const config &cfg, const bool force=false)
 Sets the config. More...
 
void append_cfg (const config &cfg)
 Appends data to the config. More...
 
void update_size_variables ()
 Update WFL size variables. More...
 
unsigned get_width () const
 
unsigned get_height () const
 
void set_size (const point &size)
 
void set_variable (const std::string &key, wfl::variant &&value)
 
wfl::variant get_variable (const std::string &key)
 

Private Member Functions

void parse_cfg (const config &cfg)
 Parses a config object. More...
 
void clear_shapes (const bool force)
 

Private Attributes

std::vector< std::unique_ptr< shape > > shapes_
 Vector with the shapes to draw. More...
 
unsigned blur_depth_
 The depth of the blur to use in the pre committing. More...
 
texture blur_texture_
 Blurred background texture. More...
 
rect blur_region_
 The region of the screen we have blurred (if any). More...
 
bool deferred_
 Whether we have deferred rendering so we can capture for blur. More...
 
unsigned w_
 The full width of the canvas. More...
 
unsigned h_
 The full height of the canvas. More...
 
wfl::map_formula_callable variables_
 The variables of the canvas. More...
 
wfl::action_function_symbol_table functions_
 Action function definitions for the canvas. More...
 

Detailed Description

A simple canvas which can be drawn upon.

The class has a config which contains what to draw.

The copy constructor does a shallow copy of the shapes to draw. a clone() will be implemented if really needed.

Definition at line 44 of file canvas.hpp.

Constructor & Destructor Documentation

◆ canvas() [1/3]

gui2::canvas::canvas ( )

Definition at line 562 of file canvas.cpp.

◆ canvas() [2/3]

gui2::canvas::canvas ( const canvas )
delete

◆ canvas() [3/3]

gui2::canvas::canvas ( canvas &&  c)
noexcept

Definition at line 574 of file canvas.cpp.

Member Function Documentation

◆ append_cfg()

void gui2::canvas::append_cfg ( const config cfg)
inline

Appends data to the config.

Parameters
cfgThe config object with the data to draw.

Definition at line 132 of file canvas.hpp.

References parse_cfg().

Referenced by gui2::drawing::append_drawing_data(), and gui2::dialogs::story_viewer::draw_floating_image().

◆ clear_shapes()

void gui2::canvas::clear_shapes ( const bool  force)
private

Definition at line 730 of file canvas.cpp.

References s, and shapes_.

Referenced by set_cfg().

◆ draw()

void gui2::canvas::draw ( )

Draw the canvas' shapes onto the screen.

It makes sure the image on the canvas is up to date. Also executes the pre-blitting functions.

Definition at line 648 of file canvas.cpp.

References draw::blit(), blur_depth_, blur_texture_, DBG_GUI_D, deferred_, gui2::canvas::shape::draw(), texture::draw_size(), gui2::log_gui_draw, shapes_, and variables_.

Referenced by gui2::panel::impl_draw_background(), gui2::styled_widget::impl_draw_background(), and gui2::panel::impl_draw_foreground().

◆ get_height()

unsigned gui2::canvas::get_height ( ) const
inline

Definition at line 147 of file canvas.hpp.

References h_.

◆ get_variable()

wfl::variant gui2::canvas::get_variable ( const std::string &  key)
inline

Definition at line 159 of file canvas.hpp.

References wfl::formula_callable::query_value(), and variables_.

◆ get_width()

unsigned gui2::canvas::get_width ( ) const
inline

Definition at line 142 of file canvas.hpp.

References w_.

◆ operator=()

canvas& gui2::canvas::operator= ( const canvas )
delete

◆ parse_cfg()

void gui2::canvas::parse_cfg ( const config cfg)
private

Parses a config object.

The config object is parsed and serialized by this function after which the config object is no longer required and thus not stored in the object.

Parameters
cfgThe config object with the data to draw

Definition at line 676 of file canvas.cpp.

References config::all_children_range(), blur_depth_, data, DBG_GUI_P, ERR_GUI_P, functions_, gui2::log_gui_parse, log_scope2, and shapes_.

Referenced by append_cfg(), and set_cfg().

◆ queue_reblur()

void gui2::canvas::queue_reblur ( )

Clear the cached blur texture, forcing it to regenerate.

Definition at line 643 of file canvas.cpp.

References blur_texture_, and texture::reset().

Referenced by gui2::dialogs::story_viewer::display_part(), and gui2::dialogs::title_screen::show_preferences().

◆ set_cfg()

void gui2::canvas::set_cfg ( const config cfg,
const bool  force = false 
)
inline

Sets the config.

Parameters
cfgThe config object with the data to draw.
forceWhether to clear all shapes or not.

Definition at line 121 of file canvas.hpp.

References clear_shapes(), and parse_cfg().

Referenced by gui2::dialogs::story_viewer::display_part(), and gui2::drawing::set_drawing_data().

◆ set_size()

void gui2::canvas::set_size ( const point size)

Definition at line 723 of file canvas.cpp.

References h_, utf8::size(), update_size_variables(), and w_.

Referenced by gui2::styled_widget::place().

◆ set_variable()

void gui2::canvas::set_variable ( const std::string &  key,
wfl::variant &&  value 
)
inline

◆ update_blur()

bool gui2::canvas::update_blur ( const rect screen_region,
const bool  force = false 
)

Update the background blur texture, if relevant and necessary.

This should be called sometime before draw(). Updating it later is less important as it's quite expensive.

Parameters
screen_regionThe area of the screen underneath the canvas.
forceRegenerate the blur even if we already did it.
Returns
True if draw should continue, false otherwise.

Definition at line 588 of file canvas.cpp.

References blur_depth_, blur_region_, blur_surface(), blur_texture_, DBG_GUI_D, deferred_, video::read_pixels_low_res(), draw_manager::request_extra_render_pass(), texture::reset(), s, draw::set_render_target(), and setter.

◆ update_size_variables()

void gui2::canvas::update_size_variables ( )

Member Data Documentation

◆ blur_depth_

unsigned gui2::canvas::blur_depth_
private

The depth of the blur to use in the pre committing.

Note
at the moment there's one pre commit function, namely the blurring so use a variable here, might get more functions in the future. When that happens need to evaluate whether variables are the best thing to use.

Definition at line 176 of file canvas.hpp.

Referenced by draw(), parse_cfg(), and update_blur().

◆ blur_region_

rect gui2::canvas::blur_region_
private

The region of the screen we have blurred (if any).

Definition at line 182 of file canvas.hpp.

Referenced by update_blur().

◆ blur_texture_

texture gui2::canvas::blur_texture_
private

Blurred background texture.

Definition at line 179 of file canvas.hpp.

Referenced by draw(), queue_reblur(), and update_blur().

◆ deferred_

bool gui2::canvas::deferred_
private

Whether we have deferred rendering so we can capture for blur.

Definition at line 185 of file canvas.hpp.

Referenced by draw(), and update_blur().

◆ functions_

wfl::action_function_symbol_table gui2::canvas::functions_
private

Action function definitions for the canvas.

Definition at line 197 of file canvas.hpp.

Referenced by parse_cfg().

◆ h_

unsigned gui2::canvas::h_
private

The full height of the canvas.

Definition at line 191 of file canvas.hpp.

Referenced by get_height(), set_size(), and update_size_variables().

◆ shapes_

std::vector<std::unique_ptr<shape> > gui2::canvas::shapes_
private

Vector with the shapes to draw.

Definition at line 166 of file canvas.hpp.

Referenced by clear_shapes(), draw(), and parse_cfg().

◆ variables_

wfl::map_formula_callable gui2::canvas::variables_
private

The variables of the canvas.

Definition at line 194 of file canvas.hpp.

Referenced by draw(), get_variable(), set_variable(), and update_size_variables().

◆ w_

unsigned gui2::canvas::w_
private

The full width of the canvas.

Definition at line 188 of file canvas.hpp.

Referenced by get_width(), set_size(), and update_size_variables().


The documentation for this class was generated from the following files: