Inherit shapes from reference_counted_object...
...so they can do their own refcounting so the shallow copies of a canvas will work properly.
This commit is contained in:
parent
6fc50d5327
commit
4a7a6ac483
2 changed files with 12 additions and 30 deletions
|
@ -73,11 +73,6 @@ tcanvas::tcanvas(const config& cfg) :
|
|||
parse_cfg(cfg);
|
||||
}
|
||||
|
||||
tcanvas::~tcanvas()
|
||||
{
|
||||
clear_shapes();
|
||||
}
|
||||
|
||||
void tcanvas::draw(const config& cfg)
|
||||
{
|
||||
parse_cfg(cfg);
|
||||
|
@ -106,7 +101,7 @@ void tcanvas::draw(const bool force)
|
|||
canvas_.assign(SDL_CreateRGBSurface(SDL_SWSURFACE, w_, h_, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000));
|
||||
|
||||
// draw items
|
||||
for(std::vector<tshape*>::iterator itor =
|
||||
for(std::vector<tshape_ptr>::iterator itor =
|
||||
shapes_.begin(); itor != shapes_.end(); ++itor) {
|
||||
log_scope2(widget, "Draw shape");
|
||||
|
||||
|
@ -120,7 +115,7 @@ void tcanvas::draw(const bool force)
|
|||
void tcanvas::parse_cfg(const config& cfg)
|
||||
{
|
||||
log_scope2(widget, "Parsing config");
|
||||
clear_shapes();
|
||||
shapes_.clear();
|
||||
|
||||
for(config::all_children_iterator itor =
|
||||
cfg.ordered_begin(); itor != cfg.ordered_end(); ++itor) {
|
||||
|
@ -145,22 +140,6 @@ void tcanvas::parse_cfg(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void tcanvas::clear_shapes()
|
||||
{
|
||||
// FIXME we copy pointers so we will get double frees, need to think about
|
||||
// whether or not to use intrusive pointers to handle this.
|
||||
// NOTE with the code disabled we don't get a double free but do leak the memory!!!
|
||||
#if 0
|
||||
|
||||
for(std::vector<tshape*>::iterator itor =
|
||||
shapes_.begin(); itor != shapes_.end(); ++itor) {
|
||||
|
||||
delete (*itor);
|
||||
}
|
||||
shapes_.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void tcanvas::tshape::put_pixel(unsigned start, Uint32 colour, unsigned w, unsigned x, unsigned y)
|
||||
{
|
||||
// fixme the 4 is true due to Uint32..
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "sdl_utils.hpp"
|
||||
#include "tstring.hpp"
|
||||
#include "reference_counted_object.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -36,16 +37,17 @@ namespace gui2 {
|
|||
//! a cache which allows the same scripts with the same input to store their
|
||||
//! output surface. But that will be looked into later.
|
||||
|
||||
|
||||
//! The copy constructor does a shallow copy of the shapes to draw.
|
||||
//! a clone() will be implemented if really needed.
|
||||
|
||||
// maybe inherit from surface...
|
||||
class tcanvas
|
||||
{
|
||||
// FIXME write a copy constructor to copy the members
|
||||
// for now every object needs to parse the config and we
|
||||
// need to remember not to copy things.
|
||||
public:
|
||||
|
||||
//! Base class for all other shapes.
|
||||
class tshape
|
||||
class tshape : public reference_counted_object
|
||||
{
|
||||
public:
|
||||
virtual void draw(surface& canvas) = 0;
|
||||
|
@ -61,6 +63,9 @@ public:
|
|||
|
||||
};
|
||||
|
||||
typedef boost::intrusive_ptr<tshape> tshape_ptr;
|
||||
typedef boost::intrusive_ptr<const tshape> const_tshape_ptr;
|
||||
|
||||
//! Definition of a line shape.
|
||||
class tline : public tshape
|
||||
{
|
||||
|
@ -135,7 +140,6 @@ public:
|
|||
|
||||
tcanvas();
|
||||
tcanvas(const config& cfg);
|
||||
~tcanvas();
|
||||
|
||||
void draw(const config& cfg);
|
||||
void draw(const bool force = false);
|
||||
|
@ -154,9 +158,8 @@ private:
|
|||
void set_dirty(const bool dirty = true) { dirty_ = dirty; }
|
||||
|
||||
void parse_cfg(const config& cfg);
|
||||
void clear_shapes();
|
||||
|
||||
std::vector<tshape*> shapes_;
|
||||
std::vector<tshape_ptr> shapes_;
|
||||
|
||||
bool dirty_;
|
||||
unsigned w_;
|
||||
|
|
Loading…
Add table
Reference in a new issue