2013-08-08 21:01:20 -03:00
|
|
|
/* Aseprite
|
2013-01-27 12:13:13 -03:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2007-09-18 23:57:02 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2009-08-17 21:38:00 +00:00
|
|
|
#ifndef RASTER_LAYER_H_INCLUDED
|
|
|
|
#define RASTER_LAYER_H_INCLUDED
|
2014-03-29 19:40:17 -03:00
|
|
|
#pragma once
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2014-08-09 08:08:20 -03:00
|
|
|
#include "base/override.h"
|
2010-12-05 11:44:01 -03:00
|
|
|
#include "raster/blend.h"
|
2012-07-08 21:09:09 -03:00
|
|
|
#include "raster/frame_number.h"
|
2013-11-09 19:59:05 -03:00
|
|
|
#include "raster/object.h"
|
2012-07-08 21:09:09 -03:00
|
|
|
|
|
|
|
#include <string>
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
namespace raster {
|
2008-03-23 02:08:06 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
class Cel;
|
|
|
|
class Image;
|
|
|
|
class Sprite;
|
|
|
|
class Layer;
|
|
|
|
class LayerImage;
|
|
|
|
class LayerFolder;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Layer class
|
2011-03-27 18:15:00 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
enum {
|
|
|
|
LAYER_IS_READABLE = 0x0001,
|
|
|
|
LAYER_IS_WRITABLE = 0x0002,
|
|
|
|
LAYER_IS_LOCKMOVE = 0x0004,
|
|
|
|
LAYER_IS_BACKGROUND = 0x0008,
|
|
|
|
};
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-11-09 19:59:05 -03:00
|
|
|
class Layer : public Object {
|
2013-08-05 21:20:19 -03:00
|
|
|
protected:
|
2013-11-09 19:59:05 -03:00
|
|
|
Layer(ObjectType type, Sprite* sprite);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
public:
|
|
|
|
virtual ~Layer();
|
2010-10-03 15:51:03 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
int getMemSize() const;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-07-30 01:28:15 -03:00
|
|
|
std::string name() const { return m_name; }
|
2013-08-05 21:20:19 -03:00
|
|
|
void setName(const std::string& name) { m_name = name; }
|
2013-01-11 12:43:25 -03:00
|
|
|
|
2014-07-30 01:28:15 -03:00
|
|
|
Sprite* sprite() const { return m_sprite; }
|
|
|
|
LayerFolder* parent() const { return m_parent; }
|
2013-08-05 21:20:19 -03:00
|
|
|
void setParent(LayerFolder* folder) { m_parent = folder; }
|
2013-01-11 12:43:25 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
// Gets the previous sibling of this layer.
|
|
|
|
Layer* getPrevious() const;
|
|
|
|
Layer* getNext() const;
|
2013-01-11 12:43:25 -03:00
|
|
|
|
2013-11-09 19:59:05 -03:00
|
|
|
bool isImage() const { return type() == OBJECT_LAYER_IMAGE; }
|
|
|
|
bool isFolder() const { return type() == OBJECT_LAYER_FOLDER; }
|
2013-08-05 21:20:19 -03:00
|
|
|
bool isBackground() const { return (m_flags & LAYER_IS_BACKGROUND) == LAYER_IS_BACKGROUND; }
|
|
|
|
bool isMoveable() const { return (m_flags & LAYER_IS_LOCKMOVE) == 0; }
|
|
|
|
bool isReadable() const { return (m_flags & LAYER_IS_READABLE) == LAYER_IS_READABLE; }
|
|
|
|
bool isWritable() const { return (m_flags & LAYER_IS_WRITABLE) == LAYER_IS_WRITABLE; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void setBackground(bool b) { if (b) m_flags |= LAYER_IS_BACKGROUND; else m_flags &= ~LAYER_IS_BACKGROUND; }
|
|
|
|
void setMoveable(bool b) { if (b) m_flags &= ~LAYER_IS_LOCKMOVE; else m_flags |= LAYER_IS_LOCKMOVE; }
|
|
|
|
void setReadable(bool b) { if (b) m_flags |= LAYER_IS_READABLE; else m_flags &= ~LAYER_IS_READABLE; }
|
|
|
|
void setWritable(bool b) { if (b) m_flags |= LAYER_IS_WRITABLE; else m_flags &= ~LAYER_IS_WRITABLE; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
uint32_t getFlags() const { return m_flags; }
|
|
|
|
void setFlags(uint32_t flags) { m_flags = flags; }
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2014-05-02 11:28:03 -03:00
|
|
|
virtual void getCels(CelList& cels) const = 0;
|
2011-03-22 21:11:25 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
private:
|
|
|
|
std::string m_name; // layer name
|
|
|
|
Sprite* m_sprite; // owner of the layer
|
|
|
|
LayerFolder* m_parent; // parent layer
|
|
|
|
unsigned short m_flags;
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
// Disable assigment
|
|
|
|
Layer& operator=(const Layer& other);
|
|
|
|
};
|
2008-10-01 01:27:51 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// LayerImage class
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
class LayerImage : public Layer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit LayerImage(Sprite* sprite);
|
|
|
|
virtual ~LayerImage();
|
2010-10-03 15:51:03 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
int getMemSize() const;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
int getBlendMode() const { return BLEND_MODE_NORMAL; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void addCel(Cel *cel);
|
|
|
|
void removeCel(Cel *cel);
|
2014-04-09 21:56:06 -03:00
|
|
|
void moveCel(Cel *cel, FrameNumber frame);
|
2013-08-05 21:20:19 -03:00
|
|
|
const Cel* getCel(FrameNumber frame) const;
|
|
|
|
Cel* getCel(FrameNumber frame);
|
2014-05-02 11:28:03 -03:00
|
|
|
void getCels(CelList& cels) const OVERRIDE;
|
2014-08-12 07:57:40 -03:00
|
|
|
Cel* getLastCel() const;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void configureAsBackground();
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
CelIterator getCelBegin() { return m_cels.begin(); }
|
|
|
|
CelIterator getCelEnd() { return m_cels.end(); }
|
|
|
|
CelConstIterator getCelBegin() const { return m_cels.begin(); }
|
|
|
|
CelConstIterator getCelEnd() const { return m_cels.end(); }
|
|
|
|
int getCelsCount() const { return m_cels.size(); }
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
private:
|
|
|
|
void destroyAllCels();
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
CelList m_cels; // List of all cels inside this layer used by frames.
|
|
|
|
};
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// LayerFolder class
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
class LayerFolder : public Layer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit LayerFolder(Sprite* sprite);
|
|
|
|
virtual ~LayerFolder();
|
2010-10-03 15:51:03 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
int getMemSize() const;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
const LayerList& getLayersList() { return m_layers; }
|
|
|
|
LayerIterator getLayerBegin() { return m_layers.begin(); }
|
|
|
|
LayerIterator getLayerEnd() { return m_layers.end(); }
|
|
|
|
LayerConstIterator getLayerBegin() const { return m_layers.begin(); }
|
|
|
|
LayerConstIterator getLayerEnd() const { return m_layers.end(); }
|
|
|
|
int getLayersCount() const { return m_layers.size(); }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void addLayer(Layer* layer);
|
|
|
|
void removeLayer(Layer* layer);
|
|
|
|
void stackLayer(Layer* layer, Layer* after);
|
2013-03-11 20:29:45 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
Layer* getFirstLayer() { return (m_layers.empty() ? NULL: m_layers.front()); }
|
|
|
|
Layer* getLastLayer() { return (m_layers.empty() ? NULL: m_layers.back()); }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-05-02 11:28:03 -03:00
|
|
|
void getCels(CelList& cels) const OVERRIDE;
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
private:
|
|
|
|
void destroyAllLayers();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
LayerList m_layers;
|
|
|
|
};
|
|
|
|
|
|
|
|
void layer_render(const Layer* layer, Image *image, int x, int y, FrameNumber frame);
|
|
|
|
|
|
|
|
} // namespace raster
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2009-08-17 21:38:00 +00:00
|
|
|
#endif
|