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