| 1 | // Aseprite |
| 2 | // Copyright (C) 2019-2020 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2017 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_UI_SKIN_SKIN_PART_H_INCLUDED |
| 9 | #define APP_UI_SKIN_SKIN_PART_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "gfx/rect.h" |
| 13 | #include "gfx/size.h" |
| 14 | #include "os/surface_list.h" |
| 15 | |
| 16 | #include <memory> |
| 17 | #include <vector> |
| 18 | |
| 19 | namespace os { |
| 20 | class Surface; |
| 21 | } |
| 22 | |
| 23 | namespace app { |
| 24 | namespace skin { |
| 25 | |
| 26 | class SkinPart { |
| 27 | public: |
| 28 | using Bitmaps = os::SurfaceList; |
| 29 | |
| 30 | SkinPart(); |
| 31 | ~SkinPart(); |
| 32 | |
| 33 | std::size_t countBitmaps() const { return m_bitmaps.size(); } |
| 34 | const gfx::Rect& spriteBounds() const { return m_spriteBounds; } |
| 35 | const gfx::Rect& slicesBounds() const { return m_slicesBounds; } |
| 36 | void clear(); |
| 37 | |
| 38 | // It doesn't destroy the previous bitmap in the given "index". |
| 39 | void setBitmap(std::size_t index, const os::SurfaceRef& bitmap); |
| 40 | void setSpriteBounds(const gfx::Rect& bounds); |
| 41 | void setSlicesBounds(const gfx::Rect& bounds); |
| 42 | |
| 43 | os::Surface* bitmap(std::size_t index) const { |
| 44 | return (index < m_bitmaps.size() ? const_cast<SkinPart*>(this)->m_bitmaps[index].get(): nullptr); |
| 45 | } |
| 46 | |
| 47 | os::SurfaceRef bitmapRef(std::size_t index) { |
| 48 | return (index < m_bitmaps.size() ? |
| 49 | const_cast<SkinPart*>(this)->m_bitmaps[index]: |
| 50 | nullptr); |
| 51 | } |
| 52 | |
| 53 | os::Surface* bitmapNW() const { return bitmap(0); } |
| 54 | os::Surface* bitmapN() const { return bitmap(1); } |
| 55 | os::Surface* bitmapNE() const { return bitmap(2); } |
| 56 | os::Surface* bitmapE() const { return bitmap(3); } |
| 57 | os::Surface* bitmapSE() const { return bitmap(4); } |
| 58 | os::Surface* bitmapS() const { return bitmap(5); } |
| 59 | os::Surface* bitmapSW() const { return bitmap(6); } |
| 60 | os::Surface* bitmapW() const { return bitmap(7); } |
| 61 | |
| 62 | gfx::Size size() const; |
| 63 | |
| 64 | private: |
| 65 | Bitmaps m_bitmaps; |
| 66 | gfx::Rect m_spriteBounds; |
| 67 | gfx::Rect m_slicesBounds; |
| 68 | }; |
| 69 | |
| 70 | typedef std::shared_ptr<SkinPart> SkinPartPtr; |
| 71 | |
| 72 | } // namespace skin |
| 73 | } // namespace app |
| 74 | |
| 75 | #endif |
| 76 | |