The Battle for Wesnoth  1.17.21+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
 
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)
 

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...
 
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 43 of file canvas.hpp.

Constructor & Destructor Documentation

◆ canvas() [1/3]

gui2::canvas::canvas ( )

Definition at line 482 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 492 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 115 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 593 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 502 of file canvas.cpp.

References draw::blit(), blur_depth_, blur_surface(), blur_texture_, DBG_GUI_D, gui2::canvas::shape::draw(), draw::get_viewport(), gui2::log_gui_draw, video::read_pixels_low_res(), s, 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 130 of file canvas.hpp.

References h_.

◆ get_width()

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

Definition at line 125 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, see GUICanvasWML

Definition at line 533 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().

◆ 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 104 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 586 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_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 154 of file canvas.hpp.

Referenced by draw(), and parse_cfg().

◆ blur_texture_

texture gui2::canvas::blur_texture_
private

Blurred background texture.

Definition at line 157 of file canvas.hpp.

Referenced by draw().

◆ functions_

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

Action function definitions for the canvas.

Definition at line 169 of file canvas.hpp.

Referenced by parse_cfg().

◆ h_

unsigned gui2::canvas::h_
private

The full height of the canvas.

Definition at line 163 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 144 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 166 of file canvas.hpp.

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

◆ w_

unsigned gui2::canvas::w_
private

The full width of the canvas.

Definition at line 160 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: