2013-10-31 16:59:18 +00:00
|
|
|
#ifndef LAYERS_H
|
|
|
|
#define LAYERS_H
|
|
|
|
|
|
|
|
#include "definition_global.h"
|
2013-11-16 18:12:42 +00:00
|
|
|
|
2015-08-12 20:21:10 +00:00
|
|
|
#include "DefinitionNode.h"
|
2013-10-31 16:59:18 +00:00
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace definition {
|
|
|
|
|
2015-08-12 20:21:10 +00:00
|
|
|
typedef DefinitionNode* (*LayerConstructor)(Layers* parent);
|
2013-10-31 16:59:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Layers of definitions, ideally all of the same type.
|
|
|
|
*/
|
2015-08-12 20:21:10 +00:00
|
|
|
class DEFINITIONSHARED_EXPORT Layers:public DefinitionNode
|
2013-10-31 16:59:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-08-12 20:21:10 +00:00
|
|
|
Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor);
|
2013-10-31 16:59:18 +00:00
|
|
|
virtual ~Layers();
|
|
|
|
|
2015-08-13 17:49:16 +00:00
|
|
|
virtual void save(PackStream *stream) const override;
|
|
|
|
virtual void load(PackStream *stream) override;
|
2015-08-12 20:21:10 +00:00
|
|
|
virtual void copy(DefinitionNode* destination) const override;
|
2013-11-16 18:12:42 +00:00
|
|
|
Layers* newCopy() const;
|
2013-10-31 16:59:18 +00:00
|
|
|
|
|
|
|
void setMaxLayerCount(int max_layer_count);
|
|
|
|
|
2013-11-15 22:26:44 +00:00
|
|
|
int count() const;
|
2015-08-12 20:21:10 +00:00
|
|
|
DefinitionNode* getLayer(int position) const;
|
|
|
|
int findLayer(DefinitionNode* layer) const;
|
2013-10-31 16:59:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add a new layer
|
|
|
|
*
|
|
|
|
* This method takes ownership of the layer definition. In any case, it will be deleted by
|
|
|
|
* this object (even if the layer could not be added).
|
|
|
|
* @return The position of the new layer, -1 if it couldn't be added.
|
|
|
|
*/
|
2015-08-12 20:21:10 +00:00
|
|
|
int addLayer(DefinitionNode *layer);
|
2013-10-31 16:59:18 +00:00
|
|
|
int addLayer();
|
|
|
|
void removeLayer(int position);
|
2015-08-12 20:21:10 +00:00
|
|
|
void removeLayer(DefinitionNode* layer);
|
2013-10-31 16:59:18 +00:00
|
|
|
void moveLayer(int old_position, int new_position);
|
2015-08-12 20:21:10 +00:00
|
|
|
void moveLayer(DefinitionNode* layer, int new_position);
|
2013-10-31 16:59:18 +00:00
|
|
|
void clear();
|
|
|
|
|
2015-08-13 21:46:50 +00:00
|
|
|
protected:
|
|
|
|
virtual DefinitionNode *findChildByName(const std::string name) override;
|
|
|
|
|
2013-11-15 22:26:44 +00:00
|
|
|
public:
|
2013-11-16 18:12:42 +00:00
|
|
|
LayerConstructor layer_constructor;
|
2013-10-31 16:59:18 +00:00
|
|
|
int max_layer_count;
|
2015-08-12 20:21:10 +00:00
|
|
|
std::vector<DefinitionNode*> layers;
|
|
|
|
DefinitionNode* null_layer;
|
2015-08-13 17:49:16 +00:00
|
|
|
|
2013-10-31 16:59:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LAYERS_H
|