The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
shape
const_shape_ptr
 

Public Member Functions

 canvas ()
 
 canvas (const canvas &)=delete
 
 canvas (canvas &&c)
 
 ~canvas ()
 
void draw (const bool force=false)
 Draws the canvas. More...
 
void blit (surface &surf, SDL_Rect rect)
 Blits the canvas unto another surface. 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_width (const unsigned width)
 
unsigned get_width () const
 
void set_height (const unsigned height)
 
unsigned get_height () const
 
surfacesurf ()
 
void set_variable (const std::string &key, const wfl::variant &value)
 
void set_is_dirty (const bool is_dirty)
 

Private Member Functions

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

Private Attributes

std::vector< shape_ptrshapes_
 Vector with the shapes to draw. More...
 
std::vector< shape_ptrdrawn_shapes_
 All shapes which have been already drawn. 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...
 
surface canvas_
 The surface we draw all items on. More...
 
SDL_Renderer * renderer_
 
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 is_dirty_
 The dirty state of 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 41 of file canvas.hpp.

Member Typedef Documentation

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

Definition at line 87 of file canvas.hpp.

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

Definition at line 86 of file canvas.hpp.

Constructor & Destructor Documentation

gui2::canvas::canvas ( )

Definition at line 1364 of file canvas.cpp.

gui2::canvas::canvas ( const canvas )
delete
gui2::canvas::canvas ( canvas &&  c)

Definition at line 1377 of file canvas.cpp.

References c.

gui2::canvas::~canvas ( )

Definition at line 1392 of file canvas.cpp.

References renderer_.

Member Function Documentation

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

Appends data to the config.

Parameters
cfgThe config object with the data to draw, see http://www.wesnoth.org/wiki/GUICanvasWML for more information.

Definition at line 135 of file canvas.hpp.

References parse_cfg().

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

void gui2::canvas::blit ( surface surf,
SDL_Rect  rect 
)

Blits the canvas unto another surface.

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

Parameters
surfThe surface to blit upon.
rectThe place to blit to.

Definition at line 1440 of file canvas.cpp.

References blur_depth_, blur_surface(), canvas_, draw(), CVideo::get_singleton(), get_surface_portion(), is_neutral(), s, and sdl_blit().

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

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

Definition at line 1510 of file canvas.cpp.

References drawn_shapes_, s, and shapes_.

Referenced by set_cfg().

void gui2::canvas::draw ( const bool  force = false)

Draws the canvas.

Parameters
forceIf the canvas isn't dirty it isn't redrawn unless force is set to true.

Definition at line 1397 of file canvas.cpp.

References wfl::map_formula_callable::add(), surface::assign(), canvas_, create_neutral_surface(), DBG_GUI_D, gui2::canvas::shape::draw(), drawn_shapes_, gui2::get_screen_size_variables(), h_, is_dirty_, gui2::log_gui_draw, log_scope2, surface::null(), renderer_, shapes_, variables_, and w_.

Referenced by blit().

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

Definition at line 161 of file canvas.hpp.

References h_.

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

Definition at line 149 of file canvas.hpp.

References w_.

void gui2::canvas::invalidate_cache ( )
private

Definition at line 1521 of file canvas.cpp.

References surface::assign(), canvas_, drawn_shapes_, and shapes_.

Referenced by set_cfg(), set_height(), set_variable(), and set_width().

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

Definition at line 1464 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_.

Referenced by append_cfg(), and 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 http://www.wesnoth.org/wiki/GUICanvasWML for more information.

Definition at line 121 of file canvas.hpp.

References clear_shapes(), invalidate_cache(), and parse_cfg().

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

void gui2::canvas::set_height ( const unsigned  height)
inline

Definition at line 154 of file canvas.hpp.

References h_, invalidate_cache(), and set_is_dirty().

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

void gui2::canvas::set_is_dirty ( const bool  is_dirty)
inline
void gui2::canvas::set_variable ( const std::string &  key,
const wfl::variant value 
)
inline
void gui2::canvas::set_width ( const unsigned  width)
inline

Definition at line 142 of file canvas.hpp.

References invalidate_cache(), set_is_dirty(), and w_.

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

surface& gui2::canvas::surf ( )
inline

Definition at line 166 of file canvas.hpp.

References canvas_.

Member Data Documentation

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

Referenced by blit(), and parse_cfg().

surface gui2::canvas::canvas_
private

The surface we draw all items on.

Definition at line 208 of file canvas.hpp.

Referenced by blit(), draw(), invalidate_cache(), and surf().

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

All shapes which have been already drawn.

Kept around in case the cache needs to be invalidated.

Definition at line 189 of file canvas.hpp.

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

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

Action function definitions for the canvas.

Definition at line 216 of file canvas.hpp.

Referenced by parse_cfg().

unsigned gui2::canvas::h_
private

Height of the canvas.

Definition at line 205 of file canvas.hpp.

Referenced by draw(), get_height(), and set_height().

bool gui2::canvas::is_dirty_
private

The dirty state of the canvas.

Definition at line 219 of file canvas.hpp.

Referenced by draw(), and set_is_dirty().

SDL_Renderer* gui2::canvas::renderer_
private

Definition at line 210 of file canvas.hpp.

Referenced by draw(), and ~canvas().

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

Vector with the shapes to draw.

Definition at line 185 of file canvas.hpp.

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

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

The variables of the canvas.

Definition at line 213 of file canvas.hpp.

Referenced by draw(), and set_variable().

unsigned gui2::canvas::w_
private

Width of the canvas.

Definition at line 202 of file canvas.hpp.

Referenced by draw(), get_width(), and set_width().


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