The Battle for Wesnoth  1.17.0-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 blit (surface &surf, SDL_Rect rect)
 Draw the canvas' shapes onto 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
 
void set_variable (const std::string &key, wfl::variant &&value)
 
void set_is_dirty (const bool is_dirty)
 

Private Member Functions

void draw (const SDL_Rect &area_to_draw, const bool force=false)
 Internal part of the blit() function - prepares the contents of the internal viewport_ surface, reallocating that surface if necessary. More...
 
void parse_cfg (const config &cfg)
 Parses a config object. More...
 
void clear_shapes (const bool force)
 
void invalidate_cache ()
 

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...
 
unsigned w_
 Width of the canvas (the full size, not limited to the view_bounds_). More...
 
unsigned h_
 Height of the canvas (the full size, not limited to the view_bounds_). More...
 
surface viewport_
 The surface we draw all items on. More...
 
SDL_Rect view_bounds_
 The placement and size of viewport_ in the coordinates of this widget; value is not useful when bool(viewport_) is false. 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 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 42 of file canvas.hpp.

Constructor & Destructor Documentation

◆ canvas() [1/3]

gui2::canvas::canvas ( )

Definition at line 762 of file canvas.cpp.

References functions_, is_dirty_, and variables_.

◆ canvas() [2/3]

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

◆ canvas() [3/3]

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

Definition at line 775 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 137 of file canvas.hpp.

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

◆ blit()

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

Draw the canvas' shapes onto 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 832 of file canvas.cpp.

References _(), blur_depth_, blur_surface(), DBG_GUI_D, draw(), CVideo::get_singleton(), get_surface_portion(), h_, surface::is_neutral(), s, sdl_blit(), shapes_, VALIDATE, view_bounds_, viewport_, and w_.

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

◆ clear_shapes()

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

Definition at line 944 of file canvas.cpp.

References s, and shapes_.

◆ draw()

void gui2::canvas::draw ( const SDL_Rect &  area_to_draw,
const bool  force = false 
)
private

Internal part of the blit() function - prepares the contents of the internal viewport_ surface, reallocating that surface if necessary.

Parameters
area_to_drawCurrently-visible part of the widget, any area outside here won't be blitted to the parent.
forceIf the canvas isn't dirty it isn't redrawn unless force is set to true.

Definition at line 788 of file canvas.cpp.

References wfl::map_formula_callable::add(), DBG_GUI_D, gui2::canvas::shape::draw(), surface::get(), gui2::get_screen_size_variables(), h_, invalidate_cache(), is_dirty_, gui2::log_gui_draw, log_scope2, shapes_, variables_, view_bounds_, viewport_, and w_.

Referenced by blit().

◆ get_height()

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

Definition at line 163 of file canvas.hpp.

◆ get_width()

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

Definition at line 151 of file canvas.hpp.

References w_.

◆ invalidate_cache()

void gui2::canvas::invalidate_cache ( )
inlineprivate

Definition at line 232 of file canvas.hpp.

Referenced by draw().

◆ 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 898 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_.

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

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

◆ set_height()

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

Definition at line 156 of file canvas.hpp.

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

◆ set_is_dirty()

void gui2::canvas::set_is_dirty ( const bool  is_dirty)
inline

◆ set_variable()

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

◆ set_width()

void gui2::canvas::set_width ( const unsigned  width)
inline

Definition at line 144 of file canvas.hpp.

References w_.

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

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

Referenced by blit(), and parse_cfg().

◆ functions_

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

Action function definitions for the canvas.

Definition at line 214 of file canvas.hpp.

Referenced by canvas(), and parse_cfg().

◆ h_

unsigned gui2::canvas::h_
private

Height of the canvas (the full size, not limited to the view_bounds_).

Definition at line 198 of file canvas.hpp.

Referenced by blit(), and draw().

◆ is_dirty_

bool gui2::canvas::is_dirty_
private

The dirty state of the canvas.

Definition at line 217 of file canvas.hpp.

Referenced by canvas(), and draw().

◆ shapes_

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

Vector with the shapes to draw.

Definition at line 182 of file canvas.hpp.

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

◆ variables_

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

The variables of the canvas.

Definition at line 211 of file canvas.hpp.

Referenced by canvas(), and draw().

◆ view_bounds_

SDL_Rect gui2::canvas::view_bounds_
private

The placement and size of viewport_ in the coordinates of this widget; value is not useful when bool(viewport_) is false.

For large widgets, a small viewport_ may be used that contains only the currently-visible part of the widget.

Definition at line 208 of file canvas.hpp.

Referenced by blit(), and draw().

◆ viewport_

surface gui2::canvas::viewport_
private

The surface we draw all items on.

Definition at line 201 of file canvas.hpp.

Referenced by blit(), and draw().

◆ w_

unsigned gui2::canvas::w_
private

Width of the canvas (the full size, not limited to the view_bounds_).

Definition at line 195 of file canvas.hpp.

Referenced by blit(), and draw().


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