The Battle for Wesnoth  1.15.0-dev
Classes | Public Types | 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 Types

typedef std::shared_ptr< shapeshape_ptr
 
typedef std::shared_ptr< const shapeconst_shape_ptr
 

Public Member Functions

 canvas ()
 
 canvas (const canvas &)=delete
 
 canvas (canvas &&c)
 
 ~canvas ()
 
void render ()
 Renders the canvas contents to 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 set_size (unsigned w, unsigned h)
 
unsigned get_width () const
 
unsigned get_height () const
 
void set_variable (const std::string &key, const 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< shape_ptrshapes_
 Vector with the shapes to draw. More...
 
unsigned blur_depth_
 The depth of the blur to use in the pre committing. More...
 
unsigned w_
 Width of the canvas. More...
 
unsigned h_
 Height of the canvas. More...
 
SDL_Renderer * renderer_
 A pointer to the window renderer. 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...
 
bool size_changed_
 Whether canvas dimensions changed. 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 41 of file canvas.hpp.

Member Typedef Documentation

◆ const_shape_ptr

typedef std::shared_ptr<const shape> gui2::canvas::const_shape_ptr

Definition at line 88 of file canvas.hpp.

◆ shape_ptr

typedef std::shared_ptr<shape> gui2::canvas::shape_ptr

Definition at line 87 of file canvas.hpp.

Constructor & Destructor Documentation

◆ canvas() [1/3]

gui2::canvas::canvas ( )

Definition at line 1353 of file canvas.cpp.

◆ canvas() [2/3]

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

◆ canvas() [3/3]

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

Definition at line 1365 of file canvas.cpp.

◆ ~canvas()

gui2::canvas::~canvas ( )

Definition at line 1377 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, see https://www.wesnoth.org/wiki/GUICanvasWML for more information.

Definition at line 121 of file canvas.hpp.

References h, and w.

Referenced by gui2::dialogs::story_viewer::draw_floating_image().

◆ clear_shapes()

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

Definition at line 1455 of file canvas.cpp.

References s, and shapes_.

◆ get_height()

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

Definition at line 135 of file canvas.hpp.

◆ get_width()

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

Definition at line 130 of file canvas.hpp.

References w_.

◆ 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 https://www.wesnoth.org/wiki/GUICanvasWML

Definition at line 1409 of file canvas.cpp.

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

◆ render()

void gui2::canvas::render ( )

Renders the canvas contents to screen.

Note
Both the clip rect and viewport should be set before this function is called. The clip rect ensures the canvas texture is cropped appropriately, and the viewport sets the origin for all the drawing operations, as well as specifying the area of the screen to which this canvas applies.

Definition at line 1381 of file canvas.cpp.

References wfl::map_formula_callable::add(), gui2::canvas::shape::draw(), gui2::get_screen_size_variables(), h_, gui2::log_gui_draw, log_scope2, renderer_, shapes_, size_changed_, variables_, and w_.

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

◆ 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, see https://www.wesnoth.org/wiki/GUICanvasWML for more information.

Definition at line 108 of file canvas.hpp.

Referenced by gui2::dialogs::story_viewer::display_part().

◆ set_size()

void gui2::canvas::set_size ( unsigned  w,
unsigned  h 
)

Definition at line 1467 of file canvas.cpp.

References h, h_, size_changed_, w, and w_.

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

◆ set_variable()

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

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

Referenced by parse_cfg().

◆ functions_

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

Action function definitions for the canvas.

Definition at line 172 of file canvas.hpp.

Referenced by parse_cfg().

◆ h_

unsigned gui2::canvas::h_
private

Height of the canvas.

Definition at line 163 of file canvas.hpp.

Referenced by render(), and set_size().

◆ renderer_

SDL_Renderer* gui2::canvas::renderer_
private

A pointer to the window renderer.

Definition at line 166 of file canvas.hpp.

Referenced by render().

◆ shapes_

std::vector<shape_ptr> gui2::canvas::shapes_
private

Vector with the shapes to draw.

Definition at line 147 of file canvas.hpp.

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

◆ size_changed_

bool gui2::canvas::size_changed_
private

Whether canvas dimensions changed.

Definition at line 175 of file canvas.hpp.

Referenced by render(), and set_size().

◆ variables_

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

The variables of the canvas.

Definition at line 169 of file canvas.hpp.

Referenced by render().

◆ w_

unsigned gui2::canvas::w_
private

Width of the canvas.

Definition at line 160 of file canvas.hpp.

Referenced by render(), and set_size().


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