1 // Aseprite Document Library
2 // Copyright (c) 2001-2016 David Capello
3 //
4 // This file is released under the terms of the MIT license.
5 // Read LICENSE.txt for more information.
6 
7 #ifndef DOC_CEL_H_INCLUDED
8 #define DOC_CEL_H_INCLUDED
9 #pragma once
10 
11 #include "base/disable_copying.h"
12 #include "doc/cel_data.h"
13 #include "doc/frame.h"
14 #include "doc/image_ref.h"
15 #include "doc/object.h"
16 #include "gfx/fwd.h"
17 #include "gfx/point.h"
18 
19 namespace doc {
20 
21   class Document;
22   class LayerImage;
23   class Sprite;
24 
25   class Cel : public Object {
26   public:
27     Cel(frame_t frame, const ImageRef& image);
28     Cel(frame_t frame, const CelDataRef& celData);
29 
30     static Cel* createCopy(const Cel* other);
31     static Cel* createLink(const Cel* other);
32 
frame()33     frame_t frame() const { return m_frame; }
x()34     int x() const { return m_data->position().x; }
y()35     int y() const { return m_data->position().y; }
position()36     gfx::Point position() const { return m_data->position(); }
bounds()37     const gfx::Rect& bounds() const { return m_data->bounds(); }
boundsF()38     const gfx::RectF& boundsF() const { return m_data->boundsF(); }
opacity()39     int opacity() const { return m_data->opacity(); }
40 
layer()41     LayerImage* layer() const { return m_layer; }
image()42     Image* image() const { return m_data->image(); }
imageRef()43     ImageRef imageRef() const { return m_data->imageRef(); }
data()44     CelData* data() const { return const_cast<CelData*>(m_data.get()); }
dataRef()45     CelDataRef dataRef() const { return m_data; }
46     Document* document() const;
47     Sprite* sprite() const;
48     Cel* link() const;
49     std::size_t links() const;
50 
51     // You should change the frame only if the cel isn't member of a
52     // layer. If the cel is already in a layer, you should use
53     // LayerImage::moveCel() member function.
54     void setFrame(frame_t frame);
55     void setDataRef(const CelDataRef& celData);
56     void setPosition(int x, int y);
57     void setPosition(const gfx::Point& pos);
58     void setBounds(const gfx::Rect& bounds);
59     void setBoundsF(const gfx::RectF& bounds);
60     void setOpacity(int opacity);
61 
getMemSize()62     virtual int getMemSize() const override {
63       return sizeof(Cel) + m_data->getMemSize();
64     }
65 
66     void setParentLayer(LayerImage* layer);
67 
68   private:
69     void fixupImage();
70 
71     LayerImage* m_layer;
72     frame_t m_frame;            // Frame position
73     CelDataRef m_data;
74 
75     Cel();
76     DISABLE_COPYING(Cel);
77   };
78 
79 } // namespace doc
80 
81 #endif
82