GUI2/Canvas: add flag for immutable shapes
Immutable shapes aren't removed when the canvas shapes are set.
This commit is contained in:
parent
3b2ff54e2f
commit
1a231c7fdc
2 changed files with 43 additions and 13 deletions
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "gui/core/canvas.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "font/text.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
@ -550,7 +549,8 @@ private:
|
|||
*/
|
||||
|
||||
line_shape::line_shape(const config& cfg)
|
||||
: x1_(cfg["x1"])
|
||||
: shape(cfg)
|
||||
, x1_(cfg["x1"])
|
||||
, y1_(cfg["y1"])
|
||||
, x2_(cfg["x2"])
|
||||
, y2_(cfg["y2"])
|
||||
|
@ -685,7 +685,8 @@ private:
|
|||
*
|
||||
*/
|
||||
rectangle_shape::rectangle_shape(const config& cfg)
|
||||
: x_(cfg["x"])
|
||||
: shape(cfg)
|
||||
, x_(cfg["x"])
|
||||
, y_(cfg["y"])
|
||||
, w_(cfg["w"])
|
||||
, h_(cfg["h"])
|
||||
|
@ -814,7 +815,8 @@ private:
|
|||
* crashing. (That should be fixed, when encountered.)
|
||||
*/
|
||||
circle_shape::circle_shape(const config& cfg)
|
||||
: x_(cfg["x"])
|
||||
: shape(cfg)
|
||||
, x_(cfg["x"])
|
||||
, y_(cfg["y"])
|
||||
, radius_(cfg["radius"])
|
||||
, color_(decode_color(cfg["color"]))
|
||||
|
@ -992,7 +994,8 @@ private:
|
|||
* Also the general variables are available, see [[#general_variables|Line]].
|
||||
*/
|
||||
image_shape::image_shape(const config& cfg)
|
||||
: x_(cfg["x"])
|
||||
: shape(cfg)
|
||||
, x_(cfg["x"])
|
||||
, y_(cfg["y"])
|
||||
, w_(cfg["w"])
|
||||
, h_(cfg["h"])
|
||||
|
@ -1283,7 +1286,8 @@ private:
|
|||
*/
|
||||
|
||||
text_shape::text_shape(const config& cfg)
|
||||
: x_(cfg["x"])
|
||||
: shape(cfg)
|
||||
, x_(cfg["x"])
|
||||
, y_(cfg["y"])
|
||||
, w_(cfg["w"])
|
||||
, h_(cfg["h"])
|
||||
|
@ -1519,6 +1523,16 @@ void canvas::parse_cfg(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void canvas::clear_shapes(const bool force)
|
||||
{
|
||||
const auto iter = std::remove_if(shapes_.begin(), shapes_.end(), [&force](const shape_ptr s)
|
||||
{
|
||||
return !s->immutable() && !force;
|
||||
});
|
||||
|
||||
shapes_.erase(iter, shapes_.end());
|
||||
}
|
||||
|
||||
/***** ***** ***** ***** ***** SHAPE ***** ***** ***** ***** *****/
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
#ifndef GUI_AUXILIARY_CANVAS_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_CANVAS_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "formula/callable.hpp"
|
||||
#include "sdl/surface.hpp"
|
||||
|
||||
class config;
|
||||
class variant;
|
||||
|
||||
namespace gui2
|
||||
|
@ -53,6 +53,10 @@ public:
|
|||
class shape
|
||||
{
|
||||
public:
|
||||
explicit shape(const config& cfg) : immutable_(cfg["immutable"].to_bool(false))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~shape()
|
||||
{
|
||||
}
|
||||
|
@ -66,10 +70,20 @@ public:
|
|||
* definition, this parameter contains the values
|
||||
* for these formulas.
|
||||
*/
|
||||
virtual void draw(surface& canvas,
|
||||
SDL_Renderer* renderer,
|
||||
const game_logic::map_formula_callable& variables)
|
||||
= 0;
|
||||
virtual void draw(surface& canvas, SDL_Renderer* renderer,
|
||||
const game_logic::map_formula_callable& variables) = 0;
|
||||
|
||||
bool immutable() const
|
||||
{
|
||||
return immutable_;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* If this is true, this shape will not be removed from the canvas even if
|
||||
* the canvas's content is reset.
|
||||
*/
|
||||
bool immutable_;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<shape> shape_ptr;
|
||||
|
@ -104,9 +118,9 @@ public:
|
|||
* http://www.wesnoth.org/wiki/GUICanvasWML for
|
||||
* more information.
|
||||
*/
|
||||
void set_cfg(const config& cfg)
|
||||
void set_cfg(const config& cfg, const bool force = false)
|
||||
{
|
||||
shapes_.clear();
|
||||
clear_shapes(force);
|
||||
parse_cfg(cfg);
|
||||
}
|
||||
|
||||
|
@ -202,6 +216,8 @@ private:
|
|||
* http://www.wesnoth.org/wiki/GUICanvasWML
|
||||
*/
|
||||
void parse_cfg(const config& cfg);
|
||||
|
||||
void clear_shapes(const bool force);
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
Loading…
Add table
Reference in a new issue